Skip to content

Commit

Permalink
Optimize checking user role/feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchdev committed May 20, 2024
1 parent f9a5326 commit 937bb1b
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions assets/chat/js/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,27 @@ class ChatUser {
}

hasAnyFeatures(...features) {
let exists = false;
features.forEach((f) => {
if (
this.features.indexOf(typeof f !== 'string' ? f.toString() : f) !== -1
)
exists = true;
});

return exists;
for (let i = 0; i < features.length; i++) {
if (this.features.includes(features[i])) return true;
}

return false;
}

hasAnyRoles(...roles) {
let exists = false;
roles.forEach((f) => {
if (this.roles.indexOf(typeof f !== 'string' ? f.toString() : f) !== -1)
exists = true;
});
for (let i = 0; i < roles.length; i++) {
if (this.roles.includes(roles[i])) return true;
}

return exists;
return false;
}

hasFeature(feature) {
return this.hasAnyFeatures(feature);
return this.features.includes(feature);
}

hasRole(role) {
return this.hasAnyRoles(role);
return this.roles.includes(role);
}

hasModPowers() {
Expand Down

0 comments on commit 937bb1b

Please sign in to comment.