001
014
015 package com.liferay.portlet.messageboards.social;
016
017 import com.liferay.portal.kernel.util.HtmlUtil;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.kernel.util.Validator;
020 import com.liferay.portal.security.permission.ActionKeys;
021 import com.liferay.portal.security.permission.PermissionChecker;
022 import com.liferay.portal.theme.ThemeDisplay;
023 import com.liferay.portlet.messageboards.model.MBMessage;
024 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
025 import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
026 import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
027 import com.liferay.portlet.social.model.SocialActivity;
028 import com.liferay.portlet.social.model.SocialActivityFeedEntry;
029
030
034 public class MBActivityInterpreter extends BaseSocialActivityInterpreter {
035
036 public String[] getClassNames() {
037 return _CLASS_NAMES;
038 }
039
040 protected SocialActivityFeedEntry doInterpret(
041 SocialActivity activity, ThemeDisplay themeDisplay)
042 throws Exception {
043
044 PermissionChecker permissionChecker =
045 themeDisplay.getPermissionChecker();
046
047 if (!MBMessagePermission.contains(
048 permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
049
050 return null;
051 }
052
053 String groupName = StringPool.BLANK;
054
055 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
056 groupName = getGroupName(activity.getGroupId(), themeDisplay);
057 }
058
059 String creatorUserName = getUserName(
060 activity.getUserId(), themeDisplay);
061 String receiverUserName = getUserName(
062 activity.getReceiverUserId(), themeDisplay);
063
064 int activityType = activity.getType();
065
066
067
068 MBMessage message = MBMessageLocalServiceUtil.getMessage(
069 activity.getClassPK());
070
071 String link =
072 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
073 "/message_boards/find_message?messageId=" +
074 message.getMessageId();
075
076
077
078 String titlePattern = null;
079
080 if (activityType == MBActivityKeys.ADD_MESSAGE) {
081 titlePattern = "activity-message-boards-add-message";
082 }
083 else if (activityType == MBActivityKeys.REPLY_MESSAGE) {
084 titlePattern = "activity-message-boards-reply-message";
085 }
086
087 if (Validator.isNotNull(groupName)) {
088 titlePattern += "-in";
089 }
090
091 String messageSubject = wrapLink(
092 link, HtmlUtil.escape(cleanContent(message.getSubject())));
093
094 Object[] titleArguments = new Object[] {
095 groupName, creatorUserName, receiverUserName, messageSubject
096 };
097
098 String title = themeDisplay.translate(titlePattern, titleArguments);
099
100
101
102 String categoryLink =
103 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
104 "/message_boards/find_category?mbCategoryId=" +
105 message.getCategoryId();
106
107 String body = wrapLink(categoryLink, "go-to-category", themeDisplay);
108
109 return new SocialActivityFeedEntry(link, title, body);
110 }
111
112 private static final String[] _CLASS_NAMES = new String[] {
113 MBMessage.class.getName()
114 };
115
116 }