Beispiel #1
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);
                        continue;
                    }
                    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);
                        continue;
                    }
                    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);
            }
        }
Beispiel #2
0
        public void AddFriend(User domainFriend, bool isTrusted, long invitationId)
        {
            IInternalFriend friend         = RemoteUserFactory.CreateFriend(domainFriend.UserId, isTrusted, domainFriend.DisplayName, domainFriend.FirstName, userDatabase);
            IInternalFriend internalFriend = friends.FirstOrDefault((IInternalFriend f) => f.Id == friend.Id && f.IsTrusted != friend.IsTrusted);

            if (internalFriend != null)
            {
                friends.Remove(internalFriend);
            }
            if (!friends.Any((IInternalFriend f) => f.Id == friend.Id))
            {
                friends.Add(friend);
                IInternalIncomingFriendInvitation internalIncomingFriendInvitation = RemoveIncomingFriendInvitation(invitationId);
                if (internalIncomingFriendInvitation != null)
                {
                    internalIncomingFriendInvitation.Accepted(isTrusted, friend);
                }
                else
                {
                    RemoveOutgoingFriendInvitation(invitationId)?.Accepted(isTrusted, friend);
                }
            }
        }