Compare commits
52 commits
Author | SHA1 | Date | |
---|---|---|---|
d983bfb9a3 | |||
097e95bdb1 | |||
fc7a556b5d | |||
10dab5a5c9 | |||
|
3e33f0a3f7 | ||
|
5470eb90d9 | ||
|
1ced8e01b2 | ||
|
5e52e5f3bd | ||
|
4178a582e8 | ||
|
67a7576e24 | ||
|
dd208b6e82 | ||
|
9928e5ffc2 | ||
|
12874dd6dc | ||
|
b5af9d176b | ||
|
7ace3647c7 | ||
|
b343c02f77 | ||
|
890417af5d | ||
|
8458f63316 | ||
|
e50f392288 | ||
|
204657b38b | ||
4e3feffaad | |||
|
e8131dc928 | ||
|
0ff6400ce7 | ||
d8fdb8edb0 | |||
ec276e5411 | |||
7ff5492156 | |||
2b1f0dada7 | |||
0f3e6dce72 | |||
4bc97fb829 | |||
3ccb424f53 | |||
|
689d560eb1 | ||
|
8bb40967e5 | ||
|
fa1f0765d5 | ||
|
21420e0d77 | ||
|
56cc98de30 | ||
|
17f823064f | ||
|
9a371b8f91 | ||
|
acc817a043 | ||
|
946b27917d | ||
219f1df6e5 | |||
e454d63249 | |||
dd56e3d6f7 | |||
149d44b705 | |||
924e9c3767 | |||
28b7d16568 | |||
a535a63ba0 | |||
25050d2f0e | |||
bfcb423cdf | |||
0f8b17383f | |||
9a52532325 | |||
3cb60fd14f | |||
2fa9670efe |
42 changed files with 3363 additions and 3462 deletions
|
@ -1,22 +1,47 @@
|
|||
stages:
|
||||
- build
|
||||
- test
|
||||
- publish
|
||||
|
||||
lint:
|
||||
image: golang:latest
|
||||
stage: build
|
||||
image: golang:1.17
|
||||
stage: test
|
||||
before_script:
|
||||
- apt-get update
|
||||
- apt-get install -y wget golang-go
|
||||
- wget https://github.com/golangci/golangci-lint/releases/download/v1.39.0/golangci-lint-1.39.0-linux-amd64.deb
|
||||
- apt-get install -y ./golangci-lint-1.39.0-linux-amd64.deb
|
||||
- wget https://github.com/golangci/golangci-lint/releases/download/v1.44.2/golangci-lint-1.44.2-linux-amd64.deb
|
||||
- apt-get install -y ./golangci-lint-1.44.2-linux-amd64.deb
|
||||
script:
|
||||
- golangci-lint run
|
||||
- golangci-lint --timeout 59m run
|
||||
- go mod tidy
|
||||
- diff --color=always go.mod "${CI_PROJECT_DIR}/go.mod"
|
||||
- diff --color=always go.sum "${CI_PROJECT_DIR}/go.sum"
|
||||
rules:
|
||||
- when: on_success
|
||||
needs: []
|
||||
|
||||
test sqlite to postgres:
|
||||
image:
|
||||
name: registry.gitlab.com/signald/signald:unstable
|
||||
entrypoint: [""]
|
||||
stage: test
|
||||
needs:
|
||||
- "build:x86"
|
||||
before_script:
|
||||
- apt-get update && apt-get install -y postgresql-client
|
||||
script:
|
||||
- cd /
|
||||
- signald --migrate-data
|
||||
- echo 'CREATE DATABASE signald' | psql -h postgres -U postgres -a
|
||||
- "${CI_PROJECT_DIR}/signaldctl db-move postgresql://postgres@postgres/signald?sslmode=disable"
|
||||
- SIGNALD_DATABASE=postgresql://postgres@postgres/signald?sslmode=disable signald --migrate-data
|
||||
variables:
|
||||
SIGNALD_VERBOSE_LOGGING: "true"
|
||||
services:
|
||||
- name: postgres:latest
|
||||
alias: postgres
|
||||
variables:
|
||||
POSTGRES_HOST_AUTH_METHOD: trust
|
||||
|
||||
.build:
|
||||
stage: build
|
||||
|
@ -37,27 +62,22 @@ lint:
|
|||
.build-deb:
|
||||
stage: build
|
||||
image: debian:buster
|
||||
script:
|
||||
before_script:
|
||||
- echo deb http://deb.debian.org/debian buster-backports main > /etc/apt/sources.list.d/backports.list
|
||||
- apt-get update
|
||||
- apt-get install -y -t buster-backports git-buildpackage dh-golang bash-completion golang-any golang-github-spf13-cobra-dev golang-github-spf13-viper-dev
|
||||
- apt-get install -y -t buster-backports git-buildpackage dh-golang bash-completion golang-any golang-github-spf13-cobra-dev golang-github-spf13-viper-dev golang-github-google-uuid-dev golang-github-mattn-go-sqlite3-dev golang-github-lib-pq-dev golang-github-satori-go.uuid-dev wget unzip
|
||||
- wget -O golang-github-mdp-qrterminal.zip --quiet "https://gitlab.com/api/v4/projects/signald%2Flibraries%2Fgolang-github-mdp-qrterminal/jobs/artifacts/master/download?job=build"
|
||||
- wget -O golang-github-jedib0t-go-pretty.zip --quiet "https://gitlab.com/api/v4/projects/signald%2Flibraries%2Fgolang-github-jedib0t-go-pretty/jobs/artifacts/master/download?job=build"
|
||||
- for z in *.zip; do unzip $z; done
|
||||
- apt-get install -y ./*.deb && rm -vf *.deb
|
||||
script:
|
||||
- 'sed -i "s/^Architecture:.*/Architecture: ${ARCH}/g" debian/control'
|
||||
- go run ./cmd/signaldctl doc -o man
|
||||
- go run ./cmd/signaldctl completion bash > debian/package.bash-completion
|
||||
- ls *.1 > debian/manpages
|
||||
- gbp dch --ignore-branch --debian-tag="%(version)s" --git-author --new-version="$(./version.sh)"
|
||||
- gbp dch --ignore-branch --debian-tag="%(version)s" --git-author --new-version="$(./version.sh | cut -c2-)"
|
||||
- dpkg-buildpackage -us -uc -b
|
||||
- mv ../*.deb .
|
||||
needs:
|
||||
- project: signald/libraries/golang-github-mdp-qrterminal
|
||||
job: build
|
||||
ref: master
|
||||
artifacts: true
|
||||
- project: signald/libraries/golang-github-jedib0t-go-pretty
|
||||
job: build
|
||||
ref: master
|
||||
artifacts: true
|
||||
variables:
|
||||
SIGNALDCTL_PUBLIC_DOC_MODE: "on"
|
||||
artifacts:
|
||||
|
@ -142,9 +162,11 @@ publish deb:
|
|||
- aptly repo create signald
|
||||
- aptly mirror create -ignore-signatures backfill-mirror https://updates.signald.org "${DISTRIBUTION}" main
|
||||
- aptly mirror update -ignore-signatures backfill-mirror
|
||||
- aptly repo import backfill-mirror signald signald signaldctl
|
||||
- aptly repo import backfill-mirror signald signald 'signaldctl (>= 0.3.0)'
|
||||
- aptly repo add signald *.deb
|
||||
- aptly publish repo -config=.aptly.conf -batch -gpg-key="${SIGNING_KEY}" -distribution="${DISTRIBUTION}" "signald" "s3:updates.signald.org:"
|
||||
- gpg1 --import "${SIGNING_KEY_PATH}"
|
||||
- gpg1 --list-secret-keys
|
||||
- aptly publish repo -config=.aptly.conf -batch -gpg-key="${SIGNING_KEY_ID}" -distribution="${DISTRIBUTION}" "signald" "s3:updates.signald.org:"
|
||||
variables:
|
||||
DISTRIBUTION: unstable
|
||||
rules:
|
||||
|
|
|
@ -34,6 +34,7 @@ import (
|
|||
var (
|
||||
testing bool
|
||||
deviceName string
|
||||
overwrite bool
|
||||
|
||||
LinkAccountCmd = &cobra.Command{
|
||||
Use: "link",
|
||||
|
@ -80,6 +81,7 @@ var (
|
|||
finishReq := v1.FinishLinkRequest{
|
||||
DeviceName: deviceName,
|
||||
SessionId: response.SessionId,
|
||||
Overwrite: overwrite,
|
||||
}
|
||||
|
||||
_, err = finishReq.Submit(common.Signald)
|
||||
|
@ -99,4 +101,5 @@ func init() {
|
|||
}
|
||||
LinkAccountCmd.Flags().BoolVarP(&testing, "testing", "t", false, "use the Signal testing server")
|
||||
LinkAccountCmd.Flags().StringVarP(&deviceName, "device-name", "n", name, "the name of this device. shown to other devices on the signal account")
|
||||
LinkAccountCmd.Flags().BoolVar(&overwrite, "overwrite", false, "if an account with the same id already exists in signald's database, delete it before linking")
|
||||
}
|
||||
|
|
36
cmd/signaldctl/cmd/account/requestsync/main.go
Normal file
36
cmd/signaldctl/cmd/account/requestsync/main.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package requestsync
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||
v1 "gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||
)
|
||||
|
||||
var (
|
||||
account string
|
||||
RequestSyncCmd = &cobra.Command{
|
||||
Use: "request-sync",
|
||||
Short: "Ask other devices on the account to send sync data. Must subscribe for result",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
}
|
||||
},
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
go common.Signald.Listen(nil)
|
||||
req := &v1.RequestSyncRequest{Account: account}
|
||||
err := req.Submit(common.Signald)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Println("sync requested. Must be subscribed to receive response")
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
RequestSyncCmd.Flags().StringVarP(&account, "account", "a", "", "the signald account to use")
|
||||
}
|
|
@ -23,6 +23,7 @@ import (
|
|||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/list"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/register"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/remoteconfig"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/requestsync"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/setprofile"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/verify"
|
||||
)
|
||||
|
@ -37,7 +38,8 @@ func init() {
|
|||
AccountCmd.AddCommand(link.LinkAccountCmd)
|
||||
AccountCmd.AddCommand(list.ListAccountCmd)
|
||||
AccountCmd.AddCommand(register.RegisterAccountCmd)
|
||||
AccountCmd.AddCommand(verify.VerifyAccountCmd)
|
||||
AccountCmd.AddCommand(setprofile.SetProfileCmd)
|
||||
AccountCmd.AddCommand(remoteconfig.RemoteConfigCmd)
|
||||
AccountCmd.AddCommand(requestsync.RequestSyncCmd)
|
||||
AccountCmd.AddCommand(setprofile.SetProfileCmd)
|
||||
AccountCmd.AddCommand(verify.VerifyAccountCmd)
|
||||
}
|
||||
|
|
|
@ -27,10 +27,14 @@ import (
|
|||
|
||||
var (
|
||||
account string
|
||||
name string
|
||||
avatar string
|
||||
emoji string
|
||||
about string
|
||||
|
||||
SetProfileCmd = &cobra.Command{
|
||||
Use: "set-profile name",
|
||||
Short: "updates the profile data with a new name",
|
||||
Use: "set-profile [name]",
|
||||
Short: "update an account's profile data",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
|
@ -39,16 +43,19 @@ var (
|
|||
common.Must(cmd.Help())
|
||||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if len(args) != 1 {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("must specify a name")
|
||||
|
||||
if len(args) > 0 {
|
||||
name = args[0]
|
||||
}
|
||||
},
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
go common.Signald.Listen(nil)
|
||||
req := v1.SetProfile{
|
||||
Account: account,
|
||||
Name: args[0],
|
||||
Account: account,
|
||||
Name: name,
|
||||
AvatarFile: avatar,
|
||||
Emoji: emoji,
|
||||
About: about,
|
||||
}
|
||||
err := req.Submit(common.Signald)
|
||||
if err != nil {
|
||||
|
@ -61,4 +68,7 @@ var (
|
|||
|
||||
func init() {
|
||||
SetProfileCmd.Flags().StringVarP(&account, "account", "a", "", "the signald account to use")
|
||||
SetProfileCmd.Flags().StringVarP(&avatar, "avatar", "A", "", "path to avatar file")
|
||||
SetProfileCmd.Flags().StringVar(&emoji, "emoji", "", "an emoji to be shown next to the about section")
|
||||
SetProfileCmd.Flags().StringVar(&about, "about", "", "profile about section")
|
||||
}
|
||||
|
|
747
cmd/signaldctl/cmd/db/migrate.go
Normal file
747
cmd/signaldctl/cmd/db/migrate.go
Normal file
|
@ -0,0 +1,747 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"github.com/spf13/cobra"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
)
|
||||
|
||||
type Migration struct {
|
||||
InstalledRank int
|
||||
Version string
|
||||
Description string
|
||||
Script string
|
||||
Checksum int
|
||||
}
|
||||
|
||||
var (
|
||||
migrations = []Migration{
|
||||
{InstalledRank: 1, Version: "1", Description: "create tables", Script: "V1__create_tables.sql", Checksum: -1247750968},
|
||||
{InstalledRank: 2, Version: "12", Description: "create contacts table", Script: "V12__create_contacts_table.sql", Checksum: -852729911},
|
||||
{InstalledRank: 3, Version: "13", Description: "recipient registration status", Script: "V13__recipient_registration_status.sql", Checksum: 405376321},
|
||||
{InstalledRank: 4, Version: "14", Description: "multiple identity keys per account", Script: "V14__multiple_identity_keys_per_account.sql", Checksum: -1635788950},
|
||||
{InstalledRank: 5, Version: "15", Description: "profiles tables", Script: "V15__profiles_tables.sql", Checksum: 809686180},
|
||||
{InstalledRank: 6, Version: "16", Description: "destination uuid in envelope", Script: "V16__destination_uuid_in_envelope.sql", Checksum: 357656854},
|
||||
{InstalledRank: 7, Version: "17", Description: "update server ca", Script: "V17__update_server_ca.sql", Checksum: 1647934070},
|
||||
}
|
||||
|
||||
sqlitePath string
|
||||
postgresURL string
|
||||
MoveCmd = &cobra.Command{
|
||||
Use: "db-move pg-url [sqlite-path]",
|
||||
Short: "move a signald database from sqlite to postgres",
|
||||
Long: `move a signald sqlite database into a postgres database.
|
||||
If sqlite-path is not specified, the default (~/.config/signald/signald.db) will be used.
|
||||
|
||||
Please note that signald must NOT be running while this command runs.
|
||||
|
||||
After the data is moved, the sqlite file will be deleted`,
|
||||
Annotations: map[string]string{common.AnnotationNoSocketConnection: "true"},
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New("at least one argument required")
|
||||
}
|
||||
postgresURL = args[0]
|
||||
if len(args) > 1 {
|
||||
sqlitePath = args[1]
|
||||
} else {
|
||||
usr, _ := user.Current()
|
||||
sqlitePath = fmt.Sprintf("%s/.config/signald/signald.db", usr.HomeDir)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
source, err := sql.Open("sqlite3", sqlitePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
if err := source.Ping(); err != nil {
|
||||
log.Println("error connecting to source database")
|
||||
return err
|
||||
}
|
||||
|
||||
if err := verifyMigration(source); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dest, err := sql.Open("postgres", postgresURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer dest.Close()
|
||||
|
||||
if err := dest.Ping(); err != nil {
|
||||
log.Println("error connecting to destination database")
|
||||
return err
|
||||
}
|
||||
|
||||
if err := createSchema(dest); err != nil {
|
||||
log.Println("error creating schema in postgres")
|
||||
return err
|
||||
}
|
||||
log.Println("created schema")
|
||||
|
||||
migrate := func(fn func(*sql.DB, *sql.DB) error, targetName string) {
|
||||
if err = fn(source, dest); err != nil {
|
||||
log.Println("error moving", targetName)
|
||||
panic(err)
|
||||
}
|
||||
log.Println("moved", targetName)
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil && r != err {
|
||||
// If r is something other than the error returned via the named return, re-panic it
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
|
||||
migrate(moveAccounts, "accounts table")
|
||||
migrate(moveRecipients, "recipients table")
|
||||
migrate(movePrekeys, "prekeys table")
|
||||
migrate(moveSessions, "sessions table")
|
||||
migrate(moveSignedPrekeys, "signed prekeys table")
|
||||
migrate(moveIdentityKeys, "identity keys table")
|
||||
migrate(moveAccountData, "account data")
|
||||
migrate(movePendingAccountData, "pending account data table")
|
||||
migrate(moveSenderKeys, "sender keys table")
|
||||
migrate(moveSenderKeyShared, "sender key shared table")
|
||||
migrate(moveGroups, "groups table")
|
||||
migrate(moveGroupCredentials, "group credentials table")
|
||||
migrate(moveContacts, "contacts table")
|
||||
migrate(moveProfileKeys, "profile keys table")
|
||||
migrate(moveProfiles, "profiles tables")
|
||||
migrate(moveProfileCapabilities, "profile capabilities tables")
|
||||
migrate(moveProfileBadges, "profile badges tables")
|
||||
|
||||
if err := os.Remove(sqlitePath); err != nil {
|
||||
log.Println("error deleting sqlite file")
|
||||
return err
|
||||
}
|
||||
log.Println("sqlite file deleted, your data is now in postgres :)")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func verifyMigration(source *sql.DB) error {
|
||||
// Lower bound of the database state.
|
||||
rows, err := source.Query("SELECT version FROM flyway_schema_history ORDER BY installed_rank DESC LIMIT 1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
if !rows.Next() {
|
||||
return errors.New("source database is not up to date! Please update signald and start it to move all data into sqlite before moving data to postgres")
|
||||
}
|
||||
|
||||
var version string
|
||||
err = rows.Scan(&version)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
expectedMigrationVersion := migrations[len(migrations)-1].Version
|
||||
if version != expectedMigrationVersion {
|
||||
return fmt.Errorf("source database must be on migration %s (found %s instead). Please update signald, or file an issue if the migrations are out of date", expectedMigrationVersion, version)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func createSchema(dest *sql.DB) error {
|
||||
_, err := dest.Exec(pgScheme)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, migration := range migrations {
|
||||
_, err = dest.Exec(`
|
||||
INSERT INTO flyway_schema_history
|
||||
(installed_rank, version, description, type, script, checksum, installed_by, execution_time, success)
|
||||
VALUES ($1, $2, $3, 'SQL', $4, $5, current_user, 0, true)
|
||||
`,
|
||||
migration.InstalledRank, migration.Version, migration.Description, migration.Script, migration.Checksum,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveAccounts(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT uuid, e164, server FROM accounts")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
e164 string
|
||||
server uuid.UUID
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &e164, &server)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_accounts (uuid, e164, server) VALUES ($1, $2, $3)", accountUUID, e164, server)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveRecipients(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT rowid, account_uuid, uuid, e164, registered FROM recipients" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
rowID int64
|
||||
accountUUID uuid.UUID
|
||||
recipientUUID uuid.NullUUID
|
||||
e164 sql.NullString
|
||||
registered bool
|
||||
)
|
||||
err = rows.Scan(&rowID, &accountUUID, &recipientUUID, &e164, ®istered)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if e164.Valid && !strings.HasPrefix(e164.String, "+") {
|
||||
log.Println("corrupt e164 found, setting to null")
|
||||
e164.Valid = false
|
||||
e164.String = ""
|
||||
}
|
||||
|
||||
_, err = dest.Exec("INSERT INTO signald_recipients (rowid, account_uuid, uuid, e164, registered) VALUES ($1, $2, $3, $4, $5)", rowID, accountUUID, recipientUUID, e164, registered)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// start new rowids one above the current max value
|
||||
_, err = dest.Exec("SELECT setval(pg_get_serial_sequence('signald_recipients', 'rowid'), (SELECT MAX(rowid) FROM signald_recipients)+1)")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func movePrekeys(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, id, record FROM prekeys" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
id int64
|
||||
record []byte
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &id, &record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_prekeys (account_uuid, id, record) VALUES ($1, $2, $3)", accountUUID, id, record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveSessions(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, recipient, device_id, record FROM sessions" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)" +
|
||||
" AND recipient IN (SELECT DISTINCT rowid FROM recipients)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
recipient int64
|
||||
deviceID int64
|
||||
record []byte
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &recipient, &deviceID, &record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_sessions (account_uuid, recipient, device_id, record) VALUES ($1, $2, $3, $4)", accountUUID, recipient, deviceID, record)
|
||||
|
||||
if err != nil {
|
||||
if pqErr, ok := err.(*pq.Error); ok {
|
||||
if pqErr.Constraint == "signald_sessions_recipient_fkey" {
|
||||
log.Println("failed to import session from non-existent recipient, ignoring")
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveSignedPrekeys(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, id, record FROM signed_prekeys" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
id int64
|
||||
record []byte
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &id, &record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_signed_prekeys (account_uuid, id, record) VALUES ($1, $2, $3)", accountUUID, id, record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveIdentityKeys(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, recipient, identity_key, trust_level, added FROM identity_keys" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
recipient int64
|
||||
identityKey []byte
|
||||
trustLevel string
|
||||
added time.Time
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &recipient, &identityKey, &trustLevel, &added)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_identity_keys (account_uuid, recipient, identity_key, trust_level, added) VALUES ($1, $2, $3, $4, $5)", accountUUID, recipient, identityKey, trustLevel, added)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveAccountData(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, key, value FROM account_data" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
key string
|
||||
value []byte
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &key, &value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_account_data (account_uuid, key, value) VALUES ($1, $2, $3)", accountUUID, key, value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func movePendingAccountData(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT username, key, value FROM pending_account_data")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
username string
|
||||
key string
|
||||
value []byte
|
||||
)
|
||||
err = rows.Scan(&username, &key, &value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_pending_account_data (username, key, value) VALUES ($1, $2, $3)", username, key, value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveSenderKeys(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, address, device, distribution_id, record, created_at FROM sender_keys" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
address string
|
||||
device int64
|
||||
distributionID uuid.UUID
|
||||
record []byte
|
||||
createdAt int64
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &address, &device, &distributionID, &record, &createdAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_sender_keys (account_uuid, address, device, distribution_id, record, created_at) VALUES ($1, $2, $3, $4, $5, $6)", accountUUID, address, device, distributionID, record, time.Unix(createdAt, 0))
|
||||
if err != nil {
|
||||
if pqErr, ok := err.(*pq.Error); ok {
|
||||
if pqErr.Constraint == "signald_sender_keys_account_uuid_fkey" {
|
||||
log.Println("failed to import sender keys from non-existent account, ignoring")
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveSenderKeyShared(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, distribution_id, address, device FROM sender_key_shared" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
distributionID uuid.UUID
|
||||
address string
|
||||
device int64
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &distributionID, &address, &device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_sender_key_shared (account_uuid, distribution_id, address, device) VALUES ($1, $2, $3, $4)", accountUUID, distributionID, address, device)
|
||||
if err != nil {
|
||||
if pqErr, ok := err.(*pq.Error); ok {
|
||||
if pqErr.Constraint == "signald_sender_key_shared_account_uuid_fkey" {
|
||||
log.Println("failed to import sender keys shared from non-existent account, ignoring")
|
||||
} else if pqErr.Constraint == "signald_sender_key_shared_pkey" {
|
||||
log.Println("failed to import duplicate sender key shared entry, ignoring")
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveGroups(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT rowid, account_uuid, group_id, master_key, revision, last_avatar_fetch, distribution_id, group_info FROM groups" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
rowID int64
|
||||
accountUUID uuid.UUID
|
||||
groupID []byte
|
||||
masterKey []byte
|
||||
revision int64
|
||||
lastAvatarFetch int64
|
||||
distributionID *uuid.UUID
|
||||
groupInfo []byte
|
||||
)
|
||||
err = rows.Scan(&rowID, &accountUUID, &groupID, &masterKey, &revision, &lastAvatarFetch, &distributionID, &groupInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_groups (rowid, account_uuid, group_id, master_key, revision, last_avatar_fetch, distribution_id, group_info) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", rowID, accountUUID, groupID, masterKey, revision, lastAvatarFetch, distributionID, groupInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// start new rowids one above the current max value
|
||||
_, err = dest.Exec("SELECT setval(pg_get_serial_sequence('signald_groups', 'rowid'), (SELECT MAX(rowid) FROM signald_groups)+1)")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveGroupCredentials(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, date, max(credential) FROM group_credentials" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)" +
|
||||
" GROUP BY account_uuid, date",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
date int64
|
||||
credential []byte
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &date, &credential)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec("INSERT INTO signald_group_credentials (account_uuid, date, credential) VALUES ($1, $2, $3)", accountUUID, date, credential)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveContacts(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, recipient, name, color, profile_key, message_expiration_time, inbox_position FROM contacts" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)" +
|
||||
" AND recipient IN (SELECT DISTINCT rowid FROM recipients)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
recipient int64
|
||||
name sql.NullString
|
||||
color sql.NullString
|
||||
profile_key []byte
|
||||
message_expiration_time sql.NullInt64
|
||||
inbox_position sql.NullInt64
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &recipient, &name, &color, &profile_key, &message_expiration_time, &inbox_position)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec(`
|
||||
INSERT INTO signald_contacts
|
||||
(account_uuid, recipient, name, color, profile_key, message_expiration_time, inbox_position)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
`, accountUUID, recipient, name, color, profile_key, message_expiration_time, inbox_position)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveProfileKeys(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, recipient, profile_key, profile_key_credential, request_pending, unidentified_access_mode FROM profile_keys" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)" +
|
||||
" AND recipient IN (SELECT DISTINCT rowid FROM recipients)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
recipient int64
|
||||
profile_key []byte
|
||||
profile_key_credential []byte
|
||||
request_pending bool
|
||||
unidentified_access_mode int
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &recipient, &profile_key, &profile_key_credential, &request_pending, &unidentified_access_mode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec(`
|
||||
INSERT INTO signald_profile_keys
|
||||
(account_uuid, recipient, profile_key, profile_key_credential, request_pending, unidentified_access_mode)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`, accountUUID, recipient, profile_key, profile_key_credential, request_pending, unidentified_access_mode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveProfiles(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, recipient, last_update, given_name, family_name, about, emoji, payment_address, badges FROM profiles" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)" +
|
||||
" AND recipient IN (SELECT DISTINCT rowid FROM recipients)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
recipient int64
|
||||
last_update int64
|
||||
given_name string
|
||||
family_name string
|
||||
about string
|
||||
emoji string
|
||||
payment_address []byte
|
||||
badges sql.NullString
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &recipient, &last_update, &given_name, &family_name, &about, &emoji, &payment_address, &badges)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec(`
|
||||
INSERT INTO signald_profiles
|
||||
(account_uuid, recipient, last_update, given_name, family_name, about, emoji, payment_address, badges)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||
`, accountUUID, recipient, last_update, given_name, family_name, about, emoji, payment_address, badges)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveProfileCapabilities(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, recipient, storage, gv1_migration, sender_key, announcement_group, change_number, stories FROM profile_capabilities" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)" +
|
||||
" AND recipient IN (SELECT DISTINCT rowid FROM recipients)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
recipient int64
|
||||
storage bool
|
||||
gv1_migration bool
|
||||
sender_key bool
|
||||
announcement_group bool
|
||||
change_number bool
|
||||
stories bool
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &recipient, &storage, &gv1_migration, &sender_key, &announcement_group, &change_number, &stories)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec(`
|
||||
INSERT INTO signald_profile_capabilities
|
||||
(account_uuid, recipient, storage, gv1_migration, sender_key, announcement_group, change_number, stories)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
`, accountUUID, recipient, storage, gv1_migration, sender_key, announcement_group, change_number, stories)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveProfileBadges(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT account_uuid, id, category, name, description, sprite6 FROM profile_badges" +
|
||||
" WHERE account_uuid IN (SELECT DISTINCT uuid FROM accounts)",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
accountUUID uuid.UUID
|
||||
id string
|
||||
category string
|
||||
name string
|
||||
description string
|
||||
sprite6 string
|
||||
)
|
||||
err = rows.Scan(&accountUUID, &id, &category, &name, &description, &sprite6)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = dest.Exec(`
|
||||
INSERT INTO signald_profile_badges
|
||||
(account_uuid, id, category, name, description, sprite6)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`, accountUUID, id, category, name, description, sprite6)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
284
cmd/signaldctl/cmd/db/postgres.go
Normal file
284
cmd/signaldctl/cmd/db/postgres.go
Normal file
|
@ -0,0 +1,284 @@
|
|||
package db
|
||||
|
||||
var (
|
||||
pgScheme = `
|
||||
CREATE TABLE public.flyway_schema_history (
|
||||
installed_rank integer NOT NULL,
|
||||
version character varying(50),
|
||||
description character varying(200) NOT NULL,
|
||||
type character varying(20) NOT NULL,
|
||||
script character varying(1000) NOT NULL,
|
||||
checksum integer,
|
||||
installed_by character varying(100) NOT NULL,
|
||||
installed_on timestamp without time zone DEFAULT now() NOT NULL,
|
||||
execution_time integer NOT NULL,
|
||||
success boolean NOT NULL
|
||||
);
|
||||
|
||||
-- from signald in src/main/resources/db/migration/postgresql/V1__create_tables.sql
|
||||
CREATE TABLE signald_message_queue (
|
||||
id SERIAL PRIMARY KEY,
|
||||
account UUID NOT NULL,
|
||||
version INTEGER NOT NULL,
|
||||
type INTEGER NOT NULL,
|
||||
source_e164 TEXT,
|
||||
source_uuid UUID,
|
||||
source_device INTEGER,
|
||||
"timestamp" BIGINT,
|
||||
content BYTEA,
|
||||
legacy_message BYTEA,
|
||||
server_received_timestamp BIGINT,
|
||||
server_delivered_timestamp BIGINT,
|
||||
server_uuid UUID,
|
||||
destination_uuid TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE signald_servers (
|
||||
server_uuid UUID PRIMARY KEY,
|
||||
service_url TEXT NOT NULL,
|
||||
cdn_urls TEXT NOT NULL,
|
||||
contact_discovery_url TEXT NOT NULL,
|
||||
key_backup_url TEXT NOT NULL,
|
||||
storage_url TEXT NOT NULL,
|
||||
zk_group_public_params BYTEA NOT NULL,
|
||||
unidentified_sender_root BYTEA NOT NULL,
|
||||
proxy TEXT,
|
||||
ca BYTEA NOT NULL,
|
||||
key_backup_service_name VARCHAR(64),
|
||||
key_backup_service_id VARCHAR(64),
|
||||
key_backup_mrenclave VARCHAR(64),
|
||||
cds_mrenclave VARCHAR(64),
|
||||
ias_ca BYTEA
|
||||
);
|
||||
|
||||
INSERT INTO signald_servers VALUES
|
||||
(
|
||||
'6e2eb5a8-5706-45d0-8377-127a816411a4', -- server_uuid
|
||||
'https://chat.signal.org', -- service_url
|
||||
'{"0":"https://cdn.signal.org","2":"https://cdn2.signal.org"}', -- cdn_urls
|
||||
'https://api.directory.signal.org', -- contact_discovery_url
|
||||
'https://api.backup.signal.org', -- key_backup_url
|
||||
'https://storage.signal.org', -- storage_url
|
||||
-- zk_group_public_params
|
||||
E'\\x00c85fe72c15c084d932c7dffde0b2b9d671f490e692491b57a3c89f31b8a7cc7756a54948588cbe7be510a5ae4686ffd5e6887ad477d4861e01b9b435d3ae1c7f108be45ec62d702e5a73228d60b2d1d605f673cb5faa1d15790384ea3e9d7963304f9b45928205ba3db4a7f85e257f9ed50a71c5ee9f12bf3000d996493d825446df17edb6e0f87de2f8f1231fd0d722d344aacdac35cba0dfbc594032e6ed7dfa9cea063ece785ec106ccf74457e8ad40d1941448d8e97f54bfe01cba4b3b369c86bc2a0ac46c202a01395f227e9cd2a5c871ce2dbe8dd4db87c81ad9ae0b58fc96091d1a28a39084a98281a9d16799b4d5184902bc92b12e78f02967fe7c43e859e4058f939b0e370a3197f6266d807baf71fa2914e60057b119a817de065d',
|
||||
-- unidentified_sender_root
|
||||
E'\\x057bba408295cf9300f20b2dcdf3a04501aac8ba8ec0d2872fa20d92fdc81d6305',
|
||||
-- proxy
|
||||
NULL,
|
||||
-- ca
|
||||
E'\\x0000000100000014e119602f608a01dba6f603f0212fa3a85bbe307c000007b7010011746578747365637572652d67636d2d63610000013da3b16fa9000000000005582e353039000003f3308203ef308202d7a00302010202090089ba2dab4ae4f362300d06092a864886f70d010105050030818d310b30090603550406130255533113301106035504080c0a43616c69666f726e69613116301406035504070c0d53616e204672616e636973636f311d301b060355040a0c144f70656e20576869737065722053797374656d73311d301b060355040b0c144f70656e20576869737065722053797374656d733113301106035504030c0a54657874536563757265301e170d3133303332353232313833355a170d3233303332333232313833355a30818d310b30090603550406130255533113301106035504080c0a43616c69666f726e69613116301406035504070c0d53616e204672616e636973636f311d301b060355040a0c144f70656e20576869737065722053797374656d73311d301b060355040b0c144f70656e20576869737065722053797374656d733113301106035504030c0a5465787453656375726530820122300d06092a864886f70d01010105000382010f003082010a0282010100c14960693820431748b8ab67788c05e4497506a5b796ba054f4028da2faa83f500cec5e5b569fbdf3e8f3ade2e82aead4a0f11e9077e84c3355c8f02e415320c7a8eedf6cd45428940b77984ad5d94d2f89ee957acfb28fa82b49fc7020301c76c2a62346b549009996bdd0d6d70702400a151c5835ac000f2a6ce41f999aa7207fae774d74b9ff420f3d02e870b9fc1962f039836761f06f20b283308b66653b446ee71d8a0c4403d99f22fbc700311bb5e2ed560c019bd479bd5bedc2b0fa082c48de9807ec41fb90c3f439df77c0b8acbe7d7284763b16e625ae462a76432f594acaa00495c388dbebdbda789094754f870a85ce48fd4f41c2fa59e9cd0870203010001a350304e301d0603551d0e04160414018b18f13ffb3919446e8586be946532a7323c90301f0603551d23041830168014018b18f13ffb3919446e8586be946532a7323c90300c0603551d13040530030101ff300d06092a864886f70d010105050003820101007e1ebe210b9ea6d0bbc902ed512ba36e3c36d330437bfe33288c51f11f83f75cf15fba98d1f9b903ab4a4f394e898c8c67ac3d570ff1159934da4d563988e85ecafed4cc939e7dbda92ce73daacbaf2387e76844a1f5b873967f8b5f1b42ad13c6864c40d48308a3727fb36585fca558672722bba6f8b9b27dd573c0b81359c089ae83bfecad6bdba64d21aba03acf5e345935522ad246ec43f8d6425efe8178bac63927b2cf9312b72d6ccc2676f9108243991bf21fca724705a0e909baaa2185688e272fc414e0b6b5c767a7e0319745a2cc3d1c2310b36040fa1d477f33a0232e03c80765f65862867b0fb435c0d522547731b85ac478169825b2c4af02d500bbf2ff8236b854e90220d0ed6cfbc9a370eed025',
|
||||
-- key_backup_service_name
|
||||
'fe7c1bfae98f9b073d220366ea31163ee82f6d04bead774f71ca8e5c40847bfe',
|
||||
-- key_backup_service_id
|
||||
'fe7c1bfae98f9b073d220366ea31163ee82f6d04bead774f71ca8e5c40847bfe',
|
||||
-- key_backup_mrenclave
|
||||
'a3baab19ef6ce6f34ab9ebb25ba722725ae44a8872dc0ff08ad6d83a9489de87',
|
||||
-- cds_mrenclave
|
||||
'c98e00a4e3ff977a56afefe7362a27e4961e4f19e211febfbb19b897e6b80b15',
|
||||
-- ias_ca
|
||||
E'\\x00000002000000141e139877c131235200356d48d741b9e8538d4a290000078101000369617300000164adeb7976000000000005582e3530390000054f3082054b308203b3a003020102020900d107765d32a3b094300d06092a864886f70d01010b0500307e310b3009060355040613025553310b300906035504080c0243413114301206035504070c0b53616e746120436c617261311a3018060355040a0c11496e74656c20436f72706f726174696f6e3130302e06035504030c27496e74656c20534758204174746573746174696f6e205265706f7274205369676e696e672043413020170d3136313131343135333733315a180f32303439313233313233353935395a307e310b3009060355040613025553310b300906035504080c0243413114301206035504070c0b53616e746120436c617261311a3018060355040a0c11496e74656c20436f72706f726174696f6e3130302e06035504030c27496e74656c20534758204174746573746174696f6e205265706f7274205369676e696e67204341308201a2300d06092a864886f70d01010105000382018f003082018a02820181009f3c647eb5773cbb512d2732c0d7415ebb55a0fa9ede2e649199e6821db910d53177370977466a6a5e4786ccd2ddebd4149d6a2f6325529dd10cc98737b0779c1a07e29c47a1ae004948476c489f45a5a15d7ac8ecc6acc645adb43d87679df59c093bc5a2e9696c5478541b979e754b573914be55d32ff4c09ddf27219934cd990527b3f92ed78fbf29246abecb71240ef39c2d7107b447545a7ffb10eb060a68a98580219e36910952683892d6a5e2a80803193e407531404e36b315623799aa825074409754a2dfe8f5afd5fe631e1fc2af3808906f28a790d9dd9fe060939b125790c5805d037df56a99531b96de69de33ed226cc1207d1042b5c9ab7f404fc711c0fe4769fb9578b1dc0ec469ea1a25e0ff9914886ef2699b235bb4847dd6ff40b606e6170793c2fb98b314587f9cfd257362dfeab10b3bd2d97673a1a4bd44c453aaf47fc1f2d3d0f384f74a06f89c089f0da6cdb7fceee8c9821a8e54f25c0416d18c46839a5f8012fbdd3dc74d256279adc2c0d55aff6f0622425d1b0203010001a381c93081c630600603551d1f045930573055a053a051864f687474703a2f2f7472757374656473657276696365732e696e74656c2e636f6d2f636f6e74656e742f43524c2f5347582f4174746573746174696f6e5265706f72745369676e696e6743412e63726c301d0603551d0e0416041478437b76a67ebcd0af7e4237eb357c3b8701513c301f0603551d2304183016801478437b76a67ebcd0af7e4237eb357c3b8701513c300e0603551d0f0101ff04040302010630120603551d130101ff040830060101ff020100300d06092a864886f70d01010b05000382018100785f2d60c5c80af42a797610213915da82c9b29e89e0902a25a6c75b16091c68ab204aae711889492c7e1e320911455a8fc13442312e77a63994d99795c8ea4576823cea8ad1e191cfa862fab8a932d3d9b0535a0702d0555f74e520e30330f33480e7adc9d7c81e20703142bf00c528a80b463381fd602a82c7035281aae59562ccb5334ea8903e650b010681f5ce8eb62eac9c414988243aec92f25bf13cdff7ebcc298ee51bba5a3538b66b26cbc45a51de003cad306531ad7cf5d4ef0f8805d1b9133d24135ab3c4641a2f8808349d7333295e0e76ee4bc5227232628efa80d79d92ab4e3d1120f3fb5ad119cd8d544aa1d4a6865e6b57beac5771307e2e3cb9070da47b4bfc8869e01413ea093541de8a792811b74636c5e91452cf0cee59f2fb404acd0bc584cb9c835404734c0e7ec6605cdfcf2ff439b6d4719f702f0e0c3fa04fdb12a6cb2ad1ab1c9af1f8f4c3a08edd72a32b0bb5d0ad256ffd159a683b2a5a1f1d11fa62532f03d754caef0da5735a1e5a884c7e89d91218c9d7008515e5f5992ccc471f3b1bc1aaec24a2997e6ad3'
|
||||
),
|
||||
(
|
||||
'97c17f0c-e53b-426f-8ffa-c052d4183f83', -- server_uuid
|
||||
'https://chat.staging.signal.org', -- service_url
|
||||
'{"0":"https://cdn-staging.signal.org","2":"https://cdn2-staging.signal.org"}', -- cdn_urls
|
||||
'https://api-staging.directory.signal.org', -- contact_discovery_url
|
||||
'https://api-staging.backup.signal.org', -- key_backup_url
|
||||
'https://storage-staging.signal.org', -- storage_url
|
||||
-- zk_group_public_params
|
||||
E'\\x001498db555c91071b49754d08645825c7d61e200c666a53b5310b7039b181d15bb69fdb5ac4b165d30acdf0a9f2bbc8b3ca1c094dc1dfb7d3debe0c8b9a807a6786791d97fbf626386479a1fba2eed0f998341fb2d008f62fb85a932d21ef0a0b7c14e70dc89eadee356566a06b692a776c35fc09ac28341ddf7398e6e1ca95274a47d89f6a2830e3a70697dd6a746daef7ad6546b20cc482e624917172a9765ba4ae9cf3b0222f1308f042525854f3903e3e15d05e145d705d1d22cad39ba83c10901bc1bdad820679d62c0a52579dbae01981b778c4c6e619f1e17e27b404418042ee3165941047d22b49a35e0fbfda53e659c4d9591f6792a81040fd2d6f3ba23e6ef81f6c0c3b8bb559a7def94c32225213f4beca2d2d7d030f2be2c3eb5d',
|
||||
-- unidentified_sender_root
|
||||
E'\\x05ba98d43ce8844e0d519a1517e2f5f2850facade420b9652c4261d949cf4ac131',
|
||||
-- proxy
|
||||
NULL,
|
||||
-- ca
|
||||
E'\\x0000000100000014e119602f608a01dba6f603f0212fa3a85bbe307c000007b7010011746578747365637572652d67636d2d63610000013da3b16fa9000000000005582e353039000003f3308203ef308202d7a00302010202090089ba2dab4ae4f362300d06092a864886f70d010105050030818d310b30090603550406130255533113301106035504080c0a43616c69666f726e69613116301406035504070c0d53616e204672616e636973636f311d301b060355040a0c144f70656e20576869737065722053797374656d73311d301b060355040b0c144f70656e20576869737065722053797374656d733113301106035504030c0a54657874536563757265301e170d3133303332353232313833355a170d3233303332333232313833355a30818d310b30090603550406130255533113301106035504080c0a43616c69666f726e69613116301406035504070c0d53616e204672616e636973636f311d301b060355040a0c144f70656e20576869737065722053797374656d73311d301b060355040b0c144f70656e20576869737065722053797374656d733113301106035504030c0a5465787453656375726530820122300d06092a864886f70d01010105000382010f003082010a0282010100c14960693820431748b8ab67788c05e4497506a5b796ba054f4028da2faa83f500cec5e5b569fbdf3e8f3ade2e82aead4a0f11e9077e84c3355c8f02e415320c7a8eedf6cd45428940b77984ad5d94d2f89ee957acfb28fa82b49fc7020301c76c2a62346b549009996bdd0d6d70702400a151c5835ac000f2a6ce41f999aa7207fae774d74b9ff420f3d02e870b9fc1962f039836761f06f20b283308b66653b446ee71d8a0c4403d99f22fbc700311bb5e2ed560c019bd479bd5bedc2b0fa082c48de9807ec41fb90c3f439df77c0b8acbe7d7284763b16e625ae462a76432f594acaa00495c388dbebdbda789094754f870a85ce48fd4f41c2fa59e9cd0870203010001a350304e301d0603551d0e04160414018b18f13ffb3919446e8586be946532a7323c90301f0603551d23041830168014018b18f13ffb3919446e8586be946532a7323c90300c0603551d13040530030101ff300d06092a864886f70d010105050003820101007e1ebe210b9ea6d0bbc902ed512ba36e3c36d330437bfe33288c51f11f83f75cf15fba98d1f9b903ab4a4f394e898c8c67ac3d570ff1159934da4d563988e85ecafed4cc939e7dbda92ce73daacbaf2387e76844a1f5b873967f8b5f1b42ad13c6864c40d48308a3727fb36585fca558672722bba6f8b9b27dd573c0b81359c089ae83bfecad6bdba64d21aba03acf5e345935522ad246ec43f8d6425efe8178bac63927b2cf9312b72d6ccc2676f9108243991bf21fca724705a0e909baaa2185688e272fc414e0b6b5c767a7e0319745a2cc3d1c2310b36040fa1d477f33a0232e03c80765f65862867b0fb435c0d522547731b85ac478169825b2c4af02d500bbf2ff8236b854e90220d0ed6cfbc9a370eed025',
|
||||
-- key_backup_service_name
|
||||
'823a3b2c037ff0cbe305cc48928cfcc97c9ed4a8ca6d49af6f7d6981fb60a4e9',
|
||||
-- key_backup_service_id
|
||||
'16b94ac6d2b7f7b9d72928f36d798dbb35ed32e7bb14c42b4301ad0344b46f29',
|
||||
-- key_backup_mrenclave
|
||||
'a3baab19ef6ce6f34ab9ebb25ba722725ae44a8872dc0ff08ad6d83a9489de87',
|
||||
-- cds_mrenclave
|
||||
'c98e00a4e3ff977a56afefe7362a27e4961e4f19e211febfbb19b897e6b80b15',
|
||||
-- ias_ca
|
||||
E'\\x00000002000000141e139877c131235200356d48d741b9e8538d4a290000078101000369617300000164adeb7976000000000005582e3530390000054f3082054b308203b3a003020102020900d107765d32a3b094300d06092a864886f70d01010b0500307e310b3009060355040613025553310b300906035504080c0243413114301206035504070c0b53616e746120436c617261311a3018060355040a0c11496e74656c20436f72706f726174696f6e3130302e06035504030c27496e74656c20534758204174746573746174696f6e205265706f7274205369676e696e672043413020170d3136313131343135333733315a180f32303439313233313233353935395a307e310b3009060355040613025553310b300906035504080c0243413114301206035504070c0b53616e746120436c617261311a3018060355040a0c11496e74656c20436f72706f726174696f6e3130302e06035504030c27496e74656c20534758204174746573746174696f6e205265706f7274205369676e696e67204341308201a2300d06092a864886f70d01010105000382018f003082018a02820181009f3c647eb5773cbb512d2732c0d7415ebb55a0fa9ede2e649199e6821db910d53177370977466a6a5e4786ccd2ddebd4149d6a2f6325529dd10cc98737b0779c1a07e29c47a1ae004948476c489f45a5a15d7ac8ecc6acc645adb43d87679df59c093bc5a2e9696c5478541b979e754b573914be55d32ff4c09ddf27219934cd990527b3f92ed78fbf29246abecb71240ef39c2d7107b447545a7ffb10eb060a68a98580219e36910952683892d6a5e2a80803193e407531404e36b315623799aa825074409754a2dfe8f5afd5fe631e1fc2af3808906f28a790d9dd9fe060939b125790c5805d037df56a99531b96de69de33ed226cc1207d1042b5c9ab7f404fc711c0fe4769fb9578b1dc0ec469ea1a25e0ff9914886ef2699b235bb4847dd6ff40b606e6170793c2fb98b314587f9cfd257362dfeab10b3bd2d97673a1a4bd44c453aaf47fc1f2d3d0f384f74a06f89c089f0da6cdb7fceee8c9821a8e54f25c0416d18c46839a5f8012fbdd3dc74d256279adc2c0d55aff6f0622425d1b0203010001a381c93081c630600603551d1f045930573055a053a051864f687474703a2f2f7472757374656473657276696365732e696e74656c2e636f6d2f636f6e74656e742f43524c2f5347582f4174746573746174696f6e5265706f72745369676e696e6743412e63726c301d0603551d0e0416041478437b76a67ebcd0af7e4237eb357c3b8701513c301f0603551d2304183016801478437b76a67ebcd0af7e4237eb357c3b8701513c300e0603551d0f0101ff04040302010630120603551d130101ff040830060101ff020100300d06092a864886f70d01010b05000382018100785f2d60c5c80af42a797610213915da82c9b29e89e0902a25a6c75b16091c68ab204aae711889492c7e1e320911455a8fc13442312e77a63994d99795c8ea4576823cea8ad1e191cfa862fab8a932d3d9b0535a0702d0555f74e520e30330f33480e7adc9d7c81e20703142bf00c528a80b463381fd602a82c7035281aae59562ccb5334ea8903e650b010681f5ce8eb62eac9c414988243aec92f25bf13cdff7ebcc298ee51bba5a3538b66b26cbc45a51de003cad306531ad7cf5d4ef0f8805d1b9133d24135ab3c4641a2f8808349d7333295e0e76ee4bc5227232628efa80d79d92ab4e3d1120f3fb5ad119cd8d544aa1d4a6865e6b57beac5771307e2e3cb9070da47b4bfc8869e01413ea093541de8a792811b74636c5e91452cf0cee59f2fb404acd0bc584cb9c835404734c0e7ec6605cdfcf2ff439b6d4719f702f0e0c3fa04fdb12a6cb2ad1ab1c9af1f8f4c3a08edd72a32b0bb5d0ad256ffd159a683b2a5a1f1d11fa62532f03d754caef0da5735a1e5a884c7e89d91218c9d7008515e5f5992ccc471f3b1bc1aaec24a2997e6ad3'
|
||||
);
|
||||
|
||||
CREATE TABLE signald_accounts (
|
||||
uuid UUID NOT NULL,
|
||||
e164 TEXT NOT NULL,
|
||||
server UUID NOT NULL REFERENCES signald_servers(server_uuid) ON DELETE CASCADE,
|
||||
|
||||
PRIMARY KEY (uuid, e164, server),
|
||||
UNIQUE (e164),
|
||||
UNIQUE (uuid)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_recipients (
|
||||
rowid SERIAL PRIMARY KEY,
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
uuid UUID,
|
||||
e164 TEXT,
|
||||
registered BOOLEAN DEFAULT true, -- from signald in src/main/resources/db/migration/postgresql/V13__recipient_registration_status.sql
|
||||
|
||||
UNIQUE (account_uuid, e164, uuid)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_prekeys (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
id INTEGER NOT NULL,
|
||||
record BYTEA NOT NULL,
|
||||
|
||||
PRIMARY KEY (account_uuid, id)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_sessions (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
recipient INTEGER NOT NULL REFERENCES signald_recipients(rowid) ON DELETE CASCADE,
|
||||
device_id INTEGER,
|
||||
record BYTEA NOT NULL,
|
||||
|
||||
PRIMARY KEY (account_uuid, recipient, device_id)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_signed_prekeys (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
id INTEGER NOT NULL,
|
||||
record BYTEA NOT NULL,
|
||||
|
||||
PRIMARY KEY (account_uuid, id)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_identity_keys (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
recipient INTEGER NOT NULL,
|
||||
identity_key BYTEA NOT NULL,
|
||||
trust_level TEXT NOT NULL,
|
||||
added TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY (account_uuid, recipient, identity_key)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_account_data (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
key TEXT NOT NULL,
|
||||
value BYTEA NOT NULL,
|
||||
|
||||
PRIMARY KEY (account_uuid, key)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_pending_account_data (
|
||||
username TEXT,
|
||||
key TEXT NOT NULL,
|
||||
value BYTEA NOT NULL,
|
||||
|
||||
PRIMARY KEY (username, key)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_sender_keys (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
address TEXT NOT NULL,
|
||||
device INTEGER NOT NULL,
|
||||
distribution_id UUID NOT NULL,
|
||||
record BYTEA NOT NULL,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
|
||||
PRIMARY KEY (account_uuid, address, device, distribution_id)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_sender_key_shared (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
distribution_id UUID NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
device INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY (account_uuid, address, device)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_groups (
|
||||
rowid SERIAL PRIMARY KEY,
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
group_id BYTEA NOT NULL,
|
||||
master_key BYTEA NOT NULL,
|
||||
revision INTEGER NOT NULL,
|
||||
last_avatar_fetch INTEGER,
|
||||
distribution_id UUID,
|
||||
group_info BYTEA,
|
||||
|
||||
UNIQUE (account_uuid, group_id)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_group_credentials (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
date BIGINT NOT NULL,
|
||||
credential BYTEA NOT NULL,
|
||||
|
||||
PRIMARY KEY (account_uuid, date)
|
||||
);
|
||||
|
||||
-- from signald in src/main/resources/db/migration/postgresql/V12__create_contacts_table.sql
|
||||
CREATE TABLE signald_contacts (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
recipient INTEGER NOT NULL REFERENCES signald_recipients(rowid) ON DELETE CASCADE,
|
||||
name TEXT,
|
||||
color TEXT,
|
||||
profile_key BYTEA,
|
||||
message_expiration_time INTEGER,
|
||||
inbox_position INTEGER,
|
||||
|
||||
PRIMARY KEY (account_uuid, recipient)
|
||||
);
|
||||
|
||||
-- from signald in src/main/resources/db/migration/postgresql/V15__profiles_tables.sql
|
||||
|
||||
CREATE TABLE signald_profile_keys (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
recipient INTEGER NOT NULL REFERENCES signald_recipients(rowid) ON DELETE CASCADE,
|
||||
profile_key BYTEA DEFAULT NULL,
|
||||
profile_key_credential BYTEA DEFAULT NULL,
|
||||
request_pending boolean DEFAULT FALSE,
|
||||
unidentified_access_mode int DEFAULT 0,
|
||||
|
||||
PRIMARY KEY (account_uuid, recipient)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_profiles (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
recipient INTEGER NOT NULL REFERENCES signald_recipients(rowid) ON DELETE CASCADE,
|
||||
last_update BIGINT,
|
||||
given_name TEXT,
|
||||
family_name TEXT,
|
||||
about TEXT,
|
||||
emoji TEXT,
|
||||
payment_address BYTEA,
|
||||
badges TEXT,
|
||||
|
||||
PRIMARY KEY (account_uuid, recipient)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_profile_capabilities (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
recipient INTEGER NOT NULL REFERENCES signald_recipients(rowid) ON DELETE CASCADE,
|
||||
storage BOOLEAN,
|
||||
gv1_migration BOOLEAN,
|
||||
sender_key BOOLEAN,
|
||||
announcement_group BOOLEAN,
|
||||
change_number BOOLEAN,
|
||||
stories BOOLEAN,
|
||||
|
||||
PRIMARY KEY (account_uuid, recipient)
|
||||
);
|
||||
|
||||
CREATE TABLE signald_profile_badges (
|
||||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
id TEXT NOT NULL,
|
||||
category TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
sprite6 TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY (account_uuid, id)
|
||||
);
|
||||
`
|
||||
)
|
|
@ -25,7 +25,7 @@ import (
|
|||
|
||||
var DeviceCmd = &cobra.Command{
|
||||
Use: "device",
|
||||
Aliases: []string{"msg", "devices"},
|
||||
Aliases: []string{"devices"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -52,7 +52,10 @@ var (
|
|||
}
|
||||
group = args[0]
|
||||
for _, member := range args[1:] {
|
||||
address := common.StringToAddress(member)
|
||||
address, err := common.StringToAddress(member)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
members = append(members, &address)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -58,7 +58,10 @@ var (
|
|||
}
|
||||
|
||||
for _, member := range args[1:] {
|
||||
address := common.StringToAddress(member)
|
||||
address, err := common.StringToAddress(member)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
req.Members = append(req.Members, &address)
|
||||
}
|
||||
|
||||
|
|
111
cmd/signaldctl/cmd/group/join/join.go
Normal file
111
cmd/signaldctl/cmd/group/join/join.go
Normal file
|
@ -0,0 +1,111 @@
|
|||
// Copyright © 2021 Finn Herzfeld <finn@janky.solutions>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package join
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||
"gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||
)
|
||||
|
||||
var (
|
||||
account string
|
||||
url string
|
||||
|
||||
JoinGroupCmd = &cobra.Command{
|
||||
Use: "join <url>",
|
||||
Short: "join a group by URL",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
}
|
||||
if account == "" {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if len(args) < 1 {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("must specify group url")
|
||||
}
|
||||
url = args[0]
|
||||
},
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
go common.Signald.Listen(nil)
|
||||
req := v1.JoinGroupRequest{
|
||||
Account: account,
|
||||
Uri: url,
|
||||
}
|
||||
|
||||
resp, err := req.Submit(common.Signald)
|
||||
if err != nil {
|
||||
log.Fatal(err, "error communicating with signald")
|
||||
}
|
||||
|
||||
if resp.PendingAdminApproval {
|
||||
log.Println("requested to join pending admin approval")
|
||||
} else {
|
||||
log.Println("joined group")
|
||||
}
|
||||
|
||||
switch common.OutputFormat {
|
||||
case common.OutputFormatJSON:
|
||||
err := json.NewEncoder(os.Stdout).Encode(resp)
|
||||
if err != nil {
|
||||
log.Fatal(err, "error encoding response to stdout")
|
||||
}
|
||||
case common.OutputFormatYAML:
|
||||
err := yaml.NewEncoder(os.Stdout).Encode(resp)
|
||||
if err != nil {
|
||||
log.Fatal(err, "error encoding response to stdout")
|
||||
}
|
||||
case common.OutputFormatCSV, common.OutputFormatTable:
|
||||
t := table.NewWriter()
|
||||
t.SetOutputMirror(os.Stdout)
|
||||
t.AppendRows([]table.Row{
|
||||
{"Group ID", resp.GroupID},
|
||||
{"Revision", resp.Revision},
|
||||
{"Title", resp.Title},
|
||||
{"Description", resp.Description},
|
||||
{"Members", resp.MemberCount},
|
||||
{"Awaiting approval", resp.PendingAdminApproval},
|
||||
})
|
||||
|
||||
if common.OutputFormat == common.OutputFormatCSV {
|
||||
t.RenderCSV()
|
||||
} else {
|
||||
common.StylizeTable(t)
|
||||
t.Render()
|
||||
}
|
||||
case common.OutputFormatQuiet, common.OutputFormatDefault:
|
||||
return
|
||||
default:
|
||||
log.Fatal("Unsupported output format")
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
JoinGroupCmd.Flags().StringVarP(&account, "account", "a", "", "the signald account to use")
|
||||
}
|
102
cmd/signaldctl/cmd/group/preview/preview.go
Normal file
102
cmd/signaldctl/cmd/group/preview/preview.go
Normal file
|
@ -0,0 +1,102 @@
|
|||
// Copyright © 2021 Finn Herzfeld <finn@janky.solutions>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package preview
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||
"gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||
)
|
||||
|
||||
var (
|
||||
account string
|
||||
joinURL string
|
||||
PreviewGroupCmd = &cobra.Command{
|
||||
Use: "preview https://signal.group/...",
|
||||
Short: "preview information about a group without joining",
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
}
|
||||
if account == "" {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return errors.New("please specify signald.group URL")
|
||||
}
|
||||
joinURL = args[0]
|
||||
|
||||
if !strings.HasPrefix(joinURL, "https://signal.group/#") {
|
||||
return errors.New("invalid group link (must start with https://signal.group/#")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
RunE: func(_ *cobra.Command, args []string) error {
|
||||
go common.Signald.Listen(nil)
|
||||
req := v1.GroupLinkInfoRequest{
|
||||
Account: account,
|
||||
Uri: joinURL,
|
||||
}
|
||||
|
||||
info, err := req.Submit(common.Signald)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch common.OutputFormat {
|
||||
case common.OutputFormatJSON:
|
||||
return json.NewEncoder(os.Stdout).Encode(info)
|
||||
case common.OutputFormatYAML:
|
||||
return yaml.NewEncoder(os.Stdout).Encode(info)
|
||||
case common.OutputFormatDefault, common.OutputFormatTable:
|
||||
t := table.NewWriter()
|
||||
t.SetOutputMirror(os.Stdout)
|
||||
|
||||
joinApproval := "unknown"
|
||||
switch info.AddFromInviteLink {
|
||||
case 3:
|
||||
joinApproval = "yes"
|
||||
case 1:
|
||||
joinApproval = "no"
|
||||
}
|
||||
|
||||
t.AppendRows([]table.Row{
|
||||
table.Row{"Title", info.Title},
|
||||
table.Row{"Group ID", info.GroupID},
|
||||
table.Row{"Member Count", info.MemberCount},
|
||||
table.Row{"Membership Approval", joinApproval},
|
||||
})
|
||||
common.StylizeTable(t)
|
||||
t.Render()
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
)
|
|
@ -52,7 +52,10 @@ var (
|
|||
}
|
||||
group = args[0]
|
||||
for _, member := range args[1:] {
|
||||
address := common.StringToAddress(member)
|
||||
address, err := common.StringToAddress(member)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
members = append(members, &address)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -21,8 +21,10 @@ import (
|
|||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/accept"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/addmember"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/create"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/join"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/leave"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/list"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/preview"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/removemember"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/show"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/update"
|
||||
|
@ -37,8 +39,10 @@ func init() {
|
|||
GroupCmd.AddCommand(accept.AcceptGroupInvitationCmd)
|
||||
GroupCmd.AddCommand(addmember.AddGroupMembersCmd)
|
||||
GroupCmd.AddCommand(create.CreateGroupCmd)
|
||||
GroupCmd.AddCommand(join.JoinGroupCmd)
|
||||
GroupCmd.AddCommand(leave.LeaveGroupCmd)
|
||||
GroupCmd.AddCommand(list.ListGroupCmd)
|
||||
GroupCmd.AddCommand(preview.PreviewGroupCmd)
|
||||
GroupCmd.AddCommand(removemember.RemoveMemberCmd)
|
||||
GroupCmd.AddCommand(show.ShowGroupCmd)
|
||||
GroupCmd.AddCommand(update.UpdateGroupCmd)
|
||||
|
|
|
@ -52,7 +52,11 @@ var (
|
|||
log.Fatal("not enough arguments provided")
|
||||
}
|
||||
group = args[0]
|
||||
address = common.StringToAddress(args[1])
|
||||
var err error
|
||||
address, err = common.StringToAddress(args[1])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
switch strings.ToLower(args[2]) {
|
||||
case "default":
|
||||
role = "DEFAULT"
|
||||
|
|
|
@ -44,7 +44,10 @@ var (
|
|||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if len(args) >= 1 {
|
||||
a := common.StringToAddress(args[0])
|
||||
a, err := common.StringToAddress(args[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
address = &a
|
||||
}
|
||||
},
|
||||
|
|
|
@ -50,7 +50,11 @@ var (
|
|||
common.Must(cmd.Help())
|
||||
log.Fatal("please specify an address")
|
||||
}
|
||||
address = common.StringToAddress(args[0])
|
||||
var err error
|
||||
address, err = common.StringToAddress(args[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if len(args) > 1 {
|
||||
safetyNumber = args[1]
|
||||
}
|
||||
|
|
|
@ -46,7 +46,11 @@ var (
|
|||
common.Must(cmd.Help())
|
||||
log.Fatal("please specify an address and a safety number")
|
||||
}
|
||||
address = common.StringToAddress(args[0])
|
||||
var err error
|
||||
address, err = common.StringToAddress(args[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
safetyNumber = args[1]
|
||||
if len(args) > 2 {
|
||||
level = strings.ToUpper(args[2])
|
||||
|
|
|
@ -44,7 +44,11 @@ var (
|
|||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
for _, address := range args {
|
||||
addresses = append(addresses, common.StringToAddress(address))
|
||||
address, err := common.StringToAddress(address)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
addresses = append(addresses, address)
|
||||
}
|
||||
},
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
|
|
|
@ -32,16 +32,25 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
account string
|
||||
author v1.JsonAddress
|
||||
timestamp int64
|
||||
emoji string
|
||||
group string
|
||||
remove bool
|
||||
account string
|
||||
threadAddress *v1.JsonAddress
|
||||
group string
|
||||
author v1.JsonAddress
|
||||
timestamp int64
|
||||
emoji string
|
||||
remove bool
|
||||
|
||||
ReactMessageCmd = &cobra.Command{
|
||||
Use: "react <author> <timestamp> <emoji>",
|
||||
Use: "react thread author timestamp emoji",
|
||||
Short: "react to a message",
|
||||
Long: `react to a message with a particular emoji
|
||||
|
||||
arguments:
|
||||
<thread> if the message being reacted to is in a 1-on-1 chat, the e164 or UUID of the person the chat is with. if the message is in a group, the group id.
|
||||
<author> the e164 or UUID of the author of the message being reacted to
|
||||
<timestamp> the timestamp of the message to react to
|
||||
<emoji> the unicode emoji to send as the reaction
|
||||
`,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
|
@ -50,16 +59,25 @@ var (
|
|||
common.Must(cmd.Help())
|
||||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if len(args) != 3 {
|
||||
if len(args) != 4 {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("not enough arguments")
|
||||
}
|
||||
author = common.StringToAddress(args[0])
|
||||
|
||||
var err error
|
||||
timestamp, err = strconv.ParseInt(args[1], 10, 64)
|
||||
threadAddress, group, err = common.StringToAddressOrGroup(args[0])
|
||||
if err != nil {
|
||||
log.Fatal("Unable to parse timestamp", args[1], ":", err.Error())
|
||||
log.Fatal(err)
|
||||
}
|
||||
emoji = args[2]
|
||||
author, err = common.StringToAddress(args[1])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
timestamp, err = strconv.ParseInt(args[2], 10, 64)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to parse timestamp", args[2], ":", err.Error())
|
||||
}
|
||||
emoji = args[3]
|
||||
},
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
go common.Signald.Listen(nil)
|
||||
|
@ -74,10 +92,10 @@ var (
|
|||
},
|
||||
}
|
||||
|
||||
if group == "" {
|
||||
req.RecipientAddress = &author
|
||||
if threadAddress != nil {
|
||||
req.RecipientAddress = threadAddress
|
||||
} else {
|
||||
req.RecipientGroupID = group
|
||||
req.RecipientAddress = &author
|
||||
}
|
||||
|
||||
resp, err := req.Submit(common.Signald)
|
||||
|
|
|
@ -18,8 +18,11 @@ package send
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
|
@ -29,16 +32,23 @@ import (
|
|||
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||
v0 "gitlab.com/signald/signald-go/signald/client-protocol/v0"
|
||||
"gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||
v1 "gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
CAPTCHA_HELPER = "signal-captcha-helper"
|
||||
)
|
||||
|
||||
var (
|
||||
account string
|
||||
attachments []string
|
||||
account string
|
||||
toAddress *v1.JsonAddress
|
||||
toGroup string
|
||||
attachments []string
|
||||
message string
|
||||
captchaHelper bool
|
||||
|
||||
SendMessageCmd = &cobra.Command{
|
||||
Use: "send <group id | phone number> <message>",
|
||||
Use: "send {group id | phone number} [message]",
|
||||
Short: "send a message",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
|
@ -48,24 +58,37 @@ var (
|
|||
common.Must(cmd.Help())
|
||||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if len(args) < 2 {
|
||||
if len(args) < 1 {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("must specify both destination (either group id or phone number) and message")
|
||||
log.Fatal("must specify both destination (either group id or phone number)")
|
||||
}
|
||||
|
||||
if len(args) == 1 {
|
||||
messageBytes, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Println("error reading message from stdin, perhaps you meant to include it in the command line arguments?")
|
||||
panic(err)
|
||||
}
|
||||
message = string(messageBytes)
|
||||
} else {
|
||||
message = strings.Join(args[1:], " ")
|
||||
}
|
||||
to, err := common.StringToAddress(args[0])
|
||||
if err != nil {
|
||||
toGroup = args[0]
|
||||
} else {
|
||||
toAddress = &to
|
||||
}
|
||||
},
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
go common.Signald.Listen(nil)
|
||||
|
||||
req := v1.SendRequest{
|
||||
Username: account,
|
||||
MessageBody: strings.Join(args[1:], " "),
|
||||
Attachments: []*v0.JsonAttachment{},
|
||||
}
|
||||
|
||||
if strings.HasPrefix(args[0], "+") {
|
||||
req.RecipientAddress = &v1.JsonAddress{Number: args[0]}
|
||||
} else {
|
||||
req.RecipientGroupID = args[0]
|
||||
Username: account,
|
||||
MessageBody: message,
|
||||
Attachments: []*v1.JsonAttachment{},
|
||||
RecipientAddress: toAddress,
|
||||
RecipientGroupID: toGroup,
|
||||
}
|
||||
|
||||
for _, attachment := range attachments {
|
||||
|
@ -74,13 +97,55 @@ var (
|
|||
log.Fatal("error resolving attachment", err)
|
||||
}
|
||||
log.Println(path)
|
||||
req.Attachments = append(req.Attachments, &v0.JsonAttachment{Filename: path})
|
||||
req.Attachments = append(req.Attachments, &v1.JsonAttachment{Filename: path})
|
||||
}
|
||||
|
||||
resp, err := req.Submit(common.Signald)
|
||||
if err != nil {
|
||||
log.Fatal("error sending request to signald: ", err)
|
||||
}
|
||||
|
||||
resends := []*v1.JsonAddress{}
|
||||
|
||||
for _, result := range resp.Results {
|
||||
if result.ProofRequiredFailure != nil {
|
||||
if captchaHelper {
|
||||
err = runCaptchaHelper(result.ProofRequiredFailure.Token)
|
||||
if err != nil {
|
||||
log.Println("error running captcha helper: ", err)
|
||||
}
|
||||
resends = append(resends, result.Address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(resends) > 0 {
|
||||
resendReq := v1.SendRequest{
|
||||
Username: req.Username,
|
||||
MessageBody: req.MessageBody,
|
||||
Attachments: req.Attachments,
|
||||
RecipientGroupID: req.RecipientGroupID,
|
||||
Members: resends,
|
||||
Timestamp: resp.Timestamp,
|
||||
}
|
||||
resendResponse, err := resendReq.Submit(common.Signald)
|
||||
if err != nil {
|
||||
log.Println("error resending messages: ", err)
|
||||
} else {
|
||||
for i, originalResult := range resp.Results {
|
||||
if originalResult.ProofRequiredFailure == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, result := range resendResponse.Results {
|
||||
if result.Address.UUID == originalResult.Address.UUID {
|
||||
resp.Results[i] = result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch common.OutputFormat {
|
||||
case common.OutputFormatJSON:
|
||||
err := json.NewEncoder(os.Stdout).Encode(resp)
|
||||
|
@ -132,7 +197,55 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
func runCaptchaHelper(challenge string) error {
|
||||
if !captchaHelper {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := exec.LookPath(CAPTCHA_HELPER)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := exec.Command(CAPTCHA_HELPER, "--challenge")
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
captchaToken := new(strings.Builder)
|
||||
_, err = io.Copy(captchaToken, stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := v1.SubmitChallengeRequest{
|
||||
Account: account,
|
||||
CaptchaToken: captchaToken.String(),
|
||||
Challenge: challenge,
|
||||
}
|
||||
|
||||
err = req.Submit(common.Signald)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
SendMessageCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use")
|
||||
SendMessageCmd.Flags().BoolVarP(&captchaHelper, "captcha-helper", "c", false, "Invoke signal-captcha-helper and process the response when a push challenge response appears. After completing the challenge, the message will be redelivered to the failed recipient")
|
||||
SendMessageCmd.Flags().StringSliceVarP(&attachments, "attachment", "A", []string{}, "attach a file to your outbound message. may be specified multiple times.")
|
||||
}
|
||||
|
|
41
cmd/signaldctl/cmd/protocol.go
Normal file
41
cmd/signaldctl/cmd/protocol.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/signald"
|
||||
)
|
||||
|
||||
var protocolCmd = &cobra.Command{
|
||||
Use: "protocol",
|
||||
Short: "return a machine-readable description of the signald client protocol. Details at https://signald.org/articles/socket-protocol/",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
go common.Signald.Listen(nil)
|
||||
|
||||
req := map[string]string{"version": "v1", "type": "protocol", "id": signald.GenerateID()}
|
||||
err := common.Signald.RawRequest(req)
|
||||
if err != nil {
|
||||
log.Println("signald-go: error submitting request to signald")
|
||||
return err
|
||||
}
|
||||
|
||||
responseChannel := common.Signald.GetResponseListener(req["id"])
|
||||
defer common.Signald.CloseResponseListener(req["id"])
|
||||
|
||||
rawResponse := <-responseChannel
|
||||
if rawResponse.Error != nil {
|
||||
return fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||
}
|
||||
|
||||
_, err = os.Stdout.Write(rawResponse.Data)
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(protocolCmd)
|
||||
}
|
60
cmd/signaldctl/cmd/raw.go
Normal file
60
cmd/signaldctl/cmd/raw.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/signald"
|
||||
)
|
||||
|
||||
var rawCmd = &cobra.Command{
|
||||
Use: "raw version type [json]",
|
||||
Short: "make a request to signald",
|
||||
Long: `make a raw request to signald, returning the result. If request data is not provided via command line argument labeled \"json\", it must be provided via stdin.
|
||||
|
||||
Example usage:
|
||||
|
||||
signaldctl raw v1 get_profile '{"account": "+12024561414", "address": {"number": "+12024561111"}}'`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 3 {
|
||||
return cmd.Help()
|
||||
}
|
||||
|
||||
var reqdata map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(args[2]), &reqdata); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
requestID := signald.GenerateID()
|
||||
reqdata["id"] = requestID
|
||||
reqdata["type"] = args[1]
|
||||
reqdata["version"] = args[0]
|
||||
|
||||
go common.Signald.Listen(nil)
|
||||
|
||||
err := common.Signald.RawRequest(reqdata)
|
||||
if err != nil {
|
||||
log.Println("error submitting request to signald")
|
||||
return err
|
||||
}
|
||||
|
||||
responseChannel := common.Signald.GetResponseListener(requestID)
|
||||
defer common.Signald.CloseResponseListener(requestID)
|
||||
|
||||
rawResponse := <-responseChannel
|
||||
if rawResponse.Error != nil {
|
||||
return fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||
}
|
||||
|
||||
_, err = os.Stdout.Write(rawResponse.Data)
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(rawCmd)
|
||||
}
|
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account"
|
||||
configcmd "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/config"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/db"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/device"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/key"
|
||||
|
@ -80,6 +81,7 @@ func init() {
|
|||
RootCmd.PersistentFlags().StringVarP(&common.OutputFormat, "output-format", "o", "default", "the output format. options are usually table, yaml and json, default is usually table. Some commands have other options.")
|
||||
RootCmd.AddCommand(account.AccountCmd)
|
||||
RootCmd.AddCommand(configcmd.ConfigCmd)
|
||||
RootCmd.AddCommand(db.MoveCmd)
|
||||
RootCmd.AddCommand(device.DeviceCmd)
|
||||
RootCmd.AddCommand(group.GroupCmd)
|
||||
RootCmd.AddCommand(key.KeyCmd)
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
package session
|
||||
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
96
cmd/signaldctl/cmd/subscribe.go
Normal file
96
cmd/signaldctl/cmd/subscribe.go
Normal file
|
@ -0,0 +1,96 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||
client_protocol "gitlab.com/signald/signald-go/signald/client-protocol"
|
||||
v1 "gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||
)
|
||||
|
||||
var (
|
||||
accountIdentifier string
|
||||
subscribeCmd = &cobra.Command{
|
||||
Use: "subscribe",
|
||||
Short: "subscribe to incoming messages from signald",
|
||||
Long: `subscribe to incoming messages from signald.
|
||||
|
||||
if no default account is set, the -a/--account argument is required.
|
||||
|
||||
the default output format (-o default) is being worked on, subject to change and should not be relied upon. Thoughts? come by the #signald IRC/matrix room
|
||||
|
||||
if you want to future-proof your scripts, use json output (-o json) and parse it.`,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if accountIdentifier == "" {
|
||||
accountIdentifier = config.Config.DefaultAccount
|
||||
}
|
||||
if accountIdentifier == "" {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
incoming := make(chan client_protocol.BasicResponse)
|
||||
go common.Signald.Listen(incoming)
|
||||
|
||||
req := v1.SubscribeRequest{Account: accountIdentifier}
|
||||
err := req.Submit(common.Signald)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for msg := range incoming {
|
||||
switch common.OutputFormat {
|
||||
case common.OutputFormatDefault:
|
||||
if msg.Type != "IncomingMessage" {
|
||||
continue
|
||||
}
|
||||
var data v1.IncomingMessage
|
||||
err := json.Unmarshal(msg.Data, &data)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if data.DataMessage == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
group := "-"
|
||||
if data.DataMessage.GroupV2 != nil {
|
||||
group = fmt.Sprintf("%s|%d", data.DataMessage.GroupV2.ID, data.DataMessage.GroupV2.Revision)
|
||||
}
|
||||
|
||||
attachment := "-"
|
||||
if len(data.DataMessage.Attachments) > 0 {
|
||||
attachment = data.DataMessage.Attachments[0].StoredFilename
|
||||
}
|
||||
|
||||
body := "-"
|
||||
if data.DataMessage.Body != "" {
|
||||
body = data.DataMessage.Body
|
||||
}
|
||||
fmt.Println(data.DataMessage.Timestamp, data.Account, data.Source.UUID, group, attachment, body)
|
||||
case common.OutputFormatJSON:
|
||||
err := json.NewEncoder(os.Stdout).Encode(msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
default:
|
||||
log.Fatal("unsupported output format")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
subscribeCmd.Flags().StringVarP(&accountIdentifier, "account", "a", "", "the signald account to use")
|
||||
RootCmd.AddCommand(subscribeCmd)
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
|
||||
"gitlab.com/signald/signald-go/signald"
|
||||
|
@ -30,6 +32,18 @@ var (
|
|||
OutputFormat string
|
||||
)
|
||||
|
||||
type InvalidAddressError struct {
|
||||
invalidAddress string
|
||||
}
|
||||
|
||||
func NewInvalidAddress(i string) InvalidAddressError {
|
||||
return InvalidAddressError{invalidAddress: i}
|
||||
}
|
||||
|
||||
func (i InvalidAddressError) Error() string {
|
||||
return fmt.Sprintf("invalid address: %s", i.invalidAddress)
|
||||
}
|
||||
|
||||
func Must(err error) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -40,9 +54,28 @@ func StylizeTable(t table.Writer) {
|
|||
t.SetStyle(table.StyleLight)
|
||||
}
|
||||
|
||||
func StringToAddress(address string) v1.JsonAddress {
|
||||
func StringToAddress(address string) (v1.JsonAddress, error) {
|
||||
if strings.HasPrefix(address, "+") {
|
||||
return v1.JsonAddress{Number: address}
|
||||
return v1.JsonAddress{Number: address}, nil
|
||||
}
|
||||
return v1.JsonAddress{UUID: address}
|
||||
|
||||
if _, err := uuid.Parse(address); err == nil {
|
||||
return v1.JsonAddress{UUID: address}, nil
|
||||
}
|
||||
return v1.JsonAddress{}, NewInvalidAddress(address)
|
||||
}
|
||||
|
||||
func StringToAddressOrGroup(identifier string) (*v1.JsonAddress, string, error) {
|
||||
// if it starts with a +, assume it's an e164
|
||||
if strings.HasPrefix(identifier, "+") {
|
||||
return &v1.JsonAddress{Number: identifier}, "", nil
|
||||
}
|
||||
|
||||
// if it parses as a UUID, assume it's a UUID
|
||||
if _, err := uuid.Parse(identifier); err == nil {
|
||||
return &v1.JsonAddress{UUID: identifier}, "", nil
|
||||
}
|
||||
|
||||
// if it doesn't start with a + and doesn't parse as a UUID, assume it's a group
|
||||
return nil, identifier, nil
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package config
|
|||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
@ -54,6 +55,9 @@ func Load() error {
|
|||
}
|
||||
|
||||
func Save() error {
|
||||
if err := os.MkdirAll(path.Dir(Path), 0770); err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.Create(Path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
6
debian/control
vendored
6
debian/control
vendored
|
@ -8,7 +8,11 @@ Build-Depends: debhelper (>= 11),
|
|||
dh-golang,
|
||||
golang-any,
|
||||
golang-github-spf13-cobra-dev,
|
||||
golang-github-spf13-viper-dev
|
||||
golang-github-spf13-viper-dev,
|
||||
golang-github-google-uuid-dev,
|
||||
golang-github-mattn-go-sqlite3-dev,
|
||||
golang-github-lib-pq-dev,
|
||||
golang-github-satori-go.uuid-dev
|
||||
Standards-Version: 4.2.1
|
||||
Homepage: https://signald.org
|
||||
Vcs-Browser: https://gitlab.com/signald/signald-go
|
||||
|
|
4
go.mod
4
go.mod
|
@ -3,11 +3,15 @@ module gitlab.com/signald/signald-go
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/jedib0t/go-pretty/v6 v6.1.0
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/lib/pq v1.10.4
|
||||
github.com/mattn/go-runewidth v0.0.10 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.11
|
||||
github.com/mdp/qrterminal v1.0.1
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/spf13/cobra v1.1.2
|
||||
github.com/stretchr/testify v1.6.1 // indirect
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -65,6 +65,8 @@ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXi
|
|||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
|
@ -110,12 +112,16 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
|
||||
github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
|
||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-sqlite3 v1.14.11 h1:gt+cp9c0XGqe9S/wAHTL3n/7MqY+siPWgWJgqdsFrzQ=
|
||||
github.com/mattn/go-sqlite3 v1.14.11/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mdp/qrterminal v1.0.1 h1:07+fzVDlPuBlXS8tB0ktTAyf+Lp1j2+2zK3fBOL5b7c=
|
||||
github.com/mdp/qrterminal v1.0.1/go.mod h1:Z33WhxQe9B6CdW37HaVqcRKzP+kByF3q/qLxOGe12xQ=
|
||||
|
@ -158,6 +164,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
|
|||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
|
|
3069
protocol.json
3069
protocol.json
File diff suppressed because one or more lines are too long
14
signald/client-protocol/protocol.go
Normal file
14
signald/client-protocol/protocol.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package client_protocol
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type BasicResponse struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
ErrorType string `json:"error_type,omitempty"`
|
||||
Error json.RawMessage `json:"error,omitempty"`
|
||||
Data json.RawMessage `json:"data,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
}
|
|
@ -158,7 +158,7 @@ type JsonMessageEnvelope struct {
|
|||
HasLegacyMessage bool `json:"hasLegacyMessage,omitempty" yaml:"hasLegacyMessage,omitempty"`
|
||||
IsUnidentifiedSender bool `json:"isUnidentifiedSender,omitempty" yaml:"isUnidentifiedSender,omitempty"`
|
||||
Receipt *JsonReceiptMessage `json:"receipt,omitempty" yaml:"receipt,omitempty"`
|
||||
Relay string `json:"relay,omitempty" yaml:"relay,omitempty"`
|
||||
Relay string `json:"relay,omitempty" yaml:"relay,omitempty"` // this field is no longer available and will never be populated
|
||||
ServerDeliveredTimestamp int64 `json:"serverDeliveredTimestamp,omitempty" yaml:"serverDeliveredTimestamp,omitempty"`
|
||||
ServerTimestamp int64 `json:"serverTimestamp,omitempty" yaml:"serverTimestamp,omitempty"`
|
||||
Source *JsonAddress `json:"source,omitempty" yaml:"source,omitempty"`
|
||||
|
@ -291,6 +291,7 @@ type OfferMessage struct {
|
|||
}
|
||||
|
||||
type Optional struct {
|
||||
Empty bool `json:"empty,omitempty" yaml:"empty,omitempty"`
|
||||
Present bool `json:"present,omitempty" yaml:"present,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -307,11 +308,5 @@ type SharedContact struct {
|
|||
Phone *Optional `json:"phone,omitempty" yaml:"phone,omitempty"`
|
||||
}
|
||||
|
||||
type Success struct {
|
||||
Duration int64 `json:"duration,omitempty" yaml:"duration,omitempty"`
|
||||
NeedsSync bool `json:"needsSync,omitempty" yaml:"needsSync,omitempty"`
|
||||
Unidentified bool `json:"unidentified,omitempty" yaml:"unidentified,omitempty"`
|
||||
}
|
||||
|
||||
type Type struct {
|
||||
}
|
||||
|
|
681
signald/client-protocol/v1/errors.go
Normal file
681
signald/client-protocol/v1/errors.go
Normal file
|
@ -0,0 +1,681 @@
|
|||
package v1
|
||||
|
||||
// DO NOT EDIT: this file is automatically generated by ./tools/generator in this repo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
client_protocol "gitlab.com/signald/signald-go/signald/client-protocol"
|
||||
)
|
||||
|
||||
func mkerr(response client_protocol.BasicResponse) error {
|
||||
switch response.ErrorType {
|
||||
case "AccountAlreadyVerifiedError":
|
||||
result := AccountAlreadyVerifiedError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "AccountHasNoKeysError":
|
||||
result := AccountHasNoKeysError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "AccountLockedError":
|
||||
result := AccountLockedError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "AttachmentTooLargeError":
|
||||
result := AttachmentTooLargeError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "AuthorizationFailedError":
|
||||
result := AuthorizationFailedError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "CaptchaRequiredError":
|
||||
result := CaptchaRequiredError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "DuplicateMessageError":
|
||||
result := DuplicateMessageError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "FingerprintVersionMismatchError":
|
||||
result := FingerprintVersionMismatchError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "GroupLinkNotActiveError":
|
||||
result := GroupLinkNotActiveError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "GroupNotActiveError":
|
||||
result := GroupNotActiveError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "GroupPatchNotAcceptedError":
|
||||
result := GroupPatchNotAcceptedError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "GroupVerificationError":
|
||||
result := GroupVerificationError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InternalError":
|
||||
result := InternalError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InvalidAttachmentError":
|
||||
result := InvalidAttachmentError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InvalidBase64Error":
|
||||
result := InvalidBase64Error{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InvalidFingerprintError":
|
||||
result := InvalidFingerprintError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InvalidGroupError":
|
||||
result := InvalidGroupError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InvalidGroupStateError":
|
||||
result := InvalidGroupStateError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InvalidInviteURIError":
|
||||
result := InvalidInviteURIError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InvalidProxyError":
|
||||
result := InvalidProxyError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InvalidRecipientError":
|
||||
result := InvalidRecipientError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "InvalidRequestError":
|
||||
result := InvalidRequestError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "NoKnownUUIDError":
|
||||
result := NoKnownUUIDError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "NoSendPermissionError":
|
||||
result := NoSendPermissionError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "NoSuchAccountError":
|
||||
result := NoSuchAccountError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "NoSuchSessionError":
|
||||
result := NoSuchSessionError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "OwnProfileKeyDoesNotExistError":
|
||||
result := OwnProfileKeyDoesNotExistError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "ProfileUnavailableError":
|
||||
result := ProfileUnavailableError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "ProofRequiredError":
|
||||
result := ProofRequiredError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "ProtocolInvalidKeyIdError":
|
||||
result := ProtocolInvalidKeyIdError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "ProtocolInvalidMessageError":
|
||||
result := ProtocolInvalidMessageError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "ProtocolNoSessionError":
|
||||
result := ProtocolNoSessionError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "RateLimitError":
|
||||
result := RateLimitError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "SQLError":
|
||||
result := SQLError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "ScanTimeoutError":
|
||||
result := ScanTimeoutError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "ServerNotFoundError":
|
||||
result := ServerNotFoundError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "UnknownGroupError":
|
||||
result := UnknownGroupError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "UnknownIdentityKeyError":
|
||||
result := UnknownIdentityKeyError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "UnregisteredUserError":
|
||||
result := UnregisteredUserError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "UnsupportedGroupError":
|
||||
result := UnsupportedGroupError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "UntrustedIdentityError":
|
||||
result := UntrustedIdentityError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
case "UserAlreadyExistsError":
|
||||
result := UserAlreadyExistsError{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result
|
||||
default:
|
||||
return fmt.Errorf("unexpected response type from signald: %s: %s", response.ErrorType, string(response.Error))
|
||||
}
|
||||
}
|
||||
|
||||
type AccountAlreadyVerifiedError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e AccountAlreadyVerifiedError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type AccountHasNoKeysError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e AccountHasNoKeysError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type AccountLockedError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
More string `json:"more,omitempty" yaml:"more,omitempty"`
|
||||
}
|
||||
|
||||
func (e AccountLockedError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type AttachmentTooLargeError struct {
|
||||
Filename string `json:"filename,omitempty" yaml:"filename,omitempty"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e AttachmentTooLargeError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
// AuthorizationFailedError: Indicates the server rejected our credentials or a failed group update. Typically means the linked device was removed by the primary device, or that the account was re-registered. For group updates, this can indicate that we lack permissions.
|
||||
type AuthorizationFailedError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e AuthorizationFailedError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type CaptchaRequiredError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
More string `json:"more,omitempty" yaml:"more,omitempty"`
|
||||
}
|
||||
|
||||
func (e CaptchaRequiredError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type DuplicateMessageError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
func (e DuplicateMessageError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type FingerprintVersionMismatchError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e FingerprintVersionMismatchError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type GroupLinkNotActiveError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e GroupLinkNotActiveError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type GroupNotActiveError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e GroupNotActiveError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
// GroupPatchNotAcceptedError: Indicates the server rejected our group update. This can be due to errors such as trying to add a user that's already in the group.
|
||||
type GroupPatchNotAcceptedError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e GroupPatchNotAcceptedError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type GroupVerificationError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e GroupVerificationError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
// InternalError: an internal error in signald has occurred. typically these are things that "should never happen" such as issues saving to the local disk, but it is also the default error type and may catch some things that should have their own error type. If you find tht your code is depending on the exception list for any particular behavior, please file an issue so we can pull those errors out to a separate error type: https://gitlab.com/signald/signald/-/issues/new
|
||||
type InternalError struct {
|
||||
Exceptions []string `json:"exceptions,omitempty" yaml:"exceptions,omitempty"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InternalError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type InvalidAttachmentError struct {
|
||||
Filename string `json:"filename,omitempty" yaml:"filename,omitempty"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InvalidAttachmentError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type InvalidBase64Error struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InvalidBase64Error) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type InvalidFingerprintError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InvalidFingerprintError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type InvalidGroupError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InvalidGroupError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type InvalidGroupStateError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InvalidGroupStateError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type InvalidInviteURIError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InvalidInviteURIError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type InvalidProxyError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InvalidProxyError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type InvalidRecipientError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InvalidRecipientError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type InvalidRequestError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e InvalidRequestError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type NoKnownUUIDError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e NoKnownUUIDError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type NoSendPermissionError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e NoSendPermissionError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type NoSuchAccountError struct {
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e NoSuchAccountError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type NoSuchSessionError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e NoSuchSessionError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type OwnProfileKeyDoesNotExistError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e OwnProfileKeyDoesNotExistError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type ProfileUnavailableError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e ProfileUnavailableError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type ProofRequiredError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
Options []string `json:"options,omitempty" yaml:"options,omitempty"` // possible list values are RECAPTCHA and PUSH_CHALLENGE
|
||||
RetryAfter int64 `json:"retry_after,omitempty" yaml:"retry_after,omitempty"` // value in seconds
|
||||
Token string `json:"token,omitempty" yaml:"token,omitempty"`
|
||||
}
|
||||
|
||||
func (e ProofRequiredError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type ProtocolInvalidKeyIdError struct {
|
||||
ContentHint int32 `json:"content_hint,omitempty" yaml:"content_hint,omitempty"`
|
||||
GroupId string `json:"group_id,omitempty" yaml:"group_id,omitempty"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
Sender string `json:"sender,omitempty" yaml:"sender,omitempty"`
|
||||
SenderDevice int32 `json:"sender_device,omitempty" yaml:"sender_device,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
func (e ProtocolInvalidKeyIdError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type ProtocolInvalidMessageError struct {
|
||||
ContentHint int32 `json:"content_hint,omitempty" yaml:"content_hint,omitempty"`
|
||||
GroupId string `json:"group_id,omitempty" yaml:"group_id,omitempty"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
Sender string `json:"sender,omitempty" yaml:"sender,omitempty"`
|
||||
SenderDevice int32 `json:"sender_device,omitempty" yaml:"sender_device,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
func (e ProtocolInvalidMessageError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type ProtocolNoSessionError struct {
|
||||
ContentHint int32 `json:"content_hint,omitempty" yaml:"content_hint,omitempty"`
|
||||
GroupId string `json:"group_id,omitempty" yaml:"group_id,omitempty"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
Sender string `json:"sender,omitempty" yaml:"sender,omitempty"`
|
||||
SenderDevice int32 `json:"sender_device,omitempty" yaml:"sender_device,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
func (e ProtocolNoSessionError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type RateLimitError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e RateLimitError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type SQLError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e SQLError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type ScanTimeoutError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e ScanTimeoutError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type ServerNotFoundError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
||||
}
|
||||
|
||||
func (e ServerNotFoundError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type UnknownGroupError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e UnknownGroupError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type UnknownIdentityKeyError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e UnknownIdentityKeyError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type UnregisteredUserError struct {
|
||||
E164Number string `json:"e164_number,omitempty" yaml:"e164_number,omitempty"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e UnregisteredUserError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
// UnsupportedGroupError: returned in response to use v1 groups, which are no longer supported
|
||||
type UnsupportedGroupError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e UnsupportedGroupError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type UntrustedIdentityError struct {
|
||||
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"`
|
||||
IdentityKey **IdentityKey `json:"identity_key,omitempty" yaml:"identity_key,omitempty"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (e UntrustedIdentityError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type UserAlreadyExistsError struct {
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
||||
}
|
||||
|
||||
func (e UserAlreadyExistsError) Error() string {
|
||||
return e.Message
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -24,6 +24,8 @@ type Account struct {
|
|||
AccountId string `json:"account_id,omitempty" yaml:"account_id,omitempty"` // The primary identifier on the account, included with all requests to signald for this account. Previously called 'username'
|
||||
Address *JsonAddress `json:"address,omitempty" yaml:"address,omitempty"` // The address of this account
|
||||
DeviceId int32 `json:"device_id,omitempty" yaml:"device_id,omitempty"` // The Signal device ID. Official Signal mobile clients (iPhone and Android) have device ID = 1, while linked devices such as Signal Desktop or Signal iPad have higher device IDs.
|
||||
Pending bool `json:"pending,omitempty" yaml:"pending,omitempty"` // indicates the account has not completed registration
|
||||
Pni string `json:"pni,omitempty" yaml:"pni,omitempty"`
|
||||
}
|
||||
|
||||
type AccountList struct {
|
||||
|
@ -34,7 +36,7 @@ type AccountList struct {
|
|||
type AddLinkedDeviceRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to interact with
|
||||
Uri string `json:"uri,omitempty" yaml:"uri,omitempty"` // the tsdevice:/ uri provided (typically in qr code form) by the new device
|
||||
Uri string `json:"uri,omitempty" yaml:"uri,omitempty"` // the sgnl://linkdevice uri provided (typically in qr code form) by the new device
|
||||
}
|
||||
|
||||
// AddServerRequest: add a new server to connect to. Returns the new server's UUID.
|
||||
|
@ -61,6 +63,24 @@ type ApproveMembershipRequest struct {
|
|||
Members []*JsonAddress `json:"members,omitempty" yaml:"members,omitempty"` // list of requesting members to approve
|
||||
}
|
||||
|
||||
// BanUserRequest: Bans users from a group. This works even if the users aren't in the group. If they are currently in the group, they will also be removed.
|
||||
type BanUserRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to interact with
|
||||
GroupId string `json:"group_id,omitempty" yaml:"group_id,omitempty"`
|
||||
Users []*JsonAddress `json:"users,omitempty" yaml:"users,omitempty"` // List of users to ban
|
||||
}
|
||||
|
||||
type BannedGroupMember struct {
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"` // Timestamp as milliseconds since Unix epoch of when the user was banned. This field is set by the server.
|
||||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
||||
}
|
||||
|
||||
// BooleanMessage: A message containing a single boolean, usually as a response
|
||||
type BooleanMessage struct {
|
||||
Value bool `json:"value,omitempty" yaml:"value,omitempty"`
|
||||
}
|
||||
|
||||
type BusyMessage struct {
|
||||
ID int64 `json:"id,omitempty" yaml:"id,omitempty"`
|
||||
}
|
||||
|
@ -76,13 +96,18 @@ type CallMessage struct {
|
|||
}
|
||||
|
||||
type Capabilities struct {
|
||||
Gv1Migration bool `json:"gv1-migration,omitempty" yaml:"gv1-migration,omitempty"`
|
||||
Gv2 bool `json:"gv2,omitempty" yaml:"gv2,omitempty"`
|
||||
Storage bool `json:"storage,omitempty" yaml:"storage,omitempty"`
|
||||
AnnouncementGroup bool `json:"announcement_group,omitempty" yaml:"announcement_group,omitempty"`
|
||||
ChangeNumber bool `json:"change_number,omitempty" yaml:"change_number,omitempty"`
|
||||
Gv1Migration bool `json:"gv1-migration,omitempty" yaml:"gv1-migration,omitempty"`
|
||||
Gv2 bool `json:"gv2,omitempty" yaml:"gv2,omitempty"` // this capability is deprecated and will always be true
|
||||
SenderKey bool `json:"sender_key,omitempty" yaml:"sender_key,omitempty"`
|
||||
Storage bool `json:"storage,omitempty" yaml:"storage,omitempty"`
|
||||
Stories bool `json:"stories,omitempty" yaml:"stories,omitempty"`
|
||||
}
|
||||
|
||||
// ClientMessageWrapper: Wraps all incoming messages after a v1 subscribe request is issued
|
||||
// ClientMessageWrapper: Wraps all incoming messages sent to the client after a v1 subscribe request is issued
|
||||
type ClientMessageWrapper struct {
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // the account this message is from
|
||||
Data interface{} `json:"data,omitempty" yaml:"data,omitempty"` // the incoming object. The structure will vary from message to message, see `type` and `version` fields
|
||||
Error bool `json:"error,omitempty" yaml:"error,omitempty"` // true if the incoming message represents an error
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"` // the type of object to expect in the `data` field
|
||||
|
@ -113,10 +138,11 @@ type DeviceInfo struct {
|
|||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
}
|
||||
|
||||
// FinishLinkRequest: After a linking URI has been requested, finish_link must be called with the session_id provided with the URI. it will return information about the new account once the linking process is completed by the other device.
|
||||
// FinishLinkRequest: After a linking URI has been requested, finish_link must be called with the session_id provided with the URI. it will return information about the new account once the linking process is completed by the other device and the new account is setup. Note that the account setup process can sometimes take some time, if rapid userfeedback is required after scanning, use wait_for_scan first, then finish setup with finish_link.
|
||||
type FinishLinkRequest struct {
|
||||
Request
|
||||
DeviceName string `json:"device_name,omitempty" yaml:"device_name,omitempty"`
|
||||
Overwrite bool `json:"overwrite,omitempty" yaml:"overwrite,omitempty"` // overwrite existing account data if the phone number conflicts. false by default
|
||||
SessionId string `json:"session_id,omitempty" yaml:"session_id,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -132,7 +158,7 @@ type GetAllIdentities struct {
|
|||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to interact with
|
||||
}
|
||||
|
||||
// GetGroupRequest: Query the server for the latest state of a known group. If no account in signald is a member of the group (anymore), an error with error_type: 'UnknownGroupException' is returned.
|
||||
// GetGroupRequest: Query the server for the latest state of a known group. If the account is not a member of the group, an UnknownGroupError is returned.
|
||||
type GetGroupRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to interact with
|
||||
|
@ -140,6 +166,15 @@ type GetGroupRequest struct {
|
|||
Revision int32 `json:"revision,omitempty" yaml:"revision,omitempty"` // the latest known revision, default value (-1) forces fetch from server
|
||||
}
|
||||
|
||||
// GetGroupRevisionPagesRequest: Query the server for group revision history. The history contains information about the changes between each revision and the user that made the change.
|
||||
type GetGroupRevisionPagesRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to interact with
|
||||
FromRevision int32 `json:"from_revision,omitempty" yaml:"from_revision,omitempty"` // The revision to start the pages from. Note that if this is lower than the revision you joined the group, an AuthorizationFailedError is returned.
|
||||
GroupId string `json:"group_id,omitempty" yaml:"group_id,omitempty"`
|
||||
IncludeFirstRevision bool `json:"include_first_revision,omitempty" yaml:"include_first_revision,omitempty"` // Whether to include the first state in the returned pages (default false)
|
||||
}
|
||||
|
||||
// GetIdentitiesRequest: Get information about a known keys for a particular address
|
||||
type GetIdentitiesRequest struct {
|
||||
Request
|
||||
|
@ -165,6 +200,11 @@ type GetServersRequest struct {
|
|||
Request
|
||||
}
|
||||
|
||||
type Gradient struct {
|
||||
EndColor string `json:"end_color,omitempty" yaml:"end_color,omitempty"`
|
||||
StartColor string `json:"start_color,omitempty" yaml:"start_color,omitempty"`
|
||||
}
|
||||
|
||||
// GroupAccessControl: group access control settings. Options for each controlled action are: UNKNOWN, ANY, MEMBER, ADMINISTRATOR, UNSATISFIABLE and UNRECOGNIZED
|
||||
type GroupAccessControl struct {
|
||||
Attributes string `json:"attributes,omitempty" yaml:"attributes,omitempty"` // who can edit group info
|
||||
|
@ -172,6 +212,42 @@ type GroupAccessControl struct {
|
|||
Members string `json:"members,omitempty" yaml:"members,omitempty"` // who can add members
|
||||
}
|
||||
|
||||
// GroupChange: Represents a group change made by a user. This can also represent request link invites. Only the fields relevant to the group change performed will be set. Note that in signald, group changes are currently only received from incoming messages from a message subscription.
|
||||
type GroupChange struct {
|
||||
DeleteMembers []*JsonAddress `json:"delete_members,omitempty" yaml:"delete_members,omitempty"` // Represents users that have been removed from the group. This can be from admins removing users, or users choosing to leave the group
|
||||
DeletePendingMembers []*JsonAddress `json:"delete_pending_members,omitempty" yaml:"delete_pending_members,omitempty"`
|
||||
DeleteRequestingMembers []*JsonAddress `json:"delete_requesting_members,omitempty" yaml:"delete_requesting_members,omitempty"`
|
||||
Editor *JsonAddress `json:"editor,omitempty" yaml:"editor,omitempty"` // The user that made the change.
|
||||
ModifiedProfileKeys []*GroupMember `json:"modified_profile_keys,omitempty" yaml:"modified_profile_keys,omitempty"` // Represents users that have rotated their profile key. Note that signald currently does not expose profile keys to clients. The joined revision property will always be 0 in this list.
|
||||
ModifyMemberRoles []*GroupMember `json:"modify_member_roles,omitempty" yaml:"modify_member_roles,omitempty"` // Represents users with their new, modified role.
|
||||
NewAccessControl *GroupAccessControl `json:"new_access_control,omitempty" yaml:"new_access_control,omitempty"` // If not null, then this group change modified one of the access controls. Some of the properties in here will be null.
|
||||
NewAvatar bool `json:"new_avatar,omitempty" yaml:"new_avatar,omitempty"` // Whether this group change changed the avatar.
|
||||
NewBannedMembers []*BannedGroupMember `json:"new_banned_members,omitempty" yaml:"new_banned_members,omitempty"`
|
||||
NewDescription string `json:"new_description,omitempty" yaml:"new_description,omitempty"`
|
||||
NewInviteLinkPassword bool `json:"new_invite_link_password,omitempty" yaml:"new_invite_link_password,omitempty"` // Whether this group change involved resetting the group invite link.
|
||||
NewIsAnnouncementGroup string `json:"new_is_announcement_group,omitempty" yaml:"new_is_announcement_group,omitempty"` // Whether this change affected the announcement group setting. Possible values are UNKNOWN, ENABLED or DISABLED
|
||||
NewMembers []*GroupMember `json:"new_members,omitempty" yaml:"new_members,omitempty"` // Represents users have been added to the group. This can be from group members adding users, or a users joining via a group link that required no approval.
|
||||
NewPendingMembers []*GroupPendingMember `json:"new_pending_members,omitempty" yaml:"new_pending_members,omitempty"` // Represents a user that has been invited to the group by another user.
|
||||
NewRequestingMembers []*GroupRequestingMember `json:"new_requesting_members,omitempty" yaml:"new_requesting_members,omitempty"` // Represents users that have requested to join the group via the group link. Note that members requesting to join might not necessarily have the list of users in the group, so they won't be able to send a peer-to-peer group update message to inform users of their request to join. Other users in the group may inform us that the revision has increased, but the members requesting access will have to be obtained from the server instead (which signald will handle). For now, a get_group request has to be made to get the users that have requested to join the group.
|
||||
NewTimer int32 `json:"new_timer,omitempty" yaml:"new_timer,omitempty"` // New disappearing messages timer value.
|
||||
NewTitle string `json:"new_title,omitempty" yaml:"new_title,omitempty"`
|
||||
NewUnbannedMembers []*BannedGroupMember `json:"new_unbanned_members,omitempty" yaml:"new_unbanned_members,omitempty"`
|
||||
PromotePendingMembers []*GroupMember `json:"promote_pending_members,omitempty" yaml:"promote_pending_members,omitempty"`
|
||||
PromoteRequestingMembers []*GroupMember `json:"promote_requesting_members,omitempty" yaml:"promote_requesting_members,omitempty"`
|
||||
Revision int32 `json:"revision,omitempty" yaml:"revision,omitempty"` // The group revision that this change brings the group to.
|
||||
}
|
||||
|
||||
type GroupHistoryEntry struct {
|
||||
Change *GroupChange `json:"change,omitempty" yaml:"change,omitempty"`
|
||||
Group *JsonGroupV2Info `json:"group,omitempty" yaml:"group,omitempty"`
|
||||
}
|
||||
|
||||
// GroupHistoryPage: The result of fetching a group's history along with paging data.
|
||||
type GroupHistoryPage struct {
|
||||
PagingData *PagingData `json:"paging_data,omitempty" yaml:"paging_data,omitempty"`
|
||||
Results []*GroupHistoryEntry `json:"results,omitempty" yaml:"results,omitempty"`
|
||||
}
|
||||
|
||||
// GroupInfo: A generic type that is used when the group version is not known
|
||||
type GroupInfo struct {
|
||||
V1 *JsonGroupInfo `json:"v1,omitempty" yaml:"v1,omitempty"`
|
||||
|
@ -187,7 +263,7 @@ type GroupLinkInfoRequest struct {
|
|||
|
||||
type GroupList struct {
|
||||
Groups []*JsonGroupV2Info `json:"groups,omitempty" yaml:"groups,omitempty"`
|
||||
LegacyGroups []*JsonGroupInfo `json:"legacyGroups,omitempty" yaml:"legacyGroups,omitempty"`
|
||||
LegacyGroups []*JsonGroupInfo `json:"legacyGroups,omitempty" yaml:"legacyGroups,omitempty"` // list of legacy (v1) groups, no longer supported (will always be empty)
|
||||
}
|
||||
|
||||
type GroupMember struct {
|
||||
|
@ -196,6 +272,18 @@ type GroupMember struct {
|
|||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
||||
}
|
||||
|
||||
type GroupPendingMember struct {
|
||||
AddedByUuid string `json:"added_by_uuid,omitempty" yaml:"added_by_uuid,omitempty"`
|
||||
Role string `json:"role,omitempty" yaml:"role,omitempty"` // possible values are: UNKNOWN, DEFAULT, ADMINISTRATOR and UNRECOGNIZED
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
||||
}
|
||||
|
||||
type GroupRequestingMember struct {
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
||||
}
|
||||
|
||||
type HangupMessage struct {
|
||||
DeviceId int32 `json:"device_id,omitempty" yaml:"device_id,omitempty"`
|
||||
ID int64 `json:"id,omitempty" yaml:"id,omitempty"`
|
||||
|
@ -234,6 +322,7 @@ type IncomingMessage struct {
|
|||
ServerReceiverTimestamp int64 `json:"server_receiver_timestamp,omitempty" yaml:"server_receiver_timestamp,omitempty"`
|
||||
Source *JsonAddress `json:"source,omitempty" yaml:"source,omitempty"`
|
||||
SourceDevice int32 `json:"source_device,omitempty" yaml:"source_device,omitempty"`
|
||||
StoryMessage *StoryMessage `json:"story_message,omitempty" yaml:"story_message,omitempty"`
|
||||
SyncMessage *JsonSyncMessage `json:"sync_message,omitempty" yaml:"sync_message,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
||||
|
@ -241,6 +330,13 @@ type IncomingMessage struct {
|
|||
UnidentifiedSender bool `json:"unidentified_sender,omitempty" yaml:"unidentified_sender,omitempty"`
|
||||
}
|
||||
|
||||
// IsIdentifierRegisteredRequest: Determine whether an account identifier is registered on the Signal service.
|
||||
type IsIdentifierRegisteredRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to use to use
|
||||
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` // The UUID of an identifier to check if it is registered on Signal. This UUID is either a Phone Number Identity (PNI) or an Account Identity (ACI).
|
||||
}
|
||||
|
||||
// JoinGroupRequest: Join a group using the a signal.group URL. Note that you must have a profile name set to join groups.
|
||||
type JoinGroupRequest struct {
|
||||
Request
|
||||
|
@ -254,30 +350,49 @@ type JsonAddress struct {
|
|||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"` // A UUID, the unique identifier for a particular Signal account.
|
||||
}
|
||||
|
||||
// JsonAttachment: represents a file attached to a message. When sending, only `filename` is required.
|
||||
type JsonAttachment struct {
|
||||
Blurhash string `json:"blurhash,omitempty" yaml:"blurhash,omitempty"`
|
||||
Caption string `json:"caption,omitempty" yaml:"caption,omitempty"`
|
||||
ContentType string `json:"contentType,omitempty" yaml:"contentType,omitempty"`
|
||||
CustomFilename string `json:"customFilename,omitempty" yaml:"customFilename,omitempty"` // the original name of the file
|
||||
Digest string `json:"digest,omitempty" yaml:"digest,omitempty"`
|
||||
Filename string `json:"filename,omitempty" yaml:"filename,omitempty"` // when sending, the path to the local file to upload
|
||||
Height int32 `json:"height,omitempty" yaml:"height,omitempty"`
|
||||
ID string `json:"id,omitempty" yaml:"id,omitempty"`
|
||||
Key string `json:"key,omitempty" yaml:"key,omitempty"`
|
||||
Size int32 `json:"size,omitempty" yaml:"size,omitempty"`
|
||||
StoredFilename string `json:"storedFilename,omitempty" yaml:"storedFilename,omitempty"` // when receiving, the path that file has been downloaded to
|
||||
VoiceNote bool `json:"voiceNote,omitempty" yaml:"voiceNote,omitempty"`
|
||||
Width int32 `json:"width,omitempty" yaml:"width,omitempty"`
|
||||
}
|
||||
|
||||
type JsonBlockedListMessage struct {
|
||||
Addresses []*JsonAddress `json:"addresses,omitempty" yaml:"addresses,omitempty"`
|
||||
GroupIds []string `json:"groupIds,omitempty" yaml:"groupIds,omitempty"`
|
||||
}
|
||||
|
||||
type JsonDataMessage struct {
|
||||
Attachments []*v0.JsonAttachment `json:"attachments,omitempty" yaml:"attachments,omitempty"` // files attached to the incoming message
|
||||
Body string `json:"body,omitempty" yaml:"body,omitempty"` // the text body of the incoming message.
|
||||
Contacts []*v0.SharedContact `json:"contacts,omitempty" yaml:"contacts,omitempty"` // if the incoming message has a shared contact, the contact's information will be here
|
||||
EndSession bool `json:"endSession,omitempty" yaml:"endSession,omitempty"`
|
||||
ExpiresInSeconds int32 `json:"expiresInSeconds,omitempty" yaml:"expiresInSeconds,omitempty"` // the expiry timer on the incoming message. Clients should delete records of the message within this number of seconds
|
||||
Group *JsonGroupInfo `json:"group,omitempty" yaml:"group,omitempty"` // if the incoming message was sent to a v1 group, information about that group will be here
|
||||
GroupV2 *JsonGroupV2Info `json:"groupV2,omitempty" yaml:"groupV2,omitempty"` // if the incoming message was sent to a v2 group, basic identifying information about that group will be here. If group information changes, JsonGroupV2Info.revision is incremented. If the group revision is higher than previously seen, a client can retrieve the group information by calling get_group.
|
||||
GroupCallUpdate string `json:"group_call_update,omitempty" yaml:"group_call_update,omitempty"` // the eraId string from a group call message update
|
||||
Mentions []*JsonMention `json:"mentions,omitempty" yaml:"mentions,omitempty"` // list of mentions in the message
|
||||
Payment *Payment `json:"payment,omitempty" yaml:"payment,omitempty"` // details about the MobileCoin payment attached to the message, if present
|
||||
Previews []*v0.JsonPreview `json:"previews,omitempty" yaml:"previews,omitempty"` // if the incoming message has a link preview, information about that preview will be here
|
||||
ProfileKeyUpdate bool `json:"profileKeyUpdate,omitempty" yaml:"profileKeyUpdate,omitempty"`
|
||||
Quote *JsonQuote `json:"quote,omitempty" yaml:"quote,omitempty"` // if the incoming message is a quote or reply to another message, this will contain information about that message
|
||||
Reaction *JsonReaction `json:"reaction,omitempty" yaml:"reaction,omitempty"` // if the message adds or removes a reaction to another message, this will indicate what change is being made
|
||||
RemoteDelete *RemoteDelete `json:"remoteDelete,omitempty" yaml:"remoteDelete,omitempty"` // if the inbound message is deleting a previously sent message, indicates which message should be deleted
|
||||
Sticker *v0.JsonSticker `json:"sticker,omitempty" yaml:"sticker,omitempty"` // if the incoming message is a sticker, information about the sicker will be here
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"` // the timestamp that the message was sent at, according to the sender's device. This is used to uniquely identify this message for things like reactions and quotes.
|
||||
ViewOnce bool `json:"viewOnce,omitempty" yaml:"viewOnce,omitempty"` // indicates the message is a view once message. View once messages typically include no body and a single image attachment. Official Signal clients will prevent the user from saving the image, and once the user has viewed the image once they will destroy the image.
|
||||
Attachments []*JsonAttachment `json:"attachments,omitempty" yaml:"attachments,omitempty"` // files attached to the incoming message
|
||||
Body string `json:"body,omitempty" yaml:"body,omitempty"` // the text body of the incoming message.
|
||||
Contacts []*SharedContact `json:"contacts,omitempty" yaml:"contacts,omitempty"` // if the incoming message has a shared contact, the contact's information will be here
|
||||
EndSession bool `json:"endSession,omitempty" yaml:"endSession,omitempty"`
|
||||
ExpiresInSeconds int32 `json:"expiresInSeconds,omitempty" yaml:"expiresInSeconds,omitempty"` // the expiry timer on the incoming message. Clients should delete records of the message within this number of seconds
|
||||
Group *JsonGroupInfo `json:"group,omitempty" yaml:"group,omitempty"` // if the incoming message was sent to a v1 group, information about that group will be here
|
||||
GroupV2 *JsonGroupV2Info `json:"groupV2,omitempty" yaml:"groupV2,omitempty"` // if the incoming message was sent to a v2 group, basic identifying information about that group will be here. If group information changes, JsonGroupV2Info.revision is incremented. If the group revision is higher than previously seen, a client can retrieve the group information by calling get_group.
|
||||
GroupCallUpdate string `json:"group_call_update,omitempty" yaml:"group_call_update,omitempty"` // the eraId string from a group call message update
|
||||
IsExpirationUpdate bool `json:"is_expiration_update,omitempty" yaml:"is_expiration_update,omitempty"` // whether or not this message changes the expiresInSeconds value for the whole chat. Some messages (remote deletes, reactions, etc) will have expiresInSeconds=0 even though the chat has disappearing messages enabled.
|
||||
Mentions []*JsonMention `json:"mentions,omitempty" yaml:"mentions,omitempty"` // list of mentions in the message
|
||||
Payment *Payment `json:"payment,omitempty" yaml:"payment,omitempty"` // details about the MobileCoin payment attached to the message, if present
|
||||
Previews []*JsonPreview `json:"previews,omitempty" yaml:"previews,omitempty"` // if the incoming message has a link preview, information about that preview will be here
|
||||
ProfileKeyUpdate bool `json:"profileKeyUpdate,omitempty" yaml:"profileKeyUpdate,omitempty"`
|
||||
Quote *JsonQuote `json:"quote,omitempty" yaml:"quote,omitempty"` // if the incoming message is a quote or reply to another message, this will contain information about that message
|
||||
Reaction *JsonReaction `json:"reaction,omitempty" yaml:"reaction,omitempty"` // if the message adds or removes a reaction to another message, this will indicate what change is being made
|
||||
RemoteDelete *RemoteDelete `json:"remoteDelete,omitempty" yaml:"remoteDelete,omitempty"` // if the inbound message is deleting a previously sent message, indicates which message should be deleted
|
||||
Sticker *v0.JsonSticker `json:"sticker,omitempty" yaml:"sticker,omitempty"` // if the incoming message is a sticker, information about the sicker will be here
|
||||
StoryContext *StoryContext `json:"story_context,omitempty" yaml:"story_context,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"` // the timestamp that the message was sent at, according to the sender's device. This is used to uniquely identify this message for things like reactions and quotes.
|
||||
ViewOnce bool `json:"viewOnce,omitempty" yaml:"viewOnce,omitempty"` // indicates the message is a view once message. View once messages typically include no body and a single image attachment. Official Signal clients will prevent the user from saving the image, and once the user has viewed the image once they will destroy the image.
|
||||
}
|
||||
|
||||
// JsonGroupInfo: information about a legacy group
|
||||
|
@ -301,19 +416,23 @@ type JsonGroupJoinInfo struct {
|
|||
|
||||
// JsonGroupV2Info: Information about a Signal group
|
||||
type JsonGroupV2Info struct {
|
||||
AccessControl *GroupAccessControl `json:"accessControl,omitempty" yaml:"accessControl,omitempty"` // current access control settings for this group
|
||||
Avatar string `json:"avatar,omitempty" yaml:"avatar,omitempty"` // path to the group's avatar on local disk, if available
|
||||
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
||||
ID string `json:"id,omitempty" yaml:"id,omitempty"`
|
||||
InviteLink string `json:"inviteLink,omitempty" yaml:"inviteLink,omitempty"` // the signal.group link, if applicable
|
||||
MemberDetail []*GroupMember `json:"memberDetail,omitempty" yaml:"memberDetail,omitempty"` // detailed member list
|
||||
Members []*JsonAddress `json:"members,omitempty" yaml:"members,omitempty"`
|
||||
PendingMemberDetail []*GroupMember `json:"pendingMemberDetail,omitempty" yaml:"pendingMemberDetail,omitempty"` // detailed pending member list
|
||||
PendingMembers []*JsonAddress `json:"pendingMembers,omitempty" yaml:"pendingMembers,omitempty"`
|
||||
RequestingMembers []*JsonAddress `json:"requestingMembers,omitempty" yaml:"requestingMembers,omitempty"`
|
||||
Revision int32 `json:"revision,omitempty" yaml:"revision,omitempty"`
|
||||
Timer int32 `json:"timer,omitempty" yaml:"timer,omitempty"`
|
||||
Title string `json:"title,omitempty" yaml:"title,omitempty"`
|
||||
AccessControl *GroupAccessControl `json:"accessControl,omitempty" yaml:"accessControl,omitempty"` // current access control settings for this group
|
||||
Announcements string `json:"announcements,omitempty" yaml:"announcements,omitempty"` // indicates if the group is an announcements group. Only admins are allowed to send messages to announcements groups. Options are UNKNOWN, ENABLED or DISABLED
|
||||
Avatar string `json:"avatar,omitempty" yaml:"avatar,omitempty"` // path to the group's avatar on local disk, if available
|
||||
BannedMembers []*BannedGroupMember `json:"banned_members,omitempty" yaml:"banned_members,omitempty"`
|
||||
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
||||
GroupChange *GroupChange `json:"group_change,omitempty" yaml:"group_change,omitempty"` // Represents a peer-to-peer group change done by a user. Will not be set if the group change signature fails verification. This is usually only set inside of incoming messages.
|
||||
ID string `json:"id,omitempty" yaml:"id,omitempty"`
|
||||
InviteLink string `json:"inviteLink,omitempty" yaml:"inviteLink,omitempty"` // the signal.group link, if applicable
|
||||
MemberDetail []*GroupMember `json:"memberDetail,omitempty" yaml:"memberDetail,omitempty"` // detailed member list
|
||||
Members []*JsonAddress `json:"members,omitempty" yaml:"members,omitempty"`
|
||||
PendingMemberDetail []*GroupMember `json:"pendingMemberDetail,omitempty" yaml:"pendingMemberDetail,omitempty"` // detailed pending member list
|
||||
PendingMembers []*JsonAddress `json:"pendingMembers,omitempty" yaml:"pendingMembers,omitempty"`
|
||||
Removed bool `json:"removed,omitempty" yaml:"removed,omitempty"` // will be set to true for incoming messages to indicate the user has been removed from the group
|
||||
RequestingMembers []*JsonAddress `json:"requestingMembers,omitempty" yaml:"requestingMembers,omitempty"`
|
||||
Revision int32 `json:"revision,omitempty" yaml:"revision,omitempty"`
|
||||
Timer int32 `json:"timer,omitempty" yaml:"timer,omitempty"`
|
||||
Title string `json:"title,omitempty" yaml:"title,omitempty"`
|
||||
}
|
||||
|
||||
type JsonMention struct {
|
||||
|
@ -322,31 +441,20 @@ type JsonMention struct {
|
|||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"` // The UUID of the account being mentioned
|
||||
}
|
||||
|
||||
type JsonMessageEnvelope struct {
|
||||
CallMessage *v0.JsonCallMessage `json:"callMessage,omitempty" yaml:"callMessage,omitempty"`
|
||||
DataMessage *JsonDataMessage `json:"dataMessage,omitempty" yaml:"dataMessage,omitempty"`
|
||||
HasContent bool `json:"hasContent,omitempty" yaml:"hasContent,omitempty"`
|
||||
HasLegacyMessage bool `json:"hasLegacyMessage,omitempty" yaml:"hasLegacyMessage,omitempty"`
|
||||
IsUnidentifiedSender bool `json:"isUnidentifiedSender,omitempty" yaml:"isUnidentifiedSender,omitempty"`
|
||||
Receipt *v0.JsonReceiptMessage `json:"receipt,omitempty" yaml:"receipt,omitempty"`
|
||||
Relay string `json:"relay,omitempty" yaml:"relay,omitempty"`
|
||||
ServerDeliveredTimestamp int64 `json:"serverDeliveredTimestamp,omitempty" yaml:"serverDeliveredTimestamp,omitempty"`
|
||||
ServerTimestamp int64 `json:"serverTimestamp,omitempty" yaml:"serverTimestamp,omitempty"`
|
||||
Source *JsonAddress `json:"source,omitempty" yaml:"source,omitempty"`
|
||||
SourceDevice int32 `json:"sourceDevice,omitempty" yaml:"sourceDevice,omitempty"`
|
||||
SyncMessage *JsonSyncMessage `json:"syncMessage,omitempty" yaml:"syncMessage,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
TimestampISO string `json:"timestampISO,omitempty" yaml:"timestampISO,omitempty"`
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
||||
Typing *v0.JsonTypingMessage `json:"typing,omitempty" yaml:"typing,omitempty"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty"`
|
||||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
||||
}
|
||||
|
||||
// JsonMessageRequestResponseMessage: Responses to message requests from unknown users or groups
|
||||
type JsonMessageRequestResponseMessage struct {
|
||||
GroupId string `json:"groupId,omitempty" yaml:"groupId,omitempty"`
|
||||
Person *JsonAddress `json:"person,omitempty" yaml:"person,omitempty"`
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"` // One of UNKNOWN, ACCEPT, DELETE, BLOCK, BLOCK_AND_DELETE, UNBLOCK_AND_ACCEPT
|
||||
}
|
||||
|
||||
// JsonPreview: metadata about one of the links in a message
|
||||
type JsonPreview struct {
|
||||
Attachment *JsonAttachment `json:"attachment,omitempty" yaml:"attachment,omitempty"` // an optional image file attached to the preview
|
||||
Date int64 `json:"date,omitempty" yaml:"date,omitempty"`
|
||||
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
||||
Title string `json:"title,omitempty" yaml:"title,omitempty"`
|
||||
Url string `json:"url,omitempty" yaml:"url,omitempty"`
|
||||
}
|
||||
|
||||
// JsonQuote: A quote is a reply to a previous message. ID is the sent time of the message being replied to
|
||||
|
@ -371,11 +479,12 @@ type JsonReadMessage struct {
|
|||
}
|
||||
|
||||
type JsonSendMessageResult struct {
|
||||
Address *JsonAddress `json:"address,omitempty" yaml:"address,omitempty"`
|
||||
IdentityFailure string `json:"identityFailure,omitempty" yaml:"identityFailure,omitempty"`
|
||||
NetworkFailure bool `json:"networkFailure,omitempty" yaml:"networkFailure,omitempty"`
|
||||
Success *v0.Success `json:"success,omitempty" yaml:"success,omitempty"`
|
||||
UnregisteredFailure bool `json:"unregisteredFailure,omitempty" yaml:"unregisteredFailure,omitempty"`
|
||||
Address *JsonAddress `json:"address,omitempty" yaml:"address,omitempty"`
|
||||
IdentityFailure string `json:"identityFailure,omitempty" yaml:"identityFailure,omitempty"`
|
||||
NetworkFailure bool `json:"networkFailure,omitempty" yaml:"networkFailure,omitempty"`
|
||||
ProofRequiredFailure *ProofRequiredError `json:"proof_required_failure,omitempty" yaml:"proof_required_failure,omitempty"`
|
||||
Success *SendSuccess `json:"success,omitempty" yaml:"success,omitempty"`
|
||||
UnregisteredFailure bool `json:"unregisteredFailure,omitempty" yaml:"unregisteredFailure,omitempty"`
|
||||
}
|
||||
|
||||
type JsonSentTranscriptMessage struct {
|
||||
|
@ -383,6 +492,7 @@ type JsonSentTranscriptMessage struct {
|
|||
ExpirationStartTimestamp int64 `json:"expirationStartTimestamp,omitempty" yaml:"expirationStartTimestamp,omitempty"`
|
||||
IsRecipientUpdate bool `json:"isRecipientUpdate,omitempty" yaml:"isRecipientUpdate,omitempty"`
|
||||
Message *JsonDataMessage `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
Story *StoryMessage `json:"story,omitempty" yaml:"story,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
UnidentifiedStatus map[string]string `json:"unidentifiedStatus,omitempty" yaml:"unidentifiedStatus,omitempty"`
|
||||
}
|
||||
|
@ -390,10 +500,10 @@ type JsonSentTranscriptMessage struct {
|
|||
type JsonSyncMessage struct {
|
||||
BlockedList *JsonBlockedListMessage `json:"blockedList,omitempty" yaml:"blockedList,omitempty"`
|
||||
Configuration *v0.ConfigurationMessage `json:"configuration,omitempty" yaml:"configuration,omitempty"`
|
||||
Contacts *v0.JsonAttachment `json:"contacts,omitempty" yaml:"contacts,omitempty"`
|
||||
Contacts *JsonAttachment `json:"contacts,omitempty" yaml:"contacts,omitempty"`
|
||||
ContactsComplete bool `json:"contactsComplete,omitempty" yaml:"contactsComplete,omitempty"`
|
||||
FetchType string `json:"fetchType,omitempty" yaml:"fetchType,omitempty"`
|
||||
Groups *v0.JsonAttachment `json:"groups,omitempty" yaml:"groups,omitempty"`
|
||||
Groups *JsonAttachment `json:"groups,omitempty" yaml:"groups,omitempty"`
|
||||
MessageRequestResponse *JsonMessageRequestResponseMessage `json:"messageRequestResponse,omitempty" yaml:"messageRequestResponse,omitempty"`
|
||||
ReadMessages []*JsonReadMessage `json:"readMessages,omitempty" yaml:"readMessages,omitempty"`
|
||||
Request string `json:"request,omitempty" yaml:"request,omitempty"`
|
||||
|
@ -453,7 +563,7 @@ type ListGroupsRequest struct {
|
|||
Account string `json:"account,omitempty" yaml:"account,omitempty"`
|
||||
}
|
||||
|
||||
// ListenerState: indicates when the incoming connection to the signal server has started or stopped
|
||||
// ListenerState: prior attempt to indicate signald connectivity state. WebSocketConnectionState messages will be delivered at the same time as well as in other parts of the websocket lifecycle.
|
||||
type ListenerState struct {
|
||||
Connected bool `json:"connected,omitempty" yaml:"connected,omitempty"`
|
||||
}
|
||||
|
@ -473,6 +583,11 @@ type OfferMessage struct {
|
|||
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
||||
}
|
||||
|
||||
type PagingData struct {
|
||||
HasMorePages bool `json:"has_more_pages,omitempty" yaml:"has_more_pages,omitempty"`
|
||||
NextPageRevision int32 `json:"next_page_revision,omitempty" yaml:"next_page_revision,omitempty"`
|
||||
}
|
||||
|
||||
// Payment: details about a MobileCoin payment
|
||||
type Payment struct {
|
||||
Note string `json:"note,omitempty" yaml:"note,omitempty"` // note attached to the payment
|
||||
|
@ -485,13 +600,15 @@ type Profile struct {
|
|||
Address *JsonAddress `json:"address,omitempty" yaml:"address,omitempty"`
|
||||
Avatar string `json:"avatar,omitempty" yaml:"avatar,omitempty"` // path to avatar on local disk
|
||||
Capabilities *Capabilities `json:"capabilities,omitempty" yaml:"capabilities,omitempty"`
|
||||
Color string `json:"color,omitempty" yaml:"color,omitempty"` // color of the chat with this user
|
||||
Color string `json:"color,omitempty" yaml:"color,omitempty"` // color of the chat with this user
|
||||
ContactName string `json:"contact_name,omitempty" yaml:"contact_name,omitempty"` // The user's name from local contact names
|
||||
Emoji string `json:"emoji,omitempty" yaml:"emoji,omitempty"`
|
||||
ExpirationTime int32 `json:"expiration_time,omitempty" yaml:"expiration_time,omitempty"`
|
||||
InboxPosition int32 `json:"inbox_position,omitempty" yaml:"inbox_position,omitempty"`
|
||||
MobilecoinAddress string `json:"mobilecoin_address,omitempty" yaml:"mobilecoin_address,omitempty"` // *base64-encoded* mobilecoin address. Note that this is not the traditional MobileCoin address encoding. Clients are responsible for converting between MobileCoin's custom base58 on the user-facing side and base64 encoding on the signald side. If unset, null or an empty string, will empty the profile payment address
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"` // The user's name from local contact names if available, or if not in contact list their Signal profile name
|
||||
ProfileName string `json:"profile_name,omitempty" yaml:"profile_name,omitempty"` // The user's Signal profile name
|
||||
VisibleBadgeIds []string `json:"visible_badge_ids,omitempty" yaml:"visible_badge_ids,omitempty"` // currently unclear how these work, as they are not available in the production Signal apps
|
||||
}
|
||||
|
||||
type ProfileList struct {
|
||||
|
@ -501,11 +618,12 @@ type ProfileList struct {
|
|||
// ReactRequest: react to a previous message
|
||||
type ReactRequest struct {
|
||||
Request
|
||||
Reaction *JsonReaction `json:"reaction,omitempty" yaml:"reaction,omitempty"`
|
||||
RecipientAddress *JsonAddress `json:"recipientAddress,omitempty" yaml:"recipientAddress,omitempty"`
|
||||
RecipientGroupID string `json:"recipientGroupId,omitempty" yaml:"recipientGroupId,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty"`
|
||||
Members []*JsonAddress `json:"members,omitempty" yaml:"members,omitempty"` // Optionally set to a sub-set of group members. Ignored if recipientGroupId isn't specified
|
||||
Reaction *JsonReaction `json:"reaction,omitempty" yaml:"reaction,omitempty"`
|
||||
RecipientAddress *JsonAddress `json:"recipientAddress,omitempty" yaml:"recipientAddress,omitempty"`
|
||||
RecipientGroupID string `json:"recipientGroupId,omitempty" yaml:"recipientGroupId,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty"`
|
||||
}
|
||||
|
||||
type ReceiptMessage struct {
|
||||
|
@ -514,6 +632,15 @@ type ReceiptMessage struct {
|
|||
When int64 `json:"when,omitempty" yaml:"when,omitempty"`
|
||||
}
|
||||
|
||||
// RefuseMembershipRequest: deny a request to join a group
|
||||
type RefuseMembershipRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to interact with
|
||||
AlsoBan bool `json:"also_ban,omitempty" yaml:"also_ban,omitempty"`
|
||||
GroupId string `json:"group_id,omitempty" yaml:"group_id,omitempty"`
|
||||
Members []*JsonAddress `json:"members,omitempty" yaml:"members,omitempty"` // list of requesting members to refuse
|
||||
}
|
||||
|
||||
// RegisterRequest: begin the account registration process by requesting a phone number verification code. when the code is received, submit it with a verify request
|
||||
type RegisterRequest struct {
|
||||
Request
|
||||
|
@ -546,10 +673,11 @@ type RemoteDelete struct {
|
|||
// RemoteDeleteRequest: delete a message previously sent
|
||||
type RemoteDeleteRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // the account to use
|
||||
Address *JsonAddress `json:"address,omitempty" yaml:"address,omitempty"` // the address to send the delete message to. should match address the message to be deleted was sent to. required if group is not set.
|
||||
Group string `json:"group,omitempty" yaml:"group,omitempty"` // the group to send the delete message to. should match group the message to be deleted was sent to. required if address is not set.
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // the account to use
|
||||
Address *JsonAddress `json:"address,omitempty" yaml:"address,omitempty"` // the address to send the delete message to. should match address the message to be deleted was sent to. required if group is not set.
|
||||
Group string `json:"group,omitempty" yaml:"group,omitempty"` // the group to send the delete message to. should match group the message to be deleted was sent to. required if address is not set.
|
||||
Members []*JsonAddress `json:"members,omitempty" yaml:"members,omitempty"` // Optionally set to a sub-set of group members. Ignored if group isn't specified
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
// RemoveLinkedDeviceRequest: Remove a linked device from the Signal account. Only allowed when the local device id is 1
|
||||
|
@ -572,6 +700,7 @@ type RequestSyncRequest struct {
|
|||
Configuration bool `json:"configuration,omitempty" yaml:"configuration,omitempty"` // request configuration sync (default true)
|
||||
Contacts bool `json:"contacts,omitempty" yaml:"contacts,omitempty"` // request contact sync (default true)
|
||||
Groups bool `json:"groups,omitempty" yaml:"groups,omitempty"` // request group sync (default true)
|
||||
Keys bool `json:"keys,omitempty" yaml:"keys,omitempty"` // request storage service keys
|
||||
}
|
||||
|
||||
// ResetSessionRequest: reset a session with a particular user
|
||||
|
@ -582,7 +711,7 @@ type ResetSessionRequest struct {
|
|||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
// ResolveAddressRequest: Resolve a partial JsonAddress with only a number or UUID to one with both. Anywhere that signald accepts a JsonAddress will except a partial, this is a convenience function for client authors, mostly because signald doesn't resolve all the partials it returns
|
||||
// ResolveAddressRequest: Resolve a partial JsonAddress with only a number or UUID to one with both. Anywhere that signald accepts a JsonAddress will except a partial, this is a convenience function for client authors, mostly because signald doesn't resolve all the partials it returns.
|
||||
type ResolveAddressRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The signal account to use
|
||||
|
@ -600,14 +729,17 @@ type SendPaymentRequest struct {
|
|||
|
||||
type SendRequest struct {
|
||||
Request
|
||||
Attachments []*v0.JsonAttachment `json:"attachments,omitempty" yaml:"attachments,omitempty"`
|
||||
Mentions []*JsonMention `json:"mentions,omitempty" yaml:"mentions,omitempty"`
|
||||
MessageBody string `json:"messageBody,omitempty" yaml:"messageBody,omitempty"`
|
||||
Quote *JsonQuote `json:"quote,omitempty" yaml:"quote,omitempty"`
|
||||
RecipientAddress *JsonAddress `json:"recipientAddress,omitempty" yaml:"recipientAddress,omitempty"`
|
||||
RecipientGroupID string `json:"recipientGroupId,omitempty" yaml:"recipientGroupId,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty"`
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"`
|
||||
Attachments []*JsonAttachment `json:"attachments,omitempty" yaml:"attachments,omitempty"`
|
||||
Members []*JsonAddress `json:"members,omitempty" yaml:"members,omitempty"` // Optionally set to a sub-set of group members. Ignored if recipientGroupId isn't specified
|
||||
Mentions []*JsonMention `json:"mentions,omitempty" yaml:"mentions,omitempty"`
|
||||
MessageBody string `json:"messageBody,omitempty" yaml:"messageBody,omitempty"`
|
||||
Previews []*JsonPreview `json:"previews,omitempty" yaml:"previews,omitempty"`
|
||||
Quote *JsonQuote `json:"quote,omitempty" yaml:"quote,omitempty"`
|
||||
RecipientAddress *JsonAddress `json:"recipientAddress,omitempty" yaml:"recipientAddress,omitempty"`
|
||||
RecipientGroupID string `json:"recipientGroupId,omitempty" yaml:"recipientGroupId,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty"`
|
||||
}
|
||||
|
||||
type SendResponse struct {
|
||||
|
@ -615,18 +747,38 @@ type SendResponse struct {
|
|||
Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
type SendSuccess struct {
|
||||
Devices []int32 `json:"devices,omitempty" yaml:"devices,omitempty"`
|
||||
Duration int64 `json:"duration,omitempty" yaml:"duration,omitempty"`
|
||||
NeedsSync bool `json:"needsSync,omitempty" yaml:"needsSync,omitempty"`
|
||||
Unidentified bool `json:"unidentified,omitempty" yaml:"unidentified,omitempty"`
|
||||
}
|
||||
|
||||
// SendSyncMessageRequest: Sends a sync message to the account's devices
|
||||
type SendSyncMessageRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"`
|
||||
MessageRequestResponse *JsonMessageRequestResponseMessage `json:"message_request_response,omitempty" yaml:"message_request_response,omitempty"` // This can be set to indicate to other devices about a response to an incoming message request from an unknown user or group. Warning: Using the BLOCK and BLOCK_AND_DELETE options relies on other devices to do the blocking, and it does not make you leave the group!
|
||||
ViewOnceOpenMessage *JsonViewOnceOpenMessage `json:"view_once_open_message,omitempty" yaml:"view_once_open_message,omitempty"` // This can be set to indicate to other devices about having viewed a view-once message.
|
||||
}
|
||||
|
||||
// Server: a Signal server
|
||||
type Server struct {
|
||||
Ca string `json:"ca,omitempty" yaml:"ca,omitempty"`
|
||||
Ca string `json:"ca,omitempty" yaml:"ca,omitempty"` // base64 encoded trust store, password must be 'whisper'
|
||||
CdnUrls []*ServerCDN `json:"cdn_urls,omitempty" yaml:"cdn_urls,omitempty"`
|
||||
CdsMrenclave string `json:"cds_mrenclave,omitempty" yaml:"cds_mrenclave,omitempty"`
|
||||
ContactDiscoveryUrl string `json:"contact_discovery_url,omitempty" yaml:"contact_discovery_url,omitempty"`
|
||||
IasCa string `json:"ias_ca,omitempty" yaml:"ias_ca,omitempty"` // base64 encoded trust store, password must be 'whisper'
|
||||
KeyBackupMrenclave string `json:"key_backup_mrenclave,omitempty" yaml:"key_backup_mrenclave,omitempty"`
|
||||
KeyBackupServiceId string `json:"key_backup_service_id,omitempty" yaml:"key_backup_service_id,omitempty"` // base64 encoded
|
||||
KeyBackupServiceName string `json:"key_backup_service_name,omitempty" yaml:"key_backup_service_name,omitempty"`
|
||||
KeyBackupUrl string `json:"key_backup_url,omitempty" yaml:"key_backup_url,omitempty"`
|
||||
Proxy string `json:"proxy,omitempty" yaml:"proxy,omitempty"`
|
||||
ServiceUrl string `json:"service_url,omitempty" yaml:"service_url,omitempty"`
|
||||
StorageUrl string `json:"storage_url,omitempty" yaml:"storage_url,omitempty"`
|
||||
UnidentifiedSenderRoot string `json:"unidentified_sender_root,omitempty" yaml:"unidentified_sender_root,omitempty"`
|
||||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"` // A unique identifier for the server, referenced when adding accounts. Must be a valid UUID. Will be generated if not specified when creating.
|
||||
ZkParam string `json:"zk_param,omitempty" yaml:"zk_param,omitempty"` // base64 encoded ZKGROUP_SERVER_PUBLIC_PARAMS value
|
||||
UnidentifiedSenderRoot string `json:"unidentified_sender_root,omitempty" yaml:"unidentified_sender_root,omitempty"` // base64 encoded
|
||||
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"` // A unique identifier for the server, referenced when adding accounts. Must be a valid UUID. Will be generated if not specified when creating.
|
||||
ZkParam string `json:"zk_param,omitempty" yaml:"zk_param,omitempty"` // base64 encoded ZKGROUP_SERVER_PUBLIC_PARAMS value
|
||||
}
|
||||
|
||||
type ServerCDN struct {
|
||||
|
@ -638,7 +790,7 @@ type ServerList struct {
|
|||
Servers []*Server `json:"servers,omitempty" yaml:"servers,omitempty"`
|
||||
}
|
||||
|
||||
// SetDeviceNameRequest: set this device's name. This will show up on the mobile device on the same account under
|
||||
// SetDeviceNameRequest: set this device's name. This will show up on the mobile device on the same account under settings -> linked devices
|
||||
type SetDeviceNameRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to set the device name of
|
||||
|
@ -656,12 +808,84 @@ type SetExpirationRequest struct {
|
|||
|
||||
type SetProfile struct {
|
||||
Request
|
||||
About string `json:"about,omitempty" yaml:"about,omitempty"` // an optional about string. If unset, null or an empty string will unset profile about field
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The phone number of the account to use
|
||||
AvatarFile string `json:"avatarFile,omitempty" yaml:"avatarFile,omitempty"` // Path to new profile avatar file. If unset or null, unset the profile avatar
|
||||
Emoji string `json:"emoji,omitempty" yaml:"emoji,omitempty"` // an optional single emoji character. If unset, null or an empty string will unset profile emoji
|
||||
MobilecoinAddress string `json:"mobilecoin_address,omitempty" yaml:"mobilecoin_address,omitempty"` // an optional *base64-encoded* MobileCoin address to set in the profile. Note that this is not the traditional MobileCoin address encoding, which is custom. Clients are responsible for converting between MobileCoin's custom base58 on the user-facing side and base64 encoding on the signald side. If unset, null or an empty string, will empty the profile payment address
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"` // New profile name. Set to empty string for no profile name
|
||||
About string `json:"about,omitempty" yaml:"about,omitempty"` // Change the 'about' profile field
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The phone number of the account to use
|
||||
AvatarFile string `json:"avatarFile,omitempty" yaml:"avatarFile,omitempty"` // Path to new profile avatar file. If unset or null, unset the profile avatar
|
||||
Emoji string `json:"emoji,omitempty" yaml:"emoji,omitempty"` // Change the profile emoji
|
||||
MobilecoinAddress string `json:"mobilecoin_address,omitempty" yaml:"mobilecoin_address,omitempty"` // Change the profile payment address. Payment address must be a *base64-encoded* MobileCoin address. Note that this is not the traditional MobileCoin address encoding, which is custom. Clients are responsible for converting between MobileCoin's custom base58 on the user-facing side and base64 encoding on the signald side.
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"` // Change the profile name
|
||||
VisibleBadgeIds []string `json:"visible_badge_ids,omitempty" yaml:"visible_badge_ids,omitempty"` // configure visible badge IDs
|
||||
}
|
||||
|
||||
type SharedContact struct {
|
||||
Address []*SharedContactAddress `json:"address,omitempty" yaml:"address,omitempty"` // the physical addresses of the shared contact
|
||||
Avatar *SharedContactAvatar `json:"avatar,omitempty" yaml:"avatar,omitempty"` // the profile picture/avatar of the shared contact
|
||||
Email []*SharedContactEmail `json:"email,omitempty" yaml:"email,omitempty"` // the email addresses of the shared contact
|
||||
Name *SharedContactName `json:"name,omitempty" yaml:"name,omitempty"` // the name of the shared contact
|
||||
Organization string `json:"organization,omitempty" yaml:"organization,omitempty"` // the organization (e.g. workplace) of the shared contact
|
||||
Phone []*SharedContactPhone `json:"phone,omitempty" yaml:"phone,omitempty"` // the phone numbers of the shared contact
|
||||
}
|
||||
|
||||
type SharedContactAddress struct {
|
||||
City string `json:"city,omitempty" yaml:"city,omitempty"`
|
||||
Country string `json:"country,omitempty" yaml:"country,omitempty"`
|
||||
Label string `json:"label,omitempty" yaml:"label,omitempty"`
|
||||
Neighborhood string `json:"neighborhood,omitempty" yaml:"neighborhood,omitempty"`
|
||||
Pobox string `json:"pobox,omitempty" yaml:"pobox,omitempty"`
|
||||
Postcode string `json:"postcode,omitempty" yaml:"postcode,omitempty"`
|
||||
Region string `json:"region,omitempty" yaml:"region,omitempty"`
|
||||
Street string `json:"street,omitempty" yaml:"street,omitempty"`
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"` // the type of address (options: HOME, WORK, CUSTOM)
|
||||
}
|
||||
|
||||
type SharedContactAvatar struct {
|
||||
Attachment *JsonAttachment `json:"attachment,omitempty" yaml:"attachment,omitempty"`
|
||||
IsProfile bool `json:"is_profile,omitempty" yaml:"is_profile,omitempty"`
|
||||
}
|
||||
|
||||
type SharedContactEmail struct {
|
||||
Label string `json:"label,omitempty" yaml:"label,omitempty"` // the type label when type is CUSTOM
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"` // the type of email (options: HOME, WORK, MOBILE, CUSTOM)
|
||||
Value string `json:"value,omitempty" yaml:"value,omitempty"` // the email address
|
||||
}
|
||||
|
||||
type SharedContactName struct {
|
||||
Display string `json:"display,omitempty" yaml:"display,omitempty"` // the full name that should be displayed
|
||||
Family string `json:"family,omitempty" yaml:"family,omitempty"` // family name (surname)
|
||||
Given string `json:"given,omitempty" yaml:"given,omitempty"` // given name
|
||||
Middle string `json:"middle,omitempty" yaml:"middle,omitempty"` // middle name
|
||||
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
||||
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
||||
}
|
||||
|
||||
type SharedContactPhone struct {
|
||||
Label string `json:"label,omitempty" yaml:"label,omitempty"` // the type label when type is CUSTOM
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"` // the type of phone (options: HOME, WORK, MOBILE, CUSTOM)
|
||||
Value string `json:"value,omitempty" yaml:"value,omitempty"` // the phone number
|
||||
}
|
||||
|
||||
// StorageChange: Broadcast to subscribed clients when there is a state change from the storage service
|
||||
type StorageChange struct {
|
||||
Version int64 `json:"version,omitempty" yaml:"version,omitempty"` // Seems to behave like the group version numbers and increments every time the state changes
|
||||
}
|
||||
|
||||
type StoryContext struct {
|
||||
Author string `json:"author,omitempty" yaml:"author,omitempty"`
|
||||
SentTimestamp int64 `json:"sent_timestamp,omitempty" yaml:"sent_timestamp,omitempty"`
|
||||
}
|
||||
|
||||
type StoryMessage struct {
|
||||
AllowReplies bool `json:"allow_replies,omitempty" yaml:"allow_replies,omitempty"`
|
||||
File *JsonAttachment `json:"file,omitempty" yaml:"file,omitempty"`
|
||||
Group *JsonGroupV2Info `json:"group,omitempty" yaml:"group,omitempty"`
|
||||
Text *TextAttachment `json:"text,omitempty" yaml:"text,omitempty"`
|
||||
}
|
||||
|
||||
type SubmitChallengeRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"`
|
||||
CaptchaToken string `json:"captcha_token,omitempty" yaml:"captcha_token,omitempty"`
|
||||
Challenge string `json:"challenge,omitempty" yaml:"challenge,omitempty"`
|
||||
}
|
||||
|
||||
// SubscribeRequest: receive incoming messages. After making a subscribe request, incoming messages will be sent to the client encoded as ClientMessageWrapper. Send an unsubscribe request or disconnect from the socket to stop receiving messages.
|
||||
|
@ -670,6 +894,16 @@ type SubscribeRequest struct {
|
|||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to subscribe to incoming message for
|
||||
}
|
||||
|
||||
type TextAttachment struct {
|
||||
BackgroundColor string `json:"background_color,omitempty" yaml:"background_color,omitempty"`
|
||||
BackgroundGradient *Gradient `json:"background_gradient,omitempty" yaml:"background_gradient,omitempty"`
|
||||
Preview *JsonPreview `json:"preview,omitempty" yaml:"preview,omitempty"`
|
||||
Style string `json:"style,omitempty" yaml:"style,omitempty"`
|
||||
Text string `json:"text,omitempty" yaml:"text,omitempty"`
|
||||
TextBackgroundColor string `json:"text_background_color,omitempty" yaml:"text_background_color,omitempty"`
|
||||
TextForegroundColor string `json:"text_foreground_color,omitempty" yaml:"text_foreground_color,omitempty"`
|
||||
}
|
||||
|
||||
// TrustRequest: Trust another user's safety number using either the QR code data or the safety number text
|
||||
type TrustRequest struct {
|
||||
Request
|
||||
|
@ -696,6 +930,14 @@ type TypingRequest struct {
|
|||
When int64 `json:"when,omitempty" yaml:"when,omitempty"`
|
||||
}
|
||||
|
||||
// UnbanUserRequest: Unbans users from a group.
|
||||
type UnbanUserRequest struct {
|
||||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to interact with
|
||||
GroupId string `json:"group_id,omitempty" yaml:"group_id,omitempty"`
|
||||
Users []*JsonAddress `json:"users,omitempty" yaml:"users,omitempty"` // List of users to unban
|
||||
}
|
||||
|
||||
// UnsubscribeRequest: See subscribe for more info
|
||||
type UnsubscribeRequest struct {
|
||||
Request
|
||||
|
@ -717,6 +959,7 @@ type UpdateGroupRequest struct {
|
|||
Request
|
||||
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The identifier of the account to interact with
|
||||
AddMembers []*JsonAddress `json:"addMembers,omitempty" yaml:"addMembers,omitempty"`
|
||||
Announcements string `json:"announcements,omitempty" yaml:"announcements,omitempty"` // ENABLED to only allow admins to post messages, DISABLED to allow anyone to post
|
||||
Avatar string `json:"avatar,omitempty" yaml:"avatar,omitempty"`
|
||||
Description string `json:"description,omitempty" yaml:"description,omitempty"` // A new group description. Set to empty string to remove an existing description.
|
||||
GroupID string `json:"groupID,omitempty" yaml:"groupID,omitempty"` // the ID of the group to update
|
||||
|
@ -738,3 +981,15 @@ type VerifyRequest struct {
|
|||
type VersionRequest struct {
|
||||
Request
|
||||
}
|
||||
|
||||
// WaitForScanRequest: An optional part of the linking process. Intended to be called after displaying the QR code, will return quickly after the user scans the QR code. finish_link must be called after wait_for_scan returns a non-error
|
||||
type WaitForScanRequest struct {
|
||||
Request
|
||||
SessionId string `json:"session_id,omitempty" yaml:"session_id,omitempty"`
|
||||
}
|
||||
|
||||
// WebSocketConnectionState: indicates when the websocket connection state to the signal server has changed
|
||||
type WebSocketConnectionState struct {
|
||||
Socket string `json:"socket,omitempty" yaml:"socket,omitempty"` // One of: UNIDENTIFIED, IDENTIFIED
|
||||
State string `json:"state,omitempty" yaml:"state,omitempty"` // One of: DISCONNECTED, CONNECTING, CONNECTED, RECONNECTING, DISCONNECTING, AUTHENTICATION_FAILED, FAILED
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ package signald
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
|
@ -28,7 +28,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"gitlab.com/signald/signald-go/signald/client-protocol/v0"
|
||||
client_protocol "gitlab.com/signald/signald-go/signald/client-protocol"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -51,17 +51,10 @@ func init() {
|
|||
// Signald is a connection to a signald instance.
|
||||
type Signald struct {
|
||||
socket net.Conn
|
||||
listeners map[string]chan BasicResponse
|
||||
listeners map[string]chan client_protocol.BasicResponse
|
||||
SocketPath string
|
||||
}
|
||||
|
||||
type BasicResponse struct {
|
||||
ID string
|
||||
Type string
|
||||
Error json.RawMessage
|
||||
Data json.RawMessage
|
||||
}
|
||||
|
||||
type UnexpectedError struct {
|
||||
Message string
|
||||
}
|
||||
|
@ -91,16 +84,27 @@ func (s *Signald) Connect() error {
|
|||
}
|
||||
|
||||
func (s *Signald) connect() error {
|
||||
socket, err := net.Dial("unix", s.SocketPath)
|
||||
var d net.Dialer
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
addr := net.UnixAddr{Name: s.SocketPath, Net: "unix"}
|
||||
socket, err := d.DialContext(ctx, "unix", addr.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.socket = socket
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Signald) Close() error {
|
||||
return s.socket.Close()
|
||||
}
|
||||
|
||||
// Listen listens for events from signald
|
||||
func (s *Signald) Listen(c chan v0.LegacyResponse) {
|
||||
func (s *Signald) Listen(c chan client_protocol.BasicResponse) error {
|
||||
for {
|
||||
msg, err := s.readNext()
|
||||
if err == io.EOF {
|
||||
|
@ -108,7 +112,11 @@ func (s *Signald) Listen(c chan v0.LegacyResponse) {
|
|||
if c != nil {
|
||||
close(c)
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if msg.Type == "unexpected_error" {
|
||||
|
@ -125,13 +133,8 @@ func (s *Signald) Listen(c chan v0.LegacyResponse) {
|
|||
subscribers <- msg
|
||||
}
|
||||
|
||||
if c != nil {
|
||||
legacyResponse := v0.LegacyResponse{ID: msg.ID, Type: msg.Type}
|
||||
if err := json.Unmarshal(msg.Data, &legacyResponse.Data); err != nil {
|
||||
log.Println("signald-go receive error: ", err)
|
||||
} else {
|
||||
c <- legacyResponse
|
||||
}
|
||||
if c != nil && !(msg.ID == "" && msg.Type == "version") {
|
||||
c <- msg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,13 +149,13 @@ func (s *Signald) RawRequest(request interface{}) error {
|
|||
return json.NewEncoder(s.socket).Encode(request)
|
||||
}
|
||||
|
||||
func (s *Signald) GetResponseListener(requestid string) chan BasicResponse {
|
||||
func (s *Signald) GetResponseListener(requestid string) chan client_protocol.BasicResponse {
|
||||
if s.listeners == nil {
|
||||
s.listeners = map[string]chan BasicResponse{}
|
||||
s.listeners = map[string]chan client_protocol.BasicResponse{}
|
||||
}
|
||||
c, ok := s.listeners[requestid]
|
||||
if !ok {
|
||||
c = make(chan BasicResponse)
|
||||
c = make(chan client_protocol.BasicResponse)
|
||||
s.listeners[requestid] = c
|
||||
}
|
||||
return c
|
||||
|
@ -167,7 +170,7 @@ func (s *Signald) CloseResponseListener(requestid string) {
|
|||
delete(s.listeners, requestid)
|
||||
}
|
||||
|
||||
func (s *Signald) readNext() (b BasicResponse, err error) {
|
||||
func (s *Signald) readNext() (b client_protocol.BasicResponse, err error) {
|
||||
if debugSignaldIO {
|
||||
buffer := bytes.Buffer{}
|
||||
err = json.NewDecoder(io.TeeReader(s.socket, &buffer)).Decode(&b)
|
||||
|
@ -175,16 +178,6 @@ func (s *Signald) readNext() (b BasicResponse, err error) {
|
|||
} else {
|
||||
err = json.NewDecoder(s.socket).Decode(&b)
|
||||
}
|
||||
if err != nil {
|
||||
log.Println("signald-go: error decoding message from signald:", err)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (b BasicResponse) GetError() error {
|
||||
if b.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("signald error: %s", string(b.Error))
|
||||
}
|
||||
|
|
37
tools/generator/errors.go.tmpl
Normal file
37
tools/generator/errors.go.tmpl
Normal file
|
@ -0,0 +1,37 @@
|
|||
package {{.Version}}
|
||||
|
||||
// {{ .Banner }}
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
client_protocol "gitlab.com/signald/signald-go/signald/client-protocol"
|
||||
)
|
||||
|
||||
func mkerr(response client_protocol.BasicResponse) error {
|
||||
switch response.ErrorType { {{ range $structName, $type := .Types }}
|
||||
case "{{ $structName }}":
|
||||
result := {{ $structName }}{}
|
||||
err := json.Unmarshal(response.Error, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result{{ end }}
|
||||
default:
|
||||
return fmt.Errorf("unexpected response type from signald: %s: %s", response.ErrorType, string(response.Error))
|
||||
}
|
||||
}
|
||||
|
||||
{{ range $structName, $type := .Types }}{{if ne $type.Doc ""}}// {{$structName}}: {{$type.Doc}}{{end}}
|
||||
type {{ $structName }} struct {
|
||||
{{if $type.Request}} Request{{end}}
|
||||
{{ range $fieldName, $field := $type.Fields }}{{ $field.FieldName }} {{if $field.List}}[]{{end}}{{ $field.Type }} `json:"{{$fieldName}},omitempty" yaml:"{{$fieldName}},omitempty"`{{if ne $field.Doc ""}} // {{$field.Doc}}{{end}}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
func (e {{ $structName }}) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
{{ end }}
|
|
@ -19,6 +19,7 @@ type Type struct {
|
|||
Fields map[string]*DataType
|
||||
Request bool `json:"-"`
|
||||
Doc string
|
||||
Error bool
|
||||
}
|
||||
|
||||
type DataType struct {
|
||||
|
@ -40,12 +41,14 @@ type StructsTemplateInput struct {
|
|||
Types map[string]*Type
|
||||
Version string
|
||||
ImportVersions []string
|
||||
Banner string
|
||||
}
|
||||
|
||||
type ActionsTemplateInput struct {
|
||||
Actions map[string]*Action
|
||||
Version string
|
||||
Responses bool
|
||||
Banner string
|
||||
}
|
||||
|
||||
var typeMap = map[string]string{
|
||||
|
@ -68,6 +71,8 @@ var fieldNameMap = map[string]string{
|
|||
"gv1-migration": "Gv1Migration",
|
||||
}
|
||||
|
||||
var banner = "DO NOT EDIT: this file is automatically generated by ./tools/generator in this repo"
|
||||
|
||||
func (d *DataType) fixForVersion(field, version string) {
|
||||
response, ok := typeMap[d.Type]
|
||||
if ok {
|
||||
|
@ -76,10 +81,12 @@ func (d *DataType) fixForVersion(field, version string) {
|
|||
}
|
||||
d.Type = response
|
||||
} else {
|
||||
if d.Version == version || d.Version == "" {
|
||||
d.Type = fmt.Sprintf("*%s", d.Type)
|
||||
} else {
|
||||
d.Type = fmt.Sprintf("*%s.%s", d.Version, d.Type)
|
||||
if d.Version != "" {
|
||||
if d.Version == version {
|
||||
d.Type = fmt.Sprintf("*%s", d.Type)
|
||||
} else {
|
||||
d.Type = fmt.Sprintf("*%s.%s", d.Version, d.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +115,7 @@ func main() {
|
|||
}
|
||||
|
||||
for version, actions := range response.Actions {
|
||||
inputs := ActionsTemplateInput{Version: version, Responses: false}
|
||||
inputs := ActionsTemplateInput{Version: version, Responses: false, Banner: banner}
|
||||
for action, a := range actions {
|
||||
actions[action].FnName = strings.Title(action)
|
||||
if a.Request != "" {
|
||||
|
@ -145,7 +152,11 @@ func main() {
|
|||
}
|
||||
|
||||
for version, types := range response.Types {
|
||||
inputs := StructsTemplateInput{Version: version}
|
||||
inputs := StructsTemplateInput{
|
||||
Version: version,
|
||||
Types: make(map[string]*Type),
|
||||
Banner: banner,
|
||||
}
|
||||
for typeName, t := range types {
|
||||
for fieldName, field := range t.Fields {
|
||||
types[typeName].Fields[fieldName].fixForVersion(fieldName, version)
|
||||
|
@ -162,8 +173,10 @@ func main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if !t.Error {
|
||||
inputs.Types[typeName] = t
|
||||
}
|
||||
}
|
||||
inputs.Types = types
|
||||
outputDir := fmt.Sprintf("signald/client-protocol/%s", version)
|
||||
err = os.MkdirAll(outputDir, os.ModePerm)
|
||||
if err != nil {
|
||||
|
@ -185,4 +198,57 @@ func main() {
|
|||
}
|
||||
fmt.Println(outputFilename)
|
||||
}
|
||||
|
||||
// errors
|
||||
for version, types := range response.Types {
|
||||
inputs := StructsTemplateInput{
|
||||
Version: version,
|
||||
Types: make(map[string]*Type),
|
||||
Banner: banner,
|
||||
}
|
||||
for typeName, t := range types {
|
||||
for fieldName, field := range t.Fields {
|
||||
types[typeName].Fields[fieldName].fixForVersion(fieldName, version)
|
||||
if field.Version != "" && field.Version != version {
|
||||
found := false
|
||||
for _, v := range inputs.ImportVersions {
|
||||
if v == field.Version {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
inputs.ImportVersions = append(inputs.ImportVersions, field.Version)
|
||||
}
|
||||
}
|
||||
}
|
||||
if t.Error {
|
||||
inputs.Types[typeName] = t
|
||||
}
|
||||
}
|
||||
if len(inputs.Types) == 0 {
|
||||
continue
|
||||
}
|
||||
outputDir := fmt.Sprintf("signald/client-protocol/%s", version)
|
||||
err = os.MkdirAll(outputDir, os.ModePerm)
|
||||
if err != nil {
|
||||
log.Fatal("Error creating", outputDir, err)
|
||||
}
|
||||
outputFilename := fmt.Sprintf("%s/%s", outputDir, "errors.go")
|
||||
log.Println("Opening", outputFilename)
|
||||
f, err := os.Create(outputFilename)
|
||||
if err != nil {
|
||||
log.Fatal(err, "\nfailed to open output file ", outputFilename)
|
||||
}
|
||||
err = tmpl.ExecuteTemplate(f, "errors.go.tmpl", inputs)
|
||||
if err != nil {
|
||||
log.Fatal(err, "\nfailed to render template")
|
||||
}
|
||||
err = exec.Command("gofmt", "-w", outputFilename).Run()
|
||||
if err != nil {
|
||||
log.Fatal(err, " error running gofmt on ", outputFilename)
|
||||
}
|
||||
fmt.Println(outputFilename)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package {{.Version}}
|
||||
|
||||
// DO NOT EDIT: this file is automatically generated by ./tools/generator in this repo
|
||||
// {{ .Banner }}
|
||||
|
||||
import ({{if .Responses}}
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"{{end}}
|
||||
|
||||
"gitlab.com/signald/signald-go/signald"
|
||||
|
@ -23,20 +22,19 @@ func {{$action.FnName}}(conn *signald.Signald) ({{if ne $action.Response ""}}res
|
|||
if(r.ID == "") {
|
||||
r.ID = signald.GenerateID()
|
||||
}
|
||||
responseChannel := conn.GetResponseListener(r.ID)
|
||||
defer conn.CloseResponseListener(r.ID)
|
||||
err = conn.RawRequest(r)
|
||||
if err != nil {
|
||||
log.Println("signald-go: error submitting request to signald")
|
||||
return
|
||||
}
|
||||
|
||||
responseChannel := conn.GetResponseListener(r.ID)
|
||||
defer conn.CloseResponseListener(r.ID)
|
||||
|
||||
rawResponse := <- responseChannel
|
||||
if rawResponse.Error != nil {
|
||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||
return
|
||||
}
|
||||
if rawResponse.Error != nil {
|
||||
err = mkerr(rawResponse)
|
||||
return
|
||||
}
|
||||
|
||||
{{if ne $action.Response ""}}
|
||||
err = json.Unmarshal(rawResponse.Data, &response)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package {{.Version}}
|
||||
|
||||
// DO NOT EDIT: this file is automatically generated by ./tools/generator in this repo
|
||||
// {{ .Banner }}
|
||||
|
||||
{{if gt (.ImportVersions | len) 0}}
|
||||
import (
|
||||
{{range $version := .ImportVersions}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue