Пример #1
0
        public void UntrustFriend(IInternalFriend friend)
        {
            friend.ChangeTrust(isTrusted: false);
            UntrustedEventArgs e = new UntrustedEventArgs(friend);

            this.OnUntrusted(this, e);
        }
Пример #2
0
        public void Untrust(IFriend trustedUser, Action <IUntrustResult> callback)
        {
            IInternalFriend internalFriend = friends.FirstOrDefault((IInternalFriend f) => f.Id == trustedUser.Id);

            if (internalFriend == null)
            {
                logger.Critical("Friend to untrust not found");
                callback(new UntrustResult(success: false));
                return;
            }
            if (!internalFriend.IsTrusted)
            {
                logger.Critical("Friend is already untrusted");
                callback(new UntrustResult(success: false));
                return;
            }
            Untruster.Untrust(logger, notificationQueue, mixWebCallFactory, internalFriend.Swid, delegate
            {
                UntrustFriend(internalFriend);
                callback(new UntrustResult(success: true));
            }, delegate
            {
                callback(new UntrustResult(success: false));
            });
        }
Пример #3
0
        private ISendFriendInvitationResult GetInvitationValidationResult(string displayName, bool requestTrust)
        {
            IInternalFriend internalFriend = friends.FirstOrDefault((IInternalFriend f) => f.DisplayName.Text == displayName);

            if (internalFriend != null)
            {
                if (internalFriend.IsTrusted)
                {
                    logger.Critical("This user is already a trusted friend");
                    return(new SendFriendInvitationAlreadyFriendsResult(success: false, null));
                }
                if (!requestTrust)
                {
                    logger.Critical("This user is already an untrusted friend");
                    return(new SendFriendInvitationAlreadyFriendsResult(success: false, null));
                }
            }
            IInternalOutgoingFriendInvitation internalOutgoingFriendInvitation = outgoingFriendInvitations.FirstOrDefault((IInternalOutgoingFriendInvitation i) => i.Invitee.DisplayName.Text == displayName);

            if (internalOutgoingFriendInvitation != null)
            {
                if (internalOutgoingFriendInvitation.RequestTrust)
                {
                    logger.Critical("We already have a trusted invitation out for this user");
                    return(new SendFriendInvitationAlreadyExistsResult(success: false, null));
                }
                if (!requestTrust)
                {
                    logger.Critical("We already have an untrusted invitation out for this user");
                    return(new SendFriendInvitationAlreadyExistsResult(success: false, null));
                }
            }
            return(null);
        }
Пример #4
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);
    }
Пример #5
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);
            }
        }
Пример #6
0
        public void UntrustFriend(string friendSwid)
        {
            IInternalFriend internalFriend = friends.FirstOrDefault((IInternalFriend f) => f.Swid == friendSwid);

            if (internalFriend != null)
            {
                UntrustFriend(internalFriend);
            }
        }
Пример #7
0
        public void RemoveFriend(string friendSwid, bool sendEvent)
        {
            IInternalFriend internalFriend = friends.FirstOrDefault((IInternalFriend f) => f.Swid == friendSwid);

            friends.Remove(internalFriend);
            if (internalFriend != null && sendEvent)
            {
                UnfriendedEventArgs e = new UnfriendedEventArgs(internalFriend);
                this.OnUnfriended(this, e);
            }
        }
Пример #8
0
        public void ReportUser(IFriend user, ReportUserReason reportUserReason, Action <IReportUserResult> callback)
        {
            string          userId         = null;
            IInternalFriend internalFriend = friends.FirstOrDefault((IInternalFriend f) => f.Id == user.Id);

            if (internalFriend != null)
            {
                userId = internalFriend.Swid;
            }
            ReportUser(userId, reportUserReason, callback);
        }
Пример #9
0
        public IOutgoingFriendInvitation SendFriendInvitation(IFriend user, bool requestTrust, Action <ISendFriendInvitationResult> callback)
        {
            IInternalFriend internalFriend = friends.FirstOrDefault((IInternalFriend f) => f.Id == user.Id);

            if (internalFriend == null)
            {
                logger.Critical("User to send friend invitation to not found");
                callback(new SendFriendInvitationResult(success: false, null));
                return(null);
            }
            IInternalUnidentifiedUser internalUser = RemoteUserFactory.CreateUnidentifiedUser(internalFriend.DisplayName.Text, internalFriend.FirstName, userDatabase);

            return(InternalSendFriendInvitation(internalUser, requestTrust, callback));
        }
    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);
            }
        }
    }
Пример #11
0
        public void Unfriend(IFriend friend, Action <IUnfriendResult> callback)
        {
            IInternalFriend internalFriend = friends.FirstOrDefault((IInternalFriend f) => f.Id == friend.Id);

            if (internalFriend == null)
            {
                logger.Critical("Friend to unfriend not found");
                callback(new UnfriendResult(success: false));
                return;
            }
            Unfriender.Unfriend(logger, notificationQueue, mixWebCallFactory, internalFriend.Swid, delegate
            {
                callback(new UnfriendResult(success: true));
            }, delegate
            {
                callback(new UnfriendResult(success: false));
            });
        }
Пример #12
0
        public void AcceptFriendInvitation(IIncomingFriendInvitation invitation, bool acceptTrust, Action <IAcceptFriendInvitationResult> callback)
        {
            IInternalIncomingFriendInvitation internalIncomingFriendInvitation = incomingFriendInvitations.FirstOrDefault((IInternalIncomingFriendInvitation i) => i.Id == invitation.Id);

            if (internalIncomingFriendInvitation == null)
            {
                logger.Critical("Friend invitation to accept not found");
                callback(new AcceptFriendInvitationResult(success: false, null));
                return;
            }
            FriendInvitationAccepter.Accept(logger, notificationQueue, mixWebCallFactory, internalIncomingFriendInvitation.InvitationId, acceptTrust, delegate(AddFriendshipNotification notification)
            {
                IInternalFriend friend = friends.FirstOrDefault((IInternalFriend f) => f.Swid == notification.Friend.UserId);
                callback(new AcceptFriendInvitationResult(success: true, friend));
            }, delegate
            {
                callback(new AcceptFriendInvitationResult(success: false, null));
            });
        }
Пример #13
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);
                }
            }
        }
 public FriendInvitationAcceptedEventArgs(bool trustAccepted, IInternalFriend friend)
 {
     base.TrustAccepted = trustAccepted;
     base.Friend        = friend;
 }
Пример #15
0
    public void Accepted(bool trustAccepted, IInternalFriend friend)
    {
        FriendInvitationAcceptedEventArgs e = new FriendInvitationAcceptedEventArgs(trustAccepted, friend);

        this.OnAccepted(this, e);
    }
Пример #16
0
 public void RemoveFriend(IInternalFriend friend)
 {
     friends.Remove(friend);
     this.OnUnfriended(this, new UnfriendedEventArgs(friend));
 }
Пример #17
0
 public void AddFriend(IInternalFriend friend)
 {
     friends.Add(friend);
 }