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,13 +230,11 @@ export class GameRoom {
}
public sendToOthersInGroupIncludingUser(user: User, message: ServerToClientMessage): void {
this.getGroupIncludingUser(user)
?.getUsers()
.forEach((currentUser: User) => {
if (currentUser.name !== user.name) {
currentUser.socket.write(message);
}
});
user.group?.getUsers().forEach((currentUser: User) => {
if (currentUser.name !== user.name) {
currentUser.socket.write(message);
}
});
}
public sendToUserWithName(name: string, message: ServerToClientMessage): void {

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 {