in Facebook/FacebookSDK/JobProcessorFB.cs [158:221]
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;
}