use of org.olat.core.commons.services.notifications.SubscriptionItem in project openolat by klemens.
the class NotificationsManagerImpl method processSubscribersByEmail.
private void processSubscribersByEmail(Identity ident) {
if (ident.getStatus().compareTo(Identity.STATUS_VISIBLE_LIMIT) >= 0) {
// send only to active user
return;
}
String userInterval = getUserIntervalOrDefault(ident);
if ("never".equals(userInterval)) {
return;
}
long start = System.currentTimeMillis();
Date compareDate = getCompareDateFromInterval(userInterval);
Property p = propertyManager.findProperty(ident, null, null, null, LATEST_EMAIL_USER_PROP);
if (p != null) {
Date latestEmail = new Date(p.getLongValue());
if (latestEmail.after(compareDate)) {
// nothing to do
return;
}
}
Date defaultCompareDate = getDefaultCompareDate();
List<Subscriber> subscribers = getSubscribers(ident);
if (subscribers.isEmpty()) {
return;
}
String langPrefs = null;
if (ident.getUser() != null && ident.getUser().getPreferences() != null) {
langPrefs = ident.getUser().getPreferences().getLanguage();
}
Locale locale = I18nManager.getInstance().getLocaleOrDefault(langPrefs);
boolean veto = false;
Subscriber latestSub = null;
List<SubscriptionItem> items = new ArrayList<>();
List<Subscriber> subsToUpdate = new ArrayList<>();
for (Subscriber sub : subscribers) {
Date latestEmail = sub.getLatestEmailed();
SubscriptionItem subsitem = null;
if (latestEmail == null || compareDate.after(latestEmail)) {
// no notif. ever sent until now
if (latestEmail == null) {
latestEmail = defaultCompareDate;
} else if (latestEmail.before(defaultCompareDate)) {
// no notification older than a month
latestEmail = defaultCompareDate;
}
subsitem = createSubscriptionItem(sub, locale, SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML, latestEmail);
} else if (latestEmail != null && latestEmail.after(compareDate)) {
// already send an email within the user's settings interval
// veto = true;
}
if (subsitem != null) {
items.add(subsitem);
subsToUpdate.add(sub);
}
latestSub = sub;
}
Translator translator = Util.createPackageTranslator(NotificationSubscriptionController.class, locale);
notifySubscribersByEmail(latestSub, items, subsToUpdate, translator, start, veto);
}
use of org.olat.core.commons.services.notifications.SubscriptionItem in project openolat by klemens.
the class NotificationsManagerImpl method createSubscriptionItem.
@Override
public SubscriptionItem createSubscriptionItem(SubscriptionInfo subsInfo, Subscriber subscriber, Locale locale, String mimeTypeTitle, String mimeTypeContent) {
Publisher pub = subscriber.getPublisher();
String title = getFormatedTitle(subsInfo, subscriber, locale, mimeTypeTitle);
String itemLink = null;
if (subsInfo.getCustomUrl() != null) {
itemLink = subsInfo.getCustomUrl();
}
if (itemLink == null && pub.getBusinessPath() != null) {
itemLink = BusinessControlFactory.getInstance().getURLFromBusinessPathString(pub.getBusinessPath());
}
String description = subsInfo.getSpecificInfo(mimeTypeContent, locale);
SubscriptionItem subscriptionItem = new SubscriptionItem(title, itemLink, description);
subscriptionItem.setSubsInfo(subsInfo);
return subscriptionItem;
}
Aggregations