Skip to content

Commit f547b99

Browse files
rsashankneiljp
authored andcommitted
messages: Implement logic to display TODO widgets.
1 parent 086985e commit f547b99

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

zulipterminal/ui_tools/messages.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from zulipterminal.server_url import near_message_url
3434
from zulipterminal.ui_tools.tables import render_table
3535
from zulipterminal.urwid_types import urwid_MarkupTuple, urwid_Size
36+
from zulipterminal.widget import find_widget_type, process_todo_widget
3637

3738

3839
if typing.TYPE_CHECKING:
@@ -729,6 +730,31 @@ def main_view(self) -> List[Any]:
729730
"/me", f"<strong>{self.message['sender_full_name']}</strong>", 1
730731
)
731732

733+
if self.message.get("submessages"):
734+
widget_type = find_widget_type(self.message.get("submessages", []))
735+
736+
if widget_type == "todo":
737+
title, tasks = process_todo_widget(self.message.get("submessages", []))
738+
739+
todo_widget = "<strong>To-do</strong>\n" + f"<strong>{title}</strong>"
740+
741+
if tasks:
742+
for task_id, task_info in tasks.items():
743+
task_status = "[✔]" if task_info["completed"] else "[ ]"
744+
task_name = task_info["task"]
745+
task_description = task_info["desc"]
746+
747+
todo_widget += f"\n{task_status} <strong>{task_name}</strong>"
748+
749+
if task_description:
750+
todo_widget += f": {task_description}"
751+
752+
# Update the message content with the latest todo_widget,
753+
# generated from submessages to reflect the current state.
754+
# The original raw content can be fetched if needed,
755+
# though it's not very useful.
756+
self.message["content"] = todo_widget
757+
732758
# Transform raw message content into markup (As needed by urwid.Text)
733759
content, self.message_links, self.time_mentions = self.transform_content(
734760
self.message["content"], self.model.server_url

0 commit comments

Comments
 (0)