Use User.group instead of iterating over groups

Thanks @moufmouf for pointing this out.
This commit is contained in:
PizZaKatZe 2021-12-15 13:21:30 +01:00
parent 1ab8165951
commit e528682403
2 changed files with 6 additions and 18 deletions

View File

@ -92,15 +92,6 @@ export class GameRoom {
return gameRoom;
}
public getGroups(): Group[] {
return Array.from(this.groups.values());
}
public getGroupIncludingUser(user: User): Group | undefined {
const foundGroups = this.getGroups().filter((grp) => grp.includes(user));
return foundGroups[0];
}
public getUsers(): Map<number, User> {
return this.users;
}
@ -239,9 +230,7 @@ export class GameRoom {
}
public sendToOthersInGroupIncludingUser(user: User, message: ServerToClientMessage): void {
this.getGroupIncludingUser(user)
?.getUsers()
.forEach((currentUser: User) => {
user.group?.getUsers().forEach((currentUser: User) => {
if (currentUser.name !== user.name) {
currentUser.socket.write(message);
}

View File

@ -860,8 +860,7 @@ export class SocketManager {
room.sendToOthersInGroupIncludingUser(user, clientMessage);
// Update followers
const group = room.getGroupIncludingUser(user);
group?.getUsers().forEach((user) => {
user.group?.getUsers().forEach((user) => {
user.following = [];
});
} else {