1
19
20 package com.liferay.portlet.messageboards.social;
21
22 import com.liferay.portal.kernel.util.StringPool;
23 import com.liferay.portal.kernel.util.Validator;
24 import com.liferay.portal.model.Group;
25 import com.liferay.portal.service.GroupLocalServiceUtil;
26 import com.liferay.portal.theme.ThemeDisplay;
27 import com.liferay.portlet.messageboards.model.MBMessage;
28 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
29 import com.liferay.portlet.messageboards.util.BBCodeUtil;
30 import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
31 import com.liferay.portlet.social.model.SocialActivity;
32 import com.liferay.portlet.social.model.SocialActivityFeedEntry;
33
34
40 public class MBActivityInterpreter extends BaseSocialActivityInterpreter {
41
42 public String[] getClassNames() {
43 return _CLASS_NAMES;
44 }
45
46 protected SocialActivityFeedEntry doInterpret(
47 SocialActivity activity, ThemeDisplay themeDisplay)
48 throws Exception {
49
50 String creatorUserName = getUserName(
51 activity.getUserId(), themeDisplay);
52 String receiverUserName = getUserName(
53 activity.getReceiverUserId(), themeDisplay);
54
55 int activityType = activity.getType();
56
57
59 MBMessage message = MBMessageLocalServiceUtil.getMessage(
60 activity.getClassPK());
61
62 String link =
63 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
64 "/message_boards/find_message?messageId=" +
65 activity.getClassPK();
66
67
69 String groupName = StringPool.BLANK;
70
71 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
72 Group group = GroupLocalServiceUtil.getGroup(activity.getGroupId());
73
74 groupName = group.getDescriptiveName();
75 }
76
77 String titlePattern = null;
78 Object[] titleArguments = null;
79
80 if (activityType == MBActivityKeys.ADD_MESSAGE) {
81 titlePattern = "activity-message-boards-add-message";
82
83 if (Validator.isNotNull(groupName)) {
84 titlePattern += "-in";
85 }
86
87 titleArguments = new Object[] {creatorUserName, groupName};
88 }
89 else if (activityType == MBActivityKeys.REPLY_MESSAGE) {
90 titlePattern = "activity-message-boards-reply-message";
91
92 if (Validator.isNotNull(groupName)) {
93 titlePattern += "-in";
94 }
95
96 titleArguments = new Object[] {
97 creatorUserName, receiverUserName, groupName
98 };
99 }
100
101 String title = themeDisplay.translate(titlePattern, titleArguments);
102
103
105 StringBuilder sb = new StringBuilder();
106
107 sb.append("<a href=\"");
108 sb.append(link);
109 sb.append("\">");
110 sb.append(cleanContent(message.getSubject()));
111 sb.append("</a><br />");
112 sb.append(cleanContent(BBCodeUtil.getHTML(message)));
113
114 String body = sb.toString();
115
116 return new SocialActivityFeedEntry(link, title, body);
117 }
118
119 private static final String[] _CLASS_NAMES = new String[] {
120 MBMessage.class.getName()
121 };
122
123 }