private async Task HandleComment(CommentDataFB comment, AuthenticationHeaderValue header, string pageId, Item postItem, ConnectorTask taskInfo, List <ItemMetadata> itemMetadata) { Item commentItem = await CreateCommentItem(comment, pageId, postItem, taskInfo, itemMetadata); commentItem.PreContext = null; if (comment.CommentCount > 0) { bool moreReplies = false; do { if (moreReplies) { // only if there are more replies to this comment, to be fetched comment.Comments = await this.downloader.GetWebContent <CommentFB, ErrorsFB>(comment.Comments.Paging.Next, header); } if (comment.Comments?.Data != null) { foreach (CommentDataFB reply in comment.Comments.Data) { await HandleReply(reply, pageId, commentItem, postItem, taskInfo, itemMetadata); } moreReplies = true; } } while (comment.Comments?.Paging?.Next != null); } }
private async Task <Item> CreateCommentItem(CommentDataFB comment, string pageId, Item postItem, ConnectorTask taskInfo, List <ItemMetadata> itemMetadata) { Item commentItem = new Item() { SchemaVersion = new Version(1, 0), Id = comment.Id, ContainerId = pageId, ContainerName = postItem.ContainerName, SourceType = "Facebook", ItemType = "Comment", ContentType = ContentType.Text, Content = comment.Message, ParentId = postItem.Id, ThreadId = postItem.Id, SentTimeUtc = DateTime.Parse(comment.CreatedTime), Sender = ToItemUser(comment.From), NumOfLikes = comment.LikeCount, MessagePreviewText = postItem.Content, Recipients = Array.Empty <User>(), PreContext = new List <Item>() { postItem }, }; if (comment.Attachment != null) { commentItem.ContentAttachments = new List <ContentAttachment>(); string attachmentType = comment.Attachment.Type; string downloadedContent = await this.downloader.DownloadFileAsBase64EncodedString(comment.Attachment.Media?.Image?.Src); ContentAttachment attachment = new ContentAttachment() { AttachmentFileName = attachmentType.Contains("share") ? "safe_image.jpg" : FetchNameFromUri(attachmentType.Contains("video") ? comment.Attachment.Media?.Source : comment.Attachment.Media?.Image?.Src), AttachmentType = attachmentType, Content = downloadedContent, Uri = new Uri(attachmentType.Contains("video") ? comment.Attachment.Url : comment.Attachment.Media?.Image?.Src), }; commentItem.ContentAttachments.Add(attachment); } string fileName = await uploader.UploadItem(taskInfo.JobId, taskInfo.TaskId, commentItem); itemMetadata.Add(new ItemMetadata(commentItem.Id, commentItem.SentTimeUtc, fileName)); return(commentItem); }
private async Task HandleReply(CommentDataFB reply, string pageId, Item commentItem, Item postItem, ConnectorTask taskInfo, List <ItemMetadata> itemMetadata) { await CreateReplyItem(reply, pageId, commentItem, postItem, taskInfo, itemMetadata); }