Skip to content

Commit 003d857

Browse files
committed
model: Handle (un)resolving topics.
Fixes zulip#1075 First using get_messages api method to get most recent message sent by user in the topic for which TopicInfoView is toggled. Then using fetch message to edit the topic and propagate mode as change_all to (un)resolve topics.
1 parent 05f369d commit 003d857

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

zulipterminal/model.py

+25
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from zulipterminal import unicode_emojis
2828
from zulipterminal.api_types import (
29+
RESOLVED_TOPIC_PREFIX,
2930
Composition,
3031
EditPropagateMode,
3132
Event,
@@ -559,6 +560,30 @@ def update_private_message(self, msg_id: int, content: str) -> bool:
559560
display_error_if_present(response, self.controller)
560561
return response["result"] == "success"
561562

563+
def toggle_topic_resolved_status(self, stream_id: int, topic_name: str) -> bool:
564+
request: Dict[str, Any] = {
565+
"anchor": "newest",
566+
"num_before": 1,
567+
"num_after": 0,
568+
"narrow": [
569+
{"operator": "sender", "operand": self.user_email},
570+
{"operator": "stream", "operand": self.stream_dict[stream_id]["name"]},
571+
{"operator": "topic", "operand": topic_name},
572+
],
573+
}
574+
response = self.client.get_messages(request)
575+
if response["messages"] != []:
576+
topic_msg_id = response["messages"][0]["id"]
577+
if topic_name.startswith(RESOLVED_TOPIC_PREFIX):
578+
request = {"message_id": topic_msg_id, "topic": topic_name[2:], "propagate_mode": "change_all"}
579+
else:
580+
request = {"message_id": topic_msg_id, "topic": RESOLVED_TOPIC_PREFIX + topic_name, "propagate_mode": "change_all"}
581+
response = self.client.update_message(request)
582+
display_error_if_present(response, self.controller)
583+
else :
584+
self.controller.report_error("You have not sent any message to the topic.")
585+
return response["result"] == "success"
586+
562587
def update_stream_message(
563588
self,
564589
topic: str,

0 commit comments

Comments
 (0)