private ActivityPostAttachment _DeserializeVideoPostAttachmentData(ActivityPost post, JSON_OBJECT jsonAttachment) { if (jsonAttachment == null || jsonAttachment.Count == 0) { return(null); } ActivityPostAttachment attachment = _DeserializeGenericPostAttachmentData(post, jsonAttachment); attachment.Type = ActivityPostAttachmentType.Video; var jsonMediaArray = jsonAttachment["media"] as JSON_ARRAY; if (jsonMediaArray != null && jsonMediaArray.Count > 0) { var jsonStreamMediaObject = jsonMediaArray[0] as JSON_OBJECT; Uri previewImageUri = _SafeGetUri(jsonStreamMediaObject, "src"); attachment.VideoPreviewImage = new FacebookImage(_service, previewImageUri); attachment.VideoSource = _SafeGetUri(jsonStreamMediaObject, "href"); // Not using this one because of a bug in Adobe's player when loading in an external browser... //XElement videoElement = streamElement.Element("video"); //if (videoElement != null) //{ // attachment.VideoSource = _SafeGetUri(videoElement, "source_url"); //} } return(attachment); }
private ActivityPostAttachment _DeserializePhotoPostAttachmentData(ActivityPost post, JSON_OBJECT jsonAttachment) { if (jsonAttachment == null || jsonAttachment.Count == 0) { return(null); } ActivityPostAttachment attachment = _DeserializeGenericPostAttachmentData(post, jsonAttachment); attachment.Type = ActivityPostAttachmentType.Photos; var photosEnum = from JSON_OBJECT jsonMediaObject in jsonAttachment["media"] as JSON_ARRAY let photoElement = jsonMediaObject["photo"] as JSON_OBJECT where photoElement != null let link = _SafeGetUri(jsonMediaObject, "href") select new FacebookPhoto( _service, _SafeGetId(photoElement, "aid"), _SafeGetId(photoElement, "pid"), _SafeGetUri(jsonMediaObject, "src")) { Link = link, OwnerId = _SafeGetId(photoElement, "owner"), }; attachment.Photos = FacebookPhotoCollection.CreateStaticCollection(photosEnum); return(attachment); }
private ActivityPostAttachment _DeserializeLinkPostAttachmentData(ActivityPost post, JSON_OBJECT jsonAttachment) { if (jsonAttachment == null || jsonAttachment.Count == 0) { return(null); } ActivityPostAttachment attachment = _DeserializeGenericPostAttachmentData(post, jsonAttachment); attachment.Type = ActivityPostAttachmentType.Links; var linksEnum = from JSON_OBJECT jsonMediaObject in jsonAttachment.Get <JSON_ARRAY>("media") let srcUri = _SafeGetUri(jsonMediaObject, "src") let hrefUri = _SafeGetUri(jsonMediaObject, "href") where srcUri != null && hrefUri != null select new FacebookImageLink { Image = new FacebookImage(_service, srcUri), Link = hrefUri, }; attachment.Links = new FacebookCollection <FacebookImageLink>(linksEnum); return(attachment); }
private ActivityPost _DeserializePost(JSON_OBJECT jsonPost) { var post = new ActivityPost(_service); JSON_OBJECT attachmentObject; if (jsonPost.TryGetTypedValue("attachment", out attachmentObject)) { string postType = null; var jsonMediaArray = (JSON_ARRAY)_SafeGetValue(jsonPost, "attachment", "media"); if (jsonMediaArray != null && jsonMediaArray.Count > 0) { postType = _SafeGetString((JSON_OBJECT)jsonMediaArray[0], "type"); } switch (postType) { case "photo": post.Attachment = _DeserializePhotoPostAttachmentData(post, attachmentObject); break; case "link": post.Attachment = _DeserializeLinkPostAttachmentData(post, attachmentObject); break; case "video": post.Attachment = _DeserializeVideoPostAttachmentData(post, attachmentObject); break; // We're not currently supporting music or flash. Just treat it like a normal post... case "music": case "swf": case "": case null: if (attachmentObject.Count != 0) { // We have attachment information but no rich stream-media associated with it. ActivityPostAttachment attachment = _DeserializeGenericPostAttachmentData(post, attachmentObject); if (!attachment.IsEmpty) { attachment.Type = ActivityPostAttachmentType.Simple; post.Attachment = attachment; } } break; default: Assert.Fail("Unknown type:" + postType); break; } } post.PostId = _SafeGetId(jsonPost, "post_id"); if (!FacebookObjectId.IsValid(post.PostId)) { // Massive Facebook failure. // This happens too frequently for the assert to be useful. // Assert.Fail(); post.PostId = SafeGetUniqueId(); } post.ActorUserId = _SafeGetId(jsonPost, "actor_id"); post.Created = _SafeGetDateTime(jsonPost, "created_time") ?? _UnixEpochTime; post.Message = _SafeGetString(jsonPost, "message"); post.TargetUserId = _SafeGetId(jsonPost, "target_id"); post.Updated = _SafeGetDateTime(jsonPost, "updated_time") ?? _UnixEpochTime; JSON_OBJECT likesElement; if (jsonPost.TryGetTypedValue("likes", out likesElement)) { post.CanLike = _SafeGetBoolean(likesElement, "can_like") ?? false; post.HasLiked = _SafeGetBoolean(likesElement, "user_likes") ?? false; post.LikedCount = _SafeGetInt32(likesElement, "count") ?? 0; post.LikeUri = _SafeGetUri(likesElement, "likes", "href"); //XElement friendsElement = likesElement.Element("friends"); //XElement sampleElement = likesElement.Element("sample"); //post.SetPeopleWhoLikeThisIds( // Enumerable.Union( // sampleElement == null // ? new FacebookObjectId[0] // : from uidElement in sampleElement.Elements("uid") select new FacebookObjectId(uidElement.Value), // friendsElement == null // ? new FacebookObjectId[0] // : from uidElement in friendsElement.Elements("uid") select new FacebookObjectId(uidElement.Value))); } JSON_OBJECT jsonComments; jsonPost.TryGetTypedValue("comments", out jsonComments); post.CanComment = _SafeGetBoolean(jsonComments, "can_post") ?? false; post.CanRemoveComments = _SafeGetBoolean(jsonComments, "can_remove") ?? false; post.CommentCount = _SafeGetInt32(jsonComments, "count") ?? 0; if (jsonComments != null && post.CommentCount != 0) { JSON_ARRAY jsonCommentList; if (jsonComments.TryGetTypedValue("comment_list", out jsonCommentList)) { var commentNodes = from JSON_OBJECT jsonComment in jsonCommentList let comment = _DeserializeComment(jsonComment) where (comment.Post = post) != null select comment; post.RawComments = new FBMergeableCollection <ActivityComment>(commentNodes); } } if (post.RawComments == null) { post.RawComments = new FBMergeableCollection <ActivityComment>(); } // post.Comments = null; return(post); }