diff --git a/src/api/api.go b/src/api/api.go index 58c3a44..7648522 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -93,10 +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"` + 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 { @@ -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..ecc682c 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"` @@ -120,6 +126,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 { @@ -282,8 +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) (*SendResponse, error) { + recipients []string, base64Attachments []string, isGroup bool, mentions []MessageMention, + quoteTimestamp *int64, quoteAuthor *string, quoteMessage *string, quoteMentions []MessageMention) (*SendResponse, error) { var resp SendResponse @@ -324,10 +336,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 +356,25 @@ func (s *SignalClient) send(number string, message string, for _, attachmentEntry := range attachmentEntries { request.Attachments = append(request.Attachments, attachmentEntry.toDataForSignal()) } + 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 = 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 { + request.QuoteMentions = nil + } rawData, err := jsonRpc2Client.getRaw("send", request) if err != nil { @@ -368,6 +404,31 @@ func (s *SignalClient) send(number string, message string, } } + for _, mention := range mentions { + cmd = append(cmd, "--mention") + cmd = append(cmd, mention.toString()) + } + + if quoteTimestamp != nil { + cmd = append(cmd, "--quote-timestamp") + cmd = append(cmd, strconv.FormatInt(*quoteTimestamp, 10)) + } + + if quoteAuthor != nil { + cmd = append(cmd, "--quote-author") + cmd = append(cmd, *quoteAuthor) + } + + if quoteMessage != nil { + cmd = append(cmd, "--quote-message") + cmd = append(cmd, *quoteMessage) + } + + for _, mention := range quoteMentions { + cmd = append(cmd, "--quote-mention") + cmd = append(cmd, mention.toString()) + } + rawData, err := s.cliClient.Execute(true, cmd, message) if err != nil { cleanupAttachmentEntries(attachmentEntries) @@ -389,8 +450,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 +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) + timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup, nil, nil, nil, nil, nil) return timestamp, err } @@ -472,7 +538,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 []MessageMention, + quoteTimestamp *int64, quoteAuthor *string, quoteMessage *string, quoteMentions []MessageMention) (*[]SendResponse, error) { if len(recps) == 0 { return nil, errors.New("Please provide at least one recipient") } @@ -502,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) + timestamp, err := s.send(number, message, []string{group}, base64Attachments, true, mentions, quoteTimestamp, quoteAuthor, quoteMessage, quoteMentions) if err != nil { return nil, err } @@ -510,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) + timestamp, err := s.send(number, message, recipients, base64Attachments, false, mentions, quoteTimestamp, quoteAuthor, quoteMessage, quoteMentions) if err != nil { return nil, err }