Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Extending "Following for Notifications"

Avatar

Community Advisor

Hello All,

I am trying to extend OOTB notifications. I see that on click of "Notifications" under "Following" as shown in image, the call "http://localhost:6503/content/usergenerated/asi/mongo/content/we-retail/community/en/blog/jcr:conten...subscriptions.social.json" is made. I see the social operation as "social:updatesubscriptions". In my custom blog post that uses OOTB comments component (extended) I do not have the click on the notifications. Rather I am looking to subscribe the user to notifications once the user adds first comment.

I am looking to know how I can trigger "social:updatesubscriptions" operation when a comment is made. Does anyone has any idea regarding this?

  • While adding a comment in the beforeAction, I am adding this entry as below to add a relationship

 

{
        "_id" : "377619aad2e22b3aee28404ebbc9778c9dd472a0",
        "type_s" : "notification",
        "endid_s" : "/content/usergenerated/asi/mongo/content/path/blog/a-post",
        "rel_type_s" : "RESOURCE",
        "parent_id_s" : "/content/usergenerated/asi/mongo/content/sites/social/relationships",
        "provider_id" : "/content/usergenerated/asi/mongo/content/sites/social/relationships/e499d8b9-7161-4049-9781-2ca46afe413d",
        "report_suite" : "mongo",
        "id" : "/content/usergenerated/asi/mongo/content/sites/social/relationships/e499d8b9-7161-4049-9781-2ca46afe413d",
        "startid_s" : "testuser",
        "timestamp" : NumberLong("1491498857673")
}

 

  • Also, created following path structure as it does OOTB /home/users/N/NsQmT0vSkB8YD4yom_lE/social/relationships/notification

Any other actions I might be missing?

Note: Using AEM 6.2 SP1, FP2

1 Accepted Solution

Avatar

Correct answer by
Employee

You can use either of the approaches you identified 

  1.  By using performBeforeActions of your custom comment social component operation extension and insert a relationship between current_user_id (as start node) and subscribed resource node (as end node) as per your required type (notification/email-subscription). only suggestion is to use appropriate SocialGraph and Relationship (Edge/Vertex) APIs in order to save your relationship in SRP. avoid creating content nodes directly with lower level of jcr apis or SRP API calls.

 

  1. Another method is exploiting javascript and post operation you already identified, where you can intercept the “addReply” success callback for a comment (OOTB) or your own callback for custom comment component. make another ajax  post call to “subscriptions.social.json” endpoint with operation = "social:updatesubscriptions", pass appropriate params to make notification set on that specific resource. 

Only issue with later approach is that it would be little less flexible in terms of adding your custom checks and logic. But with advantage of having no server side custom code.

View solution in original post

8 Replies

Avatar

Correct answer by
Employee

You can use either of the approaches you identified 

  1.  By using performBeforeActions of your custom comment social component operation extension and insert a relationship between current_user_id (as start node) and subscribed resource node (as end node) as per your required type (notification/email-subscription). only suggestion is to use appropriate SocialGraph and Relationship (Edge/Vertex) APIs in order to save your relationship in SRP. avoid creating content nodes directly with lower level of jcr apis or SRP API calls.

 

  1. Another method is exploiting javascript and post operation you already identified, where you can intercept the “addReply” success callback for a comment (OOTB) or your own callback for custom comment component. make another ajax  post call to “subscriptions.social.json” endpoint with operation = "social:updatesubscriptions", pass appropriate params to make notification set on that specific resource. 

Only issue with later approach is that it would be little less flexible in terms of adding your custom checks and logic. But with advantage of having no server side custom code.

Avatar

Community Advisor

ashokkumar wrote...

