public async Task <IActionResult> Online() { var jwtSecurityToken = _httpContextAccessor.HttpContext.Request.GetJwtToken(); var fullName = jwtSecurityToken.GetFullName(); var avatar = jwtSecurityToken.GetAvatar(); var onlineUser = new OnlineUser { UserName = _httpContextAccessor.HttpContext.User.Identity.Name, FullName = fullName, Avatar = avatar, IsOnline = true }; onlineUser.Load(); // Persist Online user await _chatUserRepository.UpsertAsync(new Chat.Entities.ChatUser { UserName = onlineUser.UserName, Avatar = onlineUser.Avatar, FullName = onlineUser.FullName }); await _chatContext.TakeOnlineAsync(onlineUser); // Boardcast all online users await _hubChatContext.Clients.All.Online(onlineUser); return(Ok(onlineUser)); }
public async Task <IActionResult> GetAllChatUsers() { var foundChatUsers = await _chatUserRepository.GetAllAsync(a => a.Deactivate == false); var onlineUsers = new List <OnlineUser>(); if (foundChatUsers != null) { foreach (var chatUser in foundChatUsers) { var onlineUser = new OnlineUser { UserName = chatUser.UserName, FullName = chatUser.FullName, Avatar = chatUser.Avatar, IsOnline = false }; onlineUser.Load(); onlineUsers.Add(onlineUser); } } return(Ok(onlineUsers)); }