From b23ee29b1fdaa2b8d20d478eb3ca2251bb816999 Mon Sep 17 00:00:00 2001 From: Jonathan Neidel Date: Fri, 26 Apr 2024 12:50:53 +0200 Subject: [PATCH 1/2] Add support for read receipts on /receive --- src/api/api.go | 9 ++++++++- src/client/client.go | 6 +++++- src/main.go | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/api/api.go b/src/api/api.go index bc27439..26d8044 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -540,6 +540,7 @@ func StringToBool(input string) bool { // @Param ignore_attachments query string false "Specify whether the attachments of the received message should be ignored" (default: false)" // @Param ignore_stories query string false "Specify whether stories should be ignored when receiving messages" (default: false)" // @Param max_messages query string false "Specify the maximum number of messages to receive (default: unlimited)". Not available in json-rpc mode. +// @Param send_read_receipts query string false "Specify whether read receipts should be sent when receiving messages" (default: false)" // @Router /v1/receive/{number} [get] func (a *Api) Receive(c *gin.Context) { number := c.Param("number") @@ -582,7 +583,13 @@ func (a *Api) Receive(c *gin.Context) { return } - jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories), maxMessagesInt) + sendReadReceipts := c.DefaultQuery("send_read_receipts", "false") + if sendReadReceipts != "true" && sendReadReceipts != "false" { + c.JSON(400, Error{Msg: "Couldn't process request - send_read_receipts parameter needs to be either 'true' or 'false'"}) + return + } + + jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories), maxMessagesInt, StringToBool(sendReadReceipts)) if err != nil { c.JSON(400, Error{Msg: err.Error()}) return diff --git a/src/client/client.go b/src/client/client.go index 80d0d36..3211936 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -720,7 +720,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas return ×tamps, nil } -func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments bool, ignoreStories bool, maxMessages int64) (string, error) { +func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments bool, ignoreStories bool, maxMessages int64, sendReadReceipts bool) (string, error) { if s.signalCliMode == JsonRpc { return "", errors.New("Not implemented") } else { @@ -739,6 +739,10 @@ func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments b command = append(command, strconv.FormatInt(maxMessages, 10)) } + if sendReadReceipts { + command = append(command, "--send-read-receipts") + } + out, err := s.cliClient.Execute(true, command, "") if err != nil { return "", err diff --git a/src/main.go b/src/main.go index 1439352..282ee50 100644 --- a/src/main.go +++ b/src/main.go @@ -297,6 +297,7 @@ func main() { autoReceiveScheduleReceiveTimeout := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_RECEIVE_TIMEOUT", "10") autoReceiveScheduleIgnoreAttachments := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_ATTACHMENTS", "false") autoReceiveScheduleIgnoreStories := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_STORIES", "false") + autoReceiveScheduleSendReadReceipts := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_SEND_READ_RECEIPTS", "false") c := cron.New() c.Schedule(schedule, cron.FuncJob(func() { @@ -325,6 +326,7 @@ func main() { q.Add("timeout", autoReceiveScheduleReceiveTimeout) q.Add("ignore_attachments", autoReceiveScheduleIgnoreAttachments) q.Add("ignore_stories", autoReceiveScheduleIgnoreStories) + q.Add("send_read_receipts", autoReceiveScheduleSendReadReceipts) req.URL.RawQuery = q.Encode() resp, err := client.Do(req) From 193a9f1e5bf465b8eefa9780aa1b112f8a1988f3 Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Sat, 27 Apr 2024 19:10:28 +0200 Subject: [PATCH 2/2] update Swagger documentation --- src/docs/docs.go | 6 ++++++ src/docs/swagger.json | 6 ++++++ src/docs/swagger.yaml | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/src/docs/docs.go b/src/docs/docs.go index 2365248..58a28ba 100644 --- a/src/docs/docs.go +++ b/src/docs/docs.go @@ -1449,6 +1449,12 @@ var doc = `{ "description": "Specify the maximum number of messages to receive (default: unlimited)", "name": "max_messages", "in": "query" + }, + { + "type": "string", + "description": "Specify whether read receipts should be sent when receiving messages", + "name": "send_read_receipts", + "in": "query" } ], "responses": { diff --git a/src/docs/swagger.json b/src/docs/swagger.json index 45cf5da..f8f7a79 100644 --- a/src/docs/swagger.json +++ b/src/docs/swagger.json @@ -1433,6 +1433,12 @@ "description": "Specify the maximum number of messages to receive (default: unlimited)", "name": "max_messages", "in": "query" + }, + { + "type": "string", + "description": "Specify whether read receipts should be sent when receiving messages", + "name": "send_read_receipts", + "in": "query" } ], "responses": { diff --git a/src/docs/swagger.yaml b/src/docs/swagger.yaml index 3b0a4f6..c9ddf2b 100644 --- a/src/docs/swagger.yaml +++ b/src/docs/swagger.yaml @@ -1303,6 +1303,10 @@ paths: in: query name: max_messages type: string + - description: Specify whether read receipts should be sent when receiving messages + in: query + name: send_read_receipts + type: string produces: - application/json responses: