scheduled_messages: Add left sidebar count.

This commit introduces logic to present a message count with the
Scheduled messages item in the left sidebar.

The count is present on the initial load, and is updated as a user
adds or removes scheduled messages.
This commit is contained in:
Karl Stolley
2023-05-02 14:08:15 -05:00
committed by Tim Abbott
parent 6dc10f8696
commit 2d9cbfa8f1
5 changed files with 22 additions and 0 deletions

View File

@@ -140,6 +140,10 @@ export function delete_scheduled_message(scheduled_msg_id, success = () => {}) {
}); });
} }
export function get_count() {
return scheduled_messages_data.length;
}
export function initialize(scheduled_messages_params) { export function initialize(scheduled_messages_params) {
scheduled_messages_data = scheduled_messages_params.scheduled_messages; scheduled_messages_data = scheduled_messages_params.scheduled_messages;

View File

@@ -69,6 +69,7 @@ import * as stream_topic_history from "./stream_topic_history";
import * as stream_ui_updates from "./stream_ui_updates"; import * as stream_ui_updates from "./stream_ui_updates";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import * as submessage from "./submessage"; import * as submessage from "./submessage";
import * as top_left_corner from "./top_left_corner";
import * as typing_events from "./typing_events"; import * as typing_events from "./typing_events";
import * as unread_ops from "./unread_ops"; import * as unread_ops from "./unread_ops";
import * as unread_ui from "./unread_ui"; import * as unread_ui from "./unread_ui";
@@ -473,6 +474,7 @@ export function dispatch_normal_event(event) {
case "add": { case "add": {
scheduled_messages.add_scheduled_messages(event.scheduled_messages); scheduled_messages.add_scheduled_messages(event.scheduled_messages);
scheduled_messages_overlay_ui.rerender(); scheduled_messages_overlay_ui.rerender();
top_left_corner.update_scheduled_messages_row();
break; break;
} }
case "remove": { case "remove": {
@@ -480,11 +482,13 @@ export function dispatch_normal_event(event) {
scheduled_messages_overlay_ui.remove_scheduled_message_id( scheduled_messages_overlay_ui.remove_scheduled_message_id(
event.scheduled_message_id, event.scheduled_message_id,
); );
top_left_corner.update_scheduled_messages_row();
break; break;
} }
case "update": { case "update": {
scheduled_messages.update_scheduled_message(event.scheduled_message); scheduled_messages.update_scheduled_message(event.scheduled_message);
scheduled_messages_overlay_ui.rerender(); scheduled_messages_overlay_ui.rerender();
top_left_corner.update_scheduled_messages_row();
break; break;
} }
// No default // No default

View File

@@ -1,6 +1,7 @@
import $ from "jquery"; import $ from "jquery";
import * as resize from "./resize"; import * as resize from "./resize";
import * as scheduled_messages from "./scheduled_messages";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
let last_mention_count = 0; let last_mention_count = 0;
@@ -10,6 +11,12 @@ export function update_starred_count(count) {
ui_util.update_unread_count_in_dom($starred_li, count); ui_util.update_unread_count_in_dom($starred_li, count);
} }
export function update_scheduled_messages_row() {
const $scheduled_li = $(".top_left_scheduled_messages");
const count = scheduled_messages.get_count();
ui_util.update_unread_count_in_dom($scheduled_li, count);
}
export function update_dom_with_unread_counts(counts) { export function update_dom_with_unread_counts(counts) {
// Note that "Private messages" counts are handled in pm_list.js. // Note that "Private messages" counts are handled in pm_list.js.
@@ -99,3 +106,7 @@ function do_new_messages_animation($li) {
setTimeout(mid_animation, 3000); setTimeout(mid_animation, 3000);
setTimeout(end_animation, 6000); setTimeout(end_animation, 6000);
} }
export function initialize() {
update_scheduled_messages_row();
}

View File

@@ -100,6 +100,7 @@ import * as stream_list_sort from "./stream_list_sort";
import * as stream_settings_ui from "./stream_settings_ui"; import * as stream_settings_ui from "./stream_settings_ui";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import * as tippyjs from "./tippyjs"; import * as tippyjs from "./tippyjs";
import * as top_left_corner from "./top_left_corner";
import * as topic_list from "./topic_list"; import * as topic_list from "./topic_list";
import * as topic_zoom from "./topic_zoom"; import * as topic_zoom from "./topic_zoom";
import * as tutorial from "./tutorial"; import * as tutorial from "./tutorial";
@@ -649,6 +650,7 @@ export function initialize_everything() {
muted_users.initialize(muted_users_params); muted_users.initialize(muted_users_params);
stream_settings_ui.initialize(); stream_settings_ui.initialize();
user_group_settings_ui.initialize(); user_group_settings_ui.initialize();
top_left_corner.initialize();
stream_list.initialize(); stream_list.initialize();
stream_list_sort.initialize(); stream_list_sort.initialize();
condense.initialize(); condense.initialize();

View File

@@ -70,6 +70,7 @@ const stream_topic_history = mock_esm("../src/stream_topic_history");
const submessage = mock_esm("../src/submessage"); const submessage = mock_esm("../src/submessage");
mock_esm("../src/top_left_corner", { mock_esm("../src/top_left_corner", {
update_starred_count() {}, update_starred_count() {},
update_scheduled_messages_row() {},
}); });
const typing_events = mock_esm("../src/typing_events"); const typing_events = mock_esm("../src/typing_events");
const unread_ops = mock_esm("../src/unread_ops"); const unread_ops = mock_esm("../src/unread_ops");