Social Activities

(从 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 附件
34558 查看
平均 (2 票)
满分为 5,平均得分为 4.0。
评论
讨论主题回复 作者 日期
Hi Friends, Very nice Wiki article. Just need... Nilesh Gundecha 2011年5月4日 上午8:07

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.
在 11-5-4 上午8:07 发帖。