From 397c0c757f9d7bdb384e8d8d7cc4da4633fa951b Mon Sep 17 00:00:00 2001 From: Ayoub Zayati Date: Fri, 30 Aug 2024 22:51:17 +0100 Subject: [PATCH] feat: Implement notePostedMention PWA notification - EXO-73814 - Meeds-io/MIPs#128 (#15) --- ...otePostedMentionPwaNotificationPlugin.java | 69 +++++++++++++++++++ .../locale/commons/Commons_en.properties | 2 + 2 files changed, 71 insertions(+) create mode 100644 pwa-plugin/src/main/java/io/meeds/pwa/plugin/notes/NotePostedMentionPwaNotificationPlugin.java diff --git a/pwa-plugin/src/main/java/io/meeds/pwa/plugin/notes/NotePostedMentionPwaNotificationPlugin.java b/pwa-plugin/src/main/java/io/meeds/pwa/plugin/notes/NotePostedMentionPwaNotificationPlugin.java new file mode 100644 index 0000000..46bad1f --- /dev/null +++ b/pwa-plugin/src/main/java/io/meeds/pwa/plugin/notes/NotePostedMentionPwaNotificationPlugin.java @@ -0,0 +1,69 @@ +/** + * This file is part of the Meeds project (https://meeds.io/). + * + * Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * This program 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package io.meeds.pwa.plugin.notes; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +import org.exoplatform.commons.api.notification.model.NotificationInfo; +import org.exoplatform.services.resources.LocaleConfig; +import org.exoplatform.services.resources.ResourceBundleService; +import org.exoplatform.social.core.manager.IdentityManager; + +import io.meeds.portal.permlink.model.PermanentLinkObject; +import io.meeds.portal.permlink.service.PermanentLinkService; +import io.meeds.pwa.model.PwaNotificationMessage; +import io.meeds.pwa.plugin.PwaNotificationPlugin; + +import lombok.Getter; + +@Profile("notes") +@Component +public class NotePostedMentionPwaNotificationPlugin implements PwaNotificationPlugin { + + private static final String TITLE_LABEL_KEY = "pwa.notification.MentionInNoteNotificationPlugin.title"; + + @Autowired + private ResourceBundleService resourceBundleService; + + @Autowired + private PermanentLinkService permanentLinkService; + + @Autowired + @Getter + private IdentityManager identityManager; + + @Override + public String getId() { + return "MentionInNoteNotificationPlugin"; + } + + @Override + public PwaNotificationMessage process(NotificationInfo notification, LocaleConfig localeConfig) { + PwaNotificationMessage notificationMessage = new PwaNotificationMessage(); + notificationMessage.setTitle(resourceBundleService.getSharedString(TITLE_LABEL_KEY, localeConfig.getLocale()) + .replace("{0}", notification.getValueOwnerParameter("CURRENT_USER"))); + notificationMessage.setBody(notification.getValueOwnerParameter("NOTE_TITLE")); + notificationMessage.setUrl(permanentLinkService.getPermanentLink(new PermanentLinkObject("notes", + notification.getValueOwnerParameter("NOTE_URL")))); + return notificationMessage; + } + +} diff --git a/pwa-webapp/src/main/resources/locale/commons/Commons_en.properties b/pwa-webapp/src/main/resources/locale/commons/Commons_en.properties index a424f3b..3fd7fd4 100644 --- a/pwa-webapp/src/main/resources/locale/commons/Commons_en.properties +++ b/pwa-webapp/src/main/resources/locale/commons/Commons_en.properties @@ -49,3 +49,5 @@ pwa.notification.TaskCompletedPlugin.title=Task Completed pwa.notification.TaskCommentedPlugin.title=New Task Comment pwa.notification.TaskMentionedPlugin.title={0} mentioned you in a Task pwa.notification.TaskEditionPlugin.title=Task Updated +#Notes +pwa.notification.MentionInNoteNotificationPlugin.title={0} mentioned you in Note