comparison libervia/frontends/quick_frontend/quick_contact_list.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents b47f21f2b8fa
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
230 entity = jid.JID(contact[0]) 230 entity = jid.JID(contact[0])
231 if entity.resource: 231 if entity.resource:
232 # we use entity's bare jid to cache data, so a resource here 232 # we use entity's bare jid to cache data, so a resource here
233 # will cause troubles 233 # will cause troubles
234 log.warning( 234 log.warning(
235 "Roster entities with resources are not managed, ignoring {entity}" 235 "Roster entities with resources are not managed, ignoring {entity}".format(
236 .format(entity=entity)) 236 entity=entity
237 )
238 )
237 continue 239 continue
238 self.host.contact_new_handler(*contact, profile=self.profile) 240 self.host.contact_new_handler(*contact, profile=self.profile)
239 handler._contacts_filled(self.profile) 241 handler._contacts_filled(self.profile)
240 242
241 def _fill(self): 243 def _fill(self):
248 250
249 def fill(self): 251 def fill(self):
250 handler.fill(self.profile) 252 handler.fill(self.profile)
251 253
252 def getCache( 254 def getCache(
253 self, entity, name=None, bare_default=True, create_if_not_found=False, 255 self,
254 default=Exception): 256 entity,
257 name=None,
258 bare_default=True,
259 create_if_not_found=False,
260 default=Exception,
261 ):
255 """Return a cache value for a contact 262 """Return a cache value for a contact
256 263
257 @param entity(jid.JID): entity of the contact from who we want data 264 @param entity(jid.JID): entity of the contact from who we want data
258 (resource is used if given) 265 (resource is used if given)
259 if a resource specific information is requested: 266 if a resource specific information is requested:
513 del attributes[C.CONTACT_SPECIAL] 520 del attributes[C.CONTACT_SPECIAL]
514 self._specials.remove(entity) 521 self._specials.remove(entity)
515 else: 522 else:
516 self._specials.add(entity) 523 self._specials.add(entity)
517 cache[C.CONTACT_MAIN_RESOURCE] = None 524 cache[C.CONTACT_MAIN_RESOURCE] = None
518 if 'nicknames' in cache: 525 if "nicknames" in cache:
519 del cache['nicknames'] 526 del cache["nicknames"]
520 527
521 # now the attributes we keep in cache 528 # now the attributes we keep in cache
522 # XXX: if entity is a full jid, we store the value for the resource only 529 # XXX: if entity is a full jid, we store the value for the resource only
523 cache_attr = ( 530 cache_attr = (
524 cache[C.CONTACT_RESOURCES].setdefault(entity.resource, {}) 531 cache[C.CONTACT_RESOURCES].setdefault(entity.resource, {})
571 or entity in selected 578 or entity in selected
572 or ( 579 or (
573 self.show_entities_with_notifs 580 self.show_entities_with_notifs
574 and next(self.host.get_notifs(entity.bare, profile=self.profile), None) 581 and next(self.host.get_notifs(entity.bare, profile=self.profile), None)
575 ) 582 )
576 or entity.resource is None and self.is_room(entity.bare) 583 or entity.resource is None
584 and self.is_room(entity.bare)
577 ) 585 )
578 586
579 def any_entity_visible(self, entities, check_resources=False): 587 def any_entity_visible(self, entities, check_resources=False):
580 """Tell if in a list of entities, at least one should be shown 588 """Tell if in a list of entities, at least one should be shown
581 589
674 # we may have resources with no priority 682 # we may have resources with no priority
675 # (when a cached value is added for a not connected resource) 683 # (when a cached value is added for a not connected resource)
676 priority_resource = max( 684 priority_resource = max(
677 resources_data, 685 resources_data,
678 key=lambda res: resources_data[res].get( 686 key=lambda res: resources_data[res].get(
679 C.PRESENCE_PRIORITY, -2 ** 32 687 C.PRESENCE_PRIORITY, -(2**32)
680 ), 688 ),
681 ) 689 )
682 cache[C.CONTACT_MAIN_RESOURCE] = priority_resource 690 cache[C.CONTACT_MAIN_RESOURCE] = priority_resource
683 if self.entity_visible(entity.bare): 691 if self.entity_visible(entity.bare):
684 update_type = C.UPDATE_MODIFY if was_visible else C.UPDATE_ADD 692 update_type = C.UPDATE_MODIFY if was_visible else C.UPDATE_ADD
708 self.update([entity], C.UPDATE_MODIFY, profile) 716 self.update([entity], C.UPDATE_MODIFY, profile)
709 717
710 def unselect(self, entity): 718 def unselect(self, entity):
711 """Unselect an entity 719 """Unselect an entity
712 720
713 @param entity(jid.JID): entity to unselect 721 @param entity(jid.JID): entity to unselect
714 """ 722 """
715 try: 723 try:
716 cache = self._cache[entity.bare] 724 cache = self._cache[entity.bare]
717 except: 725 except:
718 log.error("Try to unselect an entity not in cache") 726 log.error("Try to unselect an entity not in cache")
910 return self.items_sort(self.items) 918 return self.items_sort(self.items)
911 919
912 def items_sort(self, items): 920 def items_sort(self, items):
913 """sort items 921 """sort items
914 922
915 @param items(dict): items to sort (will be emptied !) 923 @param items(dict): items to sort (will be emptied !)
916 @return (OrderedDict): sorted items 924 @return (OrderedDict): sorted items
917 """ 925 """
918 ordered_items = OrderedDict() 926 ordered_items = OrderedDict()
919 bare_jids = sorted(items.keys()) 927 bare_jids = sorted(items.keys())
920 for jid_ in bare_jids: 928 for jid_ in bare_jids:
921 ordered_items[jid_] = items.pop(jid_) 929 ordered_items[jid_] = items.pop(jid_)
922 return ordered_items 930 return ordered_items
1041 @param do_update(bool): if True, a full update is done after unlocking 1049 @param do_update(bool): if True, a full update is done after unlocking
1042 if set to False, widget state can be inconsistent, be sure to know 1050 if set to False, widget state can be inconsistent, be sure to know
1043 what youa re doing! 1051 what youa re doing!
1044 """ 1052 """
1045 log.debug( 1053 log.debug(
1046 "Contact lists updates are now {}".format( 1054 "Contact lists updates are now {}".format("LOCKED" if locked else "UNLOCKED")
1047 "LOCKED" if locked else "UNLOCKED"
1048 )
1049 ) 1055 )
1050 self._update_locked = locked 1056 self._update_locked = locked
1051 if not locked and do_update: 1057 if not locked and do_update:
1052 self.update() 1058 self.update()
1053 1059
1087 @property 1093 @property
1088 def items(self): 1094 def items(self):
1089 return handler.items 1095 return handler.items
1090 1096
1091 @property 1097 @property
1092 def show_resources(self) -> bool|None: 1098 def show_resources(self) -> bool | None:
1093 return self._show_resources 1099 return self._show_resources
1094 1100
1095 @show_resources.setter 1101 @show_resources.setter
1096 def show_resources(self, show: bool|None) -> None: 1102 def show_resources(self, show: bool | None) -> None:
1097 self._show_resources = show 1103 self._show_resources = show
1098 1104
1099 @property 1105 @property
1100 def items_sorted(self): 1106 def items_sorted(self):
1101 return handler.items_sorted 1107 return handler.items_sorted