Skip to content

Commit

Permalink
public_inbox: Handle missing parent is __get_thread_root()
Browse files Browse the repository at this point in the history
A message can have an In-Reply-To header but the message it points to
might not be available for some reason.

In such a case, the Message.parent_id() method will return a proper
value, but __fetch_thread_root() on that message might not and would
return None.

Let's handle that case by returning the latest message we found as the
root message.

Signed-off-by: Maxime Ripard <[email protected]>
  • Loading branch information
mripard committed Jul 15, 2024
1 parent 7b96454 commit 240b72c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions did/plugins/public_inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __fetch_thread_root(self, msg: Message) -> typing.Optional[Message]:
log.warn("Couldn't find message root")
return None

def __get_thread_root(self, msg: Message) -> typing.Optional[Message]:
def __get_thread_root(self, msg: Message) -> Message:
log.debug("Looking for thread root of message %s" % msg.id())
if msg.is_thread_root():
log.debug("Message is thread root already. Returning.")
Expand All @@ -154,6 +154,10 @@ def __get_thread_root(self, msg: Message) -> typing.Optional[Message]:
parent_id = msg.parent_id()
if parent_id not in self.messages_cache:
root = self.__fetch_thread_root(msg)
if root is None:
log.debug("Can't retrieve the thread root, returning.")
return msg

log.debug("Found root message %s for message %s" % (root.id(), msg.id()))
return root

Expand All @@ -167,7 +171,11 @@ def __get_thread_root(self, msg: Message) -> typing.Optional[Message]:

parent_id = parent.parent_id()
if parent_id not in self.messages_cache:
root = self.__fetch_thread_root(msg)
root = self.__fetch_thread_root(parent)
if root is None:
log.debug("Can't retrieve the message parent, returning.")
return parent

log.debug(
"Found root message %s for message %s" %
(root.id(), msg.id()))
Expand Down

0 comments on commit 240b72c

Please sign in to comment.