Deleted users in my friends list

angelika.olsson
Member since: 2006
 

When I request a collection of my friend contacts, I don't want deleted users to be included in the result set. How do I do that?

This is my code right now:

public static ContactRelationCollection GetMyFriends(IUser user, ISite site, int page, int pageSize,
ContactRelationSortOrder sortOrder) {
if (user == null)
throw new ArgumentNullException("user");
if (site == null)
throw new ArgumentNullException("site");

var myPage = mp.MyPageHandler.GetMyPage(user, site);

if (myPage == null || myPage.Contact == null) { return new ContactRelationCollection(); }

return sc.ContactHandler.GetContacts(myPage.Contact, ContactType.Contact, Perspective.ToMe, page, pageSize, sortOrder);
}

 

 

#29911 May 22, 2009 11:51
  •  

    You could either do something like this:

    ContactRelationCollection contacts =  sc.ContactHandler.GetContacts(myPage.Contact, ContactType.Contact, Perspective.ToMe, page, pageSize, sortOrder);

    List<ContactRelation> nonRemovedContacts = contacts.Where(contact => !contact.ContactUser.Removed).ToList();

    Or use the query system to get all none removed contacts.

    #29921 May 22, 2009 13:38
  • angelika.olsson
    Member since: 2006
     

    I can't really use that solution if I also wan't the paging to be intact. I don't want to filter out the removed users after I have received the reslut set, I don't want them to be included at all.

    Do you (or anyone else) have any tips on how I can use the query system to do this? Is there a way to chain two queries together? Obviously, there is no property of the ContactRelationQuery to filter our removed users, since it is only concerned with ContactRelations, but if I could create a UserQuery and then chain it to a ContactRelationQuery...?

    #29964 May 25, 2009 10:48
  •  

    I'd have to experiment a bit with the query system to see if and how one could do that.

    On the other hand I'd still recommend doing this filtering in memory. You could simply get all of the users contacts without paging (or pagesize = maxvalue of int - 1) and then do paging with the LINQ methods Skip and Take. This way you wont have to worry about releasing the cache when a user adds a friend which you'd have to do if you use the query system.

    #29965 May 25, 2009 11:26