Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
starred_messages: Add support to unstar all messages in a topic.
Abhishek-Balaji6fba17599f7f
diff --git a/static/js/message_flags.js b/static/js/message_flags.jsindex d4c36a8c745..a425b93e4ac 100644--- a/static/js/message_flags.js+++ b/static/js/message_flags.js@@ -111,8 +111,13 @@ exports.toggle_starred_and_update_server = function (message) {}};-exports.unstar_all_messages = function () {- const starred_msg_ids = starred_messages.get_starred_msg_ids();+exports.unstar_messages = function (topic_name, stream_id) {+ let starred_msg_ids;+ if (topic_name && stream_id) {+ starred_msg_ids = starred_messages.get_topic_starred_msg_ids(topic_name, stream_id);+ } else {+ starred_msg_ids = starred_messages.get_starred_msg_ids();+ }channel.post({url: "/json/messages/flags",idempotent: true,diff --git a/static/js/starred_messages.js b/static/js/starred_messages.jsindex 6cee24933e7..7ebe9b8cc8c 100644--- a/static/js/starred_messages.js+++ b/static/js/starred_messages.js@@ -36,6 +36,16 @@ exports.get_starred_msg_ids = function () {return Array.from(exports.starred_ids);};+exports.get_topic_starred_msg_ids = function (topic_name, stream_id) {+ return Array.from(exports.starred_ids).filter((id) => {+ const message = message_store.get(id);+ return (+ message.stream_id === stream_id &&+ message.topic.toLowerCase() === topic_name.toLowerCase()+ );+ });+};+exports.rerender_ui = function () {let count = exports.get_count();diff --git a/static/js/stream_popover.js b/static/js/stream_popover.jsindex 6e3f69522c4..31db09a71c0 100644--- a/static/js/stream_popover.js+++ b/static/js/stream_popover.js@@ -218,6 +218,8 @@ function build_topic_popover(opts) {const is_muted = muting.is_topic_muted(sub.stream_id, topic_name);const can_mute_topic = !is_muted;const can_unmute_topic = is_muted;+ const starred_ids = starred_messages.get_topic_starred_msg_ids(topic_name, sub.stream_id);+ const has_starred = starred_ids.length > 0;const content = render_topic_sidebar_actions({stream_name: sub.name,@@ -227,6 +229,7 @@ function build_topic_popover(opts) {can_unmute_topic,is_realm_admin: sub.is_realm_admin,color: sub.color,+ has_starred,});$(elt).popover({@@ -404,19 +407,26 @@ exports.register_stream_handlers = function () {e.stopPropagation();});- // Unstar all messages- $("body").on("click", "#unstar_all_messages", (e) => {+ // Unstar all messages, or all messages in a topic+ $("body").on("click", "#unstar_all_messages, .sidebar-popover-unstar-all-in-topic", (e) => {exports.hide_starred_messages_popover();e.preventDefault();e.stopPropagation();$(".left-sidebar-modal-holder").empty();- $(".left-sidebar-modal-holder").html(render_unstar_messages_modal());+ const topic_name = $(".sidebar-popover-unstar-all-in-topic").attr("data-topic-name");+ const args = {+ topic_name,+ };+ $(".left-sidebar-modal-holder").html(render_unstar_messages_modal(args));+ exports.hide_topic_popover();$("#unstar-messages-modal").modal("show");});$("body").on("click", "#do_unstar_messages_button", (e) => {$("#unstar-messages-modal").modal("hide");- message_flags.unstar_all_messages();+ const topic_name = $(".sidebar-popover-unstar-all-in-topic").attr("data-topic-name");+ const stream_id = $(".sidebar-popover-unstar-all-in-topic").attr("data-stream-id");+ message_flags.unstar_messages(topic_name, Number.parseInt(stream_id, 10));e.stopPropagation();});diff --git a/static/templates/topic_sidebar_actions.hbs b/static/templates/topic_sidebar_actions.hbsindex 38ebcf38818..69039e4a6d7 100644--- a/static/templates/topic_sidebar_actions.hbs+++ b/static/templates/topic_sidebar_actions.hbs@@ -34,6 +34,15 @@</a></li>{{/if}}++ {{#if has_starred}}+ <li>+ <a href="#" class="sidebar-popover-unstar-all-in-topic" data-stream-id="{{ stream_id }}" data-topic-name="{{ topic_name }}">+ <i class="fa fa-star-o" aria-hidden="true"></i>+ {{#tr this}}Unstar all messages in topic{{/tr}}+ </a>+ </li>+ {{/if}}<li><a tabindex="0" class="sidebar-popover-mark-topic-read" data-stream-id="{{ stream_id }}" data-topic-name="{{ topic_name }}"><i class="fa fa-book" aria-hidden="true"></i>diff --git a/static/templates/unstar_messages_modal.hbs b/static/templates/unstar_messages_modal.hbsindex 2ae945ded93..791efd3595b 100644--- a/static/templates/unstar_messages_modal.hbs+++ b/static/templates/unstar_messages_modal.hbs@@ -1,10 +1,18 @@<div id="unstar-messages-modal" class="modal new-style modal-bg hide fade" tabindex="-1" role="dialog" aria-labelledby="unstar_messages_modal_label" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="{{t 'Close' }}"><span aria-hidden="true">×</span></button>+ {{#if topic_name}}+ <h3 id="unstar_messages_modal_label">{{t "Unstar all messages in this topic" }}</h3>+ {{else}}<h3 id="unstar_messages_modal_label">{{t "Unstar all messages" }}</h3>+ {{/if}}</div><div class="modal-body">+ {{#if topic_name}}+ <p>{{#tr this}}Would you like to unstar all starred messages in <b>__topic_name__</b>? This action cannot be undone.{{/tr}}</p>+ {{else}}<p>{{t "Would you like to unstar all starred messages? This action cannot be undone." }}</p>+ {{/if}}</div><div class="modal-footer"><button type="button" class="button rounded" data-dismiss="modal">{{t "Cancel" }}</button>