Implement Room User Lists
Fix ``GetAllUsers`` Response
This commit is contained in:
parent
6be9ee8b82
commit
8bbb4954c8
@ -10,6 +10,8 @@ namespace qtc_api.Hubs
|
||||
private static List<UserConnectionDto> ConnectedUsers = new List<UserConnectionDto>();
|
||||
private static List<User> OnlineUsers = new List<User>();
|
||||
|
||||
private static Dictionary<string, List<User>> GroupUsers = new();
|
||||
|
||||
public ChatHub(IUserService userService, ILogger<ChatHub> logger)
|
||||
{
|
||||
_userService = userService;
|
||||
@ -64,7 +66,7 @@ namespace qtc_api.Hubs
|
||||
|
||||
await _userService.UpdateStatus(statusDto);
|
||||
|
||||
await Clients.All.SendAsync("RefreshUserList");
|
||||
await Clients.All.SendAsync("RefreshUserLists");
|
||||
}
|
||||
|
||||
[HubMethodName("JoinLobby")]
|
||||
@ -73,6 +75,11 @@ namespace qtc_api.Hubs
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, "LOBBY");
|
||||
|
||||
await Clients.Group("LOBBY").SendAsync("RoomMessage", $"[SERVER] User {user.Username} Has Joined The Lobby");
|
||||
|
||||
if (!GroupUsers.TryGetValue("LOBBY", out _)) { GroupUsers.Add("LOBBY", new List<User>()); }
|
||||
GroupUsers["LOBBY"].Add(user);
|
||||
|
||||
await Clients.Groups("LOBBY").SendAsync("RoomUserList", GroupUsers["LOBBY"]);
|
||||
Log($"User {user.Username} Has Joined The Lobby");
|
||||
}
|
||||
|
||||
@ -82,6 +89,10 @@ namespace qtc_api.Hubs
|
||||
await Groups.RemoveFromGroupAsync(Context.ConnectionId, "LOBBY");
|
||||
|
||||
await Clients.Group("LOBBY").SendAsync("RoomMessage", $"[SERVER] User {user.Username} Has Left The Lobby");
|
||||
|
||||
if (GroupUsers.TryGetValue("LOBBY", out _)) GroupUsers["LOBBY"].Remove(user);
|
||||
|
||||
await Clients.Client("LOBBY").SendAsync("RoomUserList", GroupUsers["LOBBY"]);
|
||||
Log($"User {user.Username} Has Left The Lobby");
|
||||
}
|
||||
|
||||
@ -91,6 +102,11 @@ namespace qtc_api.Hubs
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, room.Id);
|
||||
|
||||
await Clients.Group(room.Id).SendAsync("RoomMessage", $"[SERVER] User {user.Username} Has Joined {room.Name}");
|
||||
|
||||
if (!GroupUsers.TryGetValue(room.Id, out _)) { GroupUsers.Add(room.Id, new List<User>()); }
|
||||
GroupUsers[room.Id].Add(user);
|
||||
|
||||
await Clients.Group(room.Id).SendAsync("RoomUserList", GroupUsers[room.Id]);
|
||||
Log($"User {user.Username} Has Joined {room.Name}");
|
||||
}
|
||||
|
||||
@ -100,6 +116,10 @@ namespace qtc_api.Hubs
|
||||
await Groups.RemoveFromGroupAsync(Context.ConnectionId, room.Id);
|
||||
|
||||
await Clients.Group(room.Id).SendAsync("RoomMessage", $"[SERVER] User {user.Username} Has Left {room.Name}");
|
||||
|
||||
if (GroupUsers.TryGetValue(room.Id, out _)) GroupUsers[room.Id].Remove(GroupUsers[room.Id].FirstOrDefault(e => e.Id == user.Id)!);
|
||||
|
||||
await Clients.Group(room.Id).SendAsync("RoomUserList", GroupUsers[room.Id]);
|
||||
Log($"User {user.Username} Has Left {room.Name}");
|
||||
}
|
||||
|
||||
|
@ -107,6 +107,7 @@
|
||||
x.Bio = user.Bio;
|
||||
x.DateOfBirth = user.DateOfBirth;
|
||||
x.CurrencyAmount = user.CurrencyAmount;
|
||||
x.Status = user.Status;
|
||||
|
||||
userInfoList.Add(x);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user