From ab994183e5eb0be3c503d41798e55f9307cb7b68 Mon Sep 17 00:00:00 2001 From: PizZaKatZe Date: Thu, 16 Dec 2021 21:26:30 +0100 Subject: [PATCH] Fix not following users getting "stuck" in groups --- back/src/Model/GameRoom.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index 9afeae55..43605778 100644 --- a/back/src/Model/GameRoom.ts +++ b/back/src/Model/GameRoom.ts @@ -217,9 +217,22 @@ export class GameRoom { } else { // If the user is part of a group: // should he leave the group? - const distance = GameRoom.computeDistanceBetweenPositions(user.getPosition(), user.group.getPosition()); - if (user.following.length === 0 && distance > this.groupRadius) { - this.leaveGroup(user); + const leaveIfOutOfRadius = (user: User) => { + if (user.group === undefined) { + return; + } + const usrPos = user.getPosition(); + const grpPos = user.group.getPosition(); + const distance = GameRoom.computeDistanceBetweenPositions(usrPos, grpPos); + if (distance > this.groupRadius) { + this.leaveGroup(user); + } + }; + if (user.following.length > 0) { + const users = user.group.getUsers().filter((u) => u.following.length === 0); + users.forEach((foreignUser) => leaveIfOutOfRadius(foreignUser)); + } else { + leaveIfOutOfRadius(user); } } }