Skip to content

Commit

Permalink
model: Handle (un)resolving topics.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
srdeotarse committed Jul 17, 2022
1 parent 05f369d commit 8509e66
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from zulipterminal import unicode_emojis
from zulipterminal.api_types import (
RESOLVED_TOPIC_PREFIX,
Composition,
EditPropagateMode,
Event,
Expand Down Expand Up @@ -559,6 +560,38 @@ def update_private_message(self, msg_id: int, content: str) -> bool:
display_error_if_present(response, self.controller)
return response["result"] == "success"

def toggle_topic_resolved_status(self, stream_id: int, topic_name: str) -> bool:
request: Dict[str, Any] = {
"anchor": "newest",
"num_before": 1,
"num_after": 0,
"narrow": [
{"operator": "sender", "operand": self.user_email},
{"operator": "stream", "operand": self.stream_dict[stream_id]["name"]},
{"operator": "topic", "operand": topic_name},
],
}
response = self.client.get_messages(request)
if response["messages"] != []:
topic_msg_id = response["messages"][0]["id"]
if topic_name.startswith(RESOLVED_TOPIC_PREFIX):
request = {
"message_id": topic_msg_id,
"topic": topic_name[2:],
"propagate_mode": "change_all",
}
else:
request = {
"message_id": topic_msg_id,
"topic": RESOLVED_TOPIC_PREFIX + topic_name,
"propagate_mode": "change_all",
}
response = self.client.update_message(request)
display_error_if_present(response, self.controller)
else:
self.controller.report_error("You have not sent any message to the topic.")
return response["result"] == "success"

def update_stream_message(
self,
topic: str,
Expand Down

0 comments on commit 8509e66

Please sign in to comment.