You can use either of the approaches you identified 

  1.  By using performBeforeActions of your custom comment social component operation extension and insert a relationship between current_user_id (as start node) and subscribed resource node (as end node) as per your required type (notification/email-subscription). only suggestion is to use appropriate SocialGraph and Relationship (Edge/Vertex) APIs in order to save your relationship in SRP. avoid creating content nodes directly with lower level of jcr apis or SRP API calls.

 

  1. Another method is exploiting javascript and post operation you already identified, where you can intercept the “addReply” success callback for a comment (OOTB) or your own callback for custom comment component. make another ajax  post call to “subscriptions.social.json” endpoint with operation = "social:updatesubscriptions", pass appropriate params to make notification set on that specific resource. 

Only issue with later approach is that it would be little less flexible in terms of adding your custom checks and logic. But with advantage of having no server side custom code.

 

Thanks a lot Ashok for the response. I had 

Talking about approach 1., wanted to double check something. I have been using an extension class that extends CommentOperationExtension and doing other pre actions in the beforeAction(). Is this the same method you are talking about above "performBeforeActions of your custom comment social component operation extension"?

"only suggestion is to use appropriate SocialGraph and Relationship (Edge/Vertex) APIs in order to save your relationship in SRP. avoid creating content nodes directly with lower level of jcr apis or SRP API calls. "

For above, I believe I am directly inserting an entry to MSRP like below

{ "_id" : "377619aad2e22b3aee28404ebbc9778c9dd472a0", "type_s" : "notification", "endid_s" : "/content/usergenerated/asi/mongo/content/myproj/en/home/comm/news/a-post", "rel_type_s" : "RESOURCE", "parent_id_s" : "/content/usergenerated/asi/mongo/content/sites/social/relationships", "provider_id" : "/content/usergenerated/asi/mongo/content/sites/social/relationships/e499d8b9-7161-4049-9781-2ca46afe413d", "report_suite" : "mongo", "id" : "/content/usergenerated/asi/mongo/content/sites/social/relationships/e499d8b9-7161-4049-9781-2ca46afe413d", "startid_s" : "testuser", "timestamp" : NumberLong("1491498857673") }

using code like below:

Map<String, Object> props = new HashMap<>(); props.put(Subscription.PROP_TYPE, "notification"); props.put(Subscription.PROP_ENDID, srp.getASIPath() + postPageResPath); props.put(Subscription.PROP_REL_TYPE, "RESOURCE"); props.put(Subscription.PROP_STARTID, userId); props.put(InternalSocialResourceUtilities.PN_PARENTID, parentPath); //Doing srp.create after this..

Is there any doc I could refer for calling SRP api to make entries other than what I am doing?

 

Thanks again, really appreciate the response.

Avatar

Community Advisor

@Ashok,

Update: For my question "Is there any doc I could refer for calling SRP api to make entries other than what I am doing?"I found this Following Interface and SocialGraph and Vertex

So to change the question a bit smiley, is there an example code you could add based on my previous comment's details? Please let me know if any more details required..

Avatar

Community Advisor

Thanks Ashok. Currently I am not using the SocialGraph and Relationship (Edge/Vertex) APIs but rather just catching at the beforeAction() and persisting the expected entry as shown in previous comment. I will looking into utilizing the SocialGraph API, since at the moment I do not have an idea how to use it. I request for a sample implementation if possible, meanwhile will spend more time into that.

Thanks again :)

Avatar

Level 2

snbaem

I have a similar requirement, where I have to extend the Following for notification/subscription/activity and create relationships. Could please share information as how you have used the SocialGraph/Vertex/Edge APIs to create and save relationship. A sample code would be helpful.

Avatar

Community Advisor

Hi, I had followed Extend Comments Component  (three steps) for extending the notifications component at "/libs/social/notifications/components/hbs/notifications" I did not use SocialGraph/Vertex/Edge APIs for implementing this. I did not use any backend extension for this. Any changes that were made were in notifications.hbs and notification.hbs. When you have extended your component and the user is following particular blog or post for notifications, the notification entries should get created and displayed in the component render.

the .hbs changes will control the look and feel changes plus any other formatting changes of the verbiage.