diff options
Diffstat (limited to 'alot/db/thread.py')
-rw-r--r-- | alot/db/thread.py | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/alot/db/thread.py b/alot/db/thread.py index f161cbd8..db72aad6 100644 --- a/alot/db/thread.py +++ b/alot/db/thread.py @@ -54,7 +54,7 @@ class Thread: """ self._dbman = dbman self._authors = None - self.id = thread.get_thread_id() + self.id = thread.threadid self._tags = set() self.toplevel_messages = [] @@ -68,41 +68,36 @@ class Thread: if not thread: thread = self._dbman._get_notmuch_thread(self.id) - self.total_messages = thread.get_total_messages() - self._notmuch_authors_string = thread.get_authors() + self.total_messages = len(thread) + self._notmuch_authors_string = thread.authors subject_type = settings.get('thread_subject') if subject_type == 'notmuch': - subject = thread.get_subject() + subject = thread.subject elif subject_type == 'oldest': try: - first_msg = list(thread.get_toplevel_messages())[0] - subject = first_msg.get_header('subject') - except IndexError: + first_msg = next(thread.toplevel()) + subject = first_msg.header('subject') + except (StopIteration, LookupError): subject = '' self.subject = subject self._authors = None - ts = thread.get_oldest_date() try: - self.oldest_date = datetime.fromtimestamp(ts) + self.oldest_date = datetime.fromtimestamp(thread.first) except ValueError: # year is out of range self.oldest_date = None try: - timestamp = thread.get_newest_date() - self.newest_date = datetime.fromtimestamp(timestamp) + self.newest_date = datetime.fromtimestamp(thread.last) except ValueError: # year is out of range self.newest_date = None - self._tags = {t for t in thread.get_tags()} + self._tags = thread.tags - self.messages, self.toplevel_messages, self.message_list = self._gather_messages() - - def _gather_messages(self): - query = self._dbman.query('thread:' + self.id) - nm_thread = next(query.search_threads()) + self.messages, self.toplevel_messages, self.message_list = self._gather_messages(thread) + def _gather_messages(self, thread): msgs = {} msg_tree = [] msg_list = [] @@ -113,7 +108,7 @@ class Thread: msg_list.append(msg) replies = [] - for m in nm_msg.get_replies(): + for m in nm_msg.replies(): replies.append(thread_tree_walk(m, depth + 1, msg)) msg.replies = replies @@ -122,7 +117,7 @@ class Thread: return msg - for m in nm_thread.get_toplevel_messages(): + for m in thread.toplevel(): msg_tree.append(thread_tree_walk(m, 0, None)) return msgs, msg_tree, msg_list @@ -139,7 +134,7 @@ class Thread: :type intersection: bool :rtype: set of str """ - tags = set(list(self._tags)) + tags = set(self._tags) if intersection: for m in self.messages.values(): tags = tags.intersection(set(m.get_tags())) @@ -165,10 +160,7 @@ class Thread: :type remove_rest: bool """ def myafterwards(): - if remove_rest: - self._tags = set(tags) - else: - self._tags = self._tags.union(tags) + self.refresh() if callable(afterwards): afterwards() @@ -196,11 +188,10 @@ class Thread: if rmtags: def myafterwards(): - self._tags = self._tags.difference(tags) + self.refresh() if callable(afterwards): afterwards() self._dbman.untag('thread:' + self.id, tags, myafterwards) - self._tags = self._tags.difference(rmtags) def get_authors(self): """ |