summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-10-14 17:59:28 +0200
committerDuda Dornelles <ddornell@thoughtworks.com>2014-10-14 18:01:00 +0200
commit4ddf0754fad765eb2fd31af710de9ae03f643c8a (patch)
tree714c298e3a87303a6a3dd22d21f6bc2c0344c712 /service
parentcd4dffcfcb3f7473913e2b50571a182689efeedc (diff)
Indexing mails when (un)marking as read and fixing tags count
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/search.py18
-rw-r--r--service/pixelated/adapter/tag_service.py1
-rw-r--r--service/pixelated/user_agent.py2
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/<mail_id>/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/<mail_id>/unread', methods=['POST'])
def mark_mail_as_unread(mail_id):
mail_service.mark_as_unread(mail_id)
+ search_engine.index_mail(mail)
return ""