diff options
author | mathieui <mathieui@mathieui.net> | 2021-02-08 18:33:31 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-02-08 23:01:41 +0100 |
commit | ae0888bd3d6892f3da3ff0d7c3cbb60f61653f6c (patch) | |
tree | c4828d664e85ab33feaf2293ae0adcf47c526f69 | |
parent | 6c63cdb5099e1d2b1dff53481c6241f6f3fbf6e2 (diff) | |
download | poezio-ae0888bd3d6892f3da3ff0d7c3cbb60f61653f6c.tar.gz poezio-ae0888bd3d6892f3da3ff0d7c3cbb60f61653f6c.tar.bz2 poezio-ae0888bd3d6892f3da3ff0d7c3cbb60f61653f6c.tar.xz poezio-ae0888bd3d6892f3da3ff0d7c3cbb60f61653f6c.zip |
Fix #3536: Only use JID in affiliation
add nick if present.
-rw-r--r-- | poezio/tabs/muctab.py | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 847522e5..daa17630 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -240,7 +240,6 @@ class MucTab(ChatTab): """ Change the affiliation of a nick or JID """ - if not self.joined: return @@ -250,26 +249,45 @@ class MucTab(ChatTab): 'The affiliation must be one of ' + ', '.join(valid_affiliations), 'Error') return - if nick_or_jid in [user.nick for user in self.users]: - nick = nick_or_jid - jid = None - else: - nick = None + jid = None + nick = None + for user in self.users: + if user.nick == nick_or_jid: + jid = user.jid + nick = user.nick + break + if jid is None: try: jid = JID(nick_or_jid) except InvalidJID: - self.core.information('Invalid JID or missing occupant: %s' % nick_or_jid, 'Error') + self.core.information( + f'Invalid JID or missing occupant: {nick_or_jid}', + 'Error' + ) return - async def do_set_affiliation(room: JID, jid: Optional[JID], nick: Optional[str], affiliation: str, reason: str): + async def do_set_affiliation(room: JID, jid: JID, nick: Optional[str], affiliation: str, reason: str): try: - await self.core.xmpp['xep_0045'].set_affiliation(room, jid, nick, affiliation=affiliation, reason=reason) - except (IqError, IqTimeout) as e: + await self.core.xmpp['xep_0045'].set_affiliation( + room, + nick=nick, + jid=jid, + affiliation=affiliation, + reason=reason + ) + self.core.information( + f"Affiliation of {jid} set to {affiliation} successfully", + "Info" + ) + except (IqError, IqTimeout) as exc: self.core.information( - "Could not set affiliation '%s' for '%s': %s" % - (affiliation, nick_or_jid, e), "Warning") + f"Could not set affiliation '{affiliation}' for '{jid}': {exc}", + "Warning", + ) - asyncio.ensure_future(do_set_affiliation(self.jid.bare, jid, nick, affiliation, reason)) + asyncio.ensure_future( + do_set_affiliation(self.jid.bare, jid, nick, affiliation, reason) + ) def change_role(self, nick: str, role: str, reason: str = '') -> None: """ |