예제 #1
0
        public void AddFriendshipInvitation(FriendshipInvitation invitation, User friend)
        {
            long invitationId = invitation.FriendshipInvitationId.Value;

            if (oldInvitationIds.Contains(invitationId) || outgoingFriendInvitations.Any((IInternalOutgoingFriendInvitation i) => i.InvitationId == invitationId) || incomingFriendInvitations.Any((IInternalIncomingFriendInvitation i) => i.InvitationId == invitationId))
            {
                return;
            }
            if (invitation.IsInviter.Value)
            {
                IInternalOutgoingFriendInvitation internalOutgoingFriendInvitation = outgoingFriendInvitations.FirstOrDefault((IInternalOutgoingFriendInvitation i) => i.Invitee.DisplayName.Text == invitation.FriendDisplayName && i.RequestTrust != invitation.IsTrusted);
                if (internalOutgoingFriendInvitation != null)
                {
                    RemoveOutgoingFriendInvitation(internalOutgoingFriendInvitation.InvitationId);
                }
                IInternalUnidentifiedUser invitee = RemoteUserFactory.CreateUnidentifiedUser(friend.DisplayName, friend.FirstName, userDatabase);
                OutgoingFriendInvitation  outgoingFriendInvitation = new OutgoingFriendInvitation(this, invitee, invitation.IsTrusted.Value);
                outgoingFriendInvitation.SendComplete(invitationId);
                AddOutgoingFriendInvitation(outgoingFriendInvitation);
            }
            else
            {
                IInternalIncomingFriendInvitation internalIncomingFriendInvitation = incomingFriendInvitations.FirstOrDefault((IInternalIncomingFriendInvitation i) => i.Inviter.DisplayName.Text == invitation.FriendDisplayName && i.RequestTrust != invitation.IsTrusted);
                if (internalIncomingFriendInvitation != null)
                {
                    RemoveIncomingFriendInvitation(internalIncomingFriendInvitation.InvitationId);
                }
                IInternalUnidentifiedUser inviter = RemoteUserFactory.CreateUnidentifiedUser(friend.DisplayName, friend.FirstName, userDatabase);
                IncomingFriendInvitation  incomingFriendInvitation = new IncomingFriendInvitation(inviter, this, invitation.IsTrusted.Value);
                incomingFriendInvitation.SendComplete(invitationId);
                AddIncomingFriendInvitation(incomingFriendInvitation);
            }
        }
예제 #2
0
 public void ParseFriendshipInvitations(GetStateResponse response, IUserDatabase userDatabase, IInternalLocalUser localUser, out IList <IInternalIncomingFriendInvitation> incomingFriendInvitations, out IList <IInternalOutgoingFriendInvitation> outgoingFriendInvitations)
 {
     incomingFriendInvitations = new List <IInternalIncomingFriendInvitation>();
     outgoingFriendInvitations = new List <IInternalOutgoingFriendInvitation>();
     if (response.FriendshipInvitations == null)
     {
         return;
     }
     foreach (FriendshipInvitation invitation in response.FriendshipInvitations)
     {
         List <User>       users     = response.Users;
         Func <User, bool> predicate = (User user) => user.DisplayName == invitation.FriendDisplayName;
         string            firstName = users.FirstOrDefault(predicate)?.FirstName;
         if (invitation.IsInviter.Value)
         {
             IInternalUnidentifiedUser invitee = RemoteUserFactory.CreateUnidentifiedUser(invitation.FriendDisplayName, firstName, userDatabase);
             OutgoingFriendInvitation  outgoingFriendInvitation = new OutgoingFriendInvitation(localUser, invitee, invitation.IsTrusted.Value);
             outgoingFriendInvitation.SendComplete(invitation.FriendshipInvitationId.Value);
             outgoingFriendInvitations.Add(outgoingFriendInvitation);
         }
         else
         {
             IInternalUnidentifiedUser inviter = RemoteUserFactory.CreateUnidentifiedUser(invitation.FriendDisplayName, firstName, userDatabase);
             IncomingFriendInvitation  incomingFriendInvitation = new IncomingFriendInvitation(inviter, localUser, invitation.IsTrusted.Value);
             incomingFriendInvitation.SendComplete(invitation.FriendshipInvitationId.Value);
             incomingFriendInvitations.Add(incomingFriendInvitation);
         }
     }
 }
