Skip to content

Commit

Permalink
model: Add toggle_topic_resolved_status function to (un)resolve topics.
Browse files Browse the repository at this point in the history
Fixes zulip#1075
The function calls get_latest_message_in_topic to fetch recent message
in topic to be (un)resolved. It verifies user and editing conditions
using can_user_edit_topic function and finally add or remove
RESOLVED_TOPIC_PREFIX from topic name.
  • Loading branch information
srdeotarse committed Sep 2, 2022
1 parent df86b13 commit 493e3c4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from zulipterminal import unicode_emojis
from zulipterminal.api_types import (
RESOLVED_TOPIC_PREFIX,
Composition,
EditPropagateMode,
Event,
Expand Down Expand Up @@ -629,6 +630,31 @@ def can_user_edit_topic(self) -> bool:
self.controller.report_error("User not found")
return False

def toggle_topic_resolved_status(self, stream_id: int, topic_name: str) -> None:
if self.can_user_edit_topic():
response = self.get_latest_message_in_topic(stream_id, topic_name)
if response:
time_since_msg_sent = time.time() - response[0]["timestamp"]
edit_time_limit = self.initial_data[
"realm_community_topic_editing_limit_seconds"
]
# Don't allow editing topic if time-limit exceeded.
if time_since_msg_sent >= edit_time_limit:
self.controller.report_error(
" Time limit for editing topic has been exceeded."
)
else:
if topic_name.startswith(RESOLVED_TOPIC_PREFIX):
topic_name = topic_name[2:]
else:
topic_name = RESOLVED_TOPIC_PREFIX + topic_name
args = dict(
message_id=response[0]["id"],
topic=topic_name,
propagate_mode="change_all",
)
self.update_stream_message(**args)

def update_stream_message(
self,
topic: str,
Expand Down

0 comments on commit 493e3c4

Please sign in to comment.