Skip to content

Instantly share code, notes, and snippets.

@martyychang
Created April 18, 2017 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martyychang/9175b4e9c64cf7a14cd3b1571bf645d4 to your computer and use it in GitHub Desktop.
Save martyychang/9175b4e9c64cf7a14cd3b1571bf645d4 to your computer and use it in GitHub Desktop.
Server-side controller for Lightning component enabling partner users to follow and unfollow topics
public class CommunityTopicListItemController {
@AuraEnabled
public static void subscribe(Id entityId) {
ConnectApi.Subscription subscription =
ConnectApi.ChatterUsers.follow(Network.getNetworkId(), 'me', entityId);
}
@AuraEnabled
public static void unsubscribe(Id subscriptionId) {
ConnectApi.Chatter.deleteSubscription(Network.getNetworkId(), subscriptionId);
}
@AuraEnabled
public static EntitySubscription getSubscription(Id entityId) {
List<EntitySubscription> subscriptions = [
SELECT Id
FROM EntitySubscription
WHERE ParentId = :entityId
AND SubscriberId = :UserInfo.getUserId()
AND NetworkId = :Network.getNetworkId()
LIMIT 1
];
return subscriptions.isEmpty() ? null : subscriptions.get(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment