mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 12:17:06 +00:00
Send announcement messages from a temporary MUC occupant && fix edit/delete message regression for non-MUCs
This commit is contained in:
parent
b5129906e3
commit
29e66a21d7
3 changed files with 52 additions and 6 deletions
|
|
@ -276,7 +276,7 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
|
|||
if isMUC {
|
||||
_, jids = c.getMUCJoinedJIDs(update.ChatId, nil, true)
|
||||
} else {
|
||||
c.getCarbonFullJids(true, ignoredResource)
|
||||
jids = c.getCarbonFullJids(true, ignoredResource)
|
||||
}
|
||||
if len(jids) == 0 {
|
||||
log.Info("The only resource is ignored, aborting")
|
||||
|
|
@ -409,14 +409,21 @@ func (c *Client) updateDeleteMessages(update *client.UpdateDeleteMessages) {
|
|||
if isGroupchat {
|
||||
fromJid = gateway.MUCJID(update.ChatId)
|
||||
_, jids = c.getMUCJoinedJIDs(update.ChatId, nil, true)
|
||||
} else {
|
||||
fromJid = gateway.CHATNODE(update.ChatId)
|
||||
c.getCarbonFullJids(true, "")
|
||||
var nickname string
|
||||
if chat != nil {
|
||||
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 {
|
||||
gateway.SendTextMessage(jid, fromJid, text, c.xmpp, isGroupchat)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) updateAuthorizationState(update *client.UpdateAuthorizationState) {
|
||||
|
|
|
|||
|
|
@ -2061,7 +2061,12 @@ func (c *Client) returnMessage(returnJid string, chatID int64, text string, code
|
|||
if code != 0 {
|
||||
gateway.SendErrorMessage(returnJid, gateway.MUCJID(chatID), text, code, isGroupchat, c.xmpp)
|
||||
} 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 {
|
||||
gateway.SendTextMessage(returnJid, gateway.CHATNODE(chatID), text, c.xmpp, isGroupchat)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
// 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
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue