quick_frontend, primitivus: better notifications handling
This commit is contained in:
parent
57daef07a7
commit
e32bd443a3
1 changed files with 44 additions and 26 deletions
|
|
@ -604,30 +604,49 @@ class QuickApp(object):
|
|||
self._notifications[self._notif_id] = notif_data
|
||||
self.callListeners('notification', entity, notif_data, profile=profile)
|
||||
|
||||
def getNotifs(self, entity, type_=None, profile=C.PROF_KEY_NONE):
|
||||
def getNotifs(self, entity=None, type_=None, exact_jid=None, profile=C.PROF_KEY_NONE):
|
||||
"""return notifications for given entity
|
||||
|
||||
@param entity(jid.JID, None, C.ENTITY_ALL): bare jid of the entity to check
|
||||
@param entity(jid.JID, None, C.ENTITY_ALL): jid of the entity to check
|
||||
bare jid to get all notifications, full jid to filter on resource
|
||||
None to get general notifications
|
||||
C.ENTITY_ALL to get all notifications
|
||||
@param type_(unicode, None): notification type to filter
|
||||
None to get all notifications
|
||||
@return (list[dict]): list of notifications
|
||||
@param exact_jid(bool, None): if True, only return notifications from
|
||||
exact entity jid (i.e. not including other resources)
|
||||
None for automatic selection (True for full jid, False else)
|
||||
False to get resources notifications
|
||||
False doesn't do anything if entity is not a bare jid
|
||||
@return (iter[dict]): notifications
|
||||
"""
|
||||
notif_dict = self.profiles[profile].notifications
|
||||
ret = []
|
||||
if entity == C.ENTITY_ALL:
|
||||
for type_notifs in notif_dict.itervalues():
|
||||
for notifs_list in type_notifs.itervalues():
|
||||
ret.extend(notifs_list)
|
||||
return ret
|
||||
key = '' if entity is None else entity.bare
|
||||
key_notifs = notif_dict.setdefault(key, {})
|
||||
if type_ is not None:
|
||||
return key_notifs.get(type_, ret)
|
||||
for notifs_list in key_notifs.itervalues():
|
||||
ret.extend(notifs_list)
|
||||
return ret
|
||||
main_notif_dict = self.profiles[profile].notifications
|
||||
|
||||
if entity is C.ENTITY_ALL:
|
||||
selected_notifs = main_notif_dict.itervalues()
|
||||
exact_jid = False
|
||||
else:
|
||||
if entity is None:
|
||||
key = ''
|
||||
exact_jid = False
|
||||
else:
|
||||
key = entity.bare
|
||||
if exact_jid is None:
|
||||
exact_jid = bool(entity.resource)
|
||||
selected_notifs = (main_notif_dict.setdefault(key, {}),)
|
||||
|
||||
for notifs_from_select in selected_notifs:
|
||||
|
||||
if type_ is None:
|
||||
type_notifs = notifs_from_select.itervalues()
|
||||
else:
|
||||
type_notifs = (notifs_from_select.get(type_, []),)
|
||||
|
||||
for notifs in type_notifs:
|
||||
for notif in notifs:
|
||||
if exact_jid and notif['entity'] != entity:
|
||||
continue
|
||||
yield notif
|
||||
|
||||
def clearNotifs(self, entity, type_=None, profile=C.PROF_KEY_NONE):
|
||||
"""return notifications for given entity
|
||||
|
|
|
|||
Loading…
Reference in a new issue