Skip to content

Commit 76511ae

Browse files
authored
Merge pull request #809 from bexelbie/feature/ignore-avatars-stickers
Add --ignore-avatars and --ignore-stickers support
2 parents 05235bd + fcc62a7 commit 76511ae

8 files changed

Lines changed: 79 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,6 @@ There are a bunch of environmental variables that can be set inside the docker c
156156

157157
* `JSON_RPC_IGNORE_ATTACHMENTS`: When set to `true`, attachments are not automatically downloaded in json-rpc mode (default: `false`)
158158
* `JSON_RPC_IGNORE_STORIES`: When set to `true`, stories are not automatically downloaded in json-rpc mode (default: `false`)
159+
* `JSON_RPC_IGNORE_AVATARS`: When set to `true`, avatars are not automatically downloaded in json-rpc mode (default: `false`)
160+
* `JSON_RPC_IGNORE_STICKERS`: When set to `true`, sticker packs are not automatically downloaded in json-rpc mode (default: `false`)
159161
* `JSON_RPC_TRUST_NEW_IDENTITIES`: Choose how to trust new identities in json-rpc mode. Supported values: `on-first-use`, `always`, `never`. (default: `on-first-use`)

src/api/api.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,8 @@ func StringToBool(input string) bool {
670670
// @Param timeout query string false "Receive timeout in seconds (default: 1)"
671671
// @Param ignore_attachments query string false "Specify whether the attachments of the received message should be ignored" (default: false)"
672672
// @Param ignore_stories query string false "Specify whether stories should be ignored when receiving messages" (default: false)"
673+
// @Param ignore_avatars query string false "Specify whether avatar downloads should be ignored when receiving messages" (default: false)"
674+
// @Param ignore_stickers query string false "Specify whether sticker pack downloads should be ignored when receiving messages" (default: false)"
673675
// @Param max_messages query string false "Specify the maximum number of messages to receive (default: unlimited)". Not available in json-rpc mode.
674676
// @Param send_read_receipts query string false "Specify whether read receipts should be sent when receiving messages" (default: false)"
675677
// @Router /v1/receive/{number} [get]
@@ -718,13 +720,25 @@ func (a *Api) Receive(c *gin.Context) {
718720
return
719721
}
720722

723+
ignoreAvatars := c.DefaultQuery("ignore_avatars", "false")
724+
if ignoreAvatars != "true" && ignoreAvatars != "false" {
725+
c.JSON(400, Error{Msg: "Couldn't process request - ignore_avatars parameter needs to be either 'true' or 'false'"})
726+
return
727+
}
728+
729+
ignoreStickers := c.DefaultQuery("ignore_stickers", "false")
730+
if ignoreStickers != "true" && ignoreStickers != "false" {
731+
c.JSON(400, Error{Msg: "Couldn't process request - ignore_stickers parameter needs to be either 'true' or 'false'"})
732+
return
733+
}
734+
721735
sendReadReceipts := c.DefaultQuery("send_read_receipts", "false")
722736
if sendReadReceipts != "true" && sendReadReceipts != "false" {
723737
c.JSON(400, Error{Msg: "Couldn't process request - send_read_receipts parameter needs to be either 'true' or 'false'"})
724738
return
725739
}
726740

727-
jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories), maxMessagesInt, StringToBool(sendReadReceipts))
741+
jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories), StringToBool(ignoreAvatars), StringToBool(ignoreStickers), maxMessagesInt, StringToBool(sendReadReceipts))
728742
if err != nil {
729743
c.JSON(400, Error{Msg: err.Error()})
730744
return

src/client/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
993993
return &timestamps, nil
994994
}
995995