예제 #3
0
        private void ReconcileFriendInvitations(GetStateResponse response, IInternalLocalUser localUser, IUserDatabase userDatabase)
        {
            List <FriendshipInvitation> friendshipInvitations = response.FriendshipInvitations;
            List <IInternalIncomingFriendInvitation> list     = localUser.InternalIncomingFriendInvitations.ToList();
            List <IInternalOutgoingFriendInvitation> list2    = localUser.InternalOutgoingFriendInvitations.ToList();

            if (friendshipInvitations != null)
            {
                foreach (FriendshipInvitation friendInvitation in friendshipInvitations)
                {
                    Func <IInternalIncomingFriendInvitation, bool> predicate           = (IInternalIncomingFriendInvitation i) => i.InvitationId == friendInvitation.FriendshipInvitationId;
                    IInternalIncomingFriendInvitation internalIncomingFriendInvitation = list.FirstOrDefault(predicate);
                    if (internalIncomingFriendInvitation != null)
                    {
                        if (internalIncomingFriendInvitation.RequestTrust != friendInvitation.IsTrusted)
                        {
                            internalIncomingFriendInvitation.RequestTrust = friendInvitation.IsTrusted.Value;
                        }
                        list.Remove(internalIncomingFriendInvitation);
                        continue;
                    }
                    IInternalOutgoingFriendInvitation internalOutgoingFriendInvitation = list2.FirstOrDefault((IInternalOutgoingFriendInvitation i) => i.InvitationId == friendInvitation.FriendshipInvitationId);
                    if (internalOutgoingFriendInvitation != null)
                    {
                        if (internalOutgoingFriendInvitation.RequestTrust != friendInvitation.IsTrusted)
                        {
                            internalOutgoingFriendInvitation.RequestTrust = friendInvitation.IsTrusted.Value;
                        }
                        list2.Remove(internalOutgoingFriendInvitation);
                        continue;
                    }
                    string firstName = response.Users.FirstOrDefault((User user) => user.DisplayName == friendInvitation.FriendDisplayName)?.FirstName;
                    if (friendInvitation.IsInviter.Value)
                    {
                        IInternalUnidentifiedUser invitee = RemoteUserFactory.CreateUnidentifiedUser(friendInvitation.FriendDisplayName, firstName, userDatabase);
                        OutgoingFriendInvitation  outgoingFriendInvitation = new OutgoingFriendInvitation(localUser, invitee, friendInvitation.IsTrusted.Value);
                        outgoingFriendInvitation.SendComplete(friendInvitation.FriendshipInvitationId.Value);
                        localUser.AddOutgoingFriendInvitation(outgoingFriendInvitation);
                    }
                    else
                    {
                        IInternalUnidentifiedUser inviter = RemoteUserFactory.CreateUnidentifiedUser(friendInvitation.FriendDisplayName, firstName, userDatabase);
                        IncomingFriendInvitation  incomingFriendInvitation = new IncomingFriendInvitation(inviter, localUser, friendInvitation.IsTrusted.Value);
                        incomingFriendInvitation.SendComplete(friendInvitation.FriendshipInvitationId.Value);
                        localUser.AddIncomingFriendInvitation(incomingFriendInvitation);
                    }
                }
            }
            foreach (IInternalIncomingFriendInvitation item in list)
            {
                localUser.RemoveIncomingFriendInvitation(item);
                item.Rejected();
            }
            foreach (IInternalOutgoingFriendInvitation item2 in list2)
            {
                localUser.RemoveOutgoingFriendInvitation(item2);
                item2.Rejected();
            }
        }
예제 #4
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));
        }
예제 #5
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());
 }
예제 #6
0
 public static void Search(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string displayName, IUserDatabase userDatabase, Action <IInternalUnidentifiedUser> successCallback, Action failureCallback)
 {
     try
     {
         DisplayNameSearchRequest displayNameSearchRequest = new DisplayNameSearchRequest();
         displayNameSearchRequest.DisplayName = displayName;
         DisplayNameSearchRequest request = displayNameSearchRequest;
         IWebCall <DisplayNameSearchRequest, DisplayNameSearchResponse> webCall = mixWebCallFactory.SearchDisplaynamePost(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <DisplayNameSearchResponse> e)
         {
             DisplayNameSearchResponse response = e.Response;
             if (ValidateResponse(response))
             {
                 userDatabase.InsertUserDocument(new UserDocument
                 {
                     DisplayName = response.DisplayName,
                     FirstName   = response.FirstName,
                     Swid        = null,
                     HashedSwid  = null
                 });
                 IInternalUnidentifiedUser obj = RemoteUserFactory.CreateUnidentifiedUser(response.DisplayName, response.FirstName, userDatabase);
                 successCallback(obj);
             }
             else
             {
                 logger.Critical("Failed to validate display name search response: " + JsonParser.ToJson(response));
                 failureCallback();
             }
         };
         webCall.OnError += delegate(object sender, WebCallErrorEventArgs e)
         {
             logger.Debug("Failed to find user: "******"Unhandled exception: " + ex);
         failureCallback();
     }
 }
예제 #7
0
 public static void Recommend(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, IUserDatabase userDatabase, Action <IEnumerable <IInternalUnidentifiedUser> > successCallback, Action failureCallback)
 {
     try
     {
         BaseUserRequest request = new BaseUserRequest();
         IWebCall <BaseUserRequest, GetFriendshipRecommendationResponse> webCall = mixWebCallFactory.FriendshipRecommendPost(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetFriendshipRecommendationResponse> e)
         {
             List <FriendRecommendation> friendRecommendations = e.Response.FriendRecommendations;
             if (friendRecommendations == null)
             {
                 failureCallback();
             }
             else
             {
                 foreach (FriendRecommendation item in friendRecommendations)
                 {
                     userDatabase.InsertUserDocument(new UserDocument
                     {
                         DisplayName = item.DisplayName,
                         FirstName   = item.FirstName,
                         Swid        = null,
                         HashedSwid  = null
                     });
                 }
                 IInternalUnidentifiedUser[] obj = friendRecommendations.Select((FriendRecommendation item) => RemoteUserFactory.CreateUnidentifiedUser(item.DisplayName, item.FirstName, userDatabase)).ToArray();
                 successCallback(obj);
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback();
     }
 }