Esempio n. 1
0
        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));
        }