public string[] GetWordsFromContact(FacebookContact contact) { if (contact == null) { return(null); } return(GetWords(contact.Name)); }
internal FacebookPhotoAlbumCollection(FBMergeableCollection <FacebookPhotoAlbum> sourceCollection, FacebookService service, FacebookContact owner) : base(sourceCollection, service) { VerifyAccess(); if (owner != null) { _rawCollection = sourceCollection; _owner = owner; _filteredCollection = new FBMergeableCollection <FacebookPhotoAlbum>(from album in sourceCollection where album.OwnerId == owner.UserId select album, false); base.ReplaceSourceCollection(_filteredCollection); sourceCollection.CollectionChanged += _OwnerFilterOnRawCollectionChanged; } // A null owner implicitly means that the album collection is filterable else { _interestMap = new Dictionary <FacebookContact, bool>(); _rawCollection = sourceCollection; _filteredCollection = new FBMergeableCollection <FacebookPhotoAlbum>(false); base.ReplaceSourceCollection(_filteredCollection); foreach (var album in sourceCollection) { album.PropertyChanged += _OnAlbumOwnerUpdated; if (album.Owner != null) { lock (_localLock) { if (!_interestMap.ContainsKey(album.Owner)) { _interestMap.Add(album.Owner, _IsOwnerInteresting(album)); album.Owner.PropertyChanged += _OnContactPropertyChanged; } } album.PropertyChanged -= _OnAlbumOwnerUpdated; if (_IsOwnerInteresting(album)) { _filteredCollection.Add(album); } } } sourceCollection.CollectionChanged += _InterestFilterOnRawCollectionChanged; } }
private FacebookContact _DeserializeProfile(JSON_OBJECT jsonProfile) { Uri sourceUri = _SafeGetUri(jsonProfile, "pic"); Uri sourceBigUri = _SafeGetUri(jsonProfile, "pic_big"); Uri sourceSmallUri = _SafeGetUri(jsonProfile, "pic_small"); Uri sourceSquareUri = _SafeGetUri(jsonProfile, "pic_square"); var profile = new FacebookContact(_service) { UserId = _SafeGetId(jsonProfile, "id"), Name = _SafeGetString(jsonProfile, "name"), Image = new FacebookImage(_service, sourceUri, sourceBigUri, sourceSmallUri, sourceSquareUri), ProfileUri = _SafeGetUri(jsonProfile, "url"), // ContactType = "type" => "user" | "page" }; return(profile); }
private FacebookContact _DeserializePage(JSON_OBJECT jsonPage) { Uri sourceUri = _SafeGetUri(jsonPage, "pic"); Uri sourceBigUri = _SafeGetUri(jsonPage, "pic_big"); Uri sourceSmallUri = _SafeGetUri(jsonPage, "pic_small"); Uri sourceSquareUri = _SafeGetUri(jsonPage, "pic_square"); // No idea why there are both large and big... Uri sourceLargeUri = _SafeGetUri(jsonPage, "pic_large"); // This is a light weight view of a page as a FacebookContact. // If the FacebookService were to expose pages as a first-class concept then there would be a dedicated class, // and probably a base class. var page = new FacebookContact(_service) { UserId = _SafeGetId(jsonPage, "page_id"), Name = _SafeGetString(jsonPage, "name"), ProfileUri = _SafeGetUri(jsonPage, "page_url"), Image = new FacebookImage(_service, sourceUri, sourceBigUri ?? sourceLargeUri, sourceSmallUri, sourceSquareUri), }; return(page); }
private static bool _IsInteresting(FacebookContact contact) { return(contact.InterestLevel > .1); }
public object[] GetRelevantFacebookObjects(object o) { List <object> objects = new List <object>(); FacebookContact contact = o as FacebookContact; if (contact != null) { foreach (var post in _service.RawNewsFeed) { if (post.ActorUserId == contact.UserId) { objects.Add(post); } foreach (var comment in post.Comments) { if (comment.FromUserId == contact.UserId) { objects.Add(comment); } } } foreach (var album in _service.RawPhotoAlbums) { if (album.OwnerId == contact.UserId) { objects.Add(album); } foreach (var photo in album.Photos) { if (photo.OwnerId == contact.UserId) { objects.Add(photo); continue; } foreach (var tag in photo.Tags) { if (tag.Contact != null && tag.Contact.UserId == contact.UserId) { objects.Add(photo); goto next; } } next :; } } } FacebookPhoto p = o as FacebookPhoto; if (p != null) { objects.Add(p.Album); if (p.Album.Owner != null) { objects.Add(p.Album.Owner); } foreach (var tag in p.Tags) { if (tag.Contact != null && !objects.Contains(tag.Contact)) { objects.Add(tag.Contact); } } } FacebookPhotoAlbum a = o as FacebookPhotoAlbum; if (a != null) { if (a.Owner != null) { objects.Add(a.Owner); } foreach (var photo in a.Photos) { objects.Add(photo); foreach (var tag in photo.Tags) { if (tag.Contact != null && !objects.Contains(tag.Contact)) { objects.Add(tag.Contact); } } } } ActivityPost activityPost = o as ActivityPost; if (activityPost != null) { if (activityPost.Actor != null) { objects.Add(activityPost.Actor); } if (activityPost.Target != null) { objects.Add(activityPost.Target); } foreach (var comment in activityPost.Comments) { objects.Add(comment); } } ActivityComment activityComment = o as ActivityComment; if (activityComment != null) { if (activityComment.FromUser != null) { objects.Add(activityComment.FromUser); } } objects.Sort(new SearchResultsComparer()); return(objects.ToArray()); }
public _LiteContact(FacebookContact c) { UserId = c.UserId; InterestLevel = c.NullableInterestLevel; Name = c.Name; }
private FacebookContact _DeserializeUser(JSON_OBJECT jsonUser) { Uri sourceUri = _SafeGetUri(jsonUser, "pic"); Uri sourceBigUri = _SafeGetUri(jsonUser, "pic_big"); Uri sourceSmallUri = _SafeGetUri(jsonUser, "pic_small"); Uri sourceSquareUri = _SafeGetUri(jsonUser, "pic_square"); Location currentLocation = null; Location hometownLocation = null; HighSchoolInfo hsInfo = null; List <EducationInfo> educationHistory = null; List <WorkInfo> workHistory = null; JSON_OBJECT jsonLocation; if (jsonUser.TryGetTypedValue <JSON_OBJECT>("current_location", out jsonLocation)) { currentLocation = _DeserializeLocation(jsonLocation); } JSON_OBJECT htObject; if (jsonUser.TryGetTypedValue <JSON_OBJECT>("hometown_location", out htObject)) { hometownLocation = _DeserializeLocation(htObject); } JSON_OBJECT jsonHighSchool; if (jsonUser.TryGetTypedValue <JSON_OBJECT>("hs_info", out jsonHighSchool)) { hsInfo = new HighSchoolInfo { GraduationYear = _SafeGetInt32(jsonHighSchool, "grad_year"), //Id = _SafeGetValue(hsElement, "hs1_id") ?? "0", //Id2 = _SafeGetValue(hsElement, "hs2_id") ?? "0", Name = _SafeGetString(jsonHighSchool, "hs1_name"), Name2 = _SafeGetString(jsonHighSchool, "hs2_name"), }; } JSON_ARRAY jsonEducationHistoryList; if (jsonUser.TryGetTypedValue <JSON_ARRAY>("education_history", out jsonEducationHistoryList)) { educationHistory = new List <EducationInfo>(from JSON_OBJECT jsonEducationInfo in jsonEducationHistoryList select _DeserializeEducationInfo(jsonEducationInfo)); } else { educationHistory = new List <EducationInfo>(); } JSON_ARRAY jsonWorkHistoryList; if (jsonUser.TryGetTypedValue <JSON_ARRAY>("work_history", out jsonWorkHistoryList)) { workHistory = new List <WorkInfo>(from JSON_OBJECT jsonWorkInfo in jsonWorkHistoryList select _DeserializeWorkInfo(jsonWorkInfo)); } else { workHistory = new List <WorkInfo>(); } var contact = new FacebookContact(_service) { Name = _SafeGetString(jsonUser, "name"), FirstName = _SafeGetString(jsonUser, "first_name"), LastName = _SafeGetString(jsonUser, "last_name"), AboutMe = _SafeGetString(jsonUser, "about_me"), Activities = _SafeGetString(jsonUser, "activities"), // Affilitions = // AllowedRestrictions = Birthday = _SafeGetString(jsonUser, "birthday"), MachineSafeBirthday = _SafeGetString(jsonUser, "birthday_date"), Books = _SafeGetString(jsonUser, "books"), CurrentLocation = currentLocation, EducationHistory = educationHistory.AsReadOnly(), Hometown = hometownLocation, HighSchoolInfo = hsInfo, Interests = _SafeGetString(jsonUser, "interests"), Image = new FacebookImage(_service, sourceUri, sourceBigUri, sourceSmallUri, sourceSquareUri), Movies = _SafeGetString(jsonUser, "movies"), Music = _SafeGetString(jsonUser, "music"), Quotes = _SafeGetString(jsonUser, "quotes"), RelationshipStatus = _SafeGetString(jsonUser, "relationship_status"), Religion = _SafeGetString(jsonUser, "religion"), Sex = _SafeGetString(jsonUser, "sex"), TV = _SafeGetString(jsonUser, "tv"), Website = _SafeGetString(jsonUser, "website"), ProfileUri = _SafeGetUri(jsonUser, "profile_url"), UserId = _SafeGetId(jsonUser, "uid"), UserName = _SafeGetString(jsonUser, "username"), ProfileUpdateTime = _SafeGetDateTime(jsonUser, "profile_update_time") ?? _UnixEpochTime, OnlinePresence = _DeserializePresenceFromUser(jsonUser), }; if (!string.IsNullOrEmpty(_SafeGetString(jsonUser, "status", "message"))) { contact.StatusMessage = new ActivityPost(_service) { PostId = new FacebookObjectId("status_" + contact.UserId.ToString()), ActorUserId = _SafeGetId(jsonUser, "uid"), Created = _SafeGetDateTime(jsonUser, "status", "time") ?? _UnixEpochTime, Updated = _SafeGetDateTime(jsonUser, "status", "time") ?? _UnixEpochTime, Message = _SafeGetString(jsonUser, "status", "message"), TargetUserId = default(FacebookObjectId), CanLike = false, HasLiked = false, LikedCount = 0, CanComment = false, CanRemoveComments = false, CommentCount = 0, }; } return(contact); }
private bool _IsInteresting(FacebookContact contact) { Assert.IsNotNull(contact); return(contact.InterestLevel > .1); }