mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	stream_edit: Update channel row in settings when channel is archived.
This commit is contained in:
		@@ -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("");
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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());
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
            }),
 | 
			
		||||
        ),
 | 
			
		||||
    );
 | 
			
		||||
 
 | 
			
		||||
@@ -21,11 +21,13 @@
 | 
			
		||||
        </div>
 | 
			
		||||
        <a href="{{preview_url}}" class="button small rounded tippy-zulip-delayed-tooltip" id="preview-stream-button" role="button" data-tooltip-template-id="view-stream-tooltip-template" data-tippy-placement="bottom" {{#unless should_display_preview_button }}style="display: none"{{/unless}}><i class="fa fa-eye"></i></a>
 | 
			
		||||
        {{#if is_realm_admin}}
 | 
			
		||||
        {{#unless is_archived}}
 | 
			
		||||
            <button class="button small rounded button-danger deactivate tippy-zulip-delayed-tooltip" type="button" data-tippy-content="{{t 'Archive channel'}}">
 | 
			
		||||
                <span class="icon-container">
 | 
			
		||||
                    <i class="zulip-icon zulip-icon-archive" aria-hidden="true"></i>
 | 
			
		||||
                </span>
 | 
			
		||||
            </button>
 | 
			
		||||
        {{/unless}}
 | 
			
		||||
        {{/if}}
 | 
			
		||||
    </div>
 | 
			
		||||
    {{/with}}
 | 
			
		||||
@@ -41,7 +43,8 @@
 | 
			
		||||
            <div class="stream-header">
 | 
			
		||||
                {{> stream_privacy_icon
 | 
			
		||||
                  invite_only=invite_only
 | 
			
		||||
                  is_web_public=is_web_public }}
 | 
			
		||||
                  is_web_public=is_web_public
 | 
			
		||||
                  is_archived=is_archived }}
 | 
			
		||||
                <div class="stream-name">
 | 
			
		||||
                    <span class="sub-stream-name" data-tippy-content="{{name}}">{{name}}</span>
 | 
			
		||||
                </div>
 | 
			
		||||
 
 | 
			
		||||
@@ -225,24 +225,17 @@ test("stream delete (normal)", ({override}) => {
 | 
			
		||||
        bookend_updates += 1;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const removed_stream_ids = [];
 | 
			
		||||
 | 
			
		||||
    override(stream_settings_ui, "remove_stream", (stream_id) => {
 | 
			
		||||
        removed_stream_ids.push(stream_id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    let removed_sidebar_rows = 0;
 | 
			
		||||
    override(stream_list, "remove_sidebar_row", () => {
 | 
			
		||||
        removed_sidebar_rows += 1;
 | 
			
		||||
    });
 | 
			
		||||
    override(stream_settings_ui, "update_settings_for_archived", noop);
 | 
			
		||||
    override(stream_list, "update_subscribe_to_more_streams_link", noop);
 | 
			
		||||
    override(message_live_update, "rerender_messages_view", noop);
 | 
			
		||||
    override(message_view_header, "maybe_rerender_title_area_for_stream", noop);
 | 
			
		||||
 | 
			
		||||
    dispatch(event);
 | 
			
		||||
 | 
			
		||||
    assert.deepEqual(removed_stream_ids, [event.stream_ids[0], event.stream_ids[1]]);
 | 
			
		||||
 | 
			
		||||
    // We should possibly be able to make a single call to
 | 
			
		||||
    // update_trailing_bookend, but we currently do it for each stream.
 | 
			
		||||
    assert.equal(bookend_updates, 2);
 | 
			
		||||
@@ -276,8 +269,8 @@ test("stream delete (special streams)", ({override}) => {
 | 
			
		||||
    override(realm, "realm_signup_announcements_stream_id", event.stream_ids[1]);
 | 
			
		||||
    override(realm, "realm_zulip_update_announcements_stream_id", event.stream_ids[0]);
 | 
			
		||||
 | 
			
		||||
    override(stream_settings_ui, "remove_stream", noop);
 | 
			
		||||
    override(settings_org, "sync_realm_settings", noop);
 | 
			
		||||
    override(stream_settings_ui, "update_settings_for_archived", noop);
 | 
			
		||||
    override(settings_streams, "update_default_streams_table", noop);
 | 
			
		||||
    override(message_lists.current, "update_trailing_bookend", noop);
 | 
			
		||||
    override(stream_list, "remove_sidebar_row", noop);
 | 
			
		||||
@@ -324,16 +317,11 @@ test("stream delete (stream is selected in compose)", ({override}) => {
 | 
			
		||||
        bookend_updates += 1;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const removed_stream_ids = [];
 | 
			
		||||
 | 
			
		||||
    override(stream_settings_ui, "remove_stream", (stream_id) => {
 | 
			
		||||
        removed_stream_ids.push(stream_id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    let removed_sidebar_rows = 0;
 | 
			
		||||
    override(stream_list, "remove_sidebar_row", () => {
 | 
			
		||||
        removed_sidebar_rows += 1;
 | 
			
		||||
    });
 | 
			
		||||
    override(stream_settings_ui, "update_settings_for_archived", noop);
 | 
			
		||||
    override(stream_list, "update_subscribe_to_more_streams_link", noop);
 | 
			
		||||
    override(message_live_update, "rerender_messages_view", noop);
 | 
			
		||||
    override(message_view_header, "maybe_rerender_title_area_for_stream", noop);
 | 
			
		||||
@@ -341,7 +329,6 @@ test("stream delete (stream is selected in compose)", ({override}) => {
 | 
			
		||||
    dispatch(event);
 | 
			
		||||
 | 
			
		||||
    assert.equal(compose_state.stream_name(), "");
 | 
			
		||||
    assert.deepEqual(removed_stream_ids, [event.stream_ids[0], event.stream_ids[1]]);
 | 
			
		||||
 | 
			
		||||
    // We should possibly be able to make a single call to
 | 
			
		||||
    // update_trailing_bookend, but we currently do it for each stream.
 | 
			
		||||
 
 | 
			
		||||
@@ -734,9 +734,6 @@ test("delete_sub", () => {
 | 
			
		||||
 | 
			
		||||
    blueslip.expect("warn", "Failed to archive stream 99999");
 | 
			
		||||
    stream_data.delete_sub(99999);
 | 
			
		||||
 | 
			
		||||
    blueslip.expect("warn", "Can't subscribe to an archived stream.");
 | 
			
		||||
    stream_data.subscribe_myself(canada);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test("notifications", ({override}) => {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user