reminder: Remove feature from zulip.

This is being removed to make the code simpler. We have plans
to add it as a feature in the future , but it will most likely
not use the same code.
This commit is contained in:
Aman Agrawal 2023-04-20 02:38:38 +00:00 committed by Tim Abbott
parent 6bff396711
commit f40855bad2
11 changed files with 6 additions and 317 deletions

View File

@ -87,7 +87,6 @@ EXEMPT_FILES = make_set(
"web/src/emoji_picker.js", "web/src/emoji_picker.js",
"web/src/emojisets.js", "web/src/emojisets.js",
"web/src/favicon.ts", "web/src/favicon.ts",
"web/src/feature_flags.ts",
"web/src/feedback_widget.js", "web/src/feedback_widget.js",
"web/src/flatpickr.js", "web/src/flatpickr.js",
"web/src/gear_menu.ts", "web/src/gear_menu.ts",

View File

@ -24,7 +24,6 @@ import * as narrow from "./narrow";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as popover_menus from "./popover_menus"; import * as popover_menus from "./popover_menus";
import * as reminder from "./reminder";
import * as rendered_markdown from "./rendered_markdown"; import * as rendered_markdown from "./rendered_markdown";
import * as resize from "./resize"; import * as resize from "./resize";
import * as rows from "./rows"; import * as rows from "./rows";
@ -333,9 +332,6 @@ export function finish() {
if (popover_menus.is_time_selected_for_schedule()) { if (popover_menus.is_time_selected_for_schedule()) {
schedule_message_to_custom_date(); 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 { } else {
send_message(); send_message();
} }

View File

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

View File

@ -3,7 +3,6 @@
import * as resolved_topic from "../shared/src/resolved_topic"; import * as resolved_topic from "../shared/src/resolved_topic";
import * as feature_flags from "./feature_flags";
import * as hash_util from "./hash_util"; import * as hash_util from "./hash_util";
import {$t} from "./i18n"; import {$t} from "./i18n";
import * as message_edit from "./message_edit"; import * as message_edit from "./message_edit";
@ -120,7 +119,6 @@ export function get_actions_popover_content_context(message_id) {
narrowed: narrow_state.active(), narrowed: narrow_state.active(),
should_display_delete_option, should_display_delete_option,
should_display_read_receipts_option, should_display_read_receipts_option,
should_display_reminder_option: feature_flags.reminders_in_message_action_menu,
should_display_quote_and_reply, should_display_quote_and_reply,
}; };
} }

View File

