Example #1
0
        /// <summary>
        /// Remove user from friends.
        /// </summary>
        /// <param name="user">user.</param>
        /// <param name="friendLogin">friend's login.</param>
        /// <exception cref="ConnectionInterruptedException"></exception>
        private void RemoveFriend(OnlineUser user, string friendLogin)
        {
            int friendId = DBoperations.GetUserId(friendLogin);

            if (friendId == 0)
            {
                return;
            }

            if (DBoperations.RemoveFriend(user.Id, friendId))
            {
                // send new data to user one
                SendFriends(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.RemoveFromFriends
                    });
                }
                // write to db
                else
                {
                    DBoperations.AddNotification(friendId, user.Id, UserActions.RemoveFromFriends, DateTime.Now);
                }
            }
        }