Skip to content
Snippets Groups Projects
Commit 3c3d1c48 authored by uhensler's avatar uhensler
Browse files

OO-2930: Notifications for comments in blogs/podcasts

parent 17b60c28
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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.
......@@ -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}.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment