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