add(conversation):完善私聊好友会话服务
This commit is contained in:
@@ -9,19 +9,27 @@ namespace IM_API.Hubs
|
||||
public class ChatHub:Hub
|
||||
{
|
||||
private IMessageSevice _messageService;
|
||||
public ChatHub(IMessageSevice messageService)
|
||||
private readonly IConversationService _conversationService;
|
||||
public ChatHub(IMessageSevice messageService, IConversationService conversationService)
|
||||
{
|
||||
_messageService = messageService;
|
||||
_conversationService = conversationService;
|
||||
}
|
||||
|
||||
public async override Task OnConnectedAsync()
|
||||
{
|
||||
if (!Context.User.Identity.IsAuthenticated)
|
||||
{
|
||||
await Clients.Caller.SendAsync("ReceiveMessage",new BaseResponse<object?>(CodeDefine.AUTH_FAILED));
|
||||
Context.Abort();
|
||||
return;
|
||||
}
|
||||
//将用户加入已加入聊天的会话组
|
||||
string userIdStr = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var keys = await _conversationService.GetUserAllStreamKeyAsync(int.Parse(userIdStr));
|
||||
foreach(var key in keys)
|
||||
{
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId,key);
|
||||
}
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
public async Task SendPrivateMessage(MessageBaseDto dto)
|
||||
|
||||
Reference in New Issue
Block a user