Use User.group instead of iterating over groups
Thanks @moufmouf for pointing this out.
This commit is contained in:
parent
1ab8165951
commit
e528682403
@ -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);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user