/// <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); } } }
/// <summary> /// Accept friendship request. /// </summary> /// <param name="user">user.</param> /// <param name="friendLogin">friend's login.</param> /// <exception cref="ConnectionInterruptedException"></exception> private void AcceptFriendshipRequest(OnlineUser user, string friendLogin) { int friendId = DBoperations.GetUserId(friendLogin); if (friendId == 0) { return; } if (DBoperations.SetFriendship(friendId, user.Id, true)) { // send new data to user one SendIncomeFriendshipRequests(user); 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.AcceptFriendship }); } // write to db else { DBoperations.AddNotification(friendId, user.Id, UserActions.AcceptFriendship, DateTime.Now); } } }
/// <summary> /// Handle new reply in conversation. /// </summary> /// <param name="user">user.</param> /// <param name="interlocutor">interlocutor.</param> /// <param name="text">text of reply.</param> /// <exception cref="ConnectionInterruptedException"></exception> private void HandleReply(OnlineUser user, string interlocutor, string text) { int interlocutorId = DBoperations.GetUserId(interlocutor); if (interlocutorId == 0) { return; } // time of reply DateTime time = DateTime.Now; if (DBoperations.AddNewReply(user.Id, interlocutorId, text, time)) { // send reply to user one user.Client.SendMessage(new NewReplyMessage { Interlocutor = interlocutor, Author = user.Login, Time = time, Text = text }); // send reply to user two if online OnlineUser friend = GetOnlineUser(interlocutor); if (friend != null) { friend.Client.SendMessage(new NewReplyMessage { Interlocutor = user.Login, Author = user.Login, Time = time, Text = text }); } // write notification to db else { DBoperations.AddNotification(interlocutorId, user.Id, UserActions.MessageSended, DateTime.Now); } } }