Adapt avatar hash updates for MUCs

This commit is contained in:
Bohdan Horbeshko 2025-06-30 20:48:30 -04:00
parent 4b2ae50f67
commit 35ec6d44cd
3 changed files with 57 additions and 33 deletions

View file

@ -499,9 +499,14 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
return err
}
var isMUC bool
if chat != nil && c.Session.MUC && c.IsGroup(chat) {
// allow MUC presence hack for avatars, still discard the rest
if status != "" || show != "" {
return nil
}
isMUC = true
}
var photo string
if chat != nil && chat.Photo != nil {
@ -513,6 +518,8 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
presenceType = gateway.SPType.Get(oldArgs)
}
// skip cache for MUCs
if !isMUC {
cachedStatus, ok := c.cache.GetStatus(chatID)
if status == "" {
if ok {
@ -543,6 +550,7 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
cacheShow = presenceType
}
c.cache.SetStatus(chatID, cacheShow, status)
}
newArgs := []args.V{
gateway.SPShow(show),
@ -576,7 +584,11 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
}
c.locks.mucCacheLock.Unlock()
if isMUC {
newArgs = append(newArgs, gateway.SPFullFrom(gateway.MUCJID(chatID)))
} else {
newArgs = gateway.SPAppendFrom(newArgs, chatID)
}
return c.sendPresence(newArgs...)
}
@ -1809,7 +1821,13 @@ func (c *Client) SendMessageToGateway(chatId int64, message *client.Message, id
if ok && features != nil {
for _, feature := range *features {
if feature == gateway.NodeAvatarMetadataNotify {
go gateway.SendPubSubAvatarNotification(c.xmpp, c.jid+"/"+resource, chatId, sha1, size)
var chatJid string
if isGroupchat {
chatJid = gateway.MUCJID(chatId)
} else {
chatJid = gateway.CHATJID(chatId, false)
}
go gateway.SendPubSubAvatarNotification(c.xmpp, c.jid+"/"+resource, chatJid, sha1, size)
break
}
}

View file

@ -686,7 +686,7 @@ func affiliationToRole(affilation string) string {
}
// SendPubSubAvatarNotification encourages clients to fetch an avatar
func SendPubSubAvatarNotification(component *xmpp.Component, jid string, chatId int64, sha1 string, size int64) {
func SendPubSubAvatarNotification(component *xmpp.Component, jid string, chatJid string, sha1 string, size int64) {
info := stanza.Node{
XMLName: xml.Name{Local: "info"},
Attrs: []xml.Attr{
@ -698,7 +698,7 @@ func SendPubSubAvatarNotification(component *xmpp.Component, jid string, chatId
},
}
log.WithFields(log.Fields{
"chatId": chatId,
"chatJid": chatJid,
}).Debugf("%#v", info)
event := &stanza.PubSubEvent{
@ -718,7 +718,7 @@ func SendPubSubAvatarNotification(component *xmpp.Component, jid string, chatId
message := stanza.Message{
Attrs: stanza.Attrs{
From: CHATJID(chatId, false),
From: chatJid,
To: jid,
Type: stanza.MessageTypeHeadline,
},

View file

@ -2193,7 +2193,13 @@ func sendPubSubAvatarNotifications(s xmpp.Sender, jid string, session *telegram.
sha1 := session.GetPhotoSha1(chat.Photo.Small, chat.Id)
size := session.GetPhotoSize(chat.Photo.Small)
gateway.SendPubSubAvatarNotification(component, jid, chat.Id, sha1, size)
var chatJid string
if session.Session.MUC && session.IsGroup(chat) {
chatJid = gateway.MUCJID(chat.Id)
} else {
chatJid = gateway.CHATJID(chat.Id, false)
}
gateway.SendPubSubAvatarNotification(component, jid, chatJid, sha1, size)
}
}