Skip to content

Commit 36d461b

Browse files
author
Subhasish-Behera
committed
helper: Add moved_messages to index and it's logic
1 parent 6cd0fc8 commit 36d461b

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
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: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
REGEX_COLOR_6_DIGIT,
4040
REGEX_QUOTED_FENCE_LENGTH,
4141
)
42+
from zulipterminal.config.symbols import CHECK_MARK
4243
from zulipterminal.config.ui_mappings import StreamAccessType
4344
from zulipterminal.platform_code import (
4445
PLATFORM,
@@ -90,6 +91,7 @@ class Index(TypedDict):
9091
topic_msg_ids: Dict[int, Dict[str, Set[int]]]
9192
# Extra cached information
9293
edited_messages: Set[int] # {message_id, ...}
94+
moved_messages: Set[int]
9395
topics: Dict[int, List[str]] # {topic names, ...}
9496
search: Set[int] # {message_id, ...}
9597
# Downloaded message data by message id
@@ -106,6 +108,7 @@ class Index(TypedDict):
106108
stream_msg_ids_by_stream_id=defaultdict(set),
107109
topic_msg_ids=defaultdict(dict),
108110
edited_messages=set(),
111+
moved_messages=set(),
109112
topics=defaultdict(list),
110113
search=set(),
111114
# mypy bug: https://github.com/python/mypy/issues/7217
@@ -397,10 +400,47 @@ def index_messages(messages: List[Message], model: Any, index: Index) -> Index:
397400
}
398401
"""
399402
narrow = model.narrow
403+
resolved_topic_prefix = CHECK_MARK + " "
400404
for msg in messages:
401405
if "edit_history" in msg:
402-
index["edited_messages"].add(msg["id"])
403-
406+
for edit_history_event in msg["edit_history"]:
407+
if "prev_content" in edit_history_event:
408+
index["edited_messages"].add(msg["id"])
409+
if "prev_stream" in edit_history_event:
410+
index["moved_messages"].add(msg["id"])
411+
if "prev_topic" in edit_history_event:
412+
# We know it has a topic edit. Now we need to determine if
413+
# it was a true move or a resolve/unresolve.
414+
if not edit_history_event["topic"].startswith(
415+
resolved_topic_prefix
416+
):
417+
if (
418+
edit_history_event["prev_topic"].startswith(
419+
resolved_topic_prefix
420+
)
421+
and edit_history_event["prev_topic"][2:]
422+
!= edit_history_event["topic"]
423+
):
424+
index["moved_messages"].add(msg["id"])
425+
if not edit_history_event["prev_topic"].startswith(
426+
resolved_topic_prefix
427+
) and not edit_history_event["topic"].startswith(
428+
resolved_topic_prefix
429+
):
430+
index["moved_messages"].add(msg["id"])
431+
else:
432+
if (
433+
edit_history_event["prev_topic"].startswith(
434+
resolved_topic_prefix
435+
)
436+
and edit_history_event["prev_topic"][2:]
437+
!= edit_history_event["topic"][2:]
438+
):
439+
index["moved_messages"].add(msg["id"])
440+
else:
441+
index["edited_messages"].add(msg["id"])
442+
if msg["id"] not in index["moved_messages"]:
443+
index["edited_messages"].add(msg["id"])
404444
index["messages"][msg["id"]] = msg
405445
if not narrow:
406446
index["all_msg_ids"].add(msg["id"])

0 commit comments

Comments
 (0)