scheduled_messages_data: Convert object to Map.

This commit is contained in:
Varun Singh 2024-01-10 19:24:15 +05:30 committed by Tim Abbott
parent bbe138fd0e
commit ac42de07eb
4 changed files with 10 additions and 10 deletions

View File

@ -5,7 +5,7 @@ import * as timerender from "./timerender";
export const MINIMUM_SCHEDULED_MESSAGE_DELAY_SECONDS = 5 * 60; export const MINIMUM_SCHEDULED_MESSAGE_DELAY_SECONDS = 5 * 60;
// scheduled_messages_data is a dictionary where key=scheduled_message_id and value=scheduled_messages // scheduled_messages_data is a dictionary where key=scheduled_message_id and value=scheduled_messages
export const scheduled_messages_data = {}; export const scheduled_messages_data = new Map();
let selected_send_later_timestamp; let selected_send_later_timestamp;
@ -35,22 +35,22 @@ function compute_send_times(now = new Date()) {
export function add_scheduled_messages(scheduled_messages) { export function add_scheduled_messages(scheduled_messages) {
for (const scheduled_message of scheduled_messages) { for (const scheduled_message of scheduled_messages) {
scheduled_messages_data[scheduled_message.scheduled_message_id] = scheduled_message; scheduled_messages_data.set(scheduled_message.scheduled_message_id, scheduled_message);
} }
} }
export function remove_scheduled_message(scheduled_message_id) { export function remove_scheduled_message(scheduled_message_id) {
if (scheduled_messages_data[scheduled_message_id] !== undefined) { if (scheduled_messages_data.has(scheduled_message_id)) {
delete scheduled_messages_data[scheduled_message_id]; scheduled_messages_data.delete(scheduled_message_id);
} }
} }
export function update_scheduled_message(scheduled_message) { export function update_scheduled_message(scheduled_message) {
if (scheduled_messages_data[scheduled_message.scheduled_message_id] === undefined) { if (!scheduled_messages_data.has(scheduled_message.scheduled_message_id)) {
return; return;
} }
scheduled_messages_data[scheduled_message.scheduled_message_id] = scheduled_message; scheduled_messages_data.set(scheduled_message.scheduled_message_id, scheduled_message);
} }
export function delete_scheduled_message(scheduled_msg_id, success = () => {}) { export function delete_scheduled_message(scheduled_msg_id, success = () => {}) {
@ -61,7 +61,7 @@ export function delete_scheduled_message(scheduled_msg_id, success = () => {}) {
} }
export function get_count() { export function get_count() {
return Object.keys(scheduled_messages_data).length; return scheduled_messages_data.size;
} }
export function get_filtered_send_opts(date) { export function get_filtered_send_opts(date) {

View File

@ -7,7 +7,7 @@ import * as scheduled_messages from "./scheduled_messages";
import * as util from "./util"; import * as util from "./util";
function get_scheduled_messages_matching_narrow() { function get_scheduled_messages_matching_narrow() {
const scheduled_messages_list = Object.values(scheduled_messages.scheduled_messages_data); const scheduled_messages_list = [...scheduled_messages.scheduled_messages_data.values()];
const filter = narrow_state.filter(); const filter = narrow_state.filter();
const is_conversation_view = filter === undefined ? false : filter.is_conversation_view(); const is_conversation_view = filter === undefined ? false : filter.is_conversation_view();
const current_view_type = narrow_state.narrowed_to_pms() ? "private" : "stream"; const current_view_type = narrow_state.narrowed_to_pms() ? "private" : "stream";

View File

@ -50,7 +50,7 @@ export const keyboard_handling_context = {
}; };
function sort_scheduled_messages(scheduled_messages) { function sort_scheduled_messages(scheduled_messages) {
const sorted_messages = Object.values(scheduled_messages).sort( const sorted_messages = [...scheduled_messages.values()].sort(
(msg1, msg2) => msg1.scheduled_delivery_timestamp - msg2.scheduled_delivery_timestamp, (msg1, msg2) => msg1.scheduled_delivery_timestamp - msg2.scheduled_delivery_timestamp,
); );
return sorted_messages; return sorted_messages;

View File

@ -90,7 +90,7 @@ function show_message_unscheduled_banner(scheduled_delivery_timestamp) {
} }
export function edit_scheduled_message(scheduled_message_id, should_narrow_to_recipient = true) { export function edit_scheduled_message(scheduled_message_id, should_narrow_to_recipient = true) {
const scheduled_msg = scheduled_messages.scheduled_messages_data[scheduled_message_id]; const scheduled_msg = scheduled_messages.scheduled_messages_data.get(scheduled_message_id);
scheduled_messages.delete_scheduled_message(scheduled_message_id, () => { scheduled_messages.delete_scheduled_message(scheduled_message_id, () => {
open_scheduled_message_in_compose(scheduled_msg, should_narrow_to_recipient); open_scheduled_message_in_compose(scheduled_msg, should_narrow_to_recipient);
show_message_unscheduled_banner(scheduled_msg.scheduled_delivery_timestamp); show_message_unscheduled_banner(scheduled_msg.scheduled_delivery_timestamp);