mirror of
https://github.com/zulip/zulip.git
synced 2026-07-03 21:10:12 +08:00
61 lines
2.1 KiB
JavaScript
61 lines
2.1 KiB
JavaScript
import $ from "jquery";
|
|
|
|
import * as browser_history from "./browser_history";
|
|
import * as channel from "./channel";
|
|
import * as message_store from "./message_store";
|
|
import * as narrow from "./narrow";
|
|
|
|
if (window.electron_bridge !== undefined) {
|
|
window.electron_bridge.on_event("logout", () => {
|
|
$("#logout_form").trigger("submit");
|
|
});
|
|
|
|
window.electron_bridge.on_event("show-keyboard-shortcuts", () => {
|
|
browser_history.go_to_location("keyboard-shortcuts");
|
|
});
|
|
|
|
window.electron_bridge.on_event("show-notification-settings", () => {
|
|
browser_history.go_to_location("settings/notifications");
|
|
});
|
|
|
|
// The code below is for sending a message received from notification reply which
|
|
// is often referred to as inline reply feature. This is done so desktop app doesn't
|
|
// have to depend on channel.post for setting crsf_token and narrow.by_topic
|
|
// to narrow to the message being sent.
|
|
if (window.electron_bridge.set_send_notification_reply_message_supported !== undefined) {
|
|
window.electron_bridge.set_send_notification_reply_message_supported(true);
|
|
}
|
|
window.electron_bridge.on_event("send_notification_reply_message", (message_id, reply) => {
|
|
const message = message_store.get(message_id);
|
|
const data = {
|
|
type: message.type,
|
|
content: reply,
|
|
to: message.type === "private" ? message.reply_to : message.stream,
|
|
topic: message.topic,
|
|
};
|
|
|
|
function success() {
|
|
if (message.type === "stream") {
|
|
narrow.by_topic(message_id, {trigger: "desktop_notification_reply"});
|
|
} else {
|
|
narrow.by_recipient(message_id, {trigger: "desktop_notification_reply"});
|
|
}
|
|
}
|
|
|
|
function error(error) {
|
|
window.electron_bridge.send_event("send_notification_reply_message_failed", {
|
|
data,
|
|
message_id,
|
|
error,
|
|
});
|
|
}
|
|
|
|
channel.post({
|
|
url: "/json/messages",
|
|
data,
|
|
success,
|
|
error,
|
|
});
|
|
});
|
|
}
|