From 959dc061ff30ba1cf5c699adc0f7d1d991d7afa5 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Sat, 8 Jul 2023 23:52:30 -0400 Subject: Send carbons for outgoing messages to other resources --- xmpp/gateway/gateway.go | 14 +++++++------- xmpp/handlers.go | 3 +++ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'xmpp') diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go index 29c8a07..7e54ee5 100644 --- a/xmpp/gateway/gateway.go +++ b/xmpp/gateway/gateway.go @@ -42,8 +42,8 @@ var DirtySessions = false var MessageOutgoingPermission = false // SendMessage creates and sends a message stanza -func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, isOutgoing bool) { - sendMessageWrapper(to, from, body, id, component, reply, "", isOutgoing) +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) } // SendServiceMessage creates and sends a simple message stanza from transport @@ -57,11 +57,11 @@ func SendTextMessage(to string, from string, body string, component *xmpp.Compon } // 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, isOutgoing bool) { - sendMessageWrapper(to, from, body, id, component, reply, oob, isOutgoing) +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) } -func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isOutgoing bool) { +func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isCarbon bool) { toJid, err := stanza.NewJid(to) if err != nil { log.WithFields(log.Fields{ @@ -83,7 +83,7 @@ func sendMessageWrapper(to string, from string, body string, id string, componen logFrom = from messageFrom = from + "@" + componentJid } - if isOutgoing { + if isCarbon { messageTo = messageFrom messageFrom = bareTo + "/" + Jid.Resource } else { @@ -120,7 +120,7 @@ func sendMessageWrapper(to string, from string, body string, id string, componen } } - if isOutgoing { + if isCarbon { carbonMessage := extensions.ClientMessage{ Attrs: stanza.Attrs{ From: bareTo, diff --git a/xmpp/handlers.go b/xmpp/handlers.go index 1286914..e6671bc 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -167,6 +167,8 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) { } } + session.SendMessageLock.Lock() + defer session.SendMessageLock.Unlock() tgMessageId := session.ProcessOutgoingMessage(toID, text, msg.From, replyId, replaceId) if tgMessageId != 0 { if replaceId != 0 { @@ -181,6 +183,7 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) { log.Errorf("Failed to save ids %v/%v %v", toID, tgMessageId, msg.Id) } } + session.AddToOutbox(msg.Id, resource) } else { /* // if a message failed to edit on Telegram side, match new XMPP ID with old Telegram ID anyway -- cgit v1.2.3