996-
func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments bool, ignoreStories bool, maxMessages int64, sendReadReceipts bool) (string, error) {
996+
func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments bool, ignoreStories bool, ignoreAvatars bool, ignoreStickers bool, maxMessages int64, sendReadReceipts bool) (string, error) {
997997
if s.signalCliMode == JsonRpc {
998998
return "", errors.New("Not implemented")
999999
} else {
@@ -1007,6 +1007,14 @@ func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments b
10071007
command = append(command, "--ignore-stories")
10081008
}
10091009

1010+
if ignoreAvatars {
1011+
command = append(command, "--ignore-avatars")
1012+
}
1013+
1014+
if ignoreStickers {
1015+
command = append(command, "--ignore-stickers")
1016+
}
1017+
10101018
if maxMessages > 0 {
10111019
command = append(command, "--max-messages")
10121020
command = append(command, strconv.FormatInt(maxMessages, 10))

src/docs/docs.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,18 @@ const docTemplate = `{
20432043
"name": "ignore_stories",
20442044
"in": "query"
20452045
},
2046+
{
2047+
"type": "string",
2048+
"description": "Specify whether avatar downloads should be ignored when receiving messages",
2049+
"name": "ignore_avatars",
2050+
"in": "query"
2051+
},
2052+
{
2053+
"type": "string",
2054+
"description": "Specify whether sticker pack downloads should be ignored when receiving messages",
2055+
"name": "ignore_stickers",
2056+
"in": "query"
2057+
},
20462058
{
20472059
"type": "string",
20482060
"description": "Specify the maximum number of messages to receive (default: unlimited)",

src/docs/swagger.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,18 @@
20402040
"name": "ignore_stories",
20412041
"in": "query"
20422042
},
2043+
{
2044+
"type": "string",
2045+
"description": "Specify whether avatar downloads should be ignored when receiving messages",
2046+
"name": "ignore_avatars",
2047+
"in": "query"
2048+
},
2049+
{
2050+
"type": "string",
2051+
"description": "Specify whether sticker pack downloads should be ignored when receiving messages",
2052+
"name": "ignore_stickers",
2053+
"in": "query"
2054+
},
20432055
{
20442056
"type": "string",
20452057
"description": "Specify the maximum number of messages to receive (default: unlimited)",

src/docs/swagger.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,16 @@ paths:
19161916
in: query
19171917
name: ignore_stories
19181918
type: string
1919+
- description: Specify whether avatar downloads should be ignored when receiving
1920+
messages
1921+
in: query
1922+
name: ignore_avatars
1923+
type: string
1924+
- description: Specify whether sticker pack downloads should be ignored when
1925+
receiving messages
1926+
in: query
1927+
name: ignore_stickers
1928+
type: string
19191929
- description: 'Specify the maximum number of messages to receive (default:
19201930
unlimited)'
19211931
in: query

src/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ func main() {
395395
autoReceiveScheduleReceiveTimeout := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_RECEIVE_TIMEOUT", "10")
396396
autoReceiveScheduleIgnoreAttachments := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_ATTACHMENTS", "false")
397397
autoReceiveScheduleIgnoreStories := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_STORIES", "false")
398+
autoReceiveScheduleIgnoreAvatars := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_AVATARS", "false")
399+
autoReceiveScheduleIgnoreStickers := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_STICKERS", "false")
398400
autoReceiveScheduleSendReadReceipts := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_SEND_READ_RECEIPTS", "false")
399401

400402
c := cron.New()
@@ -424,6 +426,8 @@ func main() {
424426
q.Add("timeout", autoReceiveScheduleReceiveTimeout)
425427
q.Add("ignore_attachments", autoReceiveScheduleIgnoreAttachments)
426428
q.Add("ignore_stories", autoReceiveScheduleIgnoreStories)
429+
q.Add("ignore_avatars", autoReceiveScheduleIgnoreAvatars)
430+
q.Add("ignore_stickers", autoReceiveScheduleIgnoreStickers)
427431
q.Add("send_read_receipts", autoReceiveScheduleSendReadReceipts)
428432
req.URL.RawQuery = q.Encode()
429433

src/scripts/jsonrpc2-helper.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
const supervisorctlConfigTemplate = `
1414
[program:%s]
1515
process_name=%s
16-
command=signal-cli --output=json --config %s%s daemon %s%s --tcp 127.0.0.1:%d
16+
command=signal-cli --output=json --config %s%s daemon %s%s%s%s --tcp 127.0.0.1:%d
1717
autostart=true
1818
autorestart=true
1919
startretries=10
@@ -55,6 +55,18 @@ func main() {
5555
signalCliIgnoreStories = " --ignore-stories"
5656
}
5757

58+
signalCliIgnoreAvatars := ""
59+
ignoreAvatars := utils.GetEnv("JSON_RPC_IGNORE_AVATARS", "")
60+
if ignoreAvatars == "true" {
61+
signalCliIgnoreAvatars = " --ignore-avatars"
62+
}
63+
64+
signalCliIgnoreStickers := ""
65+
ignoreStickers := utils.GetEnv("JSON_RPC_IGNORE_STICKERS", "")
66+
if ignoreStickers == "true" {
67+
signalCliIgnoreStickers = " --ignore-stickers"
68+
}
69+
5870
supervisorctlProgramName := "signal-cli-json-rpc-1"
5971
supervisorctlLogFolder := "/var/log/" + supervisorctlProgramName
6072
_, err := exec.Command("mkdir", "-p", supervisorctlLogFolder).Output()
@@ -80,7 +92,8 @@ func main() {
8092
supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-1.conf"
8193

8294
supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName,
83-
signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories, tcpPort,
95+
signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories,
96+
signalCliIgnoreAvatars, signalCliIgnoreStickers, tcpPort,
8497
supervisorctlProgramName, supervisorctlProgramName)
8598

8699
err = ioutil.WriteFile(supervisorctlConfigFilename, []byte(supervisorctlConfig), 0644)

0 commit comments

Comments
 (0)