left_sidebar: Add mark all messages unread to three dot topic menu.

This commit adds a new option to the three-dot topic menu in the
left sidebar to mark all the messages of topic as unread, provided
the topic's messages are already read before choosing this option.

This is done with the help of bulk_update_read_flags_for_narrow
method to remove the read flag on bulk of messages.

Fixes #25085
This commit is contained in:
roanster007 2024-01-24 23:33:43 +05:30 committed by Tim Abbott
parent b1ca1fd606
commit 04013cdec1
4 changed files with 31 additions and 0 deletions

View File

@ -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,

View File

@ -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});

View File

@ -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");
}

View File

@ -35,12 +35,21 @@
</li>
{{/if}}
{{#if has_unread_messages}}
<li class="topic-menu-item hidden-for-spectators">
<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>
{{t "Mark all messages as read"}}
</a>
</li>
{{else}}
<li class="topic-menu-item hidden-for-spectators">
<a tabindex="0" class="sidebar-popover-mark-topic-unread" data-stream-id="{{ stream_id }}" data-topic-name="{{ topic_name }}">
<i class="fa fa-book" aria-hidden="true"></i>
{{t "Mark all messages as unread"}}
</a>
</li>
{{/if}}
<li class="topic-menu-item">
<a tabindex="0" class="sidebar-popover-copy-link-to-topic" data-stream-id="{{ stream_id }}" data-topic-name="{{ topic_name }}" data-clipboard-text="{{ url }}">