[Git][gajim/gajim][master] 2 commits: Count MUC members correctly

Philipp Hörist gitlab at dev.gajim.org
Sat Jan 26 21:37:29 CET 2019


Philipp Hörist pushed to branch master at gajim / gajim


Commits:
e994b8f4 by Philipp Hörist at 2019-01-26T19:40:07Z
Count MUC members correctly

- Pass Affiliation enum to get_uf_affiliation
- Pass Role enum to get_uf_role

- - - - -
d6b7916f by Philipp Hörist at 2019-01-26T20:25:33Z
Prevent callbacks on destroyed objects

Fixes #9560

- - - - -


7 changed files:

- gajim/command_system/implementation/standard.py
- gajim/common/helpers.py
- gajim/groupchat_control.py
- gajim/gtk/groupchat_config.py
- gajim/gtk/tooltips.py
- gajim/gtk/util.py
- gajim/vcard.py


Changes:

=====================================
gajim/command_system/implementation/standard.py
=====================================
@@ -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)


=====================================
gajim/common/helpers.py
=====================================
@@ -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()


=====================================
gajim/groupchat_control.py
=====================================
@@ -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):


=====================================
gajim/gtk/groupchat_config.py
=====================================
@@ -15,6 +15,7 @@
 import logging
 
 import nbxmpp
+from gi.repository import Gdk
 from gi.repository import Gtk
 
 from gajim.common import app
@@ -25,6 +26,7 @@ from gajim.common.caps_cache import muc_caps_cache
 from gajim.gtk.dialogs import ErrorDialog
 from gajim.gtk.dataform import DataFormWidget
 from gajim.gtk.util import get_builder
+from gajim.gtk.util import ensure_not_destroyed
 
 log = logging.getLogger('gajim.gtk.groupchat_config')
 
@@ -36,6 +38,7 @@ class GroupchatConfig(Gtk.ApplicationWindow):
         self.set_position(Gtk.WindowPosition.CENTER)
         self.set_show_menubar(False)
         self.set_title(_('Group Chat Configuration'))
+        self._destroyed = False
 
         self.account = account
         self.jid = jid
@@ -77,6 +80,8 @@ class GroupchatConfig(Gtk.ApplicationWindow):
 
         self._ui.connect_signals(self)
         self.connect('delete-event', self._cancel)
+        self.connect('destroy', self._on_destroy)
+        self.connect('key-press-event', self._on_key_press)
         self.show_all()
         self._ui.stack.notify('visible-child-name')
 
@@ -291,6 +296,10 @@ class GroupchatConfig(Gtk.ApplicationWindow):
 
         return add, remove, modified
 
+    def _on_key_press(self, _widget, event):
+        if event.keyval == Gdk.KEY_Escape:
+            self._on_cancel()
+
     def _on_cancel(self, *args):
         self._cancel()
         self.destroy()
@@ -300,6 +309,9 @@ class GroupchatConfig(Gtk.ApplicationWindow):
             con = app.connections[self.account]
             con.get_module('MUC').cancel_config(self.jid)
 
+    def _on_destroy(self, *args):
+        self._destroyed = True
+
     def _set_affiliations(self):
         add, remove, modified = self._get_diff()
 
@@ -339,6 +351,7 @@ class GroupchatConfig(Gtk.ApplicationWindow):
         con = app.connections[self.account]
         con.get_module('MUC').set_affiliation(self.jid, diff_dict)
 
+    @ensure_not_destroyed
     def _on_affiliations_received(self, result):
         if result.is_error:
             log.info('Error while requesting %s affiliations: %s',


=====================================
gajim/gtk/tooltips.py
=====================================
@@ -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}


=====================================
gajim/gtk/util.py
=====================================
@@ -25,6 +25,7 @@ import sys
 import logging
 import xml.etree.ElementTree as ET
 from pathlib import Path
+from functools import wraps
 
 from gi.repository import Gdk
 from gi.repository import Gtk
@@ -489,3 +490,12 @@ def get_hardware_key_codes(keyval):
     if not valid:
         return []
     return [key.keycode for key in key_map_keys]
+
+
+def ensure_not_destroyed(func):
+    @wraps(func)
+    def func_wrapper(self, *args, **kwargs):
+        if self._destroyed:
+            return
+        return func(self, *args, **kwargs)
+    return func_wrapper


=====================================
gajim/vcard.py
=====================================
@@ -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)



View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/80e5934bb5e60b872b9b9dff72ecd096b19b109c...d6b7916f2b37ea9777701a3bc8c1a5633e030ff4

-- 
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/80e5934bb5e60b872b9b9dff72ecd096b19b109c...d6b7916f2b37ea9777701a3bc8c1a5633e030ff4
You're receiving this email because of your account on dev.gajim.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gajim.org/pipermail/commits/attachments/20190126/0c631fd2/attachment-0001.html>


More information about the Commits mailing list