UnSubscribe the user from the comment


  Whenever we write comment to the post(Blog or webcontent etc..) , user will automatically subscribe to the comments and also will be receving the email when ever any user update or add the comment.

  If user want to subscribe manually, it is timetaking to check each and every post.

  so here the following code which helps to unsubscribe the user from the post.

Here we are unsubscribing the "Admin" user  posts of  JournalArticle.  

String screenName = "Admin";
String className = JournalArticle.class.getName();

User user = null;
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

try {
user = UserLocalServiceUtil.getUserByScreenName(themeDisplay.getCompanyId(), screenName);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}

if(user!=null) {

List<subscription> subscriptionList = null;
try {
subscriptionList = SubscriptionLocalServiceUtil.getUserSubscriptions(user.getUserId(),className);
} catch (SystemException e) {
e.printStackTrace();
}


for(Subscription subscription : subscriptionList) {

try {
SubscriptionLocalServiceUtil.deleteSubscription(user.getUserId(), className, subscription.getClassPK());
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}

}

}else {
System.out.println("User doesn't exist");
}



Comments

Popular posts from this blog

Theme display in javascript

How to know which liferay version we are using

Viewing the SQL Query in liferay : debugging the SQL Query in Hibernate