Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for read receipts on /receive #524

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading