Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

left sidebar: Implement basic resolve topic option.

Tim Abbott696236b6fcd8
diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js
index 876f505ba89..ac5b222e7e2 100644
--- a/static/js/stream_popover.js
+++ b/static/js/stream_popover.js
@@ -1,4 +1,5 @@
import $ from "jquery";
+import _ from "lodash";
import render_all_messages_sidebar_actions from "../templates/all_messages_sidebar_actions.hbs";
import render_delete_topic_modal from "../templates/delete_topic_modal.hbs";
@@ -32,6 +33,7 @@ import * as sub_store from "./sub_store";
import * as subs from "./subs";
import * as unread_ops from "./unread_ops";
+const RESOLVED_PREFIX = "✔️ ";
// We handle stream popovers and topic popovers in this
// module. Both are popped up from the left sidebar.
let current_stream_sidebar_elem;
@@ -254,6 +256,7 @@ function build_topic_popover(opts) {
topic_muted,
can_move_topic,
is_realm_admin: page_params.is_admin,
+ topic_is_resolved: topic_name.startsWith(RESOLVED_PREFIX),
color: sub.color,
has_starred_messages,
});
@@ -656,6 +659,51 @@ export function register_topic_handlers() {
e.stopPropagation();
});
+ function mark_topic_as_resolved(stream_id, topic_name) {
+ const request = {
+ propagate_mode: "change_all",
+ topic: RESOLVED_PREFIX + topic_name,
+ send_notification_to_old_thread: false,
+ send_notification_to_new_thread: true,
+ };
+ with_first_message_id(stream_id, topic_name, (message_id) => {
+ channel.patch({
+ url: "/json/messages/" + message_id,
+ data: request,
+ });
+ });
+ }
+
+ function mark_topic_as_unresolved(stream_id, topic_name) {
+ const request = {
+ propagate_mode: "change_all",
+ topic: _.trimStart(topic_name, RESOLVED_PREFIX),
+ send_notification_to_old_thread: false,
+ send_notification_to_new_thread: true,
+ };
+ with_first_message_id(stream_id, topic_name, (message_id) => {
+ channel.patch({
+ url: "/json/messages/" + message_id,
+ data: request,
+ });
+ });
+ }
+
+ $("body").on("click", ".sidebar-popover-toggle-resolved", (e) => {
+ const topic_row = $(e.currentTarget);
+ const stream_id = Number.parseInt(topic_row.attr("data-stream-id"), 10);
+ const topic_name = topic_row.attr("data-topic-name");
+ if (topic_name.startsWith(RESOLVED_PREFIX)) {
+ mark_topic_as_unresolved(stream_id, topic_name);
+ } else {
+ mark_topic_as_resolved(stream_id, topic_name);
+ }
+
+ hide_topic_popover();
+ e.stopPropagation();
+ e.preventDefault();
+ });
+
$("body").on("click", ".sidebar-popover-move-topic-messages", (e) => {
const topic_row = $(e.currentTarget);
const stream_id = Number.parseInt(topic_row.attr("data-stream-id"), 10);
diff --git a/static/templates/topic_sidebar_actions.hbs b/static/templates/topic_sidebar_actions.hbs
index f6e461c6064..c438d3cf6b0 100644
--- a/static/templates/topic_sidebar_actions.hbs
+++ b/static/templates/topic_sidebar_actions.hbs
@@ -49,6 +49,16 @@
{{t "Move topic"}}
</a>
</li>
+ <li>
+ <a tabindex="0" class="sidebar-popover-toggle-resolved" data-stream-id="{{ stream_id }}" data-topic-name="{{ topic_name }}">
+ <i class="fa fa-check" aria-hidden="true"></i>
+ {{# if topic_is_resolved }}
+ {{t "Mark as unresolved"}}
+ {{else}}
+ {{t "Mark as resolved"}}
+ {{/if}}
+ </a>
+ </li>
{{/if}}
{{#if is_realm_admin}}
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index a0023a02da0..25b4b861610 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -5632,6 +5632,36 @@ class MessageUpdateUserInfoResult(TypedDict):
mention_user_ids: Set[int]
+RESOLVED_TOPIC_PREFIX = "✔️ "
+
+
+def maybe_send_resolve_topic_notifications(
+ *,
+ user_profile: UserProfile,
+ stream: Stream,
+ old_topic: str,
+ new_topic: str,
+) -> None:
+ if old_topic.lstrip(RESOLVED_TOPIC_PREFIX) != new_topic.lstrip(RESOLVED_TOPIC_PREFIX):
+ return
+
+ if new_topic.startswith(RESOLVED_TOPIC_PREFIX):
+ notification_string = _("{user} has marked this topic as resolved.")
+ else:
+ notification_string = _("{user} has marked this topic as unresolved.")
+ sender = get_system_bot(settings.NOTIFICATION_BOT)
+ user_mention = f"@_**{user_profile.full_name}|{user_profile.id}**"
+ with override_language(stream.realm.default_language):
+ internal_send_stream_message(
+ sender,
+ stream,
+ new_topic,
+ notification_string.format(
+ user=user_mention,
+ ),
+ )
+
+
def send_message_moved_breadcrumbs(
user_profile: UserProfile,
old_stream: Stream,
@@ -6172,6 +6202,20 @@ def do_update_message(
new_thread_notification_string,
)
+ if (
+ topic_name is not None
+ and new_stream is None
+ and content is None
+ and len(changed_messages) > 0
+ ):
+ assert stream_being_edited is not None
+ maybe_send_resolve_topic_notifications(
+ user_profile=user_profile,
+ stream=stream_being_edited,
+ old_topic=orig_topic_name,
+ new_topic=topic_name,
+ )
+
return len(changed_messages)
diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py
index 1da7eddfbe0..326def25c40 100644
--- a/zerver/tests/test_message_edit.py
+++ b/zerver/tests/test_message_edit.py
@@ -9,6 +9,7 @@ from django.http import HttpResponse
from django.utils.timezone import now as timezone_now
from zerver.lib.actions import (
+ RESOLVED_TOPIC_PREFIX,
do_change_stream_post_policy,
do_change_user_role,
do_delete_messages,
@@ -1956,6 +1957,67 @@ class EditMessageTest(EditMessageTestCase):
self.check_has_permission_policies("move_messages_between_streams_policy", validation_func)
+ def test_mark_topic_as_resolved(self) -> None:
+ self.login("iago")
+ admin_user = self.example_user("iago")
+ stream = self.make_stream("new")
+ self.subscribe(admin_user, stream.name)
+ original_topic = "topic 1"
+ id1 = self.send_stream_message(
+ self.example_user("hamlet"), "new", topic_name=original_topic
+ )
+ id2 = self.send_stream_message(admin_user, "new", topic_name=original_topic)
+
+ resolved_topic = RESOLVED_TOPIC_PREFIX + original_topic
+ result = self.client_patch(
+ "/json/messages/" + str(id1),
+ {
+ "message_id": id1,
+ "topic": resolved_topic,
+ "propagate_mode": "change_all",
+ },
+ )
+
+ self.assert_json_success(result)
+ for msg_id in [id1, id2]:
+ msg = Message.objects.get(id=msg_id)
+ self.assertEqual(
+ resolved_topic,
+ msg.topic_name(),
+ )
+
+ messages = get_topic_messages(admin_user, stream, resolved_topic)
+ self.assert_length(messages, 3)
+ self.assertEqual(
+ messages[2].content,
+ f"@_**Iago|{admin_user.id}** has marked this topic as resolved.",
+ )
+
+ unresolved_topic = original_topic
+ result = self.client_patch(
+ "/json/messages/" + str(id1),
+ {
+ "message_id": id1,
+ "topic": unresolved_topic,
+ "propagate_mode": "change_all",
+ },
+ )
+
+ self.assert_json_success(result)
+ for msg_id in [id1, id2]:
+ msg = Message.objects.get(id=msg_id)
+ self.assertEqual(
+ unresolved_topic,
+ msg.topic_name(),
+ )
+
+ messages = get_topic_messages(admin_user, stream, unresolved_topic)
+ self.assert_length(messages, 4)
+ self.assertEqual(
+ messages[3].content,
+ f"@_**Iago|{admin_user.id}** has marked this topic as unresolved.",
+ )
+
class DeleteMessageTest(ZulipTestCase):
def test_delete_message_invalid_request_format(self) -> None: