|
26 | 26 |
|
27 | 27 | from zulipterminal import unicode_emojis
|
28 | 28 | from zulipterminal.api_types import (
|
| 29 | + RESOLVED_TOPIC_PREFIX, |
29 | 30 | Composition,
|
30 | 31 | EditPropagateMode,
|
31 | 32 | Event,
|
@@ -559,6 +560,50 @@ def update_private_message(self, msg_id: int, content: str) -> bool:
|
559 | 560 | display_error_if_present(response, self.controller)
|
560 | 561 | return response["result"] == "success"
|
561 | 562 |
|
| 563 | + def toggle_topic_resolved_status(self, stream_id: int, topic_name: str) -> bool: |
| 564 | + if self.initial_data.get("realm_allow_community_topic_editing", None): |
| 565 | + self.controller.report_error(" Editing topic is disabled") |
| 566 | + else: |
| 567 | + request: Dict[str, Any] = { |
| 568 | + "anchor": "newest", |
| 569 | + "num_before": 1, |
| 570 | + "num_after": 0, |
| 571 | + "narrow": [ |
| 572 | + { |
| 573 | + "operator": "stream", |
| 574 | + "operand": self.stream_dict[stream_id]["name"], |
| 575 | + }, |
| 576 | + {"operator": "topic", "operand": topic_name}, |
| 577 | + ], |
| 578 | + } |
| 579 | + response = self.client.get_messages(request) |
| 580 | + if response["messages"] != []: |
| 581 | + time_since_msg_sent = time.time() - response["messages"][0]["timestamp"] |
| 582 | + edit_time_limit = self.initial_data[ |
| 583 | + "realm_community_topic_editing_limit_seconds" |
| 584 | + ] |
| 585 | + # Don't allow editing topic if time-limit exceeded. |
| 586 | + if time_since_msg_sent <= edit_time_limit: |
| 587 | + topic_msg_id = response["messages"][0]["id"] |
| 588 | + if topic_name.startswith(RESOLVED_TOPIC_PREFIX): |
| 589 | + request = { |
| 590 | + "message_id": topic_msg_id, |
| 591 | + "topic": topic_name[2:], |
| 592 | + "propagate_mode": "change_all", |
| 593 | + } |
| 594 | + else: |
| 595 | + request = { |
| 596 | + "message_id": topic_msg_id, |
| 597 | + "topic": RESOLVED_TOPIC_PREFIX + topic_name, |
| 598 | + "propagate_mode": "change_all", |
| 599 | + } |
| 600 | + response = self.client.update_message(request) |
| 601 | + else: |
| 602 | + self.controller.report_error( |
| 603 | + " Time limit for editing topic has been exceeded." |
| 604 | + ) |
| 605 | + return response["result"] == "success" |
| 606 | + |
562 | 607 | def update_stream_message(
|
563 | 608 | self,
|
564 | 609 | topic: str,
|
|
0 commit comments