From 279b8316341841dd32bdda5a21bb61fed8b9d1ef Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 8 Feb 2020 20:54:38 +0100 Subject: thread: implement tree decorations They were temporarily removed in the previous commit. Still not working: - theming for the decorations - drawing the connector line properly for expanded messages - configurable indentation --- alot/db/message.py | 16 ++++++++++++++++ alot/db/thread.py | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'alot/db') diff --git a/alot/db/message.py b/alot/db/message.py index 62b85788..4adb0816 100644 --- a/alot/db/message.py +++ b/alot/db/message.py @@ -41,6 +41,12 @@ class Message: """A list of replies to this message""" replies = None + """ + This message parent in the list (i.e. the message this message is a reply + to). None when this message is top-level. + """ + parent = None + def __init__(self, dbman, thread, msg, depth): """ :param dbman: db manager that is used for further lookups @@ -248,3 +254,13 @@ class Message: """tests if this messages is in the resultset for `querystring`""" searchfor = '( {} ) AND id:{}'.format(querystring, self.id) return self._dbman.count_messages(searchfor) > 0 + + def parents(self): + """ + A generator iterating over this message's parents up to the topmost + level. + """ + m = self.parent + while m: + yield m + m = m.parent diff --git a/alot/db/thread.py b/alot/db/thread.py index a76997f8..3dc90325 100644 --- a/alot/db/thread.py +++ b/alot/db/thread.py @@ -107,22 +107,23 @@ class Thread: msg_tree = [] msg_list = [] - def thread_tree_walk(nm_msg, depth): + def thread_tree_walk(nm_msg, depth, parent): msg = Message(self._dbman, self, nm_msg, depth) msg_list.append(msg) replies = [] for m in nm_msg.get_replies(): - replies.append(thread_tree_walk(m, depth + 1)) + replies.append(thread_tree_walk(m, depth + 1, msg)) msg.replies = replies + msg.parent = parent msgs[msg.id] = msg return msg for m in nm_thread.get_toplevel_messages(): - msg_tree.append(thread_tree_walk(m, 0)) + msg_tree.append(thread_tree_walk(m, 0, None)) return msgs, msg_tree, msg_list -- cgit v1.2.3