Skip to content

Commit

Permalink
Merge pull request #524 from jneidel/read-receipts
Browse files Browse the repository at this point in the history
Add support for read receipts on /receive
  • Loading branch information
bbernhard authored Apr 27, 2024
2 parents 9d6f4a0 + b23ee29 commit 451010c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
return &timestamps, 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 {
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 451010c

Please sign in to comment.