buddy_list: Refactor maybe_remove_user_id for ease of adding user lists.

This commit is contained in:
evykassirer
2024-09-18 20:49:16 -07:00
committed by Tim Abbott
parent 5c6e3a7aac
commit e7f5e526bc

View File

@@ -600,17 +600,19 @@ export class BuddyList extends BuddyListConf {
} }
maybe_remove_user_id(opts: {user_id: number}): void { maybe_remove_user_id(opts: {user_id: number}): void {
let pos = this.users_matching_view_ids.indexOf(opts.user_id); let was_removed = false;
if (pos >= 0) { for (const user_id_list of [this.users_matching_view_ids, this.other_user_ids]) {
this.users_matching_view_ids.splice(pos, 1); const pos = user_id_list.indexOf(opts.user_id);
} else { if (pos >= 0) {
pos = this.other_user_ids.indexOf(opts.user_id); user_id_list.splice(pos, 1);
if (pos < 0) { was_removed = true;
return; break;
} }
this.other_user_ids.splice(pos, 1);
} }
pos = this.all_user_ids.indexOf(opts.user_id); if (!was_removed) {
return;
}
const pos = this.all_user_ids.indexOf(opts.user_id);
this.all_user_ids.splice(pos, 1); this.all_user_ids.splice(pos, 1);
if (pos < this.render_count) { if (pos < this.render_count) {