Refactor SendMessage/SendMessageWithOOB invocations

This commit is contained in:
Bohdan Horbeshko 2026-07-27 22:58:48 -04:00
parent 0ab4073cc0
commit b9bb367287
4 changed files with 22 additions and 37 deletions

View file

@ -405,7 +405,10 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
} }
for _, jid := range jids { for _, jid := range jids {
if safeToSend { if safeToSend {
gateway.SendMessage(jid, from, text.String(), id, c.xmpp, nil, 0, replaceId, isCarbon, isMUC, false, originalFrom, "", "", "", nil) gateway.SendMessage(jid, from, c.xmpp,
gateway.SMBody(text.String()), gateway.SMId(id), gateway.SMReplaceId(replaceId),
gateway.SMIsCarbon(isCarbon), gateway.SMIsGroupchat(isMUC), gateway.SMOriginalFrom(originalFrom),
)
} else { } else {
gateway.SendMUCAnnouncement(jid, from, text.String(), nickname, id, c.xmpp) gateway.SendMUCAnnouncement(jid, from, text.String(), nickname, id, c.xmpp)
} }

View file

@ -2060,9 +2060,17 @@ func (c *Client) SendMessageToGateway(chatId int64, message *client.Message, id
} }
for _, jid := range jids { for _, jid := range jids {
gateway.SendMessageWithOOB(jid, from, text, sId, c.xmpp, reply, timestamp, oob, "", isCarbon, isGroupchat, c.Session.Receipts, originalFrom, stanzaId, mamQueryId, mucJID, mucUserItem) commonArgs := []args.V{
gateway.SMReply(reply), gateway.SMTimestamp(timestamp), gateway.SMIsCarbon(isCarbon),
gateway.SMIsGroupchat(isGroupchat), gateway.SMRequestReceipt(c.Session.Receipts),
gateway.SMOriginalFrom(originalFrom), gateway.SMMamQueryId(mamQueryId),
gateway.SMMucJID(mucJID), gateway.SMMucUserItem(mucUserItem),
}
gateway.SendMessage(jid, from, c.xmpp, append(commonArgs,
gateway.SMBody(text), gateway.SMId(sId), gateway.SMStanzaId(stanzaId), gateway.SMOOB(oob))...)
if auxText != "" { if auxText != "" {
gateway.SendMessage(jid, from, auxText, auxId, c.xmpp, reply, timestamp, "", isCarbon, isGroupchat, c.Session.Receipts, originalFrom, auxId, mamQueryId, mucJID, mucUserItem) gateway.SendMessage(jid, from, c.xmpp, append(commonArgs,
gateway.SMBody(auxText), gateway.SMId(auxId), gateway.SMStanzaId(auxId))...)
} }
} }
c.UpdateLastChatMessageId(chatId, sId) c.UpdateLastChatMessageId(chatId, sId)
@ -2951,23 +2959,9 @@ func (c *Client) sendMessagesReverse(chatID int64, messages []*client.Message, p
} }
for _, to := range plainTos { for _, to := range plainTos {
gateway.SendMessage( gateway.SendMessage(to, from, c.xmpp,
to, gateway.SMBody(c.formatMessage(0, 0, false, !isMUC, message)), gateway.SMId(sId),
from, gateway.SMReply(reply), gateway.SMIsGroupchat(isMUC), gateway.SMOriginalFrom(originalFrom),
c.formatMessage(0, 0, false, !isMUC, message),
sId,
c.xmpp,
reply,
0,
"",
false,
isMUC,
false,
originalFrom,
"",
"",
"",
nil,
) )
} }
} else { } else {

View file

@ -128,13 +128,10 @@ func ResourcePrep(resource string) (string, error) {
return resourcePrepProfile.Prepare(resource) return resourcePrepProfile.Prepare(resource)
} }
// SendMessage creates and sends a message stanza // SendMessage creates and sends a message stanza. See the SM* option
func SendMessage(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, replaceId string, isCarbon, isGroupchat, requestReceipt bool, originalFrom, stanzaId, mamQueryId, mucJID string, mucUserItem *MUCUserItem) { // constructors below (SMBody, SMReply, SMOOB, ...) for what can be set.
sendMessageWrapper(to, from, component, func SendMessage(to, from string, component *xmpp.Component, args ...args.V) {
SMBody(body), SMId(id), SMReply(reply), SMTimestamp(timestamp), SMReplaceId(replaceId), sendMessageWrapper(to, from, component, args...)
SMIsCarbon(isCarbon), SMIsGroupchat(isGroupchat), SMRequestReceipt(requestReceipt),
SMOriginalFrom(originalFrom), SMStanzaId(stanzaId), SMMamQueryId(mamQueryId), SMMucJID(mucJID), SMMucUserItem(mucUserItem),
)
} }
// SendServiceMessage creates and sends a simple message stanza from transport // SendServiceMessage creates and sends a simple message stanza from transport
@ -200,15 +197,6 @@ func SendErrorMessageWithBody(to, from, body, errorText, id string, code int, is
sendMessageWrapper(to, from, component, SMBody(body), SMErrorText(errorText), SMId(id), SMIsGroupchat(isGroupchat), SMErrorCode(code)) sendMessageWrapper(to, from, component, SMBody(body), SMErrorText(errorText), SMId(id), SMIsGroupchat(isGroupchat), SMErrorCode(code))
} }
// SendMessageWithOOB creates and sends a message stanza with OOB URL
func SendMessageWithOOB(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob, replaceId string, isCarbon, isGroupchat, requestReceipt bool, originalFrom, stanzaId, mamQueryId, mucJID string, mucUserItem *MUCUserItem) {
sendMessageWrapper(to, from, component,
SMBody(body), SMId(id), SMReply(reply), SMTimestamp(timestamp), SMOOB(oob), SMReplaceId(replaceId),
SMIsCarbon(isCarbon), SMIsGroupchat(isGroupchat), SMRequestReceipt(requestReceipt),
SMOriginalFrom(originalFrom), SMStanzaId(stanzaId), SMMamQueryId(mamQueryId), SMMucJID(mucJID), SMMucUserItem(mucUserItem),
)
}
// SendSubjectMessage creates and sends a MUC subject // SendSubjectMessage creates and sends a MUC subject
func SendSubjectMessage(to, from, subject, id string, component *xmpp.Component, timestamp int64) { func SendSubjectMessage(to, from, subject, id string, component *xmpp.Component, timestamp int64) {
sendMessageWrapper(to, from, component, SMSubject(subject), SMId(id), SMTimestamp(timestamp), SMIsGroupchat(true), SMForceSubject(true)) sendMessageWrapper(to, from, component, SMSubject(subject), SMId(id), SMTimestamp(timestamp), SMIsGroupchat(true), SMForceSubject(true))

View file

@ -344,7 +344,7 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
} }
} else if isCommand && isGroupchat && session.Session.MUC { } else if isCommand && isGroupchat && session.Session.MUC {
// pong outgoing commands back to groupchats // pong outgoing commands back to groupchats
gateway.SendMessage(msg.From, msg.To + "/" + session.GetMUCNickname(0), text, "", component, nil, 0, "", false, isGroupchat, false, "", "", "", "", nil) gateway.SendMessage(msg.From, msg.To+"/"+session.GetMUCNickname(0), component, gateway.SMBody(text), gateway.SMIsGroupchat(isGroupchat))
} else { } else {
/* /*
// if a message failed to edit on Telegram side, match new XMPP ID with old Telegram ID anyway // if a message failed to edit on Telegram side, match new XMPP ID with old Telegram ID anyway