diff --git a/telegram/utils.go b/telegram/utils.go index 618ca6f..8f27279 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -499,8 +499,13 @@ 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) { - return nil + // allow MUC presence hack for avatars, still discard the rest + if status != "" || show != "" { + return nil + } + isMUC = true } var photo string @@ -513,36 +518,39 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o presenceType = gateway.SPType.Get(oldArgs) } - cachedStatus, ok := c.cache.GetStatus(chatID) - if status == "" { - if ok { - var typ string - show, status, typ = cachedStatus.Destruct() - if presenceType == "" { - presenceType = typ + // skip cache for MUCs + if !isMUC { + cachedStatus, ok := c.cache.GetStatus(chatID) + if status == "" { + if ok { + var typ string + show, status, typ = cachedStatus.Destruct() + if presenceType == "" { + presenceType = typ + } + log.WithFields(log.Fields{ + "show": show, + "status": status, + "presenceType": presenceType, + }).Debug("Cached status") + } else if user != nil && user.Status != nil { + show, status, presenceType = c.userStatusToText(user.Status, chatID) + log.WithFields(log.Fields{ + "show": show, + "status": status, + "presenceType": presenceType, + }).Debug("Status to text") + } else { + show, status = "chat", chat.Title } - log.WithFields(log.Fields{ - "show": show, - "status": status, - "presenceType": presenceType, - }).Debug("Cached status") - } else if user != nil && user.Status != nil { - show, status, presenceType = c.userStatusToText(user.Status, chatID) - log.WithFields(log.Fields{ - "show": show, - "status": status, - "presenceType": presenceType, - }).Debug("Status to text") - } else { - show, status = "chat", chat.Title } - } - cacheShow := show - if presenceType == "unavailable" { - cacheShow = presenceType + cacheShow := show + if presenceType == "unavailable" { + cacheShow = presenceType + } + c.cache.SetStatus(chatID, cacheShow, status) } - 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() - newArgs = gateway.SPAppendFrom(newArgs, chatID) + 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 } } diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go index c6de4f8..bb3d9de 100644 --- a/xmpp/gateway/gateway.go +++ b/xmpp/gateway/gateway.go @@ -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, }, diff --git a/xmpp/handlers.go b/xmpp/handlers.go index 576b533..b41e3ad 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -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) } }