This commit is contained in:
2026-03-08 00:27:53 +01:00
parent c4ee5b0394
commit 9a3143d2f0
4 changed files with 8 additions and 73 deletions

View File

@@ -56,7 +56,6 @@ public class WhiteboardHub : Hub
if (status == WhiteboardMembershipStatus.Accepted) if (status == WhiteboardMembershipStatus.Accepted)
{ {
_whiteboardManager.AddUserToWhiteboard(userId, whiteboardId); _whiteboardManager.AddUserToWhiteboard(userId, whiteboardId);
whiteboard.AcceptUser(userId);
var state = _whiteboardManager.GetWhiteboard(whiteboardId)!; var state = _whiteboardManager.GetWhiteboard(whiteboardId)!;
await Clients.Caller.SendAsync("InitWhiteboard", state); await Clients.Caller.SendAsync("InitWhiteboard", state);
@@ -65,8 +64,6 @@ public class WhiteboardHub : Hub
} }
else else
{ {
_whiteboardManager.AddPendingUser(userId, whiteboardId);
await Clients.Caller.SendAsync("WaitingForApproval", userId.ToString()); await Clients.Caller.SendAsync("WaitingForApproval", userId.ToString());
var user = whiteboard.Users.First(u => u.UserId == userId); var user = whiteboard.Users.First(u => u.UserId == userId);
@@ -81,8 +78,6 @@ public class WhiteboardHub : Hub
await _messagingService.AcceptedUser(new AcceptUserRequestToJoinCommand(whiteboard.WhiteboardId.ToString(), targetUserId.ToString())); await _messagingService.AcceptedUser(new AcceptUserRequestToJoinCommand(whiteboard.WhiteboardId.ToString(), targetUserId.ToString()));
_whiteboardManager.MovePendingToAccepted(targetUserId, whiteboard.WhiteboardId);
await Clients.User(targetUserId.ToString()).SendAsync("Accepted"); await Clients.User(targetUserId.ToString()).SendAsync("Accepted");
await Clients.User(targetUserId.ToString()).SendAsync("InitWhiteboard", whiteboard); await Clients.User(targetUserId.ToString()).SendAsync("InitWhiteboard", whiteboard);
} }
@@ -93,8 +88,6 @@ public class WhiteboardHub : Hub
await _messagingService.RejectedUser(new RejectUserRequestToJoinCommand(whiteboard.WhiteboardId.ToString(), targetUserId.ToString())); await _messagingService.RejectedUser(new RejectUserRequestToJoinCommand(whiteboard.WhiteboardId.ToString(), targetUserId.ToString()));
_whiteboardManager.RemovePendingUser(targetUserId, whiteboard.WhiteboardId);
await Clients.User(targetUserId.ToString()).SendAsync("Rejected"); await Clients.User(targetUserId.ToString()).SendAsync("Rejected");
} }
@@ -105,10 +98,7 @@ public class WhiteboardHub : Hub
if (whiteboard != null) if (whiteboard != null)
{ {
_whiteboardManager.RemovePendingUser(userId, whiteboard.WhiteboardId); await Clients.User(whiteboard.OwnerId.ToString()).SendAsync("UserCanceledJoinRequest", userId.ToString());
await Clients.User(whiteboard.OwnerId.ToString())
.SendAsync("UserCanceledJoinRequest", userId.ToString());
} }
} }
@@ -134,8 +124,6 @@ public class WhiteboardHub : Hub
public async Task AddRectangle(Rectangle rectangle) public async Task AddRectangle(Rectangle rectangle)
{ {
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
rectangle.OwnerId = CurrentUserId; rectangle.OwnerId = CurrentUserId;
var whiteboard = CurrentWhiteboard; var whiteboard = CurrentWhiteboard;
@@ -148,8 +136,6 @@ public class WhiteboardHub : Hub
public async Task AddArrow(Arrow arrow) public async Task AddArrow(Arrow arrow)
{ {
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
arrow.OwnerId = CurrentUserId; arrow.OwnerId = CurrentUserId;
var whiteboard = CurrentWhiteboard; var whiteboard = CurrentWhiteboard;
@@ -162,8 +148,6 @@ public class WhiteboardHub : Hub
public async Task AddLine(Line line) public async Task AddLine(Line line)
{ {
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
line.OwnerId = CurrentUserId; line.OwnerId = CurrentUserId;
var whiteboard = CurrentWhiteboard; var whiteboard = CurrentWhiteboard;
@@ -176,8 +160,6 @@ public class WhiteboardHub : Hub
public async Task AddTextShape(TextShape textShape) public async Task AddTextShape(TextShape textShape)
{ {
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
textShape.OwnerId = CurrentUserId; textShape.OwnerId = CurrentUserId;
var whiteboard = CurrentWhiteboard; var whiteboard = CurrentWhiteboard;
@@ -190,8 +172,6 @@ public class WhiteboardHub : Hub
public async Task MoveShape(MoveShapeCommand moveShape) public async Task MoveShape(MoveShapeCommand moveShape)
{ {
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
var whiteboard = CurrentWhiteboard; var whiteboard = CurrentWhiteboard;
var shape = whiteboard.Shapes.Find(s => s.Id.ToString() == moveShape.ShapeId); var shape = whiteboard.Shapes.Find(s => s.Id.ToString() == moveShape.ShapeId);
@@ -209,8 +189,6 @@ public class WhiteboardHub : Hub
public async Task PlaceShape(MoveShapeCommand moveShape) public async Task PlaceShape(MoveShapeCommand moveShape)
{ {
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
await MoveShape(moveShape); await MoveShape(moveShape);
await _messagingService.MoveShape(CurrentWhiteboard.WhiteboardId, moveShape); await _messagingService.MoveShape(CurrentWhiteboard.WhiteboardId, moveShape);

View File

@@ -1,6 +1,7 @@
using AipsCore.Application.Abstract; using AipsCore.Application.Abstract;
using AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardInfoRT; using AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardInfoRT;
using AipsCore.Domain.Models.Shape.Enums; using AipsCore.Domain.Models.Shape.Enums;
using AipsCore.Domain.Models.WhiteboardMembership.Enums;
using AipsRT.Model.Whiteboard.Shapes.Map; using AipsRT.Model.Whiteboard.Shapes.Map;
using AipsRT.Model.Users; using AipsRT.Model.Users;

View File

@@ -9,9 +9,6 @@ public class Whiteboard
public Guid OwnerId { get; set; } public Guid OwnerId { get; set; }
public HashSet<Guid> AcceptedUsers { get; } = new();
public HashSet<Guid> PendingUsers { get; } = new();
public List<User> Users { get; } = []; public List<User> Users { get; } = [];
public List<Shape> Shapes { get; } = []; public List<Shape> Shapes { get; } = [];
@@ -46,16 +43,4 @@ public class Whiteboard
} }
public void AddUser(User user) => Users.Add(user); public void AddUser(User user) => Users.Add(user);
public void AddPendingUser(Guid userId) => PendingUsers.Add(userId);
public void AcceptUser(Guid userId)
{
PendingUsers.Remove(userId);
AcceptedUsers.Add(userId);
}
public void RejectUser(Guid userId) => PendingUsers.Remove(userId);
public bool IsAccepted(Guid userId) => AcceptedUsers.Contains(userId);
} }

View File

@@ -56,33 +56,4 @@ public class WhiteboardManager
{ {
return GetWhiteboard(GetUserWhiteboard(userId)); return GetWhiteboard(GetUserWhiteboard(userId));
} }
public void AddPendingUser(Guid userId, Guid whiteboardId)
{
var wb = GetWhiteboard(whiteboardId)!;
wb.AddPendingUser(userId);
_userInWhiteboards[userId] = whiteboardId;
}
public void MovePendingToAccepted(Guid userId, Guid whiteboardId)
{
var wb = GetWhiteboard(whiteboardId)!;
wb.AcceptUser(userId);
}
public void RemovePendingUser(Guid userId, Guid whiteboardId)
{
var whiteboard = GetWhiteboard(whiteboardId)!;
whiteboard.RejectUser(userId);
_userInWhiteboards.TryRemove(userId, out _);
}
public bool IsAccepted(Guid userId)
{
if (!_userInWhiteboards.TryGetValue(userId, out var whiteboardId))
return false;
var whiteboard = GetWhiteboard(whiteboardId);
return whiteboard?.IsAccepted(userId) ?? false;
}
} }