more fix
This commit is contained in:
@@ -56,7 +56,6 @@ public class WhiteboardHub : Hub
|
||||
if (status == WhiteboardMembershipStatus.Accepted)
|
||||
{
|
||||
_whiteboardManager.AddUserToWhiteboard(userId, whiteboardId);
|
||||
whiteboard.AcceptUser(userId);
|
||||
|
||||
var state = _whiteboardManager.GetWhiteboard(whiteboardId)!;
|
||||
await Clients.Caller.SendAsync("InitWhiteboard", state);
|
||||
@@ -65,8 +64,6 @@ public class WhiteboardHub : Hub
|
||||
}
|
||||
else
|
||||
{
|
||||
_whiteboardManager.AddPendingUser(userId, whiteboardId);
|
||||
|
||||
await Clients.Caller.SendAsync("WaitingForApproval", userId.ToString());
|
||||
|
||||
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()));
|
||||
|
||||
_whiteboardManager.MovePendingToAccepted(targetUserId, whiteboard.WhiteboardId);
|
||||
|
||||
await Clients.User(targetUserId.ToString()).SendAsync("Accepted");
|
||||
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()));
|
||||
|
||||
_whiteboardManager.RemovePendingUser(targetUserId, whiteboard.WhiteboardId);
|
||||
|
||||
await Clients.User(targetUserId.ToString()).SendAsync("Rejected");
|
||||
}
|
||||
|
||||
@@ -105,10 +98,7 @@ public class WhiteboardHub : Hub
|
||||
|
||||
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)
|
||||
{
|
||||
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
|
||||
|
||||
rectangle.OwnerId = CurrentUserId;
|
||||
var whiteboard = CurrentWhiteboard;
|
||||
|
||||
@@ -148,8 +136,6 @@ public class WhiteboardHub : Hub
|
||||
|
||||
public async Task AddArrow(Arrow arrow)
|
||||
{
|
||||
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
|
||||
|
||||
arrow.OwnerId = CurrentUserId;
|
||||
var whiteboard = CurrentWhiteboard;
|
||||
|
||||
@@ -162,8 +148,6 @@ public class WhiteboardHub : Hub
|
||||
|
||||
public async Task AddLine(Line line)
|
||||
{
|
||||
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
|
||||
|
||||
line.OwnerId = CurrentUserId;
|
||||
var whiteboard = CurrentWhiteboard;
|
||||
|
||||
@@ -176,8 +160,6 @@ public class WhiteboardHub : Hub
|
||||
|
||||
public async Task AddTextShape(TextShape textShape)
|
||||
{
|
||||
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
|
||||
|
||||
textShape.OwnerId = CurrentUserId;
|
||||
var whiteboard = CurrentWhiteboard;
|
||||
|
||||
@@ -190,8 +172,6 @@ public class WhiteboardHub : Hub
|
||||
|
||||
public async Task MoveShape(MoveShapeCommand moveShape)
|
||||
{
|
||||
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
|
||||
|
||||
var whiteboard = CurrentWhiteboard;
|
||||
|
||||
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)
|
||||
{
|
||||
if (!_whiteboardManager.IsAccepted(CurrentUserId)) return;
|
||||
|
||||
await MoveShape(moveShape);
|
||||
|
||||
await _messagingService.MoveShape(CurrentWhiteboard.WhiteboardId, moveShape);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardInfoRT;
|
||||
using AipsCore.Domain.Models.Shape.Enums;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.Enums;
|
||||
using AipsRT.Model.Whiteboard.Shapes.Map;
|
||||
using AipsRT.Model.Users;
|
||||
|
||||
|
||||
@@ -6,12 +6,9 @@ namespace AipsRT.Model.Whiteboard;
|
||||
public class Whiteboard
|
||||
{
|
||||
public Guid WhiteboardId { 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<Shape> Shapes { get; } = [];
|
||||
@@ -26,36 +23,24 @@ public class Whiteboard
|
||||
Shapes.Add(shape);
|
||||
Rectangles.Add(shape);
|
||||
}
|
||||
|
||||
|
||||
public void AddArrow(Arrow shape)
|
||||
{
|
||||
Shapes.Add(shape);
|
||||
Arrows.Add(shape);
|
||||
}
|
||||
|
||||
|
||||
public void AddLine(Line shape)
|
||||
{
|
||||
Shapes.Add(shape);
|
||||
Lines.Add(shape);
|
||||
}
|
||||
|
||||
|
||||
public void AddTextShape(TextShape shape)
|
||||
{
|
||||
Shapes.Add(shape);
|
||||
TextShapes.Add(shape);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -56,33 +56,4 @@ public class WhiteboardManager
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user