diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 5b7cf58384..59d2085074 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -87,7 +87,6 @@ EXEMPT_FILES = make_set( "web/src/emoji_picker.js", "web/src/emojisets.js", "web/src/favicon.ts", - "web/src/feature_flags.ts", "web/src/feedback_widget.js", "web/src/flatpickr.js", "web/src/gear_menu.ts", diff --git a/web/src/compose.js b/web/src/compose.js index c1a166446f..577ce1e583 100644 --- a/web/src/compose.js +++ b/web/src/compose.js @@ -24,7 +24,6 @@ import * as narrow from "./narrow"; import {page_params} from "./page_params"; import * as people from "./people"; import * as popover_menus from "./popover_menus"; -import * as reminder from "./reminder"; import * as rendered_markdown from "./rendered_markdown"; import * as resize from "./resize"; import * as rows from "./rows"; @@ -333,9 +332,6 @@ export function finish() { if (popover_menus.is_time_selected_for_schedule()) { schedule_message_to_custom_date(); - } else if (reminder.is_deferred_delivery(message_content)) { - const request = create_message_object(); - reminder.schedule_message(request, clear_compose_box); } else { send_message(); } diff --git a/web/src/feature_flags.ts b/web/src/feature_flags.ts deleted file mode 100644 index 51810f1449..0000000000 --- a/web/src/feature_flags.ts +++ /dev/null @@ -1,3 +0,0 @@ -// The features below have all settled into their final states and the flags -// below can be removed when we get a chance. -export const reminders_in_message_action_menu = false; diff --git a/web/src/popover_menus_data.js b/web/src/popover_menus_data.js index bd7392be06..bdf5f52204 100644 --- a/web/src/popover_menus_data.js +++ b/web/src/popover_menus_data.js @@ -3,7 +3,6 @@ import * as resolved_topic from "../shared/src/resolved_topic"; -import * as feature_flags from "./feature_flags"; import * as hash_util from "./hash_util"; import {$t} from "./i18n"; import * as message_edit from "./message_edit"; @@ -120,7 +119,6 @@ export function get_actions_popover_content_context(message_id) { narrowed: narrow_state.active(), should_display_delete_option, should_display_read_receipts_option, - should_display_reminder_option: feature_flags.reminders_in_message_action_menu, should_display_quote_and_reply, }; } diff --git a/web/src/popovers.js b/web/src/popovers.js index 6bd73da121..457471bd60 100644 --- a/web/src/popovers.js +++ b/web/src/popovers.js @@ -1,5 +1,5 @@ import ClipboardJS from "clipboard"; -import {add, formatISO, parseISO, set} from "date-fns"; +import {parseISO} from "date-fns"; import $ from "jquery"; import tippy, {hideAll} from "tippy.js"; @@ -32,7 +32,6 @@ import {page_params} from "./page_params"; import * as people from "./people"; import * as popover_menus from "./popover_menus"; import * as realm_playground from "./realm_playground"; -import * as reminder from "./reminder"; import * as resize from "./resize"; import * as rows from "./rows"; import * as settings_bots from "./settings_bots"; @@ -987,61 +986,11 @@ export function register_click_handlers() { current_user_sidebar_popover = $target.data("popover"); }); - $("body").on("click", ".remind.custom", (e) => { - $(e.currentTarget)[0]._flatpickr.toggle(); - e.stopPropagation(); - e.preventDefault(); - }); - - function reminder_click_handler(datestr, e) { - const message_id = $(".remind.custom").data("message-id"); - reminder.do_set_reminder_for_message(message_id, datestr); - hide_all(); - e.stopPropagation(); - e.preventDefault(); - } - - $("body").on("click", ".remind.in_20m", (e) => { - const datestr = formatISO(add(new Date(), {minutes: 20})); - reminder_click_handler(datestr, e); - }); - - $("body").on("click", ".remind.in_1h", (e) => { - const datestr = formatISO(add(new Date(), {hours: 1})); - reminder_click_handler(datestr, e); - }); - - $("body").on("click", ".remind.in_3h", (e) => { - const datestr = formatISO(add(new Date(), {hours: 3})); - reminder_click_handler(datestr, e); - }); - - $("body").on("click", ".remind.tomo", (e) => { - const datestr = formatISO( - set(add(new Date(), {days: 1}), {hours: 9, minutes: 0, seconds: 0}), - ); - reminder_click_handler(datestr, e); - }); - - $("body").on("click", ".remind.nxtw", (e) => { - const datestr = formatISO( - set(add(new Date(), {weeks: 1}), {hours: 9, minutes: 0, seconds: 0}), - ); - reminder_click_handler(datestr, e); - }); - $("body").on("click", ".flatpickr-calendar", (e) => { e.stopPropagation(); e.preventDefault(); }); - $("body").on("click", ".flatpickr-confirm", (e) => { - if ($(".remind.custom")[0]) { - const datestr = $(".remind.custom")[0].value; - reminder_click_handler(datestr, e); - } - }); - $("body").on("click", ".respond_personal_button, .compose_private_message", (e) => { const user_id = elem_to_user_id($(e.target).parents("ul")); const email = people.get_by_user_id(user_id).email; diff --git a/web/src/reminder.js b/web/src/reminder.js deleted file mode 100644 index 49b984e28c..0000000000 --- a/web/src/reminder.js +++ /dev/null @@ -1,197 +0,0 @@ -import $ from "jquery"; - -import * as channel from "./channel"; -import * as compose from "./compose"; -import * as compose_banner from "./compose_banner"; -import * as compose_ui from "./compose_ui"; -import * as hash_util from "./hash_util"; -import {$t} from "./i18n"; -import * as message_lists from "./message_lists"; -import * as notifications from "./notifications"; -import {page_params} from "./page_params"; -import * as people from "./people"; -import * as transmit from "./transmit"; -import * as util from "./util"; - -export const deferred_message_types = { - scheduled: { - delivery_type: "send_later", - test: /^\/schedule/, - slash_command: "/schedule", - }, - reminders: { - delivery_type: "remind", - test: /^\/remind/, - slash_command: "/remind", - }, -}; - -export function is_deferred_delivery(message_content) { - const reminders_test = deferred_message_types.reminders.test; - const scheduled_test = deferred_message_types.scheduled.test; - return reminders_test.test(message_content) || scheduled_test.test(message_content); -} - -export function patch_request_for_scheduling(request, message_content, deliver_at, delivery_type) { - if (request.type === "private") { - request.to = JSON.stringify(request.to); - } else { - request.to = JSON.stringify([request.to]); - } - - const new_request = request; - new_request.content = message_content; - new_request.deliver_at = deliver_at; - new_request.delivery_type = delivery_type; - new_request.tz_guess = new Intl.DateTimeFormat().resolvedOptions().timeZone; - return new_request; -} - -export function schedule_message( - request = compose.create_message_object(), - success_callback = () => {}, - scheduled_message_id = undefined, -) { - const raw_message = request.content.split("\n"); - const command_line = raw_message[0]; - const message = raw_message.slice(1).join("\n"); - - const deferred_message_type = Object.values(deferred_message_types).find( - (props) => command_line.match(props.test) !== null, - ); - const command = command_line.match(deferred_message_type.test)[0]; - - const deliver_at = command_line.slice(command.length + 1); - - let error_message; - if (command_line.slice(command.length, command.length + 1) !== " ") { - error_message = $t({ - defaultMessage: - "Invalid slash command. Check if you are missing a space after the command.", - }); - } else if (deliver_at.trim() === "") { - error_message = $t({defaultMessage: "Please specify a date or time."}); - } else if (message.trim() === "") { - $("#compose-textarea").toggleClass("invalid", false); - $("#compose-textarea").prop("disabled", false); - compose_ui.hide_compose_spinner(); - return; - } - - if (error_message) { - compose_banner.show_error_message( - error_message, - compose_banner.CLASSNAMES.generic_compose_error, - $("#compose-textarea"), - ); - $("#compose-textarea").prop("disabled", false); - compose_ui.hide_compose_spinner(); - return; - } - - request = patch_request_for_scheduling( - request, - message, - deliver_at, - deferred_message_type.delivery_type, - ); - - const success = function () { - if (request.delivery_type === deferred_message_types.scheduled.delivery_type) { - notifications.notify_above_composebox( - $t( - {defaultMessage: `Your message has been scheduled for {deliver_at}.`}, - {deliver_at}, - ), - "scheduled_message_banner", - "/#scheduled", - "", - $t({defaultMessage: "View scheduled messages"}), - ); - } - - success_callback(); - }; - const error = function (response) { - $("#compose-textarea").prop("disabled", false); - compose_ui.hide_compose_spinner(); - compose_banner.show_error_message( - response, - compose_banner.CLASSNAMES.generic_compose_error, - $("#compose-textarea"), - ); - }; - /* We are adding a disable on compose under this block because we - want slash commands to be blocking in nature. */ - $("#compose-textarea").prop("disabled", true); - - const future_message = true; - if (scheduled_message_id) { - request.scheduled_message_id = scheduled_message_id; - } - transmit.send_message(request, success, error, future_message); -} - -export function do_set_reminder_for_message(message_id, timestamp) { - const $row = $(`[zid='${CSS.escape(message_id)}']`); - function error() { - $row.find(".alert-msg") - .text($t({defaultMessage: "Reminder not set!"})) - .css("display", "block") - .css("color", "#b94a48") - .delay(1000) - .fadeOut(300, function () { - $(this).css("color", ""); - }); - } - - const message = message_lists.current.get(message_id); - - if (!message.raw_content) { - const msg_list = message_lists.current; - channel.get({ - url: "/json/messages/" + message.id, - success(data) { - if (message_lists.current === msg_list) { - message.raw_content = data.raw_content; - do_set_reminder_for_message(message_id, timestamp); - } - }, - error, - }); - return; - } - - const link_to_msg = hash_util.by_conversation_and_time_url(message); - const reminder_msg_content = - message.raw_content + "\n\n[Link to conversation](" + link_to_msg + ")"; - let reminder_message = { - type: "private", - sender_id: page_params.user_id, - stream: "", - }; - reminder_message.topic = ""; - - const recipient = page_params.email; - const emails = util.extract_pm_recipients(recipient); - reminder_message.to = emails; - reminder_message.reply_to = recipient; - reminder_message.private_message_recipient = recipient; - reminder_message.to_user_ids = people.email_list_to_user_ids_string(emails); - - function success() { - $row.find(".alert-msg") - .text($t({defaultMessage: "Reminder set!"})) - .css("display", "block") - .delay(1000) - .fadeOut(300); - } - - reminder_message = patch_request_for_scheduling( - reminder_message, - reminder_msg_content, - timestamp, - deferred_message_types.reminders.delivery_type, - ); - transmit.send_message(reminder_message, success, error); -} diff --git a/web/src/transmit.js b/web/src/transmit.js index 99ad29ad71..77ca51310f 100644 --- a/web/src/transmit.js +++ b/web/src/transmit.js @@ -6,7 +6,7 @@ import * as reload from "./reload"; import * as reload_state from "./reload_state"; import * as sent_messages from "./sent_messages"; -export function send_message(request, on_success, error, future_message) { +export function send_message(request, on_success, error) { channel.post({ url: "/json/messages", data: request, @@ -14,12 +14,8 @@ export function send_message(request, on_success, error, future_message) { // Call back to our callers to do things like closing the compose // box and turning off spinners and reifying locally echoed messages. on_success(data); - - // For /schedule or /reminder messages don't ack. - if (!future_message) { - // Once everything is done, get ready to report times to the server. - sent_messages.report_server_ack(request.local_id); - } + // Once everything is done, get ready to report times to the server. + sent_messages.report_server_ack(request.local_id); }, error(xhr, error_type) { if (error_type !== "timeout" && reload_state.is_pending()) { diff --git a/web/templates/actions_popover_content.hbs b/web/templates/actions_popover_content.hbs index 7e22c1e1c7..83cc5b22ac 100644 --- a/web/templates/actions_popover_content.hbs +++ b/web/templates/actions_popover_content.hbs @@ -61,14 +61,6 @@ {{/if}} - {{#if should_display_reminder_option}} -