From 4ddf0754fad765eb2fd31af710de9ae03f643c8a Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Tue, 14 Oct 2014 17:59:28 +0200 Subject: Indexing mails when (un)marking as read and fixing tags count --- service/pixelated/adapter/search.py | 18 +++++++++--------- service/pixelated/adapter/tag_service.py | 1 - service/pixelated/user_agent.py | 2 ++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py index df45b76e..69456932 100644 --- a/service/pixelated/adapter/search.py +++ b/service/pixelated/adapter/search.py @@ -16,13 +16,13 @@ class SearchEngine(object): os.makedirs(self.INDEX_FOLDER) self._index = self._create_index() - def _add_to_tags(self, tags, seen, skip_default_tags): + def _add_to_tags(self, tags, seen, skip_default_tags, count_type): for tag, count in seen.iteritems(): if skip_default_tags and tag in self.DEFAULT_TAGS: continue if not tags.get(tag): tags[tag] = {'ident': tag, 'name': tag, 'default': False, 'counts': {'total': 0, 'read': 0}, 'mails': []} - tags[tag]['counts']['read'] += count + tags[tag]['counts'][count_type] += count def _search_tag_groups(self, query): seen = None @@ -44,11 +44,11 @@ class SearchEngine(object): 'ident': default_tag, 'name': default_tag, 'default': True, - 'counts': { - 'total': 0, - 'read': 0 - }, - 'mails': [] + 'counts': { + 'total': 0, + 'read': 0 + }, + 'mails': [] } return tags @@ -56,9 +56,9 @@ class SearchEngine(object): tags = {} if not skip_default_tags: tags = self._init_tags_defaults() - self._add_to_tags(tags, total, skip_default_tags) + self._add_to_tags(tags, total, skip_default_tags, count_type='total') if seen: - self._add_to_tags(tags, seen, skip_default_tags) + self._add_to_tags(tags, seen, skip_default_tags, count_type='read') return tags.values() def tags(self, query, skip_default_tags): diff --git a/service/pixelated/adapter/tag_service.py b/service/pixelated/adapter/tag_service.py index 0a8a1b68..fa70231e 100644 --- a/service/pixelated/adapter/tag_service.py +++ b/service/pixelated/adapter/tag_service.py @@ -31,4 +31,3 @@ class TagService: if not cls.instance: cls.instance = TagService() return cls.instance - diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py index b1233fa3..d6920dc6 100644 --- a/service/pixelated/user_agent.py +++ b/service/pixelated/user_agent.py @@ -158,12 +158,14 @@ def mail_tags(mail_id): @app.route('/mail//read', methods=['POST']) def mark_mail_as_read(mail_id): mail_service.mark_as_read(mail_id) + search_engine.index_mail(mail) return "" @app.route('/mail//unread', methods=['POST']) def mark_mail_as_unread(mail_id): mail_service.mark_as_unread(mail_id) + search_engine.index_mail(mail) return "" -- cgit v1.2.3