2021-02-10 17:10:22 +01:00
|
|
|
import render_subscription_count from "../templates/subscription_count.hbs";
|
|
|
|
import render_subscription_setting_icon from "../templates/subscription_setting_icon.hbs";
|
|
|
|
import render_subscription_type from "../templates/subscription_type.hbs";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
import * as peer_data from "./peer_data";
|
2019-07-09 21:24:00 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_check_button_for_sub(sub) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const button = subs.check_button_for_sub(sub);
|
2019-03-26 05:38:37 +01:00
|
|
|
if (sub.subscribed) {
|
|
|
|
button.addClass("checked");
|
|
|
|
} else {
|
|
|
|
button.removeClass("checked");
|
|
|
|
}
|
2019-03-27 06:39:25 +01:00
|
|
|
if (sub.should_display_subscription_button) {
|
|
|
|
button.removeClass("disabled");
|
|
|
|
} else {
|
|
|
|
button.addClass("disabled");
|
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-03-26 05:38:37 +01:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function initialize_disable_btn_hint_popover(
|
2020-07-15 00:34:28 +02:00
|
|
|
btn_wrapper,
|
|
|
|
popover_btn,
|
|
|
|
disabled_btn,
|
|
|
|
hint_text,
|
|
|
|
) {
|
2019-05-06 14:35:57 +02:00
|
|
|
// Disabled button blocks mouse events(hover) from reaching
|
|
|
|
// to it's parent div element, so popover don't get triggered.
|
|
|
|
// Add css to prevent this.
|
2019-05-08 08:24:06 +02:00
|
|
|
disabled_btn.css("pointer-events", "none");
|
|
|
|
popover_btn.popover({
|
2019-05-06 14:35:57 +02:00
|
|
|
placement: "bottom",
|
2020-07-15 00:34:28 +02:00
|
|
|
content: $("<div>", {class: "sub_disable_btn_hint"}).text(hint_text).prop("outerHTML"),
|
2019-05-06 14:35:57 +02:00
|
|
|
trigger: "manual",
|
|
|
|
html: true,
|
|
|
|
animation: false,
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
btn_wrapper.on("mouseover", (e) => {
|
|
|
|
popover_btn.popover("show");
|
2019-05-06 14:35:57 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
btn_wrapper.on("mouseout", (e) => {
|
|
|
|
popover_btn.popover("hide");
|
2019-05-06 14:35:57 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-05-06 14:35:57 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function initialize_cant_subscribe_popover(sub) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const button_wrapper = stream_edit.settings_for_sub(sub).find(".sub_unsub_button_wrapper");
|
2019-11-02 00:06:25 +01:00
|
|
|
const settings_button = subs.settings_button_for_sub(sub);
|
2021-02-10 17:10:22 +01:00
|
|
|
initialize_disable_btn_hint_popover(
|
2020-07-15 00:34:28 +02:00
|
|
|
button_wrapper,
|
|
|
|
settings_button,
|
|
|
|
settings_button,
|
|
|
|
i18n.t("Only stream members can add users to a private stream"),
|
|
|
|
);
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-05-08 08:24:06 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_settings_button_for_sub(sub) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const settings_button = subs.settings_button_for_sub(sub);
|
2019-03-31 13:00:32 +02:00
|
|
|
if (sub.subscribed) {
|
|
|
|
settings_button.text(i18n.t("Unsubscribe")).removeClass("unsubscribed");
|
|
|
|
} else {
|
|
|
|
settings_button.text(i18n.t("Subscribe")).addClass("unsubscribed");
|
|
|
|
}
|
|
|
|
if (sub.should_display_subscription_button) {
|
2019-05-06 14:35:57 +02:00
|
|
|
settings_button.prop("disabled", false);
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_button.popover("destroy");
|
2019-05-06 14:35:57 +02:00
|
|
|
settings_button.css("pointer-events", "");
|
2019-03-31 13:00:32 +02:00
|
|
|
} else {
|
2019-05-06 14:35:57 +02:00
|
|
|
settings_button.attr("title", "");
|
2021-02-10 17:10:22 +01:00
|
|
|
initialize_cant_subscribe_popover(sub);
|
2020-07-22 02:59:06 +02:00
|
|
|
settings_button.prop("disabled", true);
|
2019-03-31 13:00:32 +02:00
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-03-31 13:00:32 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_regular_sub_settings(sub) {
|
2019-04-02 18:37:24 +02:00
|
|
|
if (!stream_edit.is_sub_settings_active(sub)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-03 23:23:32 +01:00
|
|
|
const $settings = $(`.subscription_settings[data-stream-id='${CSS.escape(sub.stream_id)}']`);
|
2019-04-02 18:37:24 +02:00
|
|
|
if (sub.subscribed) {
|
|
|
|
if ($settings.find(".email-address").val().length === 0) {
|
|
|
|
// Rerender stream email address, if not.
|
|
|
|
$settings.find(".email-address").text(sub.email_address);
|
|
|
|
$settings.find(".stream-email-box").show();
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
$settings.find(".regular_subscription_settings").addClass("in");
|
2019-04-02 18:37:24 +02:00
|
|
|
} else {
|
2020-07-15 01:29:15 +02:00
|
|
|
$settings.find(".regular_subscription_settings").removeClass("in");
|
2019-04-02 18:37:24 +02:00
|
|
|
// Clear email address widget
|
|
|
|
$settings.find(".email-address").html("");
|
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-04-02 18:37:24 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_change_stream_privacy_settings(sub) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_privacy_btn = $(".change-stream-privacy");
|
2019-04-02 18:43:02 +02:00
|
|
|
|
|
|
|
if (sub.can_change_stream_permissions) {
|
|
|
|
stream_privacy_btn.show();
|
|
|
|
} else {
|
|
|
|
stream_privacy_btn.hide();
|
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-04-02 18:43:02 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_notification_setting_checkbox(notification_name) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const stream_row = $("#subscriptions_table .stream-row.active");
|
2020-02-04 13:15:09 +01:00
|
|
|
if (!stream_row.length) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
const stream_id = stream_row.data("stream-id");
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`#${CSS.escape(notification_name)}_${CSS.escape(stream_id)}`).prop(
|
2020-07-15 00:34:28 +02:00
|
|
|
"checked",
|
|
|
|
stream_data.receives_notifications(stream_id, notification_name),
|
|
|
|
);
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2020-02-04 13:15:09 +01:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_stream_row_in_settings_tab(sub) {
|
2019-04-01 11:04:41 +02:00
|
|
|
// This function display/hide stream row in stream settings tab,
|
|
|
|
// used to display immediate effect of add/removal subscription event.
|
|
|
|
// If user is subscribed to stream, it will show sub row under
|
|
|
|
// "Subscribed" tab, otherwise if stream is not public hide
|
|
|
|
// stream row under tab.
|
|
|
|
if (subs.is_subscribed_stream_tab_active()) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub_row = subs.row_for_stream_id(sub.stream_id);
|
2019-04-01 11:04:41 +02:00
|
|
|
if (sub.subscribed) {
|
|
|
|
sub_row.removeClass("notdisplayed");
|
2019-05-09 07:34:31 +02:00
|
|
|
} else if (sub.invite_only || page_params.is_guest) {
|
2019-04-01 11:04:41 +02:00
|
|
|
sub_row.addClass("notdisplayed");
|
|
|
|
}
|
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-04-01 11:04:41 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_stream_privacy_type_icon(sub) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_settings = stream_edit.settings_for_sub(sub);
|
|
|
|
const sub_row = subs.row_for_stream_id(sub.stream_id);
|
|
|
|
const html = render_subscription_setting_icon(sub);
|
2019-05-02 19:10:10 +02:00
|
|
|
|
2019-05-02 19:39:23 +02:00
|
|
|
if (overlays.streams_open()) {
|
2020-07-15 01:29:15 +02:00
|
|
|
sub_row.find(".icon").expectOne().replaceWith($(html));
|
2019-05-02 19:39:23 +02:00
|
|
|
}
|
|
|
|
if (stream_edit.is_sub_settings_active(sub)) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const large_icon = stream_settings.find(".large-icon").expectOne();
|
2019-05-02 19:39:23 +02:00
|
|
|
if (sub.invite_only) {
|
2020-07-15 00:34:28 +02:00
|
|
|
large_icon
|
|
|
|
.removeClass("hash")
|
|
|
|
.addClass("lock")
|
2019-05-02 19:39:23 +02:00
|
|
|
.html("<i class='fa fa-lock' aria-hidden='true'></i>");
|
|
|
|
} else {
|
|
|
|
large_icon.addClass("hash").removeClass("lock").html("");
|
|
|
|
}
|
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-05-02 19:10:10 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_stream_subscription_type_text(sub) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_settings = stream_edit.settings_for_sub(sub);
|
2020-06-16 13:41:56 +02:00
|
|
|
const template_data = {
|
|
|
|
...sub,
|
|
|
|
stream_post_policy_values: stream_data.stream_post_policy_values,
|
2020-06-16 13:59:02 +02:00
|
|
|
message_retention_text: stream_edit.get_retention_policy_text_for_subscription_type(sub),
|
2020-06-16 13:41:56 +02:00
|
|
|
};
|
|
|
|
const html = render_subscription_type(template_data);
|
2019-05-02 19:39:23 +02:00
|
|
|
if (stream_edit.is_sub_settings_active(sub)) {
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_settings.find(".subscription-type-text").expectOne().html(html);
|
2019-05-02 19:10:10 +02:00
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-05-02 19:10:10 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_subscribers_count(sub, just_subscribed) {
|
2019-05-03 07:24:07 +02:00
|
|
|
if (!overlays.streams_open()) {
|
|
|
|
// If the streams overlay isn't open, we don't need to rerender anything.
|
|
|
|
return;
|
|
|
|
}
|
2021-01-21 15:55:49 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_row = subs.row_for_stream_id(sub.stream_id);
|
2021-01-21 15:55:49 +01:00
|
|
|
const sub_count = peer_data.get_subscriber_count(sub.stream_id);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
!sub.can_access_subscribers ||
|
|
|
|
(just_subscribed && sub.invite_only) ||
|
|
|
|
page_params.is_guest
|
|
|
|
) {
|
2021-01-21 15:55:49 +01:00
|
|
|
const rendered_sub_count = render_subscription_count({
|
|
|
|
can_access_subscribers: sub.can_access_subscribers,
|
|
|
|
subscriber_count: sub_count,
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_row.find(".subscriber-count").expectOne().html(rendered_sub_count);
|
2019-05-03 07:24:07 +02:00
|
|
|
} else {
|
2021-01-21 15:55:49 +01:00
|
|
|
stream_row.find(".subscriber-count-text").expectOne().text(sub_count);
|
2019-05-03 07:24:07 +02:00
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-05-03 07:24:07 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_subscribers_list(sub) {
|
2019-05-03 07:26:56 +02:00
|
|
|
// Render subscriptions only if stream settings is open
|
|
|
|
if (!stream_edit.is_sub_settings_active(sub)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sub.can_access_subscribers) {
|
|
|
|
$(".subscriber_list_settings_container").hide();
|
|
|
|
} else {
|
2021-01-12 21:38:01 +01:00
|
|
|
const subscribers = peer_data.get_subscribers(sub.stream_id);
|
2021-01-12 16:05:24 +01:00
|
|
|
const users = stream_edit.get_users_from_subscribers(subscribers);
|
2020-01-13 16:36:49 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
We try to find a subscribers list that is already in the
|
2021-01-29 10:27:56 +01:00
|
|
|
cache that list_widget.js maintains. The list we are
|
2020-01-13 16:36:49 +01:00
|
|
|
looking for would have been created in the function
|
|
|
|
stream_edit.show_subscription_settings, using the same
|
|
|
|
naming scheme as below for the `name` parameter.
|
|
|
|
*/
|
2021-01-29 10:27:56 +01:00
|
|
|
const subscribers_list = ListWidget.get("stream_subscribers/" + sub.stream_id);
|
2019-05-03 07:26:56 +02:00
|
|
|
|
|
|
|
// Changing the data clears the rendered list and the list needs to be re-rendered.
|
|
|
|
// Perform re-rendering only when the stream settings form of the corresponding
|
|
|
|
// stream is open.
|
|
|
|
if (subscribers_list) {
|
2020-03-08 18:45:44 +01:00
|
|
|
stream_edit.sort_but_pin_current_user_on_top(users);
|
2020-04-15 01:29:34 +02:00
|
|
|
subscribers_list.replace_list_data(users);
|
2019-05-03 07:26:56 +02:00
|
|
|
}
|
|
|
|
$(".subscriber_list_settings_container").show();
|
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|
2019-05-03 07:26:56 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
export function update_add_subscriptions_elements(sub) {
|
2019-05-03 07:59:31 +02:00
|
|
|
if (!stream_edit.is_sub_settings_active(sub)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page_params.is_guest) {
|
|
|
|
// For guest users, we just hide the add_subscribers feature.
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".add_subscribers_container").hide();
|
2019-05-03 07:59:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we adjust whether the widgets are disabled based on
|
|
|
|
// whether this user is authorized to add subscribers.
|
2020-07-15 01:29:15 +02:00
|
|
|
const input_element = $(".add_subscribers_container").find(".input").expectOne();
|
2020-07-15 00:34:28 +02:00
|
|
|
const button_element = $(".add_subscribers_container")
|
|
|
|
.find('button[name="add_subscriber"]')
|
|
|
|
.expectOne();
|
2019-11-02 00:06:25 +01:00
|
|
|
const allow_user_to_add_subs = sub.can_add_subscribers;
|
2019-05-03 07:59:31 +02:00
|
|
|
|
|
|
|
if (allow_user_to_add_subs) {
|
2020-07-22 02:59:06 +02:00
|
|
|
input_element.prop("disabled", false);
|
|
|
|
button_element.prop("disabled", false);
|
2020-07-15 01:29:15 +02:00
|
|
|
button_element.css("pointer-events", "");
|
|
|
|
$(".add_subscribers_container input").popover("destroy");
|
2019-05-03 07:59:31 +02:00
|
|
|
} else {
|
2020-07-22 02:59:06 +02:00
|
|
|
input_element.prop("disabled", true);
|
|
|
|
button_element.prop("disabled", true);
|
2019-05-03 07:59:31 +02:00
|
|
|
|
2021-02-10 17:10:22 +01:00
|
|
|
initialize_disable_btn_hint_popover(
|
2020-07-15 00:34:28 +02:00
|
|
|
$(".add_subscribers_container"),
|
|
|
|
input_element,
|
|
|
|
button_element,
|
|
|
|
i18n.t("Only stream members can add users to a private stream"),
|
|
|
|
);
|
2019-05-03 07:59:31 +02:00
|
|
|
}
|
2021-02-10 17:10:22 +01:00
|
|
|
}
|