# HG changeset patch # User Goffi # Date 1469375774 -7200 # Node ID f09562b0704d0622ffb6604d61d280b7572301fa # Parent 20fb71b656e32f29cd1f234e0f28e1898ea6e2ba quick_frontend, primitivus: better notifications handling diff -r 20fb71b656e3 -r f09562b0704d frontends/src/primitivus/constants.py --- a/frontends/src/primitivus/constants.py Sun Jul 24 17:47:09 2016 +0200 +++ b/frontends/src/primitivus/constants.py Sun Jul 24 17:56:14 2016 +0200 @@ -31,8 +31,8 @@ ('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 diff -r 20fb71b656e3 -r f09562b0704d frontends/src/primitivus/contact_list.py --- a/frontends/src/primitivus/contact_list.py Sun Jul 24 17:47:09 2016 +0200 +++ b/frontends/src/primitivus/contact_list.py Sun Jul 24 17:56:14 2016 +0200 @@ -143,7 +143,7 @@ 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 @@ 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'' diff -r 20fb71b656e3 -r f09562b0704d frontends/src/primitivus/primitivus --- a/frontends/src/primitivus/primitivus Sun Jul 24 17:47:09 2016 +0200 +++ b/frontends/src/primitivus/primitivus Sun Jul 24 17:56:14 2016 +0200 @@ -673,11 +673,11 @@ 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) diff -r 20fb71b656e3 -r f09562b0704d frontends/src/quick_frontend/quick_app.py --- a/frontends/src/quick_frontend/quick_app.py Sun Jul 24 17:47:09 2016 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Sun Jul 24 17:56:14 2016 +0200 @@ -604,30 +604,49 @@ 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 diff -r 20fb71b656e3 -r f09562b0704d frontends/src/quick_frontend/quick_contact_list.py --- a/frontends/src/quick_frontend/quick_contact_list.py Sun Jul 24 17:47:09 2016 +0200 +++ b/frontends/src/quick_frontend/quick_contact_list.py Sun Jul 24 17:56:14 2016 +0200 @@ -384,7 +384,7 @@ 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):