mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 01:16:19 +00:00
scheduled_messages: Rerender send later options at specific time.
Fixes: #25451.
This commit is contained in:
committed by
Tim Abbott
parent
45c3f8aa96
commit
e10997b0e6
@@ -1,6 +1,7 @@
|
||||
import $ from "jquery";
|
||||
|
||||
import render_success_message_scheduled_banner from "../templates/compose_banner/success_message_scheduled_banner.hbs";
|
||||
import render_send_later_modal_options from "../templates/send_later_modal_options.hbs";
|
||||
|
||||
import * as channel from "./channel";
|
||||
import * as compose from "./compose";
|
||||
@@ -16,6 +17,8 @@ import * as stream_data from "./stream_data";
|
||||
import * as timerender from "./timerender";
|
||||
|
||||
export const MINIMUM_SCHEDULED_MESSAGE_DELAY_SECONDS = 5 * 60;
|
||||
export const SCHEDULING_MODAL_UPDATE_INTERVAL_IN_MILLISECONDS = 60 * 1000;
|
||||
|
||||
export let scheduled_messages_data = [];
|
||||
|
||||
function compute_send_times(now = new Date()) {
|
||||
@@ -322,3 +325,29 @@ export function initialize(scheduled_messages_params) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
}
|
||||
|
||||
// This function is exported for unit testing purposes.
|
||||
export function should_update_send_later_options(date) {
|
||||
const current_minute = date.getMinutes();
|
||||
const current_hour = date.getHours();
|
||||
|
||||
if (current_hour === 0 && current_minute === 0) {
|
||||
// We need to rerender the available options at midnight,
|
||||
// since Monday could become in range.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Rerender at MINIMUM_SCHEDULED_MESSAGE_DELAY_SECONDS before the
|
||||
// hour, so we don't offer a 4:00PM send time at 3:59 PM.
|
||||
return current_minute === 60 - MINIMUM_SCHEDULED_MESSAGE_DELAY_SECONDS / 60;
|
||||
}
|
||||
|
||||
export function update_send_later_options() {
|
||||
const now = new Date();
|
||||
if (should_update_send_later_options(now)) {
|
||||
const filtered_send_opts = get_filtered_send_opts(now);
|
||||
$("#send_later_modal .send_later_options").replaceWith(
|
||||
render_send_later_modal_options(filtered_send_opts),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user