Fix Contacts Status' Not Updating

Implement Room User Count

SQL SCHEMA CHANGE
`ALTER TABLE Rooms ADD COLUMN UserCount INT(32) NOT NULL;`
This commit is contained in:
Alan Moon 2025-11-21 16:15:15 -08:00
parent 2d5cd25a55
commit 110f8c77dd
2 changed files with 21 additions and 0 deletions

View File

@ -113,6 +113,7 @@ namespace qtc_api.Hubs
if (res != null && res.Success && res.Data != null) if (res != null && res.Success && res.Data != null)
{ {
await Clients.All.SendAsync("RefreshUserLists"); await Clients.All.SendAsync("RefreshUserLists");
await Clients.All.SendAsync("RefreshContactsList");
Log($"Status Was Set To {res.Data.Status} On User {user.Username}"); Log($"Status Was Set To {res.Data.Status} On User {user.Username}");
} }
else else
@ -134,7 +135,14 @@ namespace qtc_api.Hubs
Log($"User {user.Username} Has Joined {room.Name}"); Log($"User {user.Username} Has Joined {room.Name}");
user.CurrentRoomId = room.Id; user.CurrentRoomId = room.Id;
ServiceResponse<Room> dbRoomRes = await _roomService.GetRoom(room.Id);
Room? dbRoom = dbRoomRes?.Data;
if(dbRoom != null) dbRoom.UserCount += 1;
await _dataContext.SaveChangesAsync(); await _dataContext.SaveChangesAsync();
await Clients.All.SendAsync("RefreshRoomList");
} }
[HubMethodName("JoinRoomGuest")] [HubMethodName("JoinRoomGuest")]
@ -148,6 +156,11 @@ namespace qtc_api.Hubs
await Groups.AddToGroupAsync(Context.ConnectionId, room.Data.Id); await Groups.AddToGroupAsync(Context.ConnectionId, room.Data.Id);
await Clients.Group(room.Data.Id).SendAsync("GuestJoin", username); await Clients.Group(room.Data.Id).SendAsync("GuestJoin", username);
room.Data.UserCount += 1;
await _dataContext.SaveChangesAsync();
await Clients.All.SendAsync("RefreshRoomList");
} }
} }
@ -165,7 +178,14 @@ namespace qtc_api.Hubs
Log($"User {user.Username} Has Left {room.Name}"); Log($"User {user.Username} Has Left {room.Name}");
user.CurrentRoomId = string.Empty; user.CurrentRoomId = string.Empty;
ServiceResponse<Room> dbRoomRes = await _roomService.GetRoom(room.Id);
Room? dbRoom = dbRoomRes?.Data;
if (dbRoom != null) dbRoom.UserCount -= 1;
await _dataContext.SaveChangesAsync(); await _dataContext.SaveChangesAsync();
await Clients.All.SendAsync("RefreshRoomList");
} }
[HubMethodName("SendMessage")] [HubMethodName("SendMessage")]

View File

@ -6,5 +6,6 @@
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public string CreatorId { get; set; } = string.Empty; public string CreatorId { get; set; } = string.Empty;
public DateTime CreatedAt { get; set; } = new DateTime(); public DateTime CreatedAt { get; set; } = new DateTime();
public int UserCount { get; set; } = 0;
} }
} }