/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This file is part of Liferay Social Office. Liferay Social Office is free
* software: you can redistribute it and/or modify it under the terms of the GNU
* Affero General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* Liferay Social Office is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* Liferay Social Office. If not, see http://www.gnu.org/licenses/agpl-3.0.html.
*/
package com.liferay.microblogs.microblogs.notifications;
import com.liferay.asset.kernel.model.AssetRenderer;
import com.liferay.microblogs.model.MicroblogsEntry;
import com.liferay.microblogs.model.MicroblogsEntryConstants;
import com.liferay.microblogs.service.MicroblogsEntryLocalServiceUtil;
import com.liferay.microblogs.util.PortletKeys;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.notifications.BaseModelUserNotificationHandler;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.service.UserLocalServiceUtil;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.StringPool;
/**
* @author Jonathan Lee
*/
public class MicroblogsUserNotificationHandler
extends BaseModelUserNotificationHandler {
public MicroblogsUserNotificationHandler() {
setPortletId(PortletKeys.MICROBLOGS);
}
@Override
protected String getTitle(
JSONObject jsonObject, AssetRenderer assetRenderer,
ServiceContext serviceContext) {
MicroblogsEntry microblogsEntry =
MicroblogsEntryLocalServiceUtil.fetchMicroblogsEntry(
assetRenderer.getClassPK());
String title = StringPool.BLANK;
String userFullName = HtmlUtil.escape(
PortalUtil.getUserName(
microblogsEntry.getUserId(), StringPool.BLANK));
int notificationType = jsonObject.getInt("notificationType");
if (notificationType ==
MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY) {
title = serviceContext.translate(
"x-commented-on-your-post", userFullName);
}
else if (notificationType ==
MicroblogsEntryConstants.
NOTIFICATION_TYPE_REPLY_TO_REPLIED) {
long parentMicroblogsEntryUserId =
microblogsEntry.fetchParentMicroblogsEntryUserId();
User user = UserLocalServiceUtil.fetchUser(
parentMicroblogsEntryUserId);
if (user != null) {
title = serviceContext.translate(
"x-also-commented-on-x's-post", userFullName,
user.getFullName());
}
}
else if (notificationType ==
MicroblogsEntryConstants.
NOTIFICATION_TYPE_REPLY_TO_TAGGED) {
title = serviceContext.translate(
"x-commented-on-a-post-you-are-tagged-in", userFullName);
}
else if (notificationType ==
MicroblogsEntryConstants.NOTIFICATION_TYPE_TAG) {
title = serviceContext.translate(
"x-tagged-you-in-a-post", userFullName);
}
return title;
}
}