Ejemplo n.º 1
0
        /// <summary>
        /// Reject friendship request.
        /// </summary>
        /// <param name="user">user.</param>
        /// <param name="friendLogin">friend's login.</param>
        /// <exception cref="ConnectionInterruptedException"></exception>
        private void RejectFriendshipRequest(OnlineUser user, string friendLogin)
        {
            int friendId = DBoperations.GetUserId(friendLogin);

            if (friendId == 0)
            {
                return;
            }

            if (DBoperations.RemoveFriendshipRequest(friendId, user.Id))
            {
                // send new data to user one
                SendIncomeFriendshipRequests(user);

                OnlineUser friend = GetOnlineUser(friendLogin);
                // send notification to user two if online
                if (friend != null)
                {
                    friend.Client.SendMessage(new UserActionMessage
                    {
                        UserLogin = user.Login,
                        Time      = DateTime.Now,
                        Action    = UserActions.RejectFriendship
                    });
                }
                // write to db
                else
                {
                    DBoperations.AddNotification(friendId, user.Id, UserActions.RejectFriendship, DateTime.Now);
                }
            }
        }