diff --git a/web/src/popover_menus_data.js b/web/src/popover_menus_data.js index cd7f158910..3d6286ce49 100644 --- a/web/src/popover_menus_data.js +++ b/web/src/popover_menus_data.js @@ -16,6 +16,7 @@ import * as settings_data from "./settings_data"; import * as starred_messages from "./starred_messages"; import * as stream_data from "./stream_data"; import * as sub_store from "./sub_store"; +import {num_unread_for_topic} from "./unread"; import {user_settings} from "./user_settings"; import * as user_status from "./user_status"; import * as user_topics from "./user_topics"; @@ -118,6 +119,7 @@ export function get_topic_popover_content_context({stream_id, topic_name, url}) const sub = sub_store.get(stream_id); const topic_unmuted = user_topics.is_topic_unmuted(sub.stream_id, topic_name); const has_starred_messages = starred_messages.get_count_in_topic(sub.stream_id, topic_name) > 0; + const has_unread_messages = num_unread_for_topic(sub.stream_id, topic_name) > 0; const can_move_topic = settings_data.user_can_move_messages_between_streams(); const can_rename_topic = settings_data.user_can_move_messages_to_another_topic(); const visibility_policy = user_topics.get_topic_visibility_policy(sub.stream_id, topic_name); @@ -133,6 +135,7 @@ export function get_topic_popover_content_context({stream_id, topic_name, url}) is_realm_admin: page_params.is_admin, topic_is_resolved: resolved_topic.is_resolved(topic_name), has_starred_messages, + has_unread_messages, url, visibility_policy, all_visibility_policies, diff --git a/web/src/topic_popover.js b/web/src/topic_popover.js index ddd8e0bd85..7f7d579088 100644 --- a/web/src/topic_popover.js +++ b/web/src/topic_popover.js @@ -123,6 +123,11 @@ export function initialize() { instance.hide(); }); + $popper.one("click", ".sidebar-popover-mark-topic-unread", () => { + unread_ops.mark_topic_as_unread(stream_id, topic_name); + instance.hide(); + }); + $popper.one("click", ".sidebar-popover-delete-topic-messages", () => { const html_body = render_delete_topic_modal({topic_name}); diff --git a/web/src/unread_ops.js b/web/src/unread_ops.js index a64852df68..8cfb895a56 100644 --- a/web/src/unread_ops.js +++ b/web/src/unread_ops.js @@ -498,6 +498,20 @@ export function mark_topic_as_read(stream_id, topic) { ); } +export function mark_topic_as_unread(stream_id, topic) { + bulk_update_read_flags_for_narrow( + [ + {operator: "stream", operand: stream_id}, + {operator: "topic", operand: topic}, + ], + "remove", + { + stream_id, + topic, + }, + ); +} + export function mark_all_as_read() { bulk_update_read_flags_for_narrow(all_unread_messages_narrow, "add"); } diff --git a/web/templates/topic_sidebar_actions.hbs b/web/templates/topic_sidebar_actions.hbs index 07b1274b1e..d45dedc684 100644 --- a/web/templates/topic_sidebar_actions.hbs +++ b/web/templates/topic_sidebar_actions.hbs @@ -35,12 +35,21 @@ {{/if}} + {{#if has_unread_messages}}
  • {{t "Mark all messages as read"}}
  • + {{else}} +
  • + + + {{t "Mark all messages as unread"}} + +
  • + {{/if}}