Ejemplo n.º 1
0
        private async Task HandlePost(PostFB post, AuthenticationHeaderValue header, string pageId, string pageName, ConnectorTask taskInfo, List <ItemMetadata> itemMetadata)
        {
            Item postItem = await CreatePostItem(post, pageId, pageName, taskInfo, itemMetadata);

            CommentFB comments     = post.Comments;
            bool      moreComments = false;

            do
            {
                if (moreComments)
                {
                    // only if there are more comments to this post, to be fetched
                    comments = await this.downloader.GetWebContent <CommentFB, ErrorsFB>(comments.Paging.Next, header);
                }

                if (comments != null && comments.Data.Count() != 0)
                {
                    List <CommentDataFB> Data = comments.Data.ToList();
                    foreach (CommentDataFB comment in Data)
                    {
                        await HandleComment(comment, header, pageId, postItem, taskInfo, itemMetadata);
                    }
                }
                moreComments = true;
            } while (comments?.Paging?.Next != null);
        }
Ejemplo n.º 2
0
        private async Task <Item> CreatePostItem(PostFB post, string pageId, string pageName, ConnectorTask taskInfo, List <ItemMetadata> itemMetadata)
        {
            Item postItem = new Item()
            {
                SchemaVersion      = new Version(1, 0),
                Id                 = post.Id,
                ContainerId        = pageId,
                ContainerName      = pageName,
                SourceType         = "Facebook",
                ItemType           = "Post",
                ContentType        = ContentType.Text,
                Content            = post.Message,
                ParentId           = string.Empty,
                ThreadId           = post.Id,
                SentTimeUtc        = DateTime.Parse(post.CreatedTime),
                Sender             = ToItemUser(post.From),
                NumOfLikes         = post.Likes?.Summary?.TotalCount ?? 0,
                MessagePreviewText = post.Message,
                Recipients         = Array.Empty <User>(),
            };

            if (post.Attachments != null)
            {
                postItem.ContentAttachments = new List <ContentAttachment>();
                if (post.Attachments.Data?[0]?.Media == null)
                {
                    AttachmentDataFB[] attachmentData = post.Attachments.Data?[0]?.Subattachments?.Data;
                    foreach (AttachmentDataFB attachmentItem in attachmentData)
                    {
                        string downloadedContent = await this.downloader.DownloadFileAsBase64EncodedString(attachmentItem.Media?.Image?.Src);

                        ContentAttachment attachment = new ContentAttachment()
                        {
                            AttachmentFileName = FetchNameFromUri(attachmentItem.Media?.Image?.Src),
                            AttachmentType     = attachmentItem.Type,
                            Content            = downloadedContent,
                            Uri = new Uri(attachmentItem.Media?.Image?.Src),
                        };

                        postItem.ContentAttachments.Add(attachment);
                    }
                }
                else
                {
                    // only one video allowed per post, checking attachment type
                    string attachmentType    = post.Attachments.Data[0].Type;
                    string downloadedContent = await this.downloader.DownloadFileAsBase64EncodedString(post.Attachments.Data[0].Media?.Image?.Src);

                    ContentAttachment attachment = new ContentAttachment()
                    {
                        AttachmentFileName = attachmentType.Contains("share") ? "safe_image.jpg" : FetchNameFromUri(attachmentType.Contains("video") ? post.Attachments.Data[0].Media?.Source : post.Attachments.Data[0].Media?.Image?.Src),
                        AttachmentType     = attachmentType,
                        Content            = downloadedContent,
                        Uri = new Uri(attachmentType.Contains("video") ? post.Attachments.Data[0].Url : post.Attachments.Data[0].Media?.Image?.Src),
                    };

                    postItem.ContentAttachments.Add(attachment);
                }
            }

            string fileName = await uploader.UploadItem(taskInfo.JobId, taskInfo.TaskId, postItem);

            itemMetadata.Add(new ItemMetadata(postItem.Id, postItem.SentTimeUtc, fileName));
            return(postItem);
        }