Store status roles in an array instead of a singular value

This commit is contained in:
Michael Rogers 2023-06-14 11:45:40 -05:00
parent 550fa7e7e7
commit c0e7804ccd
2 changed files with 17 additions and 11 deletions

View File

@ -68,7 +68,10 @@ export default class ExampleUserProvider extends EventEmitter {
this.user = undefined;
this.loggedIn = false;
this.autoLoginUser = undefined;
this.status = STATUSES[0];
this.statusRoleValues = statusRoles.map(x => ({
role: x,
status: STATUSES[0]
}));
this.pollQuestion = undefined;
// this.defaultStatusRole = defaultStatusRole;
this.statusRoles = statusRoles;
@ -109,13 +112,13 @@ export default class ExampleUserProvider extends EventEmitter {
return Promise.resolve(this.user.getRoles().includes(roleId));
}
getActiveRole() {
if (!this.loggedIn) {
Promise.resolve(undefined);
}
// getActiveRole() {
// if (!this.loggedIn) {
// Promise.resolve(undefined);
// }
return Promise.resolve(this.selectedStatusRole);
}
// return Promise.resolve(this.selectedStatusRole);
// }
getPossibleRoles() {
return this.user.getRoles();
}
@ -130,7 +133,9 @@ export default class ExampleUserProvider extends EventEmitter {
}
getStatusForRole(role) {
return Promise.resolve(this.status);
const statusForRole = this.statusRoleValues.find(x => x.role === role);
return Promise.resolve(statusForRole?.status);
}
async getDefaultStatusForRole(role) {
@ -141,7 +146,8 @@ export default class ExampleUserProvider extends EventEmitter {
setStatusForRole(role, status) {
status.timestamp = Date.now();
this.status = status;
const matchingIndex = this.statusRoleValues.findIndex(x => x.role === role);
this.statusRoleValues[matchingIndex].status = status;
this.emit('statusChange', {
role,
status

View File

@ -151,11 +151,11 @@ export default class StatusAPI extends EventEmitter {
* @param {Status} status The status to set for the provided role
* @returns {Promise<Boolean>} true if operation was successful, otherwise false.
*/
async setStatusForRole(role, status) {
setStatusForRole(_role, status) {
const provider = this.#userAPI.getProvider();
if (provider.setStatusForRole) {
const activeRole = await provider.getActiveRole();
const activeRole = this.#userAPI.getActiveRole();
if (!provider.canProvideStatusForRole(activeRole)) {
return false;
}