Count MUC members correctly

- Pass Affiliation enum to get_uf_affiliation
- Pass Role enum to get_uf_role
This commit is contained in:
Philipp Hörist 2019-01-26 20:40:07 +01:00
parent 80e5934bb5
commit e994b8f402
5 changed files with 20 additions and 20 deletions

View File

@ -379,8 +379,8 @@ class StandardGroupChatCommands(CommandContainer):
for nick in nicks:
contact = get_contact(nick)
role = helpers.get_uf_role(contact.role.value)
affiliation = helpers.get_uf_affiliation(contact.affiliation.value)
role = helpers.get_uf_role(contact.role)
affiliation = helpers.get_uf_affiliation(contact.affiliation)
self.echo("%s - %s - %s" % (nick, role, affiliation))
@command('ignore', raw=True)

View File

@ -327,19 +327,19 @@ def get_uf_ask(ask):
def get_uf_role(role, plural=False):
''' plural determines if you get Moderators or Moderator'''
if role == 'none':
if role.value == 'none':
role_name = Q_('?Group Chat Contact Role:None')
elif role == 'moderator':
elif role.value == 'moderator':
if plural:
role_name = _('Moderators')
else:
role_name = _('Moderator')
elif role == 'participant':
elif role.value == 'participant':
if plural:
role_name = _('Participants')
else:
role_name = _('Participant')
elif role == 'visitor':
elif role.value == 'visitor':
if plural:
role_name = _('Visitors')
else:
@ -348,13 +348,13 @@ def get_uf_role(role, plural=False):
def get_uf_affiliation(affiliation):
'''Get a nice and translated affilition for muc'''
if affiliation == 'none':
if affiliation.value == 'none':
affiliation_name = Q_('?Group Chat Contact Affiliation:None')
elif affiliation == 'owner':
elif affiliation.value == 'owner':
affiliation_name = _('Owner')
elif affiliation == 'admin':
elif affiliation.value == 'admin':
affiliation_name = _('Administrator')
elif affiliation == 'member':
elif affiliation.value == 'member':
affiliation_name = _('Member')
else: # Argl ! An unknown affiliation !
affiliation_name = affiliation.capitalize()

View File

@ -1768,7 +1768,7 @@ class GroupchatControl(ChatControlBase):
self.model[role_iter][Column.TEXT] = role_name
def draw_all_roles(self):
for role in ('visitor', 'participant', 'moderator'):
for role in (Role.VISITOR, Role.PARTICIPANT, Role.MODERATOR):
self.draw_role(role)
def _change_nick(self, new_nick: str) -> None:
@ -1899,7 +1899,7 @@ class GroupchatControl(ChatControlBase):
return
affiliation = helpers.get_uf_affiliation(
event.properties.affiliation.value)
event.properties.affiliation)
nick = event.properties.muc_nickname
reason = event.properties.muc_user.reason
reason = '' if reason is None else ': {reason}'.format(reason=reason)
@ -1932,7 +1932,7 @@ class GroupchatControl(ChatControlBase):
if event.room_jid != self.room_jid:
return
role = helpers.get_uf_role(event.properties.role.value)
role = helpers.get_uf_role(event.properties.role)
nick = event.properties.muc_nickname
reason = event.properties.muc_user.reason
reason = '' if reason is None else ': {reason}'.format(reason=reason)
@ -2167,17 +2167,17 @@ class GroupchatControl(ChatControlBase):
contact = app.contacts.get_gc_contact(self.account,
self.room_jid,
nick)
role_name = helpers.get_uf_role(contact.role.value, plural=True)
role_name = helpers.get_uf_role(contact.role, plural=True)
# Create Role
role_iter = self.get_role_iter(contact.role.value)
role_iter = self.get_role_iter(contact.role)
if not role_iter:
icon_name = get_icon_name('closed')
ext_columns = [None] * self.nb_ext_renderers
row = [icon_name, contact.role.value,
'role', role_name, None] + ext_columns
role_iter = self.model.append(None, row)
self._role_refs[contact.role.value] = Gtk.TreeRowReference(
self._role_refs[contact.role] = Gtk.TreeRowReference(
self.model, self.model.get_path(role_iter))
# Avatar
@ -2262,7 +2262,7 @@ class GroupchatControl(ChatControlBase):
del self._contact_refs[nick]
if self.model.iter_n_children(parent_iter) == 0:
role = self.model[parent_iter][Column.NICK]
del self._role_refs[role]
del self._role_refs[Role(role)]
self.model.remove(parent_iter)
def _message_sent(self, obj):

View File

@ -214,7 +214,7 @@ class GCTooltip():
# Affiliation
if not contact.affiliation.is_none:
uf_affiliation = helpers.get_uf_affiliation(contact.affiliation.value)
uf_affiliation = helpers.get_uf_affiliation(contact.affiliation)
uf_affiliation = \
_('%(owner_or_admin_or_member)s of this group chat') \
% {'owner_or_admin_or_member': uf_affiliation}

View File

@ -372,11 +372,11 @@ class VcardWindow:
ask_label = self.xml.get_object('ask_label')
if self.gc_contact:
self.xml.get_object('subscription_title_label').set_markup(Q_("?Role in Group Chat:<b>Role:</b>"))
uf_role = helpers.get_uf_role(self.gc_contact.role.value)
uf_role = helpers.get_uf_role(self.gc_contact.role)
subscription_label.set_text(uf_role)
self.xml.get_object('ask_title_label').set_markup(_("<b>Affiliation:</b>"))
uf_affiliation = helpers.get_uf_affiliation(self.gc_contact.affiliation.value)
uf_affiliation = helpers.get_uf_affiliation(self.gc_contact.affiliation)
ask_label.set_text(uf_affiliation)
else:
uf_sub = helpers.get_uf_sub(self.contact.sub)