Commit 9894e160 authored by mathieui's avatar mathieui

muctab: fix affiliation list command

parent ab690bbd
Pipeline #3663 passed with stages
in 5 minutes and 16 seconds
...@@ -1677,21 +1677,25 @@ class MucTab(ChatTab): ...@@ -1677,21 +1677,25 @@ class MucTab(ChatTab):
self.change_affiliation(nick, affiliation) self.change_affiliation(nick, affiliation)
async def get_users_affiliations(self, jid: JID) -> None: async def get_users_affiliations(self, jid: JID) -> None:
MUC_ADMIN_NS = 'http://jabber.org/protocol/muc#admin' owners, admins, members, outcasts = await asyncio.gather(
self.core.xmpp['xep_0045'].get_affiliation_list(jid, 'owner'),
iqs = await asyncio.gather( self.core.xmpp['xep_0045'].get_affiliation_list(jid, 'admin'),
self.core.xmpp['xep_0045'].get_users_by_affiliation(jid, 'owner'), self.core.xmpp['xep_0045'].get_affiliation_list(jid, 'member'),
self.core.xmpp['xep_0045'].get_users_by_affiliation(jid, 'admin'), self.core.xmpp['xep_0045'].get_affiliation_list(jid, 'outcast'),
self.core.xmpp['xep_0045'].get_users_by_affiliation(jid, 'member'),
self.core.xmpp['xep_0045'].get_users_by_affiliation(jid, 'outcast'),
return_exceptions=True, return_exceptions=True,
) )
all_errors = functools.reduce( all_errors = functools.reduce(
lambda acc, iq: acc and isinstance(iq, (IqError, IqTimeout)), lambda acc, iq: acc and isinstance(iq, (IqError, IqTimeout)),
iqs, (owners, admins, members, outcasts),
True, True,
) )
if all_errors:
self.core.information(
'Can’t access affiliations for %s' % jid.bare,
'Error',
)
return None
theme = get_theme() theme = get_theme()
aff_colors = { aff_colors = {
...@@ -1701,29 +1705,20 @@ class MucTab(ChatTab): ...@@ -1701,29 +1705,20 @@ class MucTab(ChatTab):
'outcast': theme.CHAR_AFFILIATION_OUTCAST, 'outcast': theme.CHAR_AFFILIATION_OUTCAST,
} }
if all_errors:
self.core.information(
'Can’t access affiliations for %s' % jid.bare,
'Error',
)
return None
lines = ['Affiliations for %s' % jid.bare] lines = ['Affiliations for %s' % jid.bare]
for iq in iqs: affiliation_dict = {
if isinstance(iq, BaseException): 'owner': owners,
continue 'admin': admins,
'member': members,
query = iq.xml.find('{%s}query' % MUC_ADMIN_NS) 'outcast': outcasts,
items = query.findall('{%s}item' % MUC_ADMIN_NS) }
if not items: # Nobody with this affiliation for affiliation, items in affiliation_dict.items():
if isinstance(items, BaseException) or not items:
continue continue
affiliation = items[0].get('affiliation')
aff_char = aff_colors[affiliation] aff_char = aff_colors[affiliation]
lines.append(' %s%s' % (aff_char, affiliation.capitalize())) lines.append(' %s%s' % (aff_char, affiliation.capitalize()))
items = map(lambda i: i.get('jid'), items)
for ajid in sorted(items): for ajid in sorted(items):
lines.append(' %s' % ajid) lines.append(' %s' % ajid)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment