forked from MirrorHub/mautrix-whatsapp
Make Portal.UpdateName work without a room
This commit is contained in:
parent
d7100cf0bd
commit
c16af35d1b
1 changed files with 21 additions and 17 deletions
38
portal.go
38
portal.go
|
@ -1011,28 +1011,32 @@ func (portal *Portal) UpdateName(name string, setBy types.JID, updateInfo bool)
|
|||
if name == "" && portal.IsBroadcastList() {
|
||||
name = UnnamedBroadcastName
|
||||
}
|
||||
if portal.Name != name || !portal.NameSet {
|
||||
if portal.Name != name || (!portal.NameSet && len(portal.MXID) > 0) {
|
||||
portal.log.Debugfln("Updating name %q -> %q", portal.Name, name)
|
||||
portal.Name = name
|
||||
portal.NameSet = false
|
||||
if updateInfo {
|
||||
defer portal.Update(nil)
|
||||
}
|
||||
|
||||
intent := portal.MainIntent()
|
||||
if !setBy.IsEmpty() {
|
||||
intent = portal.bridge.GetPuppetByJID(setBy).IntentFor(portal)
|
||||
}
|
||||
_, err := intent.SetRoomName(portal.MXID, name)
|
||||
if errors.Is(err, mautrix.MForbidden) && intent != portal.MainIntent() {
|
||||
_, err = portal.MainIntent().SetRoomName(portal.MXID, name)
|
||||
}
|
||||
if err == nil {
|
||||
portal.NameSet = true
|
||||
if updateInfo {
|
||||
portal.UpdateBridgeInfo()
|
||||
portal.Update(nil)
|
||||
if len(portal.MXID) > 0 {
|
||||
intent := portal.MainIntent()
|
||||
if !setBy.IsEmpty() {
|
||||
intent = portal.bridge.GetPuppetByJID(setBy).IntentFor(portal)
|
||||
}
|
||||
_, err := intent.SetRoomName(portal.MXID, name)
|
||||
if errors.Is(err, mautrix.MForbidden) && intent != portal.MainIntent() {
|
||||
_, err = portal.MainIntent().SetRoomName(portal.MXID, name)
|
||||
}
|
||||
if err == nil {
|
||||
portal.NameSet = true
|
||||
if updateInfo {
|
||||
portal.UpdateBridgeInfo()
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
portal.log.Warnln("Failed to set room name:", err)
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
portal.log.Warnln("Failed to set room name:", err)
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
|
Loading…
Reference in a new issue