Exemplo n.º 1
0
        public async Task <IActionResult> GetAllByCurrentUser()
        {
            var userId = GetCurrentUserId();

            if (userId == null)
            {
                return(Unauthorized());
            }
            var user = await _user.GetByIdAsync(userId);

            if (user == null)
            {
                return(Forbid());
            }

            var groupChats = await _groupChat.GetByUserAsync(user);

            if (groupChats == null)
            {
                return(BadRequest());
            }
            var res = new List <GroupChatResult>();

            foreach (var groupChat in groupChats)
            {
                res.Add(new GroupChatResult(groupChat));
            }
            return(Ok(res));
        }
Exemplo n.º 2
0
        public async Task StartAuth(string token)
        {
            var user = await _socket.GetUserByAccessToken(token);

            if (user == null)
            {
                // Send User the info that he isnt allowed
                Context.Abort();
                return;
            }

            var foundEntry = MyUsers.AddOrUpdate(user.Id, new List <string> {
                Context.ConnectionId
            }, (key, value) =>
            {
                value.Add(Context.ConnectionId);
                return(value);
            });


            var groupChats = await _groupChat.GetByUserAsync(user);

            foreach (var groupChat in groupChats)
            {
                await Groups.AddToGroupAsync(Context.ConnectionId, "groupchat#" + groupChat.Id);
            }
        }