subscribers: Add warning when last user unsubscribes from private stream.

This commit adds a warning to the confirmation modal displayed when
the last user of a private stream attempts to unsubscribe. The warning
explains that, as the only subscriber, unsubscribing will result in the
stream being automatically archived. This change helps ensure that users
are aware of the consequences of their actions and can make informed
decisions.

Fixes: #23954
This commit is contained in:
Akarsh Jain 2023-01-03 11:03:32 +05:30 committed by Tim Abbott
parent f26260c52a
commit 82aa15cb38
3 changed files with 11 additions and 0 deletions

View File

@ -243,10 +243,13 @@ function remove_subscriber({stream_id, target_user_id, $list_entry}) {
} }
if (sub.invite_only && people.is_my_user_id(target_user_id)) { if (sub.invite_only && people.is_my_user_id(target_user_id)) {
const sub_count = peer_data.get_subscriber_count(stream_id);
const html_body = render_unsubscribe_private_stream_modal({ const html_body = render_unsubscribe_private_stream_modal({
message: $t({ message: $t({
defaultMessage: "Once you leave this stream, you will not be able to rejoin.", defaultMessage: "Once you leave this stream, you will not be able to rejoin.",
}), }),
display_stream_archive_warning: sub_count === 1,
}); });
confirm_dialog.launch({ confirm_dialog.launch({

View File

@ -22,6 +22,7 @@ import * as message_live_update from "./message_live_update";
import * as message_view_header from "./message_view_header"; import * as message_view_header from "./message_view_header";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as peer_data from "./peer_data";
import * as people from "./people"; import * as people from "./people";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import * as search_util from "./search_util"; import * as search_util from "./search_util";
@ -971,10 +972,14 @@ export function open_create_stream() {
} }
export function unsubscribe_from_private_stream(sub) { export function unsubscribe_from_private_stream(sub) {
const invite_only = sub.invite_only;
const sub_count = peer_data.get_subscriber_count(sub.stream_id);
const html_body = render_unsubscribe_private_stream_modal({ const html_body = render_unsubscribe_private_stream_modal({
message: $t({ message: $t({
defaultMessage: "Once you leave this stream, you will not be able to rejoin.", defaultMessage: "Once you leave this stream, you will not be able to rejoin.",
}), }),
display_stream_archive_warning: sub_count === 1 && invite_only,
}); });
function unsubscribe_from_stream() { function unsubscribe_from_stream() {

View File

@ -1 +1,4 @@
<p>{{message}}</p> <p>{{message}}</p>
{{#if display_stream_archive_warning}}
<p>{{t "Because you are the only subscriber, this stream will be automatically archived." }}</p>
{{/if}}