2022-01-09 05:27:18 +01:00
|
|
|
package shared
|
|
|
|
|
2022-01-09 06:59:28 +01:00
|
|
|
import (
|
2022-09-20 07:49:48 +02:00
|
|
|
"database/sql/driver"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2022-01-09 06:59:28 +01:00
|
|
|
"time"
|
|
|
|
)
|
2022-01-09 05:27:18 +01:00
|
|
|
|
2022-04-03 07:27:20 +02:00
|
|
|
type EncHistoryEntry struct {
|
|
|
|
EncryptedData []byte `json:"enc_data"`
|
|
|
|
Nonce []byte `json:"nonce"`
|
|
|
|
DeviceId string `json:"device_id"`
|
|
|
|
UserId string `json:"user_id"`
|
|
|
|
Date time.Time `json:"time"`
|
2022-04-04 05:55:37 +02:00
|
|
|
EncryptedId string `json:"id"`
|
|
|
|
ReadCount int `json:"read_count"`
|
2022-04-03 07:27:20 +02:00
|
|
|
}
|
|
|
|
|
2022-10-24 02:35:30 +02:00
|
|
|
/*
|
|
|
|
Manually created the indices:
|
|
|
|
CREATE INDEX CONCURRENTLY device_id_idx ON enc_history_entries USING btree(device_id);
|
|
|
|
CREATE INDEX CONCURRENTLY read_count_idx ON enc_history_entries USING btree(read_count);
|
|
|
|
CREATE INDEX CONCURRENTLY redact_idx ON enc_history_entries USING btree(user_id, device_id, date);
|
|
|
|
*/
|
|
|
|
|
2022-04-03 07:27:20 +02:00
|
|
|
type Device struct {
|
2022-04-04 05:55:37 +02:00
|
|
|
UserId string `json:"user_id"`
|
2022-04-03 07:27:20 +02:00
|
|
|
DeviceId string `json:"device_id"`
|
2022-04-10 01:37:51 +02:00
|
|
|
// The IP address that was used to register the device. Recorded so
|
|
|
|
// that I can count how many people are using hishtory and roughly
|
|
|
|
// from where. If you would like this deleted, please email me at
|
|
|
|
// david@daviddworken.com and I can clear it from your device entries.
|
|
|
|
RegistrationIp string `json:"registration_ip"`
|
|
|
|
RegistrationDate time.Time `json:"registration_date"`
|
2022-04-03 07:27:20 +02:00
|
|
|
}
|
|
|
|
|
2022-04-28 20:46:14 +02:00
|
|
|
type DumpRequest struct {
|
|
|
|
UserId string `json:"user_id"`
|
|
|
|
RequestingDeviceId string `json:"requesting_device_id"`
|
|
|
|
RequestTime time.Time `json:"request_time"`
|
|
|
|
}
|
|
|
|
|
2022-04-17 01:34:09 +02:00
|
|
|
type UpdateInfo struct {
|
2022-04-17 21:02:56 +02:00
|
|
|
LinuxAmd64Url string `json:"linux_amd_64_url"`
|
|
|
|
LinuxAmd64AttestationUrl string `json:"linux_amd_64_attestation_url"`
|
|
|
|
DarwinAmd64Url string `json:"darwin_amd_64_url"`
|
2022-05-27 08:45:08 +02:00
|
|
|
DarwinAmd64UnsignedUrl string `json:"darwin_amd_64_unsigned_url"`
|
2022-04-17 21:02:56 +02:00
|
|
|
DarwinAmd64AttestationUrl string `json:"darwin_amd_64_attestation_url"`
|
|
|
|
DarwinArm64Url string `json:"darwin_arm_64_url"`
|
2022-05-27 08:45:08 +02:00
|
|
|
DarwinArm64UnsignedUrl string `json:"darwin_arm_64_unsigned_url"`
|
2022-04-17 21:02:56 +02:00
|
|
|
DarwinArm64AttestationUrl string `json:"darwin_arm_64_attestation_url"`
|
|
|
|
Version string `json:"version"`
|
2022-04-17 01:34:09 +02:00
|
|
|
}
|
|
|
|
|
2022-09-20 07:49:48 +02:00
|
|
|
type DeletionRequest struct {
|
|
|
|
UserId string `json:"user_id"`
|
|
|
|
DestinationDeviceId string `json:"destination_device_id"`
|
|
|
|
SendTime time.Time `json:"send_time"`
|
|
|
|
Messages MessageIdentifiers `json:"messages"`
|
2022-09-21 06:13:59 +02:00
|
|
|
ReadCount int `json:"read_count"`
|
2022-09-20 07:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type MessageIdentifiers struct {
|
|
|
|
Ids []MessageIdentifier `json:"message_ids"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessageIdentifier struct {
|
|
|
|
DeviceId string `json:"device_id"`
|
|
|
|
Date time.Time `json:"date"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessageIdentifiers) Scan(value interface{}) error {
|
|
|
|
bytes, ok := value.([]byte)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("failed to unmarshal JSONB value: %v", value)
|
|
|
|
}
|
|
|
|
|
|
|
|
result := MessageIdentifiers{}
|
|
|
|
err := json.Unmarshal(bytes, &result)
|
|
|
|
*m = result
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MessageIdentifiers) Value() (driver.Value, error) {
|
|
|
|
return json.Marshal(m)
|
|
|
|
}
|
2022-11-17 06:54:05 +01:00
|
|
|
|
|
|
|
type Feedback struct {
|
|
|
|
UserId string `json:"user_id" gorm:"not null"`
|
|
|
|
Date time.Time `json:"date" gorm:"not null"`
|
|
|
|
Feedback string `json:"feedback"`
|
|
|
|
}
|
2022-11-26 19:31:43 +01:00
|
|
|
|
|
|
|
func Chunks[k any](slice []k, chunkSize int) [][]k {
|
|
|
|
var chunks [][]k
|
|
|
|
for i := 0; i < len(slice); i += chunkSize {
|
|
|
|
end := i + chunkSize
|
|
|
|
if end > len(slice) {
|
|
|
|
end = len(slice)
|
|
|
|
}
|
|
|
|
chunks = append(chunks, slice[i:end])
|
|
|
|
}
|
|
|
|
return chunks
|
|
|
|
}
|