Skip to content

Commit

Permalink
runfix: Check team users size for broadcast (WEBAPP-6549, WEBAPP-6550) (
Browse files Browse the repository at this point in the history
  • Loading branch information
ffflorian committed Nov 21, 2019
1 parent 2140158 commit 9687f5a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/script/team/TeamRepository.js
Expand Up @@ -53,6 +53,7 @@ export class TeamRepository {
this.isTeam = ko.pureComputed(() => (this.team() ? !!this.team().id : false));
this.isTeamDeleted = ko.observable(false);

/** Note: this does not include the self user */
this.teamMembers = ko.pureComputed(() => (this.isTeam() ? this.team().members() : []));
this.memberRoles = ko.observable({});
this.memberInviters = ko.observable({});
Expand Down
42 changes: 24 additions & 18 deletions src/script/user/UserRepository.ts
Expand Up @@ -90,6 +90,7 @@ export class UserRepository {
private readonly propertyRepository: PropertiesRepository;
private readonly selfService: SelfService;
private readonly teamMembers: ko.ObservableArray<User>;
/** Note: this does not include the self user */
private readonly teamUsers: ko.ObservableArray<User>;
private readonly user_mapper: UserMapper;
private readonly user_service: UserService;
Expand Down Expand Up @@ -217,23 +218,23 @@ export class UserRepository {

async loadUsers(): Promise<void> {
if (this.isTeam()) {
if (this.isTeamTooLargeForBroadcast()) {
this.logger.warn(
`Availability not displayed since the team size is larger or equal to "${UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST}".`,
);
return;
}

const users = await this.user_service.loadUserFromDb();

if (users.length) {
if (users.length >= UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST) {
this.logger.warn(
`Availability not displayed since the team size is larger than "${UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST}".`,
);
} else {
this.logger.log(`Loaded state of '${users.length}' users from database`, users);

const mappingPromises = users.map(async user => {
const userEntity = await this.get_user_by_id(user.id);
userEntity.availability(user.availability);
});

await Promise.all(mappingPromises);
}
this.logger.log(`Loaded state of '${users.length}' users from database`, users);

await Promise.all(
users.map(user =>
this.get_user_by_id(user.id).then(userEntity => userEntity.availability(user.availability)),
),
);
}

this.users().forEach(userEntity => userEntity.subscribeToChanges());
Expand Down Expand Up @@ -275,9 +276,9 @@ export class UserRepository {
*/
onUserAvailability(event: {data: {availability: Availability.Type}; from: string}): void {
if (this.isTeam()) {
if (this.teamUsers().length >= UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST) {
if (this.isTeamTooLargeForBroadcast()) {
this.logger.warn(
`Availability not updated since the team size is larger than "${UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST}".`,
`Availability not updated since the team size is larger or equal to "${UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST}".`,
);
} else {
// prettier-ignore
Expand Down Expand Up @@ -342,6 +343,11 @@ export class UserRepository {
});
}

private isTeamTooLargeForBroadcast(): boolean {
const teamSizeIncludingSelf = this.teamUsers().length + 1;
return teamSizeIncludingSelf >= UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST;
}

/**
* Saves a new client for the first time to the database and adds it to a user's entity.
*
Expand Down Expand Up @@ -409,9 +415,9 @@ export class UserRepository {
this.logger.log(`Availability was again set to '${newAvailabilityValue}'`);
}

if (teamUsers.length >= UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST) {
if (this.isTeamTooLargeForBroadcast()) {
this.logger.warn(
`Availability update not sent since the team size is larger than "${UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST}".`,
`Availability update not sent since the team size is larger or equal to "${UserRepository.CONFIG.MAXIMUM_TEAM_SIZE_BROADCAST}".`,
);
return;
}
Expand Down

0 comments on commit 9687f5a

Please sign in to comment.