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); } } }
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(); } }
private static IEnumerable <IncomingFriendInvitation> GetIncomingFriendInvitations(IUserDatabase userDatabase, IInternalLocalUser localUser) { return((from friendInvitationDoc in userDatabase.GetFriendInvitationDocuments(isInviter : false) where userDatabase.GetUserByDisplayName(friendInvitationDoc.DisplayName) != null select friendInvitationDoc).Select(delegate(FriendInvitationDocument friendInvitationDoc) { UserDocument userByDisplayName = userDatabase.GetUserByDisplayName(friendInvitationDoc.DisplayName); string displayName = userByDisplayName.DisplayName; IInternalUnidentifiedUser inviter = RemoteUserFactory.CreateUnidentifiedUser(displayName, userByDisplayName.FirstName, userDatabase); bool isTrusted = friendInvitationDoc.IsTrusted; IncomingFriendInvitation incomingFriendInvitation = new IncomingFriendInvitation(inviter, localUser, isTrusted); incomingFriendInvitation.SendComplete(friendInvitationDoc.FriendInvitationId); return incomingFriendInvitation; }).ToList()); }