From 3c3d1c48696d91f90b515aabb9fc183be0198ad2 Mon Sep 17 00:00:00 2001 From: uhensler <none@none> Date: Fri, 11 Aug 2017 09:02:52 +0200 Subject: [PATCH] OO-2930: Notifications for comments in blogs/podcasts --- .../manager/FeedNotificationsHandler.java | 47 +++++++++++++------ .../ui/_i18n/LocalStrings_de.properties | 1 + .../ui/_i18n/LocalStrings_en.properties | 1 + 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/olat/modules/webFeed/manager/FeedNotificationsHandler.java b/src/main/java/org/olat/modules/webFeed/manager/FeedNotificationsHandler.java index 43d894f2109..bef6e18d21c 100644 --- a/src/main/java/org/olat/modules/webFeed/manager/FeedNotificationsHandler.java +++ b/src/main/java/org/olat/modules/webFeed/manager/FeedNotificationsHandler.java @@ -24,6 +24,8 @@ import java.util.Date; import java.util.List; import java.util.Locale; +import org.olat.core.commons.services.commentAndRating.CommentAndRatingService; +import org.olat.core.commons.services.commentAndRating.model.UserComment; import org.olat.core.commons.services.notifications.NotificationsHandler; import org.olat.core.commons.services.notifications.NotificationsManager; import org.olat.core.commons.services.notifications.Publisher; @@ -48,34 +50,37 @@ import org.olat.modules.webFeed.Item; import org.olat.modules.webFeed.ui.FeedMainController; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; +import org.olat.user.UserManager; import org.springframework.beans.factory.annotation.Autowired; /** - * + * * Initial date: 6 juin 2017<br> * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com * */ public abstract class FeedNotificationsHandler implements NotificationsHandler { - + private static final OLog log = Tracing.createLoggerFor(FeedNotificationsHandler.class); private static final String NOTIFICATIONS_HEADER_COURSE = "notifications.header.course"; protected static final String NOTIFICATIONS_HEADER = "notifications.header"; - + @Autowired private FeedManager feedManager; @Autowired private RepositoryManager repoManager; @Autowired private NotificationsManager notificationsManager; - + @Autowired + private CommentAndRatingService commentAndRatingService; + @Override public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) { SubscriptionInfo si; Publisher p = subscriber.getPublisher(); Date latestNews = p.getLatestNewsDate(); - + try { final Translator translator = Util.createPackageTranslator(FeedMainController.class, locale); if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) { @@ -102,7 +107,7 @@ public abstract class FeedNotificationsHandler implements NotificationsHandler { log.error("Unknown Exception", e); return notificationsManager.getNoSubscriptionInfo(); } - + OLATResourceable feedOres = OresHelper.createOLATResourceableInstance(p.getType(), new Long(p.getData())); Feed feed = feedManager.loadFeed(feedOres); List<Item> listItems = feedManager.loadItems(feed); @@ -123,7 +128,7 @@ public abstract class FeedNotificationsHandler implements NotificationsHandler { } return si; } - + private void appendSubscriptionItem(Item item, Publisher p, Date compareDate, Translator translator, List<SubscriptionListItem> items) { String title = item.getTitle(); String author = item.getAuthor(); @@ -137,7 +142,7 @@ public abstract class FeedNotificationsHandler implements NotificationsHandler { String desc = translator.translate("notifications.entry.published", new String[] { title, author }); items.add(new SubscriptionListItem(desc, urlToSend, businessPath, publishDate, iconCssClass)); } - + // Internal items are modified when the modifier key is present. // External items are modified when the creation date is unequal the // last modified date and the published date is after the last @@ -156,20 +161,34 @@ public abstract class FeedNotificationsHandler implements NotificationsHandler { items.add(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass)); } } + + List<UserComment> comments = commentAndRatingService.getComments(item.getFeed(), item.getGuid()); + for (UserComment comment : comments) { + if (compareDate.before(comment.getCreationDate())) { + String desc; + String modifier = UserManager.getInstance().getUserDisplayName(comment.getCreator().getKey()); + if(StringHelper.containsNonWhitespace(modifier)) { + desc = translator.translate("notifications.entry.commented", new String[] { title, modifier }); + } else { + desc = translator.translate("notifications.entry.commented", new String[] { title, "???" }); + } + items.add(new SubscriptionListItem(desc, urlToSend, businessPath, comment.getCreationDate(), iconCssClass)); + } + } } } - + protected abstract String getCssClassIcon(); - + protected abstract String getHeader(Translator translator, String title); - + @Override public String createTitleInfo(Subscriber subscriber, Locale locale) { Translator translator = Util.createPackageTranslator(FeedMainController.class, locale); TitleItem title = getTitleItem(subscriber.getPublisher(), translator); return title.getInfoContent("text/plain"); } - + protected TitleItem getTitleItem(Publisher p, Translator translator) { String title; try { @@ -182,11 +201,11 @@ public abstract class FeedNotificationsHandler implements NotificationsHandler { } return new TitleItem(title, CSSHelper.CSS_CLASS_FILETYPE_FOLDER); } - + protected void checkPublisher(Publisher p) { try { RepositoryEntry entry = repoManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false); - if (entry == null) { + if (entry == null) { notificationsManager.deactivate(p); } } catch (Exception e) { diff --git a/src/main/java/org/olat/modules/webFeed/ui/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/modules/webFeed/ui/_i18n/LocalStrings_de.properties index 474d6e78d86..984fd2fdccb 100644 --- a/src/main/java/org/olat/modules/webFeed/ui/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/modules/webFeed/ui/_i18n/LocalStrings_de.properties @@ -49,3 +49,4 @@ notifications.header.podcast=Neue Eintr\u00E4ge im Podcast "{0}" notifications.header.course=Neue Eintr\u00E4ge im Kurs "{0}" notifications.entry.published=Der Post "{0}" wurde von "{1}" publiziert. notifications.entry.modified=Der Post "{0}" wurde von "{1}" ge\u00E4ndert. +notifications.entry.commented=Der Post "{0}" wurde von "{1}" kommentiert. diff --git a/src/main/java/org/olat/modules/webFeed/ui/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/modules/webFeed/ui/_i18n/LocalStrings_en.properties index 90e02b89899..50f9b19f955 100644 --- a/src/main/java/org/olat/modules/webFeed/ui/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/modules/webFeed/ui/_i18n/LocalStrings_en.properties @@ -50,3 +50,4 @@ notifications.header.podcast=New entries in podcast "{0}" notifications.header.course=New entries in course "{0}" notifications.entry.published=The post "{0}" was published by {1}. notifications.entry.modified=The post "{0}" was modified by {1}. +notifications.entry.commented=The post "{0}" was commented by {1}. -- GitLab