stream_create: Do not show banner if the current user is subscribed.

There is no need to show the banner if the user creating the channel
is subscribed to it because user will eventually be narrowed to
channel narrow and seeing the banner flash doesn't look good.
This commit is contained in:
Sahil Batra 2024-10-18 14:16:29 +05:30 committed by Tim Abbott
parent 77c1204d45
commit 70b6e46516
2 changed files with 35 additions and 12 deletions

View File

@ -22,6 +22,9 @@ import * as ui_report from "./ui_report";
import * as util from "./util";
let created_stream: string | undefined;
// Default is true since the current user is added to
// the subscribers list initially.
let current_user_subscribed_to_created_stream = true;
export function reset_created_stream(): void {
created_stream = undefined;
@ -35,6 +38,18 @@ export function get_name(): string | undefined {
return created_stream;
}
export function reset_current_user_subscribed_to_created_stream(): void {
current_user_subscribed_to_created_stream = true;
}
export function set_current_user_subscribed_to_created_stream(is_subscribed: boolean): void {
current_user_subscribed_to_created_stream = is_subscribed;
}
export function get_current_user_subscribed_to_created_stream(): boolean {
return current_user_subscribed_to_created_stream;
}
export function set_first_stream_created_modal_shown(): void {
onboarding_steps.post_onboarding_step_as_read("first_stream_created_banner");
}
@ -317,6 +332,7 @@ function create_stream(): void {
// once we upgrade the backend to accept user_ids.
const user_ids = stream_create_subscribers.get_principals();
const principals = JSON.stringify(user_ids);
set_current_user_subscribed_to_created_stream(user_ids.includes(current_user.user_id));
assert(stream_settings_components.new_stream_can_remove_subscribers_group_widget !== null);
const widget_value =

View File

@ -239,9 +239,14 @@ export function add_sub_to_table(sub) {
// top of the list, so they are more visible.
stream_ui_updates.row_for_stream_id(sub.stream_id).trigger("click");
if (!stream_create.get_current_user_subscribed_to_created_stream()) {
// This banner is for administrators creating a channel that
// they are themselves not initial subscribers to; other users
// will be immediately navigated to the channel view.
//
// stream_create.get_current_user_subscribed_to_created_stream
// is just a work around because we do not have the subscribers
// info yet.
const context = {
banner_type: compose_banner.SUCCESS,
classname: "stream_creation_confirmation",
@ -252,6 +257,8 @@ export function add_sub_to_table(sub) {
render_stream_creation_confirmation_banner(context),
);
}
stream_create.reset_current_user_subscribed_to_created_stream();
}
update_empty_left_panel_message();
}