39
39
REGEX_COLOR_6_DIGIT ,
40
40
REGEX_QUOTED_FENCE_LENGTH ,
41
41
)
42
+ from zulipterminal .config .symbols import CHECK_MARK
42
43
from zulipterminal .config .ui_mappings import StreamAccessType
43
44
from zulipterminal .platform_code import (
44
45
PLATFORM ,
@@ -90,6 +91,7 @@ class Index(TypedDict):
90
91
topic_msg_ids : Dict [int , Dict [str , Set [int ]]]
91
92
# Extra cached information
92
93
edited_messages : Set [int ] # {message_id, ...}
94
+ moved_messages : Set [int ]
93
95
topics : Dict [int , List [str ]] # {topic names, ...}
94
96
search : Set [int ] # {message_id, ...}
95
97
# Downloaded message data by message id
@@ -106,6 +108,7 @@ class Index(TypedDict):
106
108
stream_msg_ids_by_stream_id = defaultdict (set ),
107
109
topic_msg_ids = defaultdict (dict ),
108
110
edited_messages = set (),
111
+ moved_messages = set (),
109
112
topics = defaultdict (list ),
110
113
search = set (),
111
114
# mypy bug: https://github.com/python/mypy/issues/7217
@@ -397,10 +400,47 @@ def index_messages(messages: List[Message], model: Any, index: Index) -> Index:
397
400
}
398
401
"""
399
402
narrow = model .narrow
403
+ resolved_topic_prefix = CHECK_MARK + " "
400
404
for msg in messages :
401
405
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" ])
404
444
index ["messages" ][msg ["id" ]] = msg
405
445
if not narrow :
406
446
index ["all_msg_ids" ].add (msg ["id" ])
0 commit comments