Update protocol and fix translating of fields with underscores in them

This commit is contained in:
Finn 2021-02-17 23:32:28 -08:00
parent 37291ba3bd
commit 2e75854f8e
5 changed files with 156 additions and 28 deletions

View file

@ -2,9 +2,9 @@
"doc_version": "v1", "doc_version": "v1",
"version": { "version": {
"name": "signald", "name": "signald",
"version": "0.12.0+git2021-02-12r1f18d539.24", "version": "0.12.0+git2021-02-18r64bd433c.35",
"branch": "main", "branch": "main",
"commit": "1f18d539bb0d09ea51948e9559ab5e04ca9359a5" "commit": "64bd433c25d9f66523171d53aa7a26ec921a6473"
}, },
"info": "This document describes objects that may be used when communicating with signald.", "info": "This document describes objects that may be used when communicating with signald.",
"types": { "types": {
@ -34,7 +34,7 @@
}, },
"timestamp": { "timestamp": {
"type": "long", "type": "long",
"example": "1613092537706" "example": "1613632213480"
}, },
"timestampISO": { "timestampISO": {
"type": "String" "type": "String"
@ -44,7 +44,7 @@
}, },
"serverDeliveredTimestamp": { "serverDeliveredTimestamp": {
"type": "long", "type": "long",
"example": "161309253770680" "example": "161363221348080"
}, },
"hasLegacyMessage": { "hasLegacyMessage": {
"type": "boolean" "type": "boolean"
@ -124,7 +124,7 @@
}, },
"timestamp": { "timestamp": {
"type": "long", "type": "long",
"example": "1613092537706" "example": "1613632213480"
} }
} }
}, },
@ -165,7 +165,7 @@
}, },
"version": { "version": {
"type": "String", "type": "String",
"example": "\"0.12.0+git2021-02-12r1f18d539.24\"" "example": "\"0.12.0+git2021-02-18r64bd433c.35\""
}, },
"branch": { "branch": {
"type": "String", "type": "String",
@ -173,7 +173,7 @@
}, },
"commit": { "commit": {
"type": "String", "type": "String",
"example": "\"1f18d539bb0d09ea51948e9559ab5e04ca9359a5\"" "example": "\"64bd433c25d9f66523171d53aa7a26ec921a6473\""
} }
} }
}, },
@ -517,7 +517,7 @@
"list": true, "list": true,
"type": "Long", "type": "Long",
"doc": "List of messages to mark as read", "doc": "List of messages to mark as read",
"example": "1613092537706", "example": "1613632213480",
"required": true "required": true
} }
} }
@ -669,12 +669,44 @@
} }
} }
}, },
"GenerateLinkingURIRequest": {
"fields": {},
"doc": "Generate a linking URI. Typically this is QR encoded and scanned by the primary device. Submit the returned session_id with a finish_link request."
},
"FinishLinkRequest": {
"fields": {
"device_name": {
"type": "String"
},
"session_id": {
"type": "String"
}
}
},
"Account": {
"fields": {
"address": {
"type": "JsonAddress",
"version": "v1",
"doc": "The address of this account"
},
"device_id": {
"type": "int",
"doc": "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."
},
"account_id": {
"type": "String",
"doc": "The primary identifier on the account, included with all requests to signald for this account. Previously called 'username'"
}
},
"doc": "A local account in signald"
},
"JsonDataMessage": { "JsonDataMessage": {
"fields": { "fields": {
"timestamp": { "timestamp": {
"type": "long", "type": "long",
"doc": "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.", "doc": "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.",
"example": "1613092537706" "example": "1613632213480"
}, },
"attachments": { "attachments": {
"list": true, "list": true,
@ -811,7 +843,7 @@
"id": { "id": {
"type": "long", "type": "long",
"doc": "the client timestamp of the message being quoted", "doc": "the client timestamp of the message being quoted",
"example": "1613092537706" "example": "1613632213480"
}, },
"author": { "author": {
"type": "JsonAddress", "type": "JsonAddress",
@ -899,7 +931,7 @@
"targetSentTimestamp": { "targetSentTimestamp": {
"type": "long", "type": "long",
"doc": "the client timestamp of the message being reacted to", "doc": "the client timestamp of the message being reacted to",
"example": "1613092537706" "example": "1613632213480"
} }
} }
}, },
@ -979,7 +1011,7 @@
}, },
"timestamp": { "timestamp": {
"type": "long", "type": "long",
"example": "1613092537706" "example": "1613632213480"
}, },
"expirationStartTimestamp": { "expirationStartTimestamp": {
"type": "long" "type": "long"
@ -1017,7 +1049,7 @@
}, },
"timestamp": { "timestamp": {
"type": "long", "type": "long",
"example": "1613092537706" "example": "1613632213480"
} }
} }
}, },
@ -1029,7 +1061,7 @@
}, },
"timestamp": { "timestamp": {
"type": "long", "type": "long",
"example": "1613092537706" "example": "1613632213480"
} }
} }
}, },
@ -1803,6 +1835,15 @@
"leave_group": { "leave_group": {
"request": "LeaveGroupRequest", "request": "LeaveGroupRequest",
"response": "GroupInfo" "response": "GroupInfo"
},
"generate_linking_uri": {
"request": "GenerateLinkingURIRequest",
"response": "String",
"doc": "Generate a linking URI. Typically this is QR encoded and scanned by the primary device. Submit the returned session_id with a finish_link request."
},
"finish_link": {
"request": "FinishLinkRequest",
"response": "Account"
} }
}, },
"v1alpha1": { "v1alpha1": {

View file

@ -48,7 +48,7 @@ type IceUpdateMessage struct {
type JsonAccount struct { type JsonAccount struct {
DeviceId int32 `json:"deviceId,omitempty" yaml:"deviceId,omitempty"` DeviceId int32 `json:"deviceId,omitempty" yaml:"deviceId,omitempty"`
Filename string `json:"filename,omitempty" yaml:"filename,omitempty"` Filename string `json:"filename,omitempty" yaml:"filename,omitempty"`
Has_keys bool `json:"has_keys,omitempty" yaml:"has_keys,omitempty"` HasKeys bool `json:"has_keys,omitempty" yaml:"has_keys,omitempty"`
Registered bool `json:"registered,omitempty" yaml:"registered,omitempty"` Registered bool `json:"registered,omitempty" yaml:"registered,omitempty"`
Subscribed bool `json:"subscribed,omitempty" yaml:"subscribed,omitempty"` Subscribed bool `json:"subscribed,omitempty" yaml:"subscribed,omitempty"`
Username string `json:"username,omitempty" yaml:"username,omitempty"` Username string `json:"username,omitempty" yaml:"username,omitempty"`

View file

@ -108,6 +108,71 @@ func (r *CreateGroupRequest) Submit(conn *signald.Signald) (response JsonGroupV2
} }
func (r *FinishLinkRequest) Submit(conn *signald.Signald) (response Account, err error) {
r.Version = "v1"
r.Type = "finish_link"
if r.ID == "" {
r.ID = signald.GenerateID()
}
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
}
err = json.Unmarshal(rawResponse.Data, &response)
if err != nil {
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
return
}
return response, nil
}
// Submit: Generate a linking URI. Typically this is QR encoded and scanned by the primary device. Submit the returned session_id with a finish_link request.
func (r *GenerateLinkingURIRequest) Submit(conn *signald.Signald) (response string, err error) {
r.Version = "v1"
r.Type = "generate_linking_uri"
if r.ID == "" {
r.ID = signald.GenerateID()
}
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
}
err = json.Unmarshal(rawResponse.Data, &response)
if err != nil {
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
return
}
return response, nil
}
// Submit: Query the server for the latest state of a known group // Submit: Query the server for the latest state of a known group
func (r *GetGroupRequest) Submit(conn *signald.Signald) (response JsonGroupV2Info, err error) { func (r *GetGroupRequest) Submit(conn *signald.Signald) (response JsonGroupV2Info, err error) {
r.Version = "v1" r.Version = "v1"

View file

@ -19,6 +19,13 @@ type AcceptInvitationRequest struct {
GroupID string `json:"groupID,omitempty" yaml:"groupID,omitempty"` GroupID string `json:"groupID,omitempty" yaml:"groupID,omitempty"`
} }
// Account: A local account in signald
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.
}
// ApproveMembershipRequest: approve a request to join a group // ApproveMembershipRequest: approve a request to join a group
type ApproveMembershipRequest struct { type ApproveMembershipRequest struct {
Request Request
@ -37,12 +44,23 @@ type CreateGroupRequest struct {
Request Request
Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to interact with Account string `json:"account,omitempty" yaml:"account,omitempty"` // The account to interact with
Avatar string `json:"avatar,omitempty" yaml:"avatar,omitempty"` Avatar string `json:"avatar,omitempty" yaml:"avatar,omitempty"`
Member_role string `json:"member_role,omitempty" yaml:"member_role,omitempty"` // The role of all members other than the group creator. Options are ADMINISTRATOR or DEFAULT (case insensitive) MemberRole string `json:"member_role,omitempty" yaml:"member_role,omitempty"` // The role of all members other than the group creator. Options are ADMINISTRATOR or DEFAULT (case insensitive)
Members []*JsonAddress `json:"members,omitempty" yaml:"members,omitempty"` Members []*JsonAddress `json:"members,omitempty" yaml:"members,omitempty"`
Timer int32 `json:"timer,omitempty" yaml:"timer,omitempty"` // the message expiration timer Timer int32 `json:"timer,omitempty" yaml:"timer,omitempty"` // the message expiration timer
Title string `json:"title,omitempty" yaml:"title,omitempty"` Title string `json:"title,omitempty" yaml:"title,omitempty"`
} }
type FinishLinkRequest struct {
Request
DeviceName string `json:"device_name,omitempty" yaml:"device_name,omitempty"`
SessionId string `json:"session_id,omitempty" yaml:"session_id,omitempty"`
}
// GenerateLinkingURIRequest: Generate a linking URI. Typically this is QR encoded and scanned by the primary device. Submit the returned session_id with a finish_link request.
type GenerateLinkingURIRequest struct {
Request
}
// GetGroupRequest: Query the server for the latest state of a known group // GetGroupRequest: Query the server for the latest state of a known group
type GetGroupRequest struct { type GetGroupRequest struct {
Request Request
@ -84,7 +102,7 @@ type GroupList struct {
} }
type GroupMember struct { type GroupMember struct {
Joined_revision int32 `json:"joined_revision,omitempty" yaml:"joined_revision,omitempty"` JoinedRevision int32 `json:"joined_revision,omitempty" yaml:"joined_revision,omitempty"`
Role string `json:"role,omitempty" yaml:"role,omitempty"` // possible values are: UNKNOWN, DEFAULT, ADMINISTRATOR and UNRECOGNIZED Role string `json:"role,omitempty" yaml:"role,omitempty"` // possible values are: UNKNOWN, DEFAULT, ADMINISTRATOR and UNRECOGNIZED
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"` UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
} }

View file

@ -64,9 +64,6 @@ var fieldNameMap = map[string]string{
"id": "ID", "id": "ID",
"recipientGroupId": "RecipientGroupID", "recipientGroupId": "RecipientGroupID",
"uuid": "UUID", "uuid": "UUID",
"expiration_time": "ExpirationTime",
"inbox_position": "InboxPosition",
"profile_name": "ProfileName",
"gv1-migration": "Gv1Migration", "gv1-migration": "Gv1Migration",
} }
@ -89,7 +86,11 @@ func (d *DataType) fixForVersion(field, version string) {
if ok { if ok {
d.FieldName = fieldName d.FieldName = fieldName
} else { } else {
d.FieldName = strings.Title(field) components := strings.Split(field, "_")
for i, c := range components {
components[i] = strings.Title(c)
}
d.FieldName = strings.Join(components, "")
} }
} }
@ -115,6 +116,9 @@ func main() {
if a.Response != "" { if a.Response != "" {
inputs.Responses = true inputs.Responses = true
} }
if r, ok := typeMap[a.Response]; ok {
a.Response = r
}
} }
inputs.Actions = actions inputs.Actions = actions
outputDir := fmt.Sprintf("signald/client-protocol/%s", version) outputDir := fmt.Sprintf("signald/client-protocol/%s", version)