quick_frontend, primitivus: better notifications handling
This commit is contained in:
parent
57daef07a7
commit
e32bd443a3
5 changed files with 44 additions and 26 deletions
|
|
@ -31,8 +31,8 @@ class Const(constants.Const):
|
|||
('selected_focus', 'default,bold', 'dark red'),
|
||||
('default', 'default', 'default'),
|
||||
('default_focus', 'default,bold', 'default'),
|
||||
('cl_notifs', 'default,underline', 'yellow'),
|
||||
('cl_notifs_focus', 'default,bold,underline', 'yellow'),
|
||||
('cl_notifs', 'yellow', 'default'),
|
||||
('cl_notifs_focus', 'yellow,bold', 'default'),
|
||||
('cl_mention', 'dark red', 'default'),
|
||||
('cl_mention_focus', 'dark red,bold', 'default'),
|
||||
# Messages
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ class ContactList(PrimitivusWidget, QuickContactList):
|
|||
self._emit('click', entity)
|
||||
|
||||
def onNotification(self, entity, notif, profile):
|
||||
notifs = self.host.getNotifs(C.ENTITY_ALL, profile=self.profile)
|
||||
notifs = list(self.host.getNotifs(C.ENTITY_ALL, profile=self.profile))
|
||||
if notifs:
|
||||
self.title_dynamic = u"({})".format(len(notifs))
|
||||
else:
|
||||
|
|
@ -197,11 +197,10 @@ class ContactList(PrimitivusWidget, QuickContactList):
|
|||
else:
|
||||
entity_attr = 'default'
|
||||
|
||||
notifs = self.host.getNotifs(entity.bare, profile=self.profile)
|
||||
notifs = list(self.host.getNotifs(entity, exact_jid=special, profile=self.profile))
|
||||
if notifs:
|
||||
entity_attr = 'cl_notifs'
|
||||
header = u'({}) '.format(len(notifs))
|
||||
if self.host.getNotifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile):
|
||||
header = [('cl_notifs', u'({})'.format(len(notifs))), u' ']
|
||||
if list(self.host.getNotifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile)):
|
||||
header = ('cl_mention', header)
|
||||
else:
|
||||
header = u''
|
||||
|
|
|
|||
|
|
@ -673,11 +673,11 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
self.notif_bar.setProgress(percentage)
|
||||
|
||||
def contactSelected(self, contact_list, entity):
|
||||
self.clearNotifs(entity, profile=contact_list.profile)
|
||||
if entity.resource:
|
||||
# we have clicked on a private MUC conversation
|
||||
chat_widget = self.widgets.getOrCreateWidget(Chat, entity, on_new_widget=None, force_hash = Chat.getPrivateHash(contact_list.profile, entity), profile=contact_list.profile)
|
||||
else:
|
||||
self.clearNotifs(entity, profile=contact_list.profile)
|
||||
chat_widget = self.widgets.getOrCreateWidget(Chat, entity, on_new_widget=None, profile=contact_list.profile)
|
||||
self.selectWidget(chat_widget)
|
||||
self.menu_roller.addMenu(_('Chat menu'), chat_widget.getMenu(), C.MENU_ID_WIDGET)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ class ProfileContactList(object):
|
|||
return ((show is not None and show != C.PRESENCE_UNAVAILABLE)
|
||||
or self.show_disconnected
|
||||
or entity in selected
|
||||
or self.host.getNotifs(entity.bare, profile=self.profile)
|
||||
or next(self.host.getNotifs(entity.bare, profile=self.profile), None)
|
||||
)
|
||||
|
||||
def anyEntityToShow(self, entities, check_resources=False):
|
||||
|
|
|
|||
Loading…
Reference in a new issue