comparison frontends/src/quick_frontend/quick_app.py @ 2016:f09562b0704d

quick_frontend, primitivus: better notifications handling
author Goffi <goffi@goffi.org>
date Sun, 24 Jul 2016 17:56:14 +0200
parents 90134b2e3dc4
children 01aff34e8873
comparison
equal deleted inserted replaced
2015:20fb71b656e3 2016:f09562b0704d
602 notif_data[widget] = widget 602 notif_data[widget] = widget
603 type_notifs.append(notif_data) 603 type_notifs.append(notif_data)
604 self._notifications[self._notif_id] = notif_data 604 self._notifications[self._notif_id] = notif_data
605 self.callListeners('notification', entity, notif_data, profile=profile) 605 self.callListeners('notification', entity, notif_data, profile=profile)
606 606
607 def getNotifs(self, entity, type_=None, profile=C.PROF_KEY_NONE): 607 def getNotifs(self, entity=None, type_=None, exact_jid=None, profile=C.PROF_KEY_NONE):
608 """return notifications for given entity 608 """return notifications for given entity
609 609
610 @param entity(jid.JID, None, C.ENTITY_ALL): bare jid of the entity to check 610 @param entity(jid.JID, None, C.ENTITY_ALL): jid of the entity to check
611 bare jid to get all notifications, full jid to filter on resource
611 None to get general notifications 612 None to get general notifications
612 C.ENTITY_ALL to get all notifications 613 C.ENTITY_ALL to get all notifications
613 @param type_(unicode, None): notification type to filter 614 @param type_(unicode, None): notification type to filter
614 None to get all notifications 615 None to get all notifications
615 @return (list[dict]): list of notifications 616 @param exact_jid(bool, None): if True, only return notifications from
616 """ 617 exact entity jid (i.e. not including other resources)
617 notif_dict = self.profiles[profile].notifications 618 None for automatic selection (True for full jid, False else)
618 ret = [] 619 False to get resources notifications
619 if entity == C.ENTITY_ALL: 620 False doesn't do anything if entity is not a bare jid
620 for type_notifs in notif_dict.itervalues(): 621 @return (iter[dict]): notifications
621 for notifs_list in type_notifs.itervalues(): 622 """
622 ret.extend(notifs_list) 623 main_notif_dict = self.profiles[profile].notifications
623 return ret 624
624 key = '' if entity is None else entity.bare 625 if entity is C.ENTITY_ALL:
625 key_notifs = notif_dict.setdefault(key, {}) 626 selected_notifs = main_notif_dict.itervalues()
626 if type_ is not None: 627 exact_jid = False
627 return key_notifs.get(type_, ret) 628 else:
628 for notifs_list in key_notifs.itervalues(): 629 if entity is None:
629 ret.extend(notifs_list) 630 key = ''
630 return ret 631 exact_jid = False
632 else:
633 key = entity.bare
634 if exact_jid is None:
635 exact_jid = bool(entity.resource)
636 selected_notifs = (main_notif_dict.setdefault(key, {}),)
637
638 for notifs_from_select in selected_notifs:
639
640 if type_ is None:
641 type_notifs = notifs_from_select.itervalues()
642 else:
643 type_notifs = (notifs_from_select.get(type_, []),)
644
645 for notifs in type_notifs:
646 for notif in notifs:
647 if exact_jid and notif['entity'] != entity:
648 continue
649 yield notif
631 650
632 def clearNotifs(self, entity, type_=None, profile=C.PROF_KEY_NONE): 651 def clearNotifs(self, entity, type_=None, profile=C.PROF_KEY_NONE):
633 """return notifications for given entity 652 """return notifications for given entity
634 653
635 @param entity(jid.JID, None): bare jid of the entity to check 654 @param entity(jid.JID, None): bare jid of the entity to check