Exemple #1
0
    public IList <IInternalFriend> ParseFriendships(GetStateResponse response, IUserDatabase userDatabase)
    {
        List <IInternalFriend> list  = new List <IInternalFriend>();
        List <User>            users = response.Users;

        if (response.Friendships != null)
        {
            foreach (Friendship friendship in response.Friendships)
            {
                string userId          = friendship.FriendUserId;
                bool   value           = friendship.IsTrusted.Value;
                string displayNameText = string.Empty;
                string firstName       = string.Empty;
                if (users != null)
                {
                    User user = users.FirstOrDefault((User u) => u.UserId == userId);
                    if (user != null)
                    {
                        displayNameText = user.DisplayName;
                        firstName       = user.FirstName;
                    }
                }
                IInternalFriend item = RemoteUserFactory.CreateFriend(userId, value, displayNameText, firstName, userDatabase);
                list.Add(item);
            }
        }
        return(list);
    }
 private static IList <IInternalFriend> CreateFriends(IUserDatabase userDatabase)
 {
     return(userDatabase.GetAllFriendDocuments().Select(delegate(FriendDocument friendDoc)
     {
         UserDocument userBySwid = userDatabase.GetUserBySwid(friendDoc.Swid);
         return RemoteUserFactory.CreateFriend(friendDoc.Swid, friendDoc.IsTrusted, userBySwid.DisplayName, userBySwid.FirstName, userDatabase);
     }).ToList());
 }
Exemple #3
0
    private void ReconcileFriends(GetStateResponse response, IInternalLocalUser localUser, IUserDatabase userDatabase)
    {
        List <IInternalFriend> list = localUser.InternalFriends.ToList();
        List <IInternalIncomingFriendInvitation> list2 = localUser.InternalIncomingFriendInvitations.ToList();
        List <IInternalOutgoingFriendInvitation> list3 = localUser.InternalOutgoingFriendInvitations.ToList();

        if (response.Friendships != null)
        {
            foreach (Friendship friendship in response.Friendships)
            {
                string          friendUserId   = friendship.FriendUserId;
                IInternalFriend internalFriend = list.FirstOrDefault((IInternalFriend f) => f.Swid == friendUserId);
                User            user           = response.Users.First((User u) => u.UserId == friendUserId);
                if (internalFriend != null)
                {
                    if (internalFriend.IsTrusted != friendship.IsTrusted)
                    {
                        if (friendship.IsTrusted.Value)
                        {
                            internalFriend.ChangeTrust(isTrusted: true);
                        }
                        else
                        {
                            localUser.UntrustFriend(internalFriend);
                        }
                    }
                    list.Remove(internalFriend);
                }
                else
                {
                    IInternalFriend internalFriend2 = RemoteUserFactory.CreateFriend(friendship.FriendUserId, friendship.IsTrusted.Value, user.DisplayName, user.FirstName, userDatabase);
                    IInternalIncomingFriendInvitation internalIncomingFriendInvitation = list2.FirstOrDefault((IInternalIncomingFriendInvitation i) => i.InternalInviter.DisplayName.Text == user.DisplayName);
                    if (internalIncomingFriendInvitation != null)
                    {
                        localUser.AddFriend(internalFriend2);
                        internalIncomingFriendInvitation.Accepted(internalFriend2.IsTrusted, internalFriend2);
                        list2.Remove(internalIncomingFriendInvitation);
                        localUser.RemoveIncomingFriendInvitation(internalIncomingFriendInvitation);
                    }
                    else
                    {
                        IInternalOutgoingFriendInvitation internalOutgoingFriendInvitation = list3.FirstOrDefault((IInternalOutgoingFriendInvitation i) => i.InternalInvitee.DisplayName.Text == user.DisplayName);
                        if (internalOutgoingFriendInvitation != null)
                        {
                            localUser.AddFriend(internalFriend2);
                            internalOutgoingFriendInvitation.Accepted(internalFriend2.IsTrusted, internalFriend2);
                            list3.Remove(internalOutgoingFriendInvitation);
                            localUser.RemoveOutgoingFriendInvitation(internalOutgoingFriendInvitation);
                        }
                        else
                        {
                            localUser.AddFriend(internalFriend2);
                        }
                    }
                }
            }
        }
        foreach (IInternalFriend item in list)
        {
            localUser.RemoveFriend(item);
        }
    }