Skip to content

Commit

Permalink
fix: user list elements not getting removed sometimes (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
vyneer authored Jul 23, 2024
1 parent 3a8dcb9 commit 24c9856
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions assets/chat/js/menus/ChatUserMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,25 @@ export default class ChatUserMenu extends ChatMenu {
}

addAndRedraw(user) {
if (!this.hasElement(user)) {
if (!this.getElement(user)) {
this.addElement(user, true);
this.filter();
this.redraw();
}
}

removeAndRedraw(user) {
if (this.hasElement(user)) {
this.removeElement(user);
const el = this.getElement(user);
if (el) {
this.removeElement(el);
this.redraw();
}
}

replaceAndRedraw(user) {
if (this.hasElement(user)) {
this.removeElement(user);
const el = this.getElement(user);
if (el) {
this.removeElement(el);
this.addElement(user, true);
this.filter();
this.redraw();
Expand Down Expand Up @@ -227,8 +229,9 @@ export default class ChatUserMenu extends ChatMenu {
this.container.append(section);
}

removeElement(user) {
this.container.find(`.user-entry[data-user-id="${user.id}"]`).remove();
/** @param {HTMLElement} element */
removeElement(element) {
element.remove();
this.totalcount -= 1;
}

Expand Down Expand Up @@ -264,9 +267,10 @@ export default class ChatUserMenu extends ChatMenu {
this.totalcount += 1;
}

hasElement(user) {
return (
this.container.find(`.user-entry[data-user-id="${user.id}"]`).length > 0
getElement(user) {
const section = this.sections.get(this.highestSection(user));
return section.users.querySelector(
`.user-entry[data-user-id="${user.id}"]`,
);
}

Expand Down

0 comments on commit 24c9856

Please sign in to comment.