Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion force-app/main/default/aura/SearchGIPHY/SearchGIPHY.cmp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">

<div class="preview-image">
<iframe src="{!v.selectedGif}" width="{!v.selectedGifWidth}" height="{!v.selectedGifHeight}" frameBorder="0" />
<img src="{!v.selectedGif}" height="{!v.selectedGifHeight}" />
</div>
<br />
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
var height = selectedGif.images.original.height;

component.set("v.selectedGifWidth", width);
component.set("v.selectedGifHeight", height);
component.set("v.selectedGif", "https://media0.giphy.com/media/" + id + "/giphy.gif");
component.set("v.selectedGifHeight", 200);
// Force Giphy to return images limited to 200 pixel height to prevent file size limit error
component.set("v.selectedGif", "https://media0.giphy.com/media/" + id + "/200.gif");

},

Expand Down
40 changes: 18 additions & 22 deletions force-app/main/default/classes/ChatterHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,26 @@ public with sharing class ChatterHelper {
Blob imageData = getImageData(imageUrl);

ID fileId = saveFile(fileName, imageData);
ID postParentId = UserInfo.getUserId();

FeedItem post = new FeedItem(
ParentId = postParentId,
Body = body,
IsRichText = true
);

insert post;
// Use Salesforce "ConnectApi" class so the animated Gif may be embedded Inline
ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

String feedItemId = post.Id;
ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = chatterText;
messageInput.messageSegments.add(textSegment);

// Add image(s) to the chatter post
// Requires 'Allow users to edit posts and comments' in Setup | Chatter | Chatter Settings
// because adding the feed attachments edits the original post.
// http://salesforce.stackexchange.com/questions/156588/feedattachment-invalid-operation-cannot-create-update-or-delete-feed-attachme
List<FeedAttachment> feedAttachments = new List<FeedAttachment>();
feedAttachments.add( new FeedAttachment(
feedEntityId = feedItemId,
recordId = fileId,
type = 'Content'
));
ConnectApi.InlineImageSegmentInput inlineImageSegment = new ConnectApi.InlineImageSegmentInput();
inlineImageSegment.fileId = fileId;
inlineImageSegment.altText = chatterText;
messageInput.messageSegments.add(inlineImageSegment);

insert feedAttachments;
ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
input.body = messageInput;
input.subjectId = 'me';

return feedItemId;
ConnectApi.FeedElement fe = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input);
return fe.Id;
}

private static ID saveFile(String fileNameWithExt, Blob fileData) {
Expand All @@ -47,7 +41,9 @@ public with sharing class ChatterHelper {

insert file;

return file.Id;
// The ConnectApi class requires a ContentDocument Id -- not the ContentVersion Id
ContentVersion file2 = [select id,ContentDocumentId from ContentVersion where id= :file.id];
return file2.ContentDocumentId;
}

private static Blob getImageData(String url) {
Expand Down