From 70b6e46516926f1f3bd355d97059723016ae9f0f Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Fri, 18 Oct 2024 14:16:29 +0530 Subject: [PATCH] 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. --- web/src/stream_create.ts | 16 ++++++++++++++++ web/src/stream_settings_ui.js | 31 +++++++++++++++++++------------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/web/src/stream_create.ts b/web/src/stream_create.ts index 75e5b08115..2f58be4d7d 100644 --- a/web/src/stream_create.ts +++ b/web/src/stream_create.ts @@ -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 = diff --git a/web/src/stream_settings_ui.js b/web/src/stream_settings_ui.js index 67bbe71640..7ee0f08f44 100644 --- a/web/src/stream_settings_ui.js +++ b/web/src/stream_settings_ui.js @@ -239,18 +239,25 @@ 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"); - // 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. - const context = { - banner_type: compose_banner.SUCCESS, - 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), - ); + 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", + 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(); }