From f89ae911e1c36a132b5f10eaf98b4acb93df51f8 Mon Sep 17 00:00:00 2001 From: Robin THONI Date: Sun, 3 Apr 2022 19:08:52 +0200 Subject: [PATCH 1/3] Added support for missing send arguments: - Mentions - Quote timestamp - Quote author - Quote message - Quote mentions --- src/api/api.go | 8 +++++- src/client/client.go | 65 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/api/api.go b/src/api/api.go index 58c3a44..7a6eddf 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -97,6 +97,11 @@ type SendMessageV2 struct { Recipients []string `json:"recipients"` Message string `json:"message"` Base64Attachments []string `json:"base64_attachments" example:",data:;base64,data:;filename=;base64"` + Mentions []string `json:"mentions"` + QuoteTimestamp *int64 `json:"quote_timestamp"` + QuoteAuthor *string `json:"quote_author"` + QuoteMessage *string `json:"quote_message"` + QuoteMentions []string `json:"quote_mentions"` } type TypingIndicatorRequest struct { @@ -354,7 +359,8 @@ func (a *Api) SendV2(c *gin.Context) { return } - timestamps, err := a.signalClient.SendV2(req.Number, req.Message, req.Recipients, req.Base64Attachments) + timestamps, err := a.signalClient.SendV2(req.Number, req.Message, req.Recipients, req.Base64Attachments, + req.Mentions, req.QuoteTimestamp, req.QuoteAuthor, req.QuoteMessage, req.QuoteMentions) if err != nil { c.JSON(400, Error{Msg: err.Error()}) return diff --git a/src/client/client.go b/src/client/client.go index c198769..b2ce956 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -120,6 +120,7 @@ type About struct { BuildNr int `json:"build"` Mode string `json:"mode"` Version string `json:"version"` + Capabilities map[string][]string `json:"capabilities"` } type SearchResultEntry struct { @@ -283,7 +284,8 @@ func (s *SignalClient) Init() error { } func (s *SignalClient) send(number string, message string, - recipients []string, base64Attachments []string, isGroup bool) (*SendResponse, error) { + recipients []string, base64Attachments []string, isGroup bool, mentions []string, + quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []string) (*SendResponse, error) { var resp SendResponse @@ -324,10 +326,15 @@ func (s *SignalClient) send(number string, message string, } type Request struct { - Recipients []string `json:"recipient,omitempty"` - Message string `json:"message"` - GroupId string `json:"group-id,omitempty"` - Attachments []string `json:"attachment,omitempty"` + Recipients []string `json:"recipient,omitempty"` + Message string `json:"message"` + GroupId string `json:"group-id,omitempty"` + Attachments []string `json:"attachment,omitempty"` + Mentions []string `json:"mentions,omitempty"` + QuoteTimestamp *int64 `json:"quote-timestamp,omitempty"` + QuoteAuthor *string `json:"quote-author,omitempty"` + QuoteMessage *string `json:"quote-message,omitempty"` + QuoteMentions []string `json:"quote-mentions,omitempty"` } request := Request{Message: message} @@ -339,6 +346,11 @@ func (s *SignalClient) send(number string, message string, for _, attachmentEntry := range attachmentEntries { request.Attachments = append(request.Attachments, attachmentEntry.toDataForSignal()) } + request.Mentions = mentions + request.QuoteTimestamp = quote_timestamp + request.QuoteAuthor = quote_author + request.QuoteMessage = quote_message + request.QuoteMentions = quote_mentions rawData, err := jsonRpc2Client.getRaw("send", request) if err != nil { @@ -368,6 +380,31 @@ func (s *SignalClient) send(number string, message string, } } + for _, mention := range mentions { + cmd = append(cmd, "--mention") + cmd = append(cmd, mention) + } + + if quote_timestamp != nil { + cmd = append(cmd, "--quote-timestamp") + cmd = append(cmd, strconv.FormatInt(*quote_timestamp, 10)) + } + + if quote_author != nil { + cmd = append(cmd, "--quote-author") + cmd = append(cmd, *quote_author) + } + + if quote_message != nil { + cmd = append(cmd, "--quote-message") + cmd = append(cmd, *quote_message) + } + + for _, mention := range quote_mentions { + cmd = append(cmd, "--quote-mention") + cmd = append(cmd, mention) + } + rawData, err := s.cliClient.Execute(true, cmd, message) if err != nil { cleanupAttachmentEntries(attachmentEntries) @@ -389,8 +426,13 @@ func (s *SignalClient) send(number string, message string, } func (s *SignalClient) About() About { - about := About{SupportedApiVersions: []string{"v1", "v2"}, BuildNr: 2, Mode: getSignalCliModeString(s.signalCliMode), - Version: utils.GetEnv("BUILD_VERSION", "unset")} + about := About{ + SupportedApiVersions: []string{"v1", "v2"}, + BuildNr: 2, + Mode: getSignalCliModeString(s.signalCliMode), + Version: utils.GetEnv("BUILD_VERSION", "unset"), + Capabilities: map[string][]string{"v2/send": []string{"quotes", "mentions"}}, + } return about } @@ -453,7 +495,7 @@ func (s *SignalClient) VerifyRegisteredNumber(number string, token string, pin s } func (s *SignalClient) SendV1(number string, message string, recipients []string, base64Attachments []string, isGroup bool) (*SendResponse, error) { - timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup) + timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup, []string{}, nil, nil, nil, []string{}) return timestamp, err } @@ -472,7 +514,8 @@ func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client { return jsonRpc2Clients } -func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string) (*[]SendResponse, error) { +func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, mentions []string, + quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []string) (*[]SendResponse, error) { if len(recps) == 0 { return nil, errors.New("Please provide at least one recipient") } @@ -502,7 +545,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas timestamps := []SendResponse{} for _, group := range groups { - timestamp, err := s.send(number, message, []string{group}, base64Attachments, true) + timestamp, err := s.send(number, message, []string{group}, base64Attachments, true, mentions, quote_timestamp, quote_author, quote_message, quote_mentions) if err != nil { return nil, err } @@ -510,7 +553,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas } if len(recipients) > 0 { - timestamp, err := s.send(number, message, recipients, base64Attachments, false) + timestamp, err := s.send(number, message, recipients, base64Attachments, false, mentions, quote_timestamp, quote_author, quote_message, quote_mentions) if err != nil { return nil, err } From fce14ba0492f7501d1bf5d53157e20879cf2cb42 Mon Sep 17 00:00:00 2001 From: Robin THONI Date: Thu, 3 Nov 2022 20:29:32 +0100 Subject: [PATCH 2/3] Added nested object for mentions (direct and quote) --- src/api/api.go | 18 +++++++++--------- src/client/client.go | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/api/api.go b/src/api/api.go index 7a6eddf..7648522 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -93,15 +93,15 @@ type SendMessageV1 struct { } type SendMessageV2 struct { - Number string `json:"number"` - Recipients []string `json:"recipients"` - Message string `json:"message"` - Base64Attachments []string `json:"base64_attachments" example:",data:;base64,data:;filename=;base64"` - Mentions []string `json:"mentions"` - QuoteTimestamp *int64 `json:"quote_timestamp"` - QuoteAuthor *string `json:"quote_author"` - QuoteMessage *string `json:"quote_message"` - QuoteMentions []string `json:"quote_mentions"` + Number string `json:"number"` + Recipients []string `json:"recipients"` + Message string `json:"message"` + Base64Attachments []string `json:"base64_attachments" example:",data:;base64,data:;filename=;base64"` + Mentions []client.MessageMention `json:"mentions"` + QuoteTimestamp *int64 `json:"quote_timestamp"` + QuoteAuthor *string `json:"quote_author"` + QuoteMessage *string `json:"quote_message"` + QuoteMentions []client.MessageMention `json:"quote_mentions"` } type TypingIndicatorRequest struct { diff --git a/src/client/client.go b/src/client/client.go index b2ce956..80f5b37 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -59,6 +59,12 @@ func (g GroupLinkState) String() string { return []string{"", "enabled", "enabled-with-approval", "disabled"}[g] } +type MessageMention struct { + Start int64 `json:"start"` + Length int64 `json:"length"` + Author string `json:"author"` +} + type GroupEntry struct { Name string `json:"name"` Id string `json:"id"` @@ -283,9 +289,13 @@ func (s *SignalClient) Init() error { return nil } +func (s *MessageMention) toString() string { + return fmt.Sprintf("%d:%d:%s", s.Start, s.Length, s.Author) +} + func (s *SignalClient) send(number string, message string, - recipients []string, base64Attachments []string, isGroup bool, mentions []string, - quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []string) (*SendResponse, error) { + recipients []string, base64Attachments []string, isGroup bool, mentions []MessageMention, + quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []MessageMention) (*SendResponse, error) { var resp SendResponse @@ -346,11 +356,25 @@ func (s *SignalClient) send(number string, message string, for _, attachmentEntry := range attachmentEntries { request.Attachments = append(request.Attachments, attachmentEntry.toDataForSignal()) } - request.Mentions = mentions + if mentions != nil { + request.Mentions = make([]string, len(mentions)) + for i, mention := range mentions { + request.Mentions[i] = mention.toString() + } + } else { + request.Mentions = nil + } request.QuoteTimestamp = quote_timestamp request.QuoteAuthor = quote_author request.QuoteMessage = quote_message - request.QuoteMentions = quote_mentions + if quote_mentions != nil { + request.QuoteMentions = make([]string, len(quote_mentions)) + for i, mention := range quote_mentions { + request.QuoteMentions[i] = mention.toString() + } + } else { + request.QuoteMentions = nil + } rawData, err := jsonRpc2Client.getRaw("send", request) if err != nil { @@ -382,7 +406,7 @@ func (s *SignalClient) send(number string, message string, for _, mention := range mentions { cmd = append(cmd, "--mention") - cmd = append(cmd, mention) + cmd = append(cmd, mention.toString()) } if quote_timestamp != nil { @@ -402,7 +426,7 @@ func (s *SignalClient) send(number string, message string, for _, mention := range quote_mentions { cmd = append(cmd, "--quote-mention") - cmd = append(cmd, mention) + cmd = append(cmd, mention.toString()) } rawData, err := s.cliClient.Execute(true, cmd, message) @@ -495,7 +519,7 @@ func (s *SignalClient) VerifyRegisteredNumber(number string, token string, pin s } func (s *SignalClient) SendV1(number string, message string, recipients []string, base64Attachments []string, isGroup bool) (*SendResponse, error) { - timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup, []string{}, nil, nil, nil, []string{}) + timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup, nil, nil, nil, nil, nil) return timestamp, err } @@ -514,8 +538,8 @@ func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client { return jsonRpc2Clients } -func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, mentions []string, - quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []string) (*[]SendResponse, error) { +func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, mentions []MessageMention, + quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []MessageMention) (*[]SendResponse, error) { if len(recps) == 0 { return nil, errors.New("Please provide at least one recipient") } From e5bd4dd30a626a8ff40c31871088161033411105 Mon Sep 17 00:00:00 2001 From: Robin THONI Date: Mon, 7 Nov 2022 17:18:38 +0100 Subject: [PATCH 3/3] Changed snake case variables to camel case --- src/client/client.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/client/client.go b/src/client/client.go index 80f5b37..ecc682c 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -295,7 +295,7 @@ func (s *MessageMention) toString() string { func (s *SignalClient) send(number string, message string, recipients []string, base64Attachments []string, isGroup bool, mentions []MessageMention, - quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []MessageMention) (*SendResponse, error) { + quoteTimestamp *int64, quoteAuthor *string, quoteMessage *string, quoteMentions []MessageMention) (*SendResponse, error) { var resp SendResponse @@ -364,12 +364,12 @@ func (s *SignalClient) send(number string, message string, } else { request.Mentions = nil } - request.QuoteTimestamp = quote_timestamp - request.QuoteAuthor = quote_author - request.QuoteMessage = quote_message - if quote_mentions != nil { - request.QuoteMentions = make([]string, len(quote_mentions)) - for i, mention := range quote_mentions { + request.QuoteTimestamp = quoteTimestamp + request.QuoteAuthor = quoteAuthor + request.QuoteMessage = quoteMessage + if quoteMentions != nil { + request.QuoteMentions = make([]string, len(quoteMentions)) + for i, mention := range quoteMentions { request.QuoteMentions[i] = mention.toString() } } else { @@ -409,22 +409,22 @@ func (s *SignalClient) send(number string, message string, cmd = append(cmd, mention.toString()) } - if quote_timestamp != nil { + if quoteTimestamp != nil { cmd = append(cmd, "--quote-timestamp") - cmd = append(cmd, strconv.FormatInt(*quote_timestamp, 10)) + cmd = append(cmd, strconv.FormatInt(*quoteTimestamp, 10)) } - if quote_author != nil { + if quoteAuthor != nil { cmd = append(cmd, "--quote-author") - cmd = append(cmd, *quote_author) + cmd = append(cmd, *quoteAuthor) } - if quote_message != nil { + if quoteMessage != nil { cmd = append(cmd, "--quote-message") - cmd = append(cmd, *quote_message) + cmd = append(cmd, *quoteMessage) } - for _, mention := range quote_mentions { + for _, mention := range quoteMentions { cmd = append(cmd, "--quote-mention") cmd = append(cmd, mention.toString()) } @@ -539,7 +539,7 @@ func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client { } func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, mentions []MessageMention, - quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []MessageMention) (*[]SendResponse, error) { + quoteTimestamp *int64, quoteAuthor *string, quoteMessage *string, quoteMentions []MessageMention) (*[]SendResponse, error) { if len(recps) == 0 { return nil, errors.New("Please provide at least one recipient") } @@ -569,7 +569,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas timestamps := []SendResponse{} for _, group := range groups { - timestamp, err := s.send(number, message, []string{group}, base64Attachments, true, mentions, quote_timestamp, quote_author, quote_message, quote_mentions) + timestamp, err := s.send(number, message, []string{group}, base64Attachments, true, mentions, quoteTimestamp, quoteAuthor, quoteMessage, quoteMentions) if err != nil { return nil, err } @@ -577,7 +577,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas } if len(recipients) > 0 { - timestamp, err := s.send(number, message, recipients, base64Attachments, false, mentions, quote_timestamp, quote_author, quote_message, quote_mentions) + timestamp, err := s.send(number, message, recipients, base64Attachments, false, mentions, quoteTimestamp, quoteAuthor, quoteMessage, quoteMentions) if err != nil { return nil, err }