add(components): 添加MyInput组件
This commit is contained in:
@@ -8,28 +8,35 @@ namespace IM_API.Hubs
|
||||
{
|
||||
public class ChatHub:Hub
|
||||
{
|
||||
private IJWTService _JWTService;
|
||||
public ChatHub(IJWTService jWTService)
|
||||
private IMessageSevice _messageService;
|
||||
public ChatHub(IMessageSevice messageService)
|
||||
{
|
||||
_JWTService = jWTService;
|
||||
_messageService = messageService;
|
||||
}
|
||||
|
||||
public async override Task OnConnectedAsync()
|
||||
{
|
||||
var userIdStr = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if(userIdStr is null)
|
||||
if (!Context.User.Identity.IsAuthenticated)
|
||||
{
|
||||
await Clients.Caller.SendAsync("ReceiveMessage",new BaseResponse<object?>(CodeDefine.AUTH_FAILED));
|
||||
Context.Abort();
|
||||
return;
|
||||
}
|
||||
int userId = int.Parse(userIdStr);
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
public async Task SendMessage(MessageBaseDto dto)
|
||||
public async Task SendPrivateMessage(MessageBaseDto dto)
|
||||
{
|
||||
|
||||
await Clients.Caller.SendAsync("ReceiveMessage", "qwfqwfqw","test");
|
||||
if (!Context.User.Identity.IsAuthenticated)
|
||||
{
|
||||
await Clients.Caller.SendAsync("ReceiveMessage", new BaseResponse<object?>(CodeDefine.AUTH_FAILED));
|
||||
Context.Abort();
|
||||
return;
|
||||
}
|
||||
var userIdStr = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
await _messageService.SendPrivateMessageAsync(int.Parse(userIdStr),dto.ReceiverId,dto);
|
||||
await Clients.Caller.SendAsync("ReceiveMessage",userIdStr,"qfqwfqwfqw");
|
||||
await Clients.Users(dto.ReceiverId.ToString()).SendAsync("ReceiveMessage", userIdStr, dto.Content);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user