Send announcement messages from a temporary MUC occupant && fix edit/delete message regression for non-MUCs

This commit is contained in:
Bohdan Horbeshko 2025-07-06 23:11:54 -04:00
parent b5129906e3
commit 29e66a21d7
3 changed files with 52 additions and 6 deletions

View file

@ -276,7 +276,7 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
if isMUC { if isMUC {
_, jids = c.getMUCJoinedJIDs(update.ChatId, nil, true) _, jids = c.getMUCJoinedJIDs(update.ChatId, nil, true)
} else { } else {
c.getCarbonFullJids(true, ignoredResource) jids = c.getCarbonFullJids(true, ignoredResource)
} }
if len(jids) == 0 { if len(jids) == 0 {
log.Info("The only resource is ignored, aborting") log.Info("The only resource is ignored, aborting")
@ -409,15 +409,22 @@ func (c *Client) updateDeleteMessages(update *client.UpdateDeleteMessages) {
if isGroupchat { if isGroupchat {
fromJid = gateway.MUCJID(update.ChatId) fromJid = gateway.MUCJID(update.ChatId)
_, jids = c.getMUCJoinedJIDs(update.ChatId, nil, true) _, jids = c.getMUCJoinedJIDs(update.ChatId, nil, true)
} else { var nickname string
fromJid = gateway.CHATNODE(update.ChatId) if chat != nil {
c.getCarbonFullJids(true, "") nickname = chat.Title
} }
for _, jid := range jids {
gateway.SendMUCAnnouncement(jid, fromJid, text, nickname, c.xmpp)
}
} else {
fromJid = gateway.CHATNODE(update.ChatId)
jids = c.getCarbonFullJids(true, "")
for _, jid := range jids { for _, jid := range jids {
gateway.SendTextMessage(jid, fromJid, text, c.xmpp, isGroupchat) gateway.SendTextMessage(jid, fromJid, text, c.xmpp, isGroupchat)
} }
} }
} }
}
func (c *Client) updateAuthorizationState(update *client.UpdateAuthorizationState) { func (c *Client) updateAuthorizationState(update *client.UpdateAuthorizationState) {
switch update.AuthorizationState.AuthorizationStateType() { switch update.AuthorizationState.AuthorizationStateType() {

View file

@ -2061,7 +2061,12 @@ func (c *Client) returnMessage(returnJid string, chatID int64, text string, code
if code != 0 { if code != 0 {
gateway.SendErrorMessage(returnJid, gateway.MUCJID(chatID), text, code, isGroupchat, c.xmpp) gateway.SendErrorMessage(returnJid, gateway.MUCJID(chatID), text, code, isGroupchat, c.xmpp)
} else { } else {
gateway.SendTextMessage(returnJid, gateway.MUCJID(chatID), text, c.xmpp, isGroupchat) var nickname string
chat, err := c.GetChatByID(chatID, nil)
if err == nil {
nickname = chat.Title
}
gateway.SendMUCAnnouncement(returnJid, gateway.MUCJID(chatID), text, nickname, c.xmpp)
} }
} else { } else {
gateway.SendTextMessage(returnJid, gateway.CHATNODE(chatID), text, c.xmpp, isGroupchat) gateway.SendTextMessage(returnJid, gateway.CHATNODE(chatID), text, c.xmpp, isGroupchat)

View file

@ -110,6 +110,40 @@ func SendTextMessage(to, from, body string, component *xmpp.Component, isGroupch
sendMessageWrapper(to, from, body, "", "", id, component, nil, nil, 0, "", "", false, isGroupchat, false, false, "", 0, "", "", 0) sendMessageWrapper(to, from, body, "", "", id, component, nil, nil, 0, "", "", false, isGroupchat, false, false, "", 0, "", "", 0)
} }
// SendMUCAnnouncement creates and sends a message by a temporary occupant
func SendMUCAnnouncement(to, from, body, nickname string, component *xmpp.Component) {
if nickname == "" {
nickname = "announcement"
}
fullFrom := from + "/" + nickname
SendPresence(
component,
to,
SPFullFrom(fullFrom),
SPMUCAffiliation("admin"),
SPMUCRole("moderator"),
SPMUCJid(from),
)
var id string
if uuid, err := uuid.NewRandom(); err == nil {
id = uuid.String()
}
sendMessageWrapper(to, fullFrom, body, "", "", id, component, nil, nil, 0, "", "", false, true, false, false, "", 0, "", "", 0)
SendPresence(
component,
to,
SPType("unavailable"),
SPFullFrom(fullFrom),
SPMUCAffiliation("none"),
SPMUCRole("none"),
SPMUCJid(from),
)
}
// SendErrorMessage creates and sends an error message stanza // SendErrorMessage creates and sends an error message stanza
func SendErrorMessage(to, from, text string, code int, isGroupchat bool, component *xmpp.Component) { func SendErrorMessage(to, from, text string, code int, isGroupchat bool, component *xmpp.Component) {
sendMessageWrapper(to, from, "", "", text, "", component, nil, nil, 0, "", "", false, isGroupchat, false, false, "", code, "", "", 0) sendMessageWrapper(to, from, "", "", text, "", component, nil, nil, 0, "", "", false, isGroupchat, false, false, "", code, "", "", 0)