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"; import * as util from "./util";
let created_stream: string | undefined; 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 { export function reset_created_stream(): void {
created_stream = undefined; created_stream = undefined;
@ -35,6 +38,18 @@ export function get_name(): string | undefined {
return created_stream; 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 { export function set_first_stream_created_modal_shown(): void {
onboarding_steps.post_onboarding_step_as_read("first_stream_created_banner"); 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. // once we upgrade the backend to accept user_ids.
const user_ids = stream_create_subscribers.get_principals(); const user_ids = stream_create_subscribers.get_principals();
const principals = JSON.stringify(user_ids); 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); assert(stream_settings_components.new_stream_can_remove_subscribers_group_widget !== null);
const widget_value = const widget_value =

View File

@ -239,18 +239,25 @@ export function add_sub_to_table(sub) {
// top of the list, so they are more visible. // top of the list, so they are more visible.
stream_ui_updates.row_for_stream_id(sub.stream_id).trigger("click"); stream_ui_updates.row_for_stream_id(sub.stream_id).trigger("click");
// This banner is for administrators creating a channel that if (!stream_create.get_current_user_subscribed_to_created_stream()) {
// they are themselves not initial subscribers to; other users // This banner is for administrators creating a channel that
// will be immediately navigated to the channel view. // they are themselves not initial subscribers to; other users
const context = { // will be immediately navigated to the channel view.
banner_type: compose_banner.SUCCESS, //
classname: "stream_creation_confirmation", // stream_create.get_current_user_subscribed_to_created_stream
stream_name: sub.name, // is just a work around because we do not have the subscribers
stream_url: hash_util.by_stream_url(sub.stream_id), // info yet.
}; const context = {
$("#stream_settings .stream-creation-confirmation-banner").html( banner_type: compose_banner.SUCCESS,
render_stream_creation_confirmation_banner(context), classname: "stream_creation_confirmation",
); stream_name: sub.name,
stream_url: hash_util.by_stream_url(sub.stream_id),
};
$("#stream_settings .stream-creation-confirmation-banner").html(
render_stream_creation_confirmation_banner(context),
);
}
stream_create.reset_current_user_subscribed_to_created_stream();
} }
update_empty_left_panel_message(); update_empty_left_panel_message();
} }