diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2024-01-27 14:13:45 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2024-01-27 14:13:45 +0300 |
commit | 599cf16cdbb8567cf2ab1ce42aee5f493884de96 (patch) | |
tree | bc9be25328223d6ce5b3c3d3868496dd0ccdc75e /xmpp | |
parent | 81fc3ea3707cdf73b846ab55b2ecc5b8f68ccd21 (diff) |
Request and send to Telegram XEP-0333 displayed markers by "receipts" option
Diffstat (limited to 'xmpp')
-rw-r--r-- | xmpp/gateway/gateway.go | 19 | ||||
-rw-r--r-- | xmpp/handlers.go | 24 |
2 files changed, 35 insertions, 8 deletions
diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go index 5ba201a..7d3cbb6 100644 --- a/xmpp/gateway/gateway.go +++ b/xmpp/gateway/gateway.go @@ -54,23 +54,23 @@ var DirtySessions = false var MessageOutgoingPermissionVersion = 0 // SendMessage creates and sends a message stanza -func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, isCarbon bool) { - sendMessageWrapper(to, from, body, id, component, reply, nil, "", isCarbon) +func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, isCarbon, requestReceipt bool) { + sendMessageWrapper(to, from, body, id, component, reply, nil, "", isCarbon, requestReceipt) } // SendServiceMessage creates and sends a simple message stanza from transport func SendServiceMessage(to string, body string, component *xmpp.Component) { - sendMessageWrapper(to, "", body, "", component, nil, nil, "", false) + sendMessageWrapper(to, "", body, "", component, nil, nil, "", false, false) } // SendTextMessage creates and sends a simple message stanza func SendTextMessage(to string, from string, body string, component *xmpp.Component) { - sendMessageWrapper(to, from, body, "", component, nil, nil, "", false) + sendMessageWrapper(to, from, body, "", component, nil, nil, "", false, false) } // SendMessageWithOOB creates and sends a message stanza with OOB URL -func SendMessageWithOOB(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isCarbon bool) { - sendMessageWrapper(to, from, body, id, component, reply, nil, oob, isCarbon) +func SendMessageWithOOB(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isCarbon, requestReceipt bool) { + sendMessageWrapper(to, from, body, id, component, reply, nil, oob, isCarbon, requestReceipt) } // SendMessageMarker creates and sends a message stanza with a XEP-0333 marker @@ -78,10 +78,10 @@ func SendMessageMarker(to string, from string, component *xmpp.Component, marker sendMessageWrapper(to, from, "", "", component, nil, &marker{ Type: markerType, Id: markerId, - }, "", false) + }, "", false, false) } -func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, marker *marker, oob string, isCarbon bool) { +func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, marker *marker, oob string, isCarbon, requestReceipt bool) { toJid, err := stanza.NewJid(to) if err != nil { log.WithFields(log.Fields{ @@ -150,6 +150,9 @@ func sendMessageWrapper(to string, from string, body string, id string, componen if !isCarbon && toJid.Resource != "" { message.Extensions = append(message.Extensions, stanza.HintNoCopy{}) } + if requestReceipt { + message.Extensions = append(message.Extensions, stanza.ReceiptRequest{}) + } if isCarbon { carbonMessage := extensions.ClientMessage{ diff --git a/xmpp/handlers.go b/xmpp/handlers.go index 541eb63..9caf886 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -254,6 +254,30 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) { gateway.MessageOutgoingPermissionVersion = 2 } } + + var displayed stanza.MarkDisplayed + msg.Get(&displayed) + if displayed.ID != "" { + log.Debugf("displayed: %#v", displayed) + + bare, _, ok := gateway.SplitJID(msg.From) + if !ok { + return + } + session, ok := sessions[bare] + if !ok { + return + } + toID, ok := toToID(msg.To) + if !ok { + return + } + msgId, err := strconv.ParseInt(displayed.ID, 10, 64) + if err == nil { + session.MarkAsRead(toID, msgId) + } + return + } } if msg.Type == "error" { |