private static void HandleFriendshipRemoved(IUserDatabase userDatabase, IInternalLocalUser localUser, AbstractRemoveFriendshipNotificationEventArgs e) { string swid = e.Notification.FriendUserId; string displayName = null; IInternalFriend internalFriend = localUser.InternalFriends.FirstOrDefault((IInternalFriend f) => f.Swid == swid); if (internalFriend != null) { displayName = internalFriend.DisplayName.Text; } else { UserDocument userBySwid = userDatabase.GetUserBySwid(swid); if (userBySwid != null) { displayName = userBySwid.DisplayName; } } userDatabase.DeleteFriend(swid); localUser.RemoveFriend(swid, sendEvent: true); if (displayName != null) { FriendInvitationDocument incomingInvitation = userDatabase.GetFriendInvitationDocuments(isInviter: false).FirstOrDefault((FriendInvitationDocument doc) => doc.DisplayName == displayName); if (incomingInvitation != null) { foreach (IInternalIncomingFriendInvitation item in from i in localUser.InternalIncomingFriendInvitations where i.InvitationId == incomingInvitation.FriendInvitationId select i) { localUser.RemoveIncomingFriendInvitation(item); } userDatabase.DeleteFriendInvitation(incomingInvitation.FriendInvitationId); } FriendInvitationDocument outgoingInvitation = userDatabase.GetFriendInvitationDocuments(isInviter: true).FirstOrDefault((FriendInvitationDocument doc) => doc.DisplayName == displayName); if (outgoingInvitation != null) { foreach (IInternalOutgoingFriendInvitation item2 in from i in localUser.InternalOutgoingFriendInvitations where i.InvitationId == outgoingInvitation.FriendInvitationId select i) { localUser.RemoveOutgoingFriendInvitation(item2); } userDatabase.DeleteFriendInvitation(outgoingInvitation.FriendInvitationId); } } }