mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 20:17:08 +00:00
Adapt avatar hash updates for MUCs
This commit is contained in:
parent
4b2ae50f67
commit
35ec6d44cd
3 changed files with 57 additions and 33 deletions
|
|
@ -499,8 +499,13 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isMUC bool
|
||||||
if chat != nil && c.Session.MUC && c.IsGroup(chat) {
|
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
|
var photo string
|
||||||
|
|
@ -513,36 +518,39 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
|
||||||
presenceType = gateway.SPType.Get(oldArgs)
|
presenceType = gateway.SPType.Get(oldArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedStatus, ok := c.cache.GetStatus(chatID)
|
// skip cache for MUCs
|
||||||
if status == "" {
|
if !isMUC {
|
||||||
if ok {
|
cachedStatus, ok := c.cache.GetStatus(chatID)
|
||||||
var typ string
|
if status == "" {
|
||||||
show, status, typ = cachedStatus.Destruct()
|
if ok {
|
||||||
if presenceType == "" {
|
var typ string
|
||||||
presenceType = typ
|
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
|
cacheShow := show
|
||||||
if presenceType == "unavailable" {
|
if presenceType == "unavailable" {
|
||||||
cacheShow = presenceType
|
cacheShow = presenceType
|
||||||
|
}
|
||||||
|
c.cache.SetStatus(chatID, cacheShow, status)
|
||||||
}
|
}
|
||||||
c.cache.SetStatus(chatID, cacheShow, status)
|
|
||||||
|
|
||||||
newArgs := []args.V{
|
newArgs := []args.V{
|
||||||
gateway.SPShow(show),
|
gateway.SPShow(show),
|
||||||
|
|
@ -576,7 +584,11 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
|
||||||
}
|
}
|
||||||
c.locks.mucCacheLock.Unlock()
|
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...)
|
return c.sendPresence(newArgs...)
|
||||||
}
|
}
|
||||||
|
|
@ -1809,7 +1821,13 @@ func (c *Client) SendMessageToGateway(chatId int64, message *client.Message, id
|
||||||
if ok && features != nil {
|
if ok && features != nil {
|
||||||
for _, feature := range *features {
|
for _, feature := range *features {
|
||||||
if feature == gateway.NodeAvatarMetadataNotify {
|
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
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -686,7 +686,7 @@ func affiliationToRole(affilation string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendPubSubAvatarNotification encourages clients to fetch an avatar
|
// 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{
|
info := stanza.Node{
|
||||||
XMLName: xml.Name{Local: "info"},
|
XMLName: xml.Name{Local: "info"},
|
||||||
Attrs: []xml.Attr{
|
Attrs: []xml.Attr{
|
||||||
|
|
@ -698,7 +698,7 @@ func SendPubSubAvatarNotification(component *xmpp.Component, jid string, chatId
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"chatId": chatId,
|
"chatJid": chatJid,
|
||||||
}).Debugf("%#v", info)
|
}).Debugf("%#v", info)
|
||||||
|
|
||||||
event := &stanza.PubSubEvent{
|
event := &stanza.PubSubEvent{
|
||||||
|
|
@ -718,7 +718,7 @@ func SendPubSubAvatarNotification(component *xmpp.Component, jid string, chatId
|
||||||
|
|
||||||
message := stanza.Message{
|
message := stanza.Message{
|
||||||
Attrs: stanza.Attrs{
|
Attrs: stanza.Attrs{
|
||||||
From: CHATJID(chatId, false),
|
From: chatJid,
|
||||||
To: jid,
|
To: jid,
|
||||||
Type: stanza.MessageTypeHeadline,
|
Type: stanza.MessageTypeHeadline,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -2193,7 +2193,13 @@ func sendPubSubAvatarNotifications(s xmpp.Sender, jid string, session *telegram.
|
||||||
sha1 := session.GetPhotoSha1(chat.Photo.Small, chat.Id)
|
sha1 := session.GetPhotoSha1(chat.Photo.Small, chat.Id)
|
||||||
size := session.GetPhotoSize(chat.Photo.Small)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue