Exemplo n.º 1
0
        public async Task <IActionResult> CancelInvitation([FromBody] FriendIdModel model)
        {
            if (!await Users.CheckIfExists(model.FriendId))
            {
                return(NotFound());
            }
            if (!await Friendships.CheckIfInvitationExistByInvitationRoles(model.FriendId, User.Id()))
            {
                return(NotFound());
            }

            await HubContext.Clients.Clients(await SignalRService.GetUserConnections(model.FriendId))
            .RefreshNotifications(await Friendships.RemoveInvitation(User.Id(), model.FriendId));

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AcceptInvitation([FromBody] FriendIdModel model)
        {
            if (!await Friendships.CheckIfInvitationExistByInvitationRoles(User.Id(), model.FriendId))
            {
                return(NotFound());
            }

            await HubContext.Clients.Clients(await SignalRService.GetUserConnections(model.FriendId))
            .NotificationReceived(await Friendships.AcceptInvitation(User.Id(), model.FriendId));

            await Notifications.SetDecisionAccepted(User.Id(), model.FriendId);

            await HubContext.Clients.Clients
                ((await SignalRService.GetUserConnections(model.FriendId))
                .Concat(await SignalRService.GetUserConnections(User.Id())).ToList())
            .RefreshChatList();

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Invite([FromBody] FriendIdModel model)
        {
            if (model.FriendId == User.Id())
            {
                return(BadRequest("Nie można wysłać zaproszenia do siebie"));
            }
            if (!await Users.CheckIfExists(model.FriendId))
            {
                return(NotFound());
            }
            if (await Friendships.CheckIfFriendshipExist(User.Id(), model.FriendId))
            {
                return(BadRequest("Użytkownicy są już znajomymi."));
            }

            await HubContext.Clients.Clients(await SignalRService.GetUserConnections(model.FriendId))
            .NotificationReceived(await Friendships.InviteFriend(User.Id(), model.FriendId));

            return(Ok());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> RemoveFriend([FromBody] FriendIdModel model)
        {
            if (!await Users.CheckIfExists(model.FriendId))
            {
                return(NotFound());
            }
            if (!await Friendships.CheckIfFriendshipExist(User.Id(), model.FriendId))
            {
                return(NotFound());
            }

            await Friendships.RemoveFriend(User.Id(), model.FriendId);

            await HubContext.Clients.Clients
                ((await SignalRService.GetUserConnections(model.FriendId))
                .Concat(await SignalRService.GetUserConnections(User.Id())).ToList())
            .RefreshChatList();

            return(Ok());
        }