Exemple #1
0
        public async Task <ReceiveFriendResponse> Handle(ReceiveFriendRequest request,
                                                         CancellationToken cancellationToken)
        {
            var receiveResult =
                await friendService.Receive(request.SenderId, request.RecipientId, accepted : request.Accepted);

            var friendUpdated = receiveResult?.Friend != null?mapper.Map <FriendDto>(receiveResult.Friend) : null;

            string currentUserId = httpContextReader.CurrentUserId;

            if (receiveResult != null)
            {
                await hubManager.Invoke(SignalrActions.ON_FRIEND_RECEIVED,
                                        currentUserId == request.SenderId?request.RecipientId : request.SenderId, request);

                if (request.Accepted)
                {
                    await notifier.Push(currentUserId == friendUpdated.SenderId
                                        ?NotificationMessages.FriendAcceptedNotification(friendUpdated.RecipientName)
                                        : NotificationMessages.FriendAcceptedNotification(friendUpdated.SenderName),
                                        currentUserId == friendUpdated.SenderId
                                        ?friendUpdated.RecipientId
                                        : friendUpdated.SenderId,
                                        NotificationType.FriendAccepted);
                }

                return(new ReceiveFriendResponse
                {
                    FriendAccepted = receiveResult.FriendAccepted, Friend = friendUpdated
                });
            }

            throw new CrudException("Friend invite has not been accepted");
        }