@ -1,5 +1,5 @@
import ClipboardJS from "clipboard"; import ClipboardJS from "clipboard";
import {add, formatISO, parseISO, set} from "date-fns"; import {parseISO} from "date-fns";
import $ from "jquery"; import $ from "jquery";
import tippy, {hideAll} from "tippy.js"; import tippy, {hideAll} from "tippy.js";
@ -32,7 +32,6 @@ import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as popover_menus from "./popover_menus"; import * as popover_menus from "./popover_menus";
import * as realm_playground from "./realm_playground"; import * as realm_playground from "./realm_playground";
import * as reminder from "./reminder";
import * as resize from "./resize"; import * as resize from "./resize";
import * as rows from "./rows"; import * as rows from "./rows";
import * as settings_bots from "./settings_bots"; import * as settings_bots from "./settings_bots";
@ -987,61 +986,11 @@ export function register_click_handlers() {
current_user_sidebar_popover = $target.data("popover"); 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) => { $("body").on("click", ".flatpickr-calendar", (e) => {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); 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) => { $("body").on("click", ".respond_personal_button, .compose_private_message", (e) => {
const user_id = elem_to_user_id($(e.target).parents("ul")); const user_id = elem_to_user_id($(e.target).parents("ul"));
const email = people.get_by_user_id(user_id).email; const email = people.get_by_user_id(user_id).email;

View File

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

View File

@ -6,7 +6,7 @@ import * as reload from "./reload";
import * as reload_state from "./reload_state"; import * as reload_state from "./reload_state";
import * as sent_messages from "./sent_messages"; 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({ channel.post({
url: "/json/messages", url: "/json/messages",
data: request, 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 // Call back to our callers to do things like closing the compose
// box and turning off spinners and reifying locally echoed messages. // box and turning off spinners and reifying locally echoed messages.
on_success(data); 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. // Once everything is done, get ready to report times to the server.
sent_messages.report_server_ack(request.local_id); sent_messages.report_server_ack(request.local_id);
}
}, },
error(xhr, error_type) { error(xhr, error_type) {
if (error_type !== "timeout" && reload_state.is_pending()) { if (error_type !== "timeout" && reload_state.is_pending()) {

View File

@ -61,14 +61,6 @@
</li> </li>
{{/if}} {{/if}}
{{#if should_display_reminder_option}}
<li>
<a class='reminder_button' data-message-id="{{message_id}}" tabindex="0">
<i class="fa fa-bell" aria-hidden="true"></i> {{t "Remind me about this" }}
</a>
</li>
{{/if}}
{{#if should_display_hide_option}} {{#if should_display_hide_option}}
<li> <li>
<a class="rehide_muted_user_message" data-message-id="{{message_id}}" tabindex="0"> <a class="rehide_muted_user_message" data-message-id="{{message_id}}" tabindex="0">

View File

@ -41,7 +41,6 @@ const compose_pm_pill = mock_esm("../src/compose_pm_pill");
const loading = mock_esm("../src/loading"); const loading = mock_esm("../src/loading");
const markdown = mock_esm("../src/markdown"); const markdown = mock_esm("../src/markdown");
const narrow_state = mock_esm("../src/narrow_state"); const narrow_state = mock_esm("../src/narrow_state");
const reminder = mock_esm("../src/reminder");
const rendered_markdown = mock_esm("../src/rendered_markdown"); const rendered_markdown = mock_esm("../src/rendered_markdown");
const resize = mock_esm("../src/resize"); const resize = mock_esm("../src/resize");
const sent_messages = mock_esm("../src/sent_messages"); const sent_messages = mock_esm("../src/sent_messages");
@ -321,7 +320,6 @@ test_ui("enter_with_preview_open", ({override, override_rewire}) => {
}; };
override_rewire(compose_banner, "clear_message_sent_banners", () => {}); override_rewire(compose_banner, "clear_message_sent_banners", () => {});
override(reminder, "is_deferred_delivery", () => false);
override(document, "to_$", () => $("document-stub")); override(document, "to_$", () => $("document-stub"));
let show_button_spinner_called = false; let show_button_spinner_called = false;
override(loading, "show_button_spinner", ($spinner) => { override(loading, "show_button_spinner", ($spinner) => {
@ -369,11 +367,8 @@ test_ui("enter_with_preview_open", ({override, override_rewire}) => {
test_ui("finish", ({override, override_rewire}) => { test_ui("finish", ({override, override_rewire}) => {
mock_banners(); mock_banners();
mock_stream_header_colorblock(); mock_stream_header_colorblock();
override_rewire(stream_bar, "decorate", noop);
override_rewire(compose_recipient, "update_on_recipient_change", noop);
override_rewire(compose_banner, "clear_message_sent_banners", () => {}); override_rewire(compose_banner, "clear_message_sent_banners", () => {});
override(reminder, "is_deferred_delivery", () => false);
override(document, "to_$", () => $("document-stub")); override(document, "to_$", () => $("document-stub"));
let show_button_spinner_called = false; let show_button_spinner_called = false;
override(loading, "show_button_spinner", ($spinner) => { override(loading, "show_button_spinner", ($spinner) => {
@ -426,29 +421,6 @@ test_ui("finish", ({override, override_rewire}) => {
assert.ok($("#compose .markdown_preview").visible()); assert.ok($("#compose .markdown_preview").visible());
assert.ok(send_message_called); assert.ok(send_message_called);
assert.ok(compose_finished_event_checked); assert.ok(compose_finished_event_checked);
// Testing successful scheduling of message.
$("#compose .undo_markdown_preview").show();
$("#compose .preview_message_area").show();
$("#compose .markdown_preview").hide();
$("#compose-textarea").val("foobarfoobar");
compose_ui.compose_spinner_visible = false;
compose_state.set_message_type("stream");
compose_state.set_stream_name("social");
override_rewire(people, "get_by_user_id", () => []);
compose_finished_event_checked = false;
let schedule_message = false;
override(reminder, "schedule_message", () => {
schedule_message = true;
});
reminder.is_deferred_delivery = () => true;
assert.ok(compose.finish());
assert.ok($("#compose-textarea").visible());
assert.ok(!$("#compose .undo_markdown_preview").visible());
assert.ok(!$("#compose .preview_message_area").visible());
assert.ok($("#compose .markdown_preview").visible());
assert.ok(schedule_message);
assert.ok(compose_finished_event_checked);
})(); })();
}); });

View File

@ -9,7 +9,7 @@ from zerver.lib.addressee import Addressee
from zerver.lib.exceptions import JsonableError from zerver.lib.exceptions import JsonableError
from zerver.lib.message import SendMessageRequest, render_markdown from zerver.lib.message import SendMessageRequest, render_markdown
from zerver.lib.scheduled_messages import access_scheduled_message from zerver.lib.scheduled_messages import access_scheduled_message
from zerver.models import Client, Realm, Recipient, ScheduledMessage, UserProfile from zerver.models import Client, Realm, ScheduledMessage, UserProfile
from zerver.tornado.django_api import send_event from zerver.tornado.django_api import send_event
@ -21,13 +21,11 @@ def check_schedule_message(
topic_name: Optional[str], topic_name: Optional[str],
message_content: str, message_content: str,
scheduled_message_id: Optional[int], scheduled_message_id: Optional[int],
delivery_type: str,
deliver_at: datetime.datetime, deliver_at: datetime.datetime,
realm: Optional[Realm] = None, realm: Optional[Realm] = None,
forwarder_user_profile: Optional[UserProfile] = None, forwarder_user_profile: Optional[UserProfile] = None,
) -> int: ) -> int:
addressee = Addressee.legacy_build(sender, recipient_type_name, message_to, topic_name) addressee = Addressee.legacy_build(sender, recipient_type_name, message_to, topic_name)
send_request = check_message( send_request = check_message(
sender, sender,
client, client,
@ -37,13 +35,6 @@ def check_schedule_message(
forwarder_user_profile=forwarder_user_profile, forwarder_user_profile=forwarder_user_profile,
) )
send_request.deliver_at = deliver_at send_request.deliver_at = deliver_at
send_request.delivery_type = delivery_type
recipient = send_request.message.recipient
if delivery_type == "remind" and (
recipient.type != Recipient.STREAM and recipient.type_id != sender.id
):
raise JsonableError(_("Reminders can only be set for streams."))
if scheduled_message_id is not None: if scheduled_message_id is not None:
return edit_scheduled_message(scheduled_message_id, send_request, sender) return edit_scheduled_message(scheduled_message_id, send_request, sender)
@ -70,10 +61,7 @@ def do_schedule_messages(send_message_requests: Sequence[SendMessageRequest]) ->
scheduled_message.realm = send_request.realm scheduled_message.realm = send_request.realm
assert send_request.deliver_at is not None assert send_request.deliver_at is not None
scheduled_message.scheduled_timestamp = send_request.deliver_at scheduled_message.scheduled_timestamp = send_request.deliver_at
if send_request.delivery_type == "send_later":
scheduled_message.delivery_type = ScheduledMessage.SEND_LATER scheduled_message.delivery_type = ScheduledMessage.SEND_LATER
elif send_request.delivery_type == "remind":
scheduled_message.delivery_type = ScheduledMessage.REMIND
scheduled_messages.append(scheduled_message) scheduled_messages.append(scheduled_message)

View File

@ -74,7 +74,6 @@ def scheduled_messages_backend(
topic_name, topic_name,
message_content, message_content,
scheduled_message_id, scheduled_message_id,
"send_later",
deliver_at, deliver_at,
realm=user_profile.realm, realm=user_profile.realm,
forwarder_user_profile=user_profile, forwarder_user_profile=user_profile,