Social Activities

(Redirected from Social Activities in Liferay.)

Table of Contents [-]

Introduction #

World of Liferay portlets (Friends Activity and Recent Activity) give you a feed of activities information about your friends and others. This article explains how the Blogs portlet can generate a feed for these portlets.

Method #

  • Define the Activity Interpreter class in liferay-portlet.xml. In this case it's BlogsActivityInterpreter.java.
<portlet>
	<portlet-name>33</portlet-name>
	<icon>/html/icons/blogs.png</icon>
	<struts-path>blogs</struts-path>
		...
	<social-activity-interpreter-class>com.liferay.portlet.blogs.social.BlogsActivityInterpreter
	</social-activity-interpreter-class>
		...
</portlet>
  • Define an Activity Keys class, which tells the type of activity. In the case of Blogs portlet it's BlogsActivityKeys.java. There are two types of keys that are defined:
public static final int ADD_COMMENT = 1;
public static final int ADD_ENTRY = 2;
  • Save the data in the SocailActivity table which you want to display as feed. In the case of the Blogs portlet there are 3 places:
    • Add new Blog Entry

socialActivityLocalService.addActivity(userId, groupId, BlogsEntry.class.getName(), entryId, BlogsActivityKeys.ADD_ENTRY, StringPool.BLANK, 0); }}}

    • Update an existing Blog Entry

socialActivityLocalService.addActivity(userId, entry.getGroupId(), BlogsEntry.class.getName(), entryId, BlogsActivityKeys.ADD_ENTRY, StringPool.BLANK, 0); }}}

    • Delete a Blog Entry

socialActivityLocalService.deleteActivities( BlogsEntry.class.getName(), entry.getEntryId()); }}}

  • Implement interpreting logic in Interpreter Class. In case of blog portlet it’s BlogsActivityInterpreter.java. You need to implement doInterpret() Method defined in base class:
protected SocialActivityFeedEntry doInterpret(
	SocialActivity activity, ThemeDisplay themeDisplay)
	throws Exception {
		...
}

There are three variables which decide the Feed Entry.

  1. Link – Anchor link which will take you to original Entry (If you want to do that)
  2. Title – Title of the Feed. [Ex: UserX added a new blog entry, UserX added a new event etc.]
  3. Body – Body of the feed entry

Let's see how it's done in Blog portlet:

  1. Link - It's the finder link for Blog Entry (/c/blogs/find_entry?entryId=100)
  2. Title - (User added a new blog entry ). Text is defined in language.properties, Ex: "activity-blogs-add-entry". You can change the text .
  3. Body – It's the title (embedded with link) and preview of the entry.
0 Attachments
34559 Views
Average (2 Votes)
The average rating is 4.0 stars out of 5.
Comments
Threaded Replies Author Date
Hi Friends, Very nice Wiki article. Just need... Nilesh Gundecha May 4, 2011 8:07 AM

Hi Friends,

Very nice Wiki article. Just need clarification on -
How The ActivitiesPortlet (like MembersActivitiesPortlet / UserActivitiesPortlet / FriendsActivitiesPortlet) will know about my defined custom activity type?? Should not I configure/define about my activity type to it??

Please provide me some inputs on this??

Thanks and Regards,
Nilesh.
Posted on 5/4/11 8:07 AM.