aboutsummaryrefslogtreecommitdiff
path: root/xmpp
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2024-01-27 05:02:47 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2024-01-27 05:02:47 +0300
commite37c428c6764eff8e7b5ea286b1c7a0ba52be11a (patch)
treeff1dd7c431499e93dff99669b8df90805ea59118 /xmpp
parentb9b6ba14a442f3c4394c535461bd6b1d03a7ef7b (diff)
XEP-0333 read markers for outgoing messages
Diffstat (limited to 'xmpp')
-rw-r--r--xmpp/gateway/gateway.go36
-rw-r--r--xmpp/handlers.go7
2 files changed, 36 insertions, 7 deletions
diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go
index 981858d..4b2a07f 100644
--- a/xmpp/gateway/gateway.go
+++ b/xmpp/gateway/gateway.go
@@ -23,6 +23,17 @@ type Reply struct {
End uint64
}
+type MarkerType byte
+const (
+ MarkerTypeReceived MarkerType = iota
+ MarkerTypeDisplayed
+)
+
+type marker struct {
+ Type MarkerType
+ Id string
+}
+
const NSNick string = "http://jabber.org/protocol/nick"
// Queue stores presences to send later
@@ -44,25 +55,33 @@ 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, "", isCarbon)
+ sendMessageWrapper(to, from, body, id, component, reply, nil, "", isCarbon)
}
// SendServiceMessage creates and sends a simple message stanza from transport
func SendServiceMessage(to string, body string, component *xmpp.Component) {
- sendMessageWrapper(to, "", body, "", component, nil, "", false)
+ sendMessageWrapper(to, "", body, "", component, nil, nil, "", 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, "", false)
+ sendMessageWrapper(to, from, body, "", component, nil, nil, "", 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, oob, isCarbon)
+ sendMessageWrapper(to, from, body, id, component, reply, nil, oob, isCarbon)
}
-func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isCarbon bool) {
+// SendMessageMarker creates and sends a message stanza with a XEP-0333 marker
+func SendMessageMarker(to string, from string, component *xmpp.Component, markerType MarkerType, markerId string) {
+ sendMessageWrapper(to, from, "", "", component, nil, &marker{
+ Type: markerType,
+ Id: markerId,
+ }, "", false)
+}
+
+func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, marker *marker, oob string, isCarbon bool) {
toJid, err := stanza.NewJid(to)
if err != nil {
log.WithFields(log.Fields{
@@ -120,6 +139,13 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
message.Extensions = append(message.Extensions, extensions.NewReplyFallback(reply.Start, reply.End))
}
}
+ if marker != nil {
+ if marker.Type == MarkerTypeReceived {
+ message.Extensions = append(message.Extensions, stanza.MarkReceived{ID: marker.Id})
+ } else if marker.Type == MarkerTypeDisplayed {
+ message.Extensions = append(message.Extensions, stanza.MarkDisplayed{ID: marker.Id})
+ }
+ }
if !isCarbon && toJid.Resource != "" {
message.Extensions = append(message.Extensions, stanza.HintNoCopy{})
}
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index 4c27b3c..088cb21 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -199,10 +199,12 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
if err != nil {
log.Errorf("Failed to replace id %v with %v %v", replace.Id, msg.Id, tgMessageId)
} */
- session.AddToOutbox(replace.Id, resource)
+ session.AddToEditOutbox(replace.Id, resource)
} else {
err = gateway.IdsDB.Set(session.Session.Login, bare, toID, tgMessageId, msg.Id)
- if err != nil {
+ if err == nil {
+ session.AddToOutbox(msg.Id, resource)
+ } else {
log.Errorf("Failed to save ids %v/%v %v", toID, tgMessageId, msg.Id)
}
}
@@ -458,6 +460,7 @@ func handleGetDiscoInfo(s xmpp.Sender, iq *stanza.IQ) {
_, ok := toToID(iq.To)
if ok {
disco.AddIdentity("", "account", "registered")
+ disco.AddFeatures(stanza.NSMsgChatMarkers)
} else {
disco.AddIdentity("Telegram Gateway", "gateway", "telegram")
disco.AddFeatures("jabber:iq:register")