forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanels.js
135 lines (117 loc) · 4.43 KB
/
panels.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"use strict";
const util = require("./util");
const resize_app = function () {
const panels_height = $("#panels").height();
$("body > .app").height("calc(100% - " + panels_height + "px)");
// the floating recipient bar is usually positioned right below
// the `.header` element (including padding).
const frb_top =
panels_height +
$(".header").height() +
Number.parseInt($(".header").css("paddingBottom"), 10);
$("#floating_recipient_bar").css("top", frb_top + "px");
};
exports.resize_app = resize_app;
const show_step = function ($process, step) {
$process
.find("[data-step]")
.hide()
.filter("[data-step=" + step + "]")
.show();
};
const get_step = function ($process) {
return $process.find("[data-step]:visible").data("step");
};
function should_show_notifications(ls) {
// if the user said to never show banner on this computer again, it will
// be stored as `true` so we want to negate that.
if (localstorage.supported() && ls.get("dontAskForNotifications") === true) {
return false;
}
return (
// notifications *basically* don't work on any mobile platforms, so don't
// event show the banners. This prevents trying to access things that
// don't exist like `Notification.permission`.
!util.is_mobile() &&
// if permission has not been granted yet.
!notifications.granted_desktop_notifications_permission() &&
// if permission is allowed to be requested (e.g. not in "denied" state).
notifications.permission_state() !== "denied"
);
}
exports.check_profile_incomplete = function () {
if (!page_params.is_admin) {
return;
}
// Eventually, we might also check page_params.realm_icon_source,
// but it feels too aggressive to ask users to do change that
// since their organization might not have a logo yet.
if (
page_params.realm_description === "" ||
page_params.realm_description.startsWith("Organization imported from")
) {
$("[data-process='profile-incomplete']").show();
} else {
$("[data-process='profile-incomplete']").hide();
}
};
exports.initialize = function () {
const ls = localstorage();
if (page_params.insecure_desktop_app) {
exports.open($("[data-process='insecure-desktop-app']"));
} else if (page_params.warn_no_email === true && page_params.is_admin) {
// if email has not been set up and the user is the admin,
// display a warning to tell them to set up an email server.
exports.open($("[data-process='email-server']"));
} else if (should_show_notifications(ls)) {
exports.open($("[data-process='notifications']"));
} else if (unread_ui.should_display_bankruptcy_banner()) {
exports.open($("[data-process='bankruptcy']"));
} else {
// TODO: This should be restructured with separate check and
// show calls.
exports.check_profile_incomplete();
}
// Configure click handlers.
$(".request-desktop-notifications").on("click", function (e) {
e.preventDefault();
$(this).closest(".alert").hide();
notifications.request_desktop_notifications_permission();
resize_app();
});
$(".reject-notifications").on("click", function () {
$(this).closest(".alert").hide();
ls.set("dontAskForNotifications", true);
resize_app();
});
$(".accept-bankruptcy").on("click", function (e) {
e.preventDefault();
$(this).closest(".alert").hide();
$(".bankruptcy-loader").show();
setTimeout(unread_ops.mark_all_as_read, 1000);
resize_app();
});
$("#panels").on("click", ".alert .close, .alert .exit", function (e) {
e.stopPropagation();
const $process = $(e.target).closest("[data-process]");
if (get_step($process) === 1 && $process.data("process") === "notifications") {
show_step($process, 2);
} else {
$(this).closest(".alert").hide();
}
resize_app();
});
// Treat Enter with links in the panels UI focused like a click.,
$("#panels").on("keyup", ".alert-link[role=button]", function (e) {
e.stopPropagation();
if (e.key === "Enter") {
$(this).click();
}
});
};
exports.open = function ($process) {
$("[data-process]").hide();
$process.show();
resize_app();
};
window.panels = exports;