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


Commits:
3a4006ec by Philipp Hörist at 2020-01-26T22:26:21+01:00
Roster: Correctly process roster item updates

A roster push contains always the whole entry, so instead of updating
only the attributes which are present in the roster push, fill all missing
attrs with default values, e.g. None for a missing name attr

Fixes #9963

- - - - -


1 changed file:

- gajim/common/modules/roster.py


Changes:

=====================================
gajim/common/modules/roster.py
=====================================
@@ -149,34 +149,33 @@ class Roster(BaseModule):
 
         for item in query.getTags('item'):
             jid = item.getAttr('jid')
-            self._data[jid] = self._get_item_attrs(item, update=False)
+            self._data[jid] = self._get_item_attrs(item)
             self._log.info('Item %s: %s', jid, self._data[jid])
         return version
 
     @staticmethod
-    def _get_item_attrs(item, update=True):
+    def _get_item_attrs(item, update=False):
         '''
         update: True
-            returns only the attrs that are present in the item
+            Omit avatar_sha from the returned attrs
 
         update: False
-            returns the attrs of the item but fills missing
-            attrs with default values
+            Include the default value fro avatar_sha in the returned attrs
         '''
 
         default_attrs = {'name': None,
                          'ask': None,
                          'subscription': None,
-                         'groups': [],
-                         'avatar_sha': None}
+                         'groups': []}
+
+        if not update:
+            default_attrs['avatar_sha'] = None
 
         attrs = item.getAttrs()
         del attrs['jid']
         groups = {group.getData() for group in item.getTags('group')}
         attrs['groups'] = list(groups)
 
-        if update:
-            return attrs
         default_attrs.update(attrs)
         return default_attrs
 
@@ -196,13 +195,13 @@ class Roster(BaseModule):
 
         if item.getAttr('subscription') == 'remove':
             self._data.pop(jid, None)
-            attrs = self._get_item_attrs(item, update=False)
+            attrs = self._get_item_attrs(item)
             return RosterItem(jid, attrs)
 
         if jid not in self._data:
-            self._data[jid] = self._get_item_attrs(item, update=False)
+            self._data[jid] = self._get_item_attrs(item)
         else:
-            self._data[jid].update(self._get_item_attrs(item))
+            self._data[jid].update(self._get_item_attrs(item, update=True))
 
         return RosterItem(jid, self._data[jid])
 



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/3a4006ecbfde2282b2d9c0b202c9d739fe5a9528

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/3a4006ecbfde2282b2d9c0b202c9d739fe5a9528
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to