diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js index ea053b87a3..28d0df63cc 100644 --- a/web/src/server_events_dispatch.js +++ b/web/src/server_events_dispatch.js @@ -645,12 +645,13 @@ export function dispatch_normal_event(event) { break; case "delete": for (const stream_id of event.stream_ids) { - const was_subscribed = sub_store.get(stream_id).subscribed; + const sub = sub_store.get(stream_id); + const is_subscribed = sub.subscribed; const is_narrowed_to_stream = narrow_state.narrowed_to_stream_id(stream_id); stream_data.delete_sub(stream_id); - stream_settings_ui.remove_stream(stream_id); + stream_settings_ui.update_settings_for_archived(sub); message_view_header.maybe_rerender_title_area_for_stream(stream_id); - if (was_subscribed) { + if (is_subscribed) { stream_list.remove_sidebar_row(stream_id); if (stream_id === compose_state.selected_recipient_id) { compose_state.set_selected_recipient_id(""); diff --git a/web/src/stream_data.ts b/web/src/stream_data.ts index 60eb521ad1..6ed3059702 100644 --- a/web/src/stream_data.ts +++ b/web/src/stream_data.ts @@ -139,10 +139,6 @@ export function rename_sub(sub: StreamSubscription, new_name: string): void { } export function subscribe_myself(sub: StreamSubscription): void { - if (sub.is_archived) { - blueslip.warn("Can't subscribe to an archived stream."); - return; - } const user_id = people.my_current_user_id(); peer_data.add_subscriber(sub.stream_id, user_id); sub.subscribed = true; diff --git a/web/src/stream_edit.ts b/web/src/stream_edit.ts index 566367e4e2..0e5c16a3c1 100644 --- a/web/src/stream_edit.ts +++ b/web/src/stream_edit.ts @@ -350,19 +350,12 @@ function stream_setting_changed(elem: HTMLInputElement): void { ); } -export function archive_stream( - stream_id: number, - $alert_element: JQuery, - $stream_row: JQuery, -): void { +export function archive_stream(stream_id: number, $alert_element: JQuery): void { channel.del({ url: "/json/streams/" + stream_id, error(xhr) { ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $alert_element); }, - success() { - $stream_row.remove(); - }, }); } @@ -713,8 +706,7 @@ export function initialize(): void { function do_archive_stream(): void { const stream_id = Number($(".dialog_submit_button").attr("data-stream-id")); - const $row = $(".stream-row.active"); - archive_stream(stream_id, $(".stream_change_property_info"), $row); + archive_stream(stream_id, $(".stream_change_property_info")); } const stream_id = get_stream_id(this); diff --git a/web/src/stream_settings_ui.ts b/web/src/stream_settings_ui.ts index 86f1111ab1..833772de78 100644 --- a/web/src/stream_settings_ui.ts +++ b/web/src/stream_settings_ui.ts @@ -307,21 +307,6 @@ export function add_sub_to_table(sub: StreamSubscription): void { update_empty_left_panel_message(); } -export function remove_stream(stream_id: number): void { - if (!overlays.streams_open()) { - return; - } - - // It is possible that row is empty when we deactivate a - // stream, but we let jQuery silently handle that. - const $row = stream_ui_updates.row_for_stream_id(stream_id); - $row.remove(); - update_empty_left_panel_message(); - if (hash_parser.is_editing_stream(stream_id)) { - stream_edit.open_edit_panel_empty(); - } -} - export function update_settings_for_subscribed(slim_sub: StreamSubscription): void { const sub = stream_settings_data.get_sub_for_settings(slim_sub); stream_ui_updates.update_add_subscriptions_elements(sub); @@ -351,6 +336,32 @@ export function update_settings_for_subscribed(slim_sub: StreamSubscription): vo update_empty_left_panel_message(); } +export function update_settings_for_archived(slim_sub: StreamSubscription): void { + if (!overlays.streams_open()) { + return; + } + + const sub = stream_settings_data.get_sub_for_settings(slim_sub); + update_left_panel_row(sub); + redraw_left_panel(); + $(".stream_settings_filter_container").removeClass("hide_filter"); + + const active_data = stream_settings_components.get_active_data(); + if (active_data.id === sub.stream_id) { + const $archive_button = $(".stream_settings_header .deactivate"); + + if ($archive_button.length > 0) { + $archive_button.remove(); + } + + stream_settings_components.set_right_panel_title(sub); + stream_ui_updates.update_toggler_for_sub(sub); + stream_ui_updates.enable_or_disable_permission_settings_in_edit_panel(sub); + stream_ui_updates.update_stream_privacy_icon_in_settings(sub); + stream_ui_updates.update_regular_sub_settings(sub); + } +} + export function show_active_stream_in_left_panel(): void { const selected_row = Number.parseFloat(hash_parser.get_current_hash_section()); diff --git a/web/src/stream_ui_updates.ts b/web/src/stream_ui_updates.ts index d6914cc326..9a99a66c3e 100644 --- a/web/src/stream_ui_updates.ts +++ b/web/src/stream_ui_updates.ts @@ -142,7 +142,7 @@ export function initialize_cant_subscribe_popover(): void { } export function set_up_right_panel_section(sub: StreamSubscription): void { - if (sub.subscribed) { + if (sub.subscribed && !sub.is_archived) { stream_edit_toggler.toggler.enable_tab("personal"); stream_edit_toggler.toggler.goto(stream_edit_toggler.select_tab); } else { @@ -374,6 +374,7 @@ export function update_stream_privacy_icon_in_settings(sub: StreamSubscription): invite_only: sub.invite_only, color: sub.color, is_web_public: sub.is_web_public, + is_archived: sub.is_archived, }), ), ); diff --git a/web/templates/stream_settings/stream_settings.hbs b/web/templates/stream_settings/stream_settings.hbs index 4df93d90a8..8b08e627ab 100644 --- a/web/templates/stream_settings/stream_settings.hbs +++ b/web/templates/stream_settings/stream_settings.hbs @@ -21,11 +21,13 @@ {{#if is_realm_admin}} - + {{#unless is_archived}} + + {{/unless}} {{/if}} {{/with}} @@ -41,7 +43,8 @@