forked from MirrorHub/mautrix-whatsapp
Fix potential bugs in direct chat portal info updating
This commit is contained in:
parent
9a6670eb93
commit
95aa6c01a6
1 changed files with 11 additions and 13 deletions
24
puppet.go
24
puppet.go
|
@ -246,7 +246,6 @@ func reuploadAvatar(intent *appservice.IntentAPI, url string) (id.ContentURI, er
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) UpdateAvatar(source *User) bool {
|
func (puppet *Puppet) UpdateAvatar(source *User) bool {
|
||||||
oldAvatarID := puppet.Avatar
|
|
||||||
changed := source.updateAvatar(puppet.JID, &puppet.Avatar, &puppet.AvatarURL, &puppet.AvatarSet, puppet.log, puppet.DefaultIntent())
|
changed := source.updateAvatar(puppet.JID, &puppet.Avatar, &puppet.AvatarURL, &puppet.AvatarSet, puppet.log, puppet.DefaultIntent())
|
||||||
if !changed || puppet.Avatar == "unauthorized" {
|
if !changed || puppet.Avatar == "unauthorized" {
|
||||||
return changed
|
return changed
|
||||||
|
@ -255,7 +254,6 @@ func (puppet *Puppet) UpdateAvatar(source *User) bool {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
puppet.log.Warnln("Failed to set avatar:", err)
|
puppet.log.Warnln("Failed to set avatar:", err)
|
||||||
} else {
|
} else {
|
||||||
puppet.log.Debugln("Updated avatar", oldAvatarID, "->", puppet.Avatar)
|
|
||||||
puppet.AvatarSet = true
|
puppet.AvatarSet = true
|
||||||
}
|
}
|
||||||
go puppet.updatePortalAvatar()
|
go puppet.updatePortalAvatar()
|
||||||
|
@ -294,28 +292,28 @@ func (puppet *Puppet) updatePortalMeta(meta func(portal *Portal)) {
|
||||||
|
|
||||||
func (puppet *Puppet) updatePortalAvatar() {
|
func (puppet *Puppet) updatePortalAvatar() {
|
||||||
puppet.updatePortalMeta(func(portal *Portal) {
|
puppet.updatePortalMeta(func(portal *Portal) {
|
||||||
|
if portal.Avatar == puppet.Avatar && portal.AvatarURL == puppet.AvatarURL && portal.AvatarSet {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
portal.AvatarURL = puppet.AvatarURL
|
||||||
|
portal.Avatar = puppet.Avatar
|
||||||
|
portal.AvatarSet = false
|
||||||
|
defer portal.Update(nil)
|
||||||
if len(portal.MXID) > 0 {
|
if len(portal.MXID) > 0 {
|
||||||
_, err := portal.MainIntent().SetRoomAvatar(portal.MXID, puppet.AvatarURL)
|
_, err := portal.MainIntent().SetRoomAvatar(portal.MXID, puppet.AvatarURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Warnln("Failed to set avatar:", err)
|
portal.log.Warnln("Failed to set avatar:", err)
|
||||||
|
} else {
|
||||||
|
portal.AvatarSet = true
|
||||||
|
portal.UpdateBridgeInfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
portal.AvatarURL = puppet.AvatarURL
|
|
||||||
portal.Avatar = puppet.Avatar
|
|
||||||
portal.Update(nil)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) updatePortalName() {
|
func (puppet *Puppet) updatePortalName() {
|
||||||
puppet.updatePortalMeta(func(portal *Portal) {
|
puppet.updatePortalMeta(func(portal *Portal) {
|
||||||
if len(portal.MXID) > 0 {
|
portal.UpdateName(puppet.Displayname, types.EmptyJID, true)
|
||||||
_, err := portal.MainIntent().SetRoomName(portal.MXID, puppet.Displayname)
|
|
||||||
if err != nil {
|
|
||||||
portal.log.Warnln("Failed to set name:", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
portal.Name = puppet.Displayname
|
|
||||||
portal.Update(nil)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue