summaryrefslogtreecommitdiff
path: root/alot/commands/search.py
diff options
context:
space:
mode:
Diffstat (limited to 'alot/commands/search.py')
-rw-r--r--alot/commands/search.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/alot/commands/search.py b/alot/commands/search.py
index 9e4a3688..79aaee56 100644
--- a/alot/commands/search.py
+++ b/alot/commands/search.py
@@ -175,24 +175,29 @@ class TagCommand(Command):
if not self._thread:
testquery += ' and (%s)' % searchbuffer.querystring
+ if self._action == 'add':
+ task = ui.dbman.tags_add(testquery, self._tags)
+ if self._action == 'set':
+ task = ui.dbman.tags_set(testquery, self._tags)
+ elif self._action == 'remove':
+ task = ui.dbman.tags_remove(testquery, self._tags)
+ elif self._action == 'toggle':
+ if not self._all_threads:
+ to_remove = set()
+ to_add = set()
+ for t in self._tags:
+ if t in thread.get_tags():
+ to_remove.add(t)
+ else:
+ to_add.add(t)
+
+ write = ui.dbman.db_write_create()
+ write.queue_tag_remove(to_remove, 'thread:' + thread.id)
+ write.queue_tag_add(to_add, 'thread:' + thread.id)
+ task = write.apply()
+
try:
- if self._action == 'add':
- await ui.dbman.tags_add(testquery, self._tags)
- if self._action == 'set':
- await ui.dbman.tags_set(testquery, self._tags)
- elif self._action == 'remove':
- await ui.dbman.tags_remove(testquery, self._tags)
- elif self._action == 'toggle':
- if not self._all_threads:
- to_remove = set()
- to_add = set()
- for t in self._tags:
- if t in thread.get_tags():
- to_remove.add(t)
- else:
- to_add.add(t)
- await thread.tags_remove(to_remove)
- await thread.tags_add(to_add)
+ await task
except DatabaseROError:
ui.notify('index in read-only mode', priority='error')
return