Skip to content

Commit 6167f01

Browse files
author
Subhasish-Behera
committed
helper/messages: Add moved_messages to index and it's logic.
1 parent 6cd0fc8 commit 6167f01

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ def empty_index(
822822
stream_msg_ids_by_stream_id=defaultdict(set, {}),
823823
topic_msg_ids=defaultdict(dict, {}),
824824
edited_messages=set(),
825+
moved_messages=set(),
825826
topics=defaultdict(list),
826827
search=set(),
827828
messages=defaultdict(

zulipterminal/api_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class Message(TypedDict, total=False):
8181
# NOTE: `subject_links` in Zulip 2.1; deprecated from Zulip 3.0 / ZFL 1
8282
subject_links: List[str]
8383
is_me_message: bool
84+
edit_history: List[Dict[str, Any]]
8485
reactions: List[Dict[str, Any]]
8586
submessages: List[Dict[str, Any]]
8687
flags: List[MessageFlag]

zulipterminal/helper.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
)
4848

4949

50+
RESOLVED_TOPIC_PREFIX = "✔ "
51+
52+
5053
class StreamData(TypedDict):
5154
name: str
5255
id: int
@@ -90,6 +93,7 @@ class Index(TypedDict):
9093
topic_msg_ids: Dict[int, Dict[str, Set[int]]]
9194
# Extra cached information
9295
edited_messages: Set[int] # {message_id, ...}
96+
moved_messages: Set[int]
9397
topics: Dict[int, List[str]] # {topic names, ...}
9498
search: Set[int] # {message_id, ...}
9599
# Downloaded message data by message id
@@ -106,6 +110,7 @@ class Index(TypedDict):
106110
stream_msg_ids_by_stream_id=defaultdict(set),
107111
topic_msg_ids=defaultdict(dict),
108112
edited_messages=set(),
113+
moved_messages=set(),
109114
topics=defaultdict(list),
110115
search=set(),
111116
# mypy bug: https://github.com/python/mypy/issues/7217
@@ -399,8 +404,44 @@ def index_messages(messages: List[Message], model: Any, index: Index) -> Index:
399404
narrow = model.narrow
400405
for msg in messages:
401406
if "edit_history" in msg:
402-
index["edited_messages"].add(msg["id"])
403-
407+
for edit_history_event in msg["edit_history"]:
408+
if "prev_content" in edit_history_event:
409+
index["edited_messages"].add(msg["id"])
410+
if "prev_stream" in edit_history_event:
411+
index["moved_messages"].add(msg["id"])
412+
if "prev_topic" in edit_history_event:
413+
# We know it has a topic edit. Now we need to determine if
414+
# it was a true move or a resolve/unresolve.
415+
if not edit_history_event["topic"].startswith(
416+
RESOLVED_TOPIC_PREFIX
417+
):
418+
if (
419+
edit_history_event["prev_topic"].startswith(
420+
RESOLVED_TOPIC_PREFIX
421+
)
422+
and edit_history_event["prev_topic"][2:]
423+
!= edit_history_event["topic"]
424+
):
425+
index["moved_messages"].add(msg["id"])
426+
if not edit_history_event["prev_topic"].startswith(
427+
RESOLVED_TOPIC_PREFIX
428+
) and not edit_history_event["topic"].startswith(
429+
RESOLVED_TOPIC_PREFIX
430+
):
431+
index["moved_messages"].add(msg["id"])
432+
else:
433+
if (
434+
edit_history_event["prev_topic"].startswith(
435+
RESOLVED_TOPIC_PREFIX
436+
)
437+
and edit_history_event["prev_topic"][2:]
438+
!= edit_history_event["topic"][2:]
439+
):
440+
index["moved_messages"].add(msg["id"])
441+
else:
442+
index["edited_messages"].add(msg["id"])
443+
if msg["id"] not in index["moved_messages"]:
444+
index["edited_messages"].add(msg["id"])
404445
index["messages"][msg["id"]] = msg
405446
if not narrow:
406447
index["all_msg_ids"].add(msg["id"])

zulipterminal/ui_tools/messages.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,14 +723,24 @@ def main_view(self) -> List[Any]:
723723
if self.message["id"] in self.model.index["edited_messages"]:
724724
edited_label_size = 7
725725
left_padding = 1
726+
is_edited = True
727+
elif self.message["id"] in self.model.index["moved_messages"]:
728+
edited_label_size = 6
729+
left_padding = 2
730+
is_edited = False
726731
else:
727732
edited_label_size = 0
728733
left_padding = 8
734+
is_edited = True
735+
if is_edited:
736+
label_text = "EDITED"
737+
else:
738+
label_text = "MOVED"
729739

730740
wrapped_content = urwid.Padding(
731741
urwid.Columns(
732742
[
733-
(edited_label_size, urwid.Text("EDITED")),
743+
(edited_label_size, urwid.Text(label_text)),
734744
urwid.LineBox(
735745
urwid.Columns(
736746
[

0 commit comments

Comments
 (0)