delete_sub: Do not remove archived stream when deactivated.

Stream is simply marked as `archived: true` instead of removing
the stream from `sub_store` and `stream_info`.

A check in `subscribe_myself` is added before subscribing to a
stream.
This commit is contained in:
sanchi-t
2024-07-02 00:49:22 +05:30
committed by Tim Abbott
parent fa268877d3
commit a29b6485d6
5 changed files with 35 additions and 6 deletions

View File

@@ -143,6 +143,10 @@ 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;
@@ -297,12 +301,13 @@ export function slug_to_stream_id(slug: string): number | undefined {
}
export function delete_sub(stream_id: number): void {
if (!stream_info.get(stream_id)) {
const sub = get_sub_by_id(stream_id);
if (sub === undefined || !stream_info.get(stream_id)) {
blueslip.warn("Failed to archive stream " + stream_id.toString());
return;
}
sub_store.delete_sub(stream_id);
stream_info.delete(stream_id);
sub.is_archived = true;
stream_info.set_false(stream_id, sub);
}
export function get_non_default_stream_names(): {name: string; unique_id: number}[] {