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;
|
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> {
|
public getUsers(): Map<number, User> {
|
||||||
return this.users;
|
return this.users;
|
||||||
}
|
}
|
||||||
@ -239,13 +230,11 @@ export class GameRoom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public sendToOthersInGroupIncludingUser(user: User, message: ServerToClientMessage): void {
|
public sendToOthersInGroupIncludingUser(user: User, message: ServerToClientMessage): void {
|
||||||
this.getGroupIncludingUser(user)
|
user.group?.getUsers().forEach((currentUser: User) => {
|
||||||
?.getUsers()
|
if (currentUser.name !== user.name) {
|
||||||
.forEach((currentUser: User) => {
|
currentUser.socket.write(message);
|
||||||
if (currentUser.name !== user.name) {
|
}
|
||||||
currentUser.socket.write(message);
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sendToUserWithName(name: string, message: ServerToClientMessage): void {
|
public sendToUserWithName(name: string, message: ServerToClientMessage): void {
|
||||||
|
@ -860,8 +860,7 @@ export class SocketManager {
|
|||||||
room.sendToOthersInGroupIncludingUser(user, clientMessage);
|
room.sendToOthersInGroupIncludingUser(user, clientMessage);
|
||||||
|
|
||||||
// Update followers
|
// Update followers
|
||||||
const group = room.getGroupIncludingUser(user);
|
user.group?.getUsers().forEach((user) => {
|
||||||
group?.getUsers().forEach((user) => {
|
|
||||||
user.following = [];
|
user.following = [];
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user