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) { 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); } } } }
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); } }
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(); } }
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 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()); }
public IOutgoingFriendInvitation SendFriendInvitation(IUnidentifiedUser user, bool requestTrust, Action <ISendFriendInvitationResult> callback) { IInternalUnidentifiedUser internalUnidentifiedUser = unidentifiedUsers.FirstOrDefault((IInternalUnidentifiedUser u) => u.DisplayName.Text == user.DisplayName.Text); if (internalUnidentifiedUser == null) { logger.Critical("User to send friend invitation to not found"); callback(new SendFriendInvitationResult(success: false, null)); return(null); } ISendFriendInvitationResult invitationValidationResult = GetInvitationValidationResult(user.DisplayName.Text, requestTrust); if (invitationValidationResult != null) { callback(invitationValidationResult); return(null); } return(InternalSendFriendInvitation(internalUnidentifiedUser, requestTrust, callback)); }
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: " + arg); failureCallback(); } }
private IOutgoingFriendInvitation InternalSendFriendInvitation(IInternalUnidentifiedUser internalUser, bool requestTrust, Action <ISendFriendInvitationResult> callback) { ISendFriendInvitationResult invitationValidationResult = GetInvitationValidationResult(internalUser.DisplayName.Text, requestTrust); if (invitationValidationResult != null) { callback(invitationValidationResult); return(null); } OutgoingFriendInvitation invitation = new OutgoingFriendInvitation(this, internalUser, requestTrust); AddOutgoingFriendInvitation(invitation); FriendInvitationSender.Send(logger, notificationQueue, mixWebCallFactory, internalUser.DisplayName.Text, requestTrust, delegate { callback(new SendFriendInvitationResult(success: true, invitation)); }, delegate(ISendFriendInvitationResult r) { RemoveOutgoingFriendInvitation(invitation); callback(r); }); return(invitation); }
public OutgoingFriendInvitation(IInternalLocalUser inviter, IInternalUnidentifiedUser invitee, bool requestTrust) : base(requestTrust) { this.inviter = inviter; this.invitee = invitee; }
public FindUserResult(bool success, IInternalUnidentifiedUser user) { Success = success; this.user = user; }