private static void HandleFriendshipInvitationRemoved(IUserDatabase userDatabase, IInternalLocalUser localUser, AbstractRemoveFriendshipInvitationNotificationEventArgs e)
    {
        long value = e.Notification.InvitationId.Value;

        userDatabase.DeleteFriendInvitation(value);
        localUser.RemoveFriendshipInvitation(value);
    }
    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);
            }
        }
    }
    private static void HandleFriendshipAdded(IUserDatabase userDatabase, IInternalLocalUser localUser, AbstractAddFriendshipNotificationEventArgs e)
    {
        AddFriendshipNotification notification = e.Notification;
        User friend = notification.Friend;

        userDatabase.PersistUser(friend.UserId, friend.HashedUserId, friend.DisplayName, friend.FirstName, friend.Status);
        FriendDocument friendDocument = new FriendDocument();

        friendDocument.Swid      = friend.UserId;
        friendDocument.IsTrusted = notification.IsTrusted.Value;
        friendDocument.Nickname  = null;
        FriendDocument doc = friendDocument;

        userDatabase.InsertFriend(doc);
        long value = e.Notification.FriendshipInvitationId.Value;

        userDatabase.DeleteFriendInvitation(value);
        localUser.AddFriend(friend, notification.IsTrusted.Value, value);
    }