mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-21 18:22:00 -08:00
Prevent re-requesting avatar data (xmpp) (#1117)
Prevent asking the server again and again for a user's avatar if the server does not respond to our initial request.
This commit is contained in:
parent
9440b9e313
commit
900375679b
@ -24,14 +24,16 @@ type Bxmpp struct {
|
|||||||
connected bool
|
connected bool
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
||||||
avatarMap map[string]string
|
avatarAvailability map[string]bool
|
||||||
|
avatarMap map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *bridge.Config) bridge.Bridger {
|
func New(cfg *bridge.Config) bridge.Bridger {
|
||||||
return &Bxmpp{
|
return &Bxmpp{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
xmppMap: make(map[string]string),
|
xmppMap: make(map[string]string),
|
||||||
avatarMap: make(map[string]string),
|
avatarAvailability: make(map[string]bool),
|
||||||
|
avatarMap: make(map[string]string),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,10 +246,14 @@ func (b *Bxmpp) handleXMPP() error {
|
|||||||
event = config.EventTopicChange
|
event = config.EventTopicChange
|
||||||
}
|
}
|
||||||
|
|
||||||
avatar := getAvatar(b.avatarMap, v.Remote, b.General)
|
available, sok := b.avatarAvailability[v.Remote]
|
||||||
if avatar == "" {
|
avatar := ""
|
||||||
|
if !sok {
|
||||||
b.Log.Debugf("Requesting avatar data")
|
b.Log.Debugf("Requesting avatar data")
|
||||||
|
b.avatarAvailability[v.Remote] = false
|
||||||
b.xc.AvatarRequestData(v.Remote)
|
b.xc.AvatarRequestData(v.Remote)
|
||||||
|
} else if available {
|
||||||
|
avatar = getAvatar(b.avatarMap, v.Remote, b.General)
|
||||||
}
|
}
|
||||||
|
|
||||||
msgID := v.ID
|
msgID := v.ID
|
||||||
@ -278,6 +284,8 @@ func (b *Bxmpp) handleXMPP() error {
|
|||||||
}
|
}
|
||||||
case xmpp.AvatarData:
|
case xmpp.AvatarData:
|
||||||
b.handleDownloadAvatar(v)
|
b.handleDownloadAvatar(v)
|
||||||
|
b.avatarAvailability[v.From] = true
|
||||||
|
b.Log.Debugf("Avatar for %s is now available", v.From)
|
||||||
case xmpp.Presence:
|
case xmpp.Presence:
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user