forked from forcedotcom/GIFter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request forcedotcom#2 from forcedotcom/ChatterWorking
Updates that fix chatter posts
- Loading branch information
Showing
6 changed files
with
95 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,69 @@ | ||
public with sharing class ChatterHelper { | ||
|
||
@AuraEnabled | ||
public static String getChatterGroups() { | ||
public static String getChatterGroups(String imageUrl, String chatterText) { | ||
|
||
// System.debug('getChatterGroups'); | ||
System.debug('getChatterGroups'); | ||
|
||
// ConnectApi.ContentHubRepositoryCollection repositoryCollection = ConnectApi.ContentHub.getRepositories(); | ||
|
||
// System.debug('repository'); | ||
|
||
// for(ConnectApi.ContentHubRepository repository : repositoryCollection.repositories){ | ||
|
||
// System.debug(repository); | ||
|
||
// } | ||
|
||
|
||
|
||
|
||
|
||
// String userId = UserInfo.getUserId(); | ||
// System.debug('userId: ' + userId); | ||
// String imageUrl = 'https://media0.giphy.com/media/xTiTncVep2khPGhK1i/giphy.gif'; | ||
String fileName = 'me.gif'; | ||
String body = chatterText; | ||
|
||
// String communityId = null; | ||
// String imageId = '069D00000001INA'; // need to replace | ||
// // String mentionedUserId = '005D0000001QNpr'; | ||
// String targetUserOrGroupOrRecordId = 'me'; // is this right? | ||
|
||
// ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput(); | ||
// input.subjectId = targetUserOrGroupOrRecordId; | ||
// input.feedElementType = ConnectApi.FeedElementType.FeedItem; | ||
Blob imageData = getImageData(imageUrl); | ||
|
||
// ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput(); | ||
// ConnectApi.TextSegmentInput textSegment; | ||
// ConnectApi.MentionSegmentInput mentionSegment; | ||
// ConnectApi.MarkupBeginSegmentInput markupBeginSegment; | ||
// ConnectApi.MarkupEndSegmentInput markupEndSegment; | ||
// ConnectApi.InlineImageSegmentInput inlineImageSegment; | ||
ID fileId = saveFile(fileName, imageData); | ||
ID postParentId = UserInfo.getUserId(); | ||
|
||
// System.debug('here 1'); | ||
FeedItem post = new FeedItem( | ||
ParentId = postParentId, | ||
Body = body, | ||
IsRichText = true | ||
); | ||
|
||
// messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>(); | ||
insert post; | ||
|
||
// markupBeginSegment = new ConnectApi.MarkupBeginSegmentInput(); | ||
// markupBeginSegment.markupType = ConnectApi.MarkupType.Bold; | ||
// messageInput.messageSegments.add(markupBeginSegment); | ||
String feedItemId = post.Id; | ||
|
||
// System.debug('here 2'); | ||
// 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' | ||
)); | ||
|
||
// textSegment = new ConnectApi.TextSegmentInput(); | ||
// textSegment.text = 'Hello '; | ||
// messageInput.messageSegments.add(textSegment); | ||
insert feedAttachments; | ||
|
||
// System.debug('here 3'); | ||
|
||
// // mentionSegment = new ConnectApi.MentionSegmentInput(); | ||
// // mentionSegment.id = mentionedUserId; | ||
// // messageInput.messageSegments.add(mentionSegment); | ||
|
||
// System.debug('here 4'); | ||
|
||
// textSegment = new ConnectApi.TextSegmentInput(); | ||
// textSegment.text = '!'; | ||
// messageInput.messageSegments.add(textSegment); | ||
|
||
// System.debug('here 5'); | ||
|
||
// markupEndSegment = new ConnectApi.MarkupEndSegmentInput(); | ||
// markupEndSegment.markupType = ConnectApi.MarkupType.Bold; | ||
// messageInput.messageSegments.add(markupEndSegment); | ||
return feedItemId; | ||
} | ||
|
||
// System.debug('here 6'); | ||
private static ID saveFile(String fileNameWithExt, Blob fileData) { | ||
|
||
// inlineImageSegment = new ConnectApi.InlineImageSegmentInput(); | ||
// inlineImageSegment.altText = 'image one'; | ||
// inlineImageSegment.fileId = imageId; | ||
// messageInput.messageSegments.add(inlineImageSegment); | ||
ContentVersion file = new ContentVersion( | ||
versionData = fileData, | ||
title = fileNameWithExt, | ||
pathOnClient = '/' + fileNameWithExt | ||
); | ||
|
||
// input.body = messageInput; | ||
insert file; | ||
|
||
// System.debug('here 7'); | ||
return file.Id; | ||
} | ||
|
||
// ConnectApi.ChatterFeeds.postFeedElement(communityId, input, null); | ||
private static Blob getImageData(String url) { | ||
|
||
// System.debug('here 8'); | ||
HttpRequest req = new HttpRequest(); | ||
req.setEndpoint( url ); | ||
req.setHeader('accept', 'image/*'); | ||
|
||
req.setMethod('GET'); | ||
req.setCompressed( false ); | ||
|
||
return 'finished'; | ||
HttpResponse res = new Http().send( req ); | ||
return res.getBodyAsBlob(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="ChatterHelper"> | ||
<apiVersion>35.0</apiVersion> | ||
<apiVersion>42.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> | ||
</ApexClass> |
6 changes: 6 additions & 0 deletions
6
force-app/main/default/remoteSiteSettings/GiphyMedia0.remoteSite-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<RemoteSiteSetting xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<disableProtocolSecurity>false</disableProtocolSecurity> | ||
<isActive>true</isActive> | ||
<url>https://media0.giphy.com</url> | ||
</RemoteSiteSetting> |
File renamed without changes.