Merge pull request #50 from StewKI/bugfix-whiteboard-joining-flow

fixes
This commit is contained in:
2026-03-08 18:16:39 +01:00
committed by GitHub
5 changed files with 56 additions and 8 deletions

View File

@@ -21,12 +21,14 @@ public class WhiteboardHub : Hub
private readonly WhiteboardManager _whiteboardManager;
private readonly IMessagingService _messagingService;
private readonly MembershipService _membershipService;
private readonly GetUserService _getUserService;
public WhiteboardHub(WhiteboardManager whiteboardManager, IMessagingService messagingService, MembershipService membershipService)
public WhiteboardHub(WhiteboardManager whiteboardManager, IMessagingService messagingService, MembershipService membershipService, GetUserService getUserService)
{
_whiteboardManager = whiteboardManager;
_messagingService = messagingService;
_membershipService = membershipService;
_getUserService = getUserService;
}
public override async Task OnDisconnectedAsync(Exception? exception)
@@ -71,9 +73,10 @@ public class WhiteboardHub : Hub
status = await _membershipService.GetMembershipStatus(whiteboardId, userId);
}
_whiteboardManager.AddUserToWhiteboard(userId, whiteboardId);
if (status == WhiteboardMembershipStatus.Accepted)
{
_whiteboardManager.AddUserToWhiteboard(userId, whiteboardId);
var joiningUser = whiteboard.Users.FirstOrDefault(u => u.UserId == userId);
if (joiningUser == null)
@@ -84,8 +87,7 @@ public class WhiteboardHub : Hub
}
else
{
joiningUser = new User(userId, Context.User?.Identity?.Name ?? "Unknown",
"");
joiningUser = new User(userId, Context.User?.Identity?.Name ?? "Unknown", "");
whiteboard.AddUser(joiningUser);
}
}
@@ -101,7 +103,12 @@ public class WhiteboardHub : Hub
{
await Clients.Caller.SendAsync("WaitingForApproval", userId.ToString());
var user = whiteboard.Users.First(u => u.UserId == userId);
var user = whiteboard.Users.FirstOrDefault(u => u.UserId == userId);
if (user == null)
{
user = await _getUserService.GetUser(userId);
}
await Clients.User(ownerId.ToString()).SendAsync("UserWaitingForApproval", user);
}
@@ -113,8 +120,15 @@ public class WhiteboardHub : Hub
await _messagingService.AcceptedUser(new AcceptUserRequestToJoinCommand(whiteboard.WhiteboardId.ToString(), targetUserId.ToString()));
var user = whiteboard.Users.FirstOrDefault(u => u.UserId == targetUserId);
whiteboard.AddActiveUser(user!);
await Clients.User(targetUserId.ToString()).SendAsync("Accepted");
await Clients.User(targetUserId.ToString()).SendAsync("InitWhiteboard", whiteboard);
await Clients.GroupExcept(whiteboard.WhiteboardId.ToString(),
Context.ConnectionId).SendAsync("Joined", user);
}
public async Task RejectUser(Guid targetUserId)

View File

@@ -0,0 +1,22 @@
using AipsCore.Application.Abstract;
using AipsCore.Application.Models.User.Query.GetUser;
namespace AipsRT.Model.Users;
public class GetUserService
{
private readonly IDispatcher _dispatcher;
public GetUserService(IDispatcher dispatcher)
{
_dispatcher = dispatcher;
}
public async Task<User> GetUser(Guid userId)
{
var query = new GetUserQuery(userId.ToString());
var userQueryDto = await _dispatcher.Execute(query);
return new User(Guid.Parse(userQueryDto.Id), userQueryDto.UserName, userQueryDto.Email);
}
}

View File

@@ -2,6 +2,7 @@ using AipsCore.Application.Common.Message.ErrorMessage;
using AipsCore.Infrastructure.DI;
using AipsRT.Hubs;
using AipsRT.Model.Memberships;
using AipsRT.Model.Users;
using AipsRT.Model.Whiteboard;
using AipsRT.Services;
using AipsRT.Services.Interfaces;
@@ -26,6 +27,7 @@ builder.Services.AddSingleton<IErrorMessageHandleStrategy, RtErrorHandleStrategy
builder.Services.AddHostedService<ErrorSubscriberBackgroundService>();
builder.Services.AddTransient<MembershipService>();
builder.Services.AddTransient<GetUserService>();
builder.Services.AddScoped<GetWhiteboardService>();
builder.Services.AddSingleton<WhiteboardManager>();

View File

@@ -51,11 +51,21 @@ export const useWhiteboardStore = defineStore('whiteboard', () => {
}
function registerHubEvents() {
whiteboardHubService.offAll()
whiteboardHubService.onInitWhiteboard((wb) => {
console.log('InitWhiteboard payload:', JSON.stringify(wb, null, 2))
deselectShape()
whiteboard.value = wb
connectedUsers.value = wb.activeUsers ?? []
const uniqueUsers = new Map()
for (const user of wb.activeUsers ?? []) {
uniqueUsers.set(user.userId, user)
}
connectedUsers.value = Array.from(uniqueUsers.values())
isLoading.value = false
})
@@ -95,7 +105,7 @@ export const useWhiteboardStore = defineStore('whiteboard', () => {
})
whiteboardHubService.onUserWaitingForApproval((user) => {
if (!pendingUsers.value.includes(user)) {
if (!pendingUsers.value.some(u => u.userId === user.userId)) {
pendingUsers.value.push(user)
}
})