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);
            }
        }
    }
Пример #2
0
 private static IEnumerable <OutgoingFriendInvitation> GetOutgoingFriendInvitations(IUserDatabase userDatabase, IInternalLocalUser localUser)
 {
     return((from friendInvitationDoc in userDatabase.GetFriendInvitationDocuments(isInviter : true)
             where userDatabase.GetUserByDisplayName(friendInvitationDoc.DisplayName) != null
             select friendInvitationDoc).Select(delegate(FriendInvitationDocument friendInvitationDoc)
     {
         UserDocument userByDisplayName = userDatabase.GetUserByDisplayName(friendInvitationDoc.DisplayName);
         string displayName = userByDisplayName.DisplayName;
         IInternalUnidentifiedUser invitee = RemoteUserFactory.CreateUnidentifiedUser(displayName, userByDisplayName.FirstName, userDatabase);
         bool isTrusted = friendInvitationDoc.IsTrusted;
         OutgoingFriendInvitation outgoingFriendInvitation = new OutgoingFriendInvitation(localUser, invitee, isTrusted);
         outgoingFriendInvitation.SendComplete(friendInvitationDoc.FriendInvitationId);
         return outgoingFriendInvitation;
     }).ToList());
 }