Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
## ---------------------------------------------------------------------------
## See the NOTICE file distributed with this work for additional
## information regarding copyright ownership.
##
## This 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 2.1 of
## the License, or (at your option) any later version.
##
## This software 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 software; if not, write to the Free
## Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA, or see the FSF site: http://www.fsf.org.
## ---------------------------------------------------------------------------

#set ($mainIcon = 'list')
#set ($smallIcon = '')

#macro (getGenericFieldDescription $customEventInfo $eventText)
## The notification text will be available in `$eventText` after calling this macro.
#set ($localizationParams = [
$customEventInfo['currentValue'],
$customEventInfo['previousValue']
])
#set ($localizationId = "taskmanager.events.taskChangedEvent.details.${customEventInfo['type']}" )
#set ($eventText = $services.localization.render($localizationId, 'xhtml/1.0', $localizationParams))
#end

#macro (getAssigneeDescription $customEventInfo $eventText $mode)
#set ($oldUserSet = $collectiontool.getSet())
#foreach ($user in $customEventInfo['previousValue'].split(','))
#set ($discard = $oldUserSet.add($user))
#end
#set ($newUserSet = $collectiontool.getSet())
#foreach ($user in $customEventInfo['currentValue'].split(','))
#set ($discard = $newUserSet.add($user))
#end
#set ($currentUserName = $xwiki.getUser().getUser().getFullName())
#set ($intersectionUsers = $collectiontool.intersection($newUserSet, $oldUserSet))
#set ($unassignedUsers = $collectiontool.disjunction($oldUserSet, $intersectionUsers))
#set ($assignedUsers = $collectiontool.disjunction($newUserSet, $intersectionUsers))
##
#set ($localizationParams = [])
#if ($newUserSet.isEmpty())
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.none')
#elseif ($unassignedUsers.contains($currentUserName))
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.you.unassigned')
#elseif ($assignedUsers.contains($currentUserName))
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.you.assigned')
#else
## This branch has more complex logic, so it handles its own output.
#if (!$assignedUsers.isEmpty())
#set ($localizationParams = ['__assignedUsers__'])
#set ($assignedUsersString = '')
#foreach ($username in $assignedUsers)
#if ($assignedUsersString != '')
#set ($assignedUsersString = "$assignedUsersString,")
#end
#if ($mode == 'email')
#set ($assignedUsersString = "$assignedUsersString#displayEmailNotificationEventUser($xwiki.getUser($username).getUser().getUserReference(), false)")
#else
#set ($assignedUsersString = "$assignedUsersString#displayNotificationEventUser($username, false)")
#end
#end
#set ($localizationId = "taskmanager.events.taskChangedEvent.details.assignee.assigned" )
#set ($eventText = $services.localization.render($localizationId, 'xhtml/1.0', $localizationParams) )
#set ($eventText = $eventText.replace('__assignedUsers__', $!assignedUsersString))
#end
#if (!$unassignedUsers.isEmpty())
#if (!$assignedUsers.isEmpty())
## Newline if users were both assigned and unassigned.
#set ($eventText = "$eventText<br>")
#end
#set ($localizationParams = ['__unassignedUsers__'])
#set ($unassignedUsersString = '')
#foreach ($username in $unassignedUsers)
#if ($unassignedUsersString != '')
#set ($unassignedUsersString = "$unassignedUsersString,")
#end
#if ($mode == 'email')
#set ($unassignedUsersString = "$unassignedUsersString#displayEmailNotificationEventUser($xwiki.getUser($username).getUser().getUserReference(), false)")
#else
#set ($unassignedUsersString = "$unassignedUsersString#displayNotificationEventUser($username, false)")
#end
#end
#set ($localizationId = "taskmanager.events.taskChangedEvent.details.assignee.unassigned" )
#set ($eventText = "$eventText$services.localization.render($localizationId, 'xhtml/1.0', $localizationParams)" )
#set ($eventText = $eventText.replace('__unassignedUsers__', $!unassignedUsersString))
#end
#end
#if ($localizationParams.isEmpty())
## Default branch output.
#set ($localizationId = "taskmanager.events.taskChangedEvent.details.${customEventInfo['type']}" )
#set ($eventText = $services.localization.render($localizationId, 'xhtml/1.0', $localizationParams) )
#end
#end

#macro (getDueDateDescription $customEventInfo $eventText)
## Send different messages if the due date was extended or reduced.
## The date is displayed using the format configured in datemacro.
#set ($displayDateFormat = $services.datemacro.configuration.displayDateFormat)
#set ($displayDateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern($displayDateFormat))
#if ($customEventInfo['previousValue'])
#if (!$customEventInfo['currentValue'])
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.none')
#elseif ($customEventInfo['previousValue'] < $customEventInfo['currentValue'])
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.later')
#else
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.earlier')
#end
#set ($customEventInfo['previousValue'] =
$!escapetool.xml($displayDateFormatter.print(
$xwiki.jodatime.getDateTime($customEventInfo['previousValue'])
))
)
#end
#if ($customEventInfo['currentValue'])
#set ($customEventInfo['currentValue'] =
$!escapetool.xml($displayDateFormatter.print(
$xwiki.jodatime.getDateTime($customEventInfo['currentValue'])
))
)
#end
#getGenericFieldDescription($customEventInfo $eventText)
#end
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

package com.xwiki.task.internal.notifications.taskchanged;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Named;
Expand Down Expand Up @@ -54,6 +56,8 @@
@Named("com.xwiki.task.internal.notifications.taskchanged.TaskChangedEventListener")
public class TaskChangedEventListener extends AbstractEventListener
{
static final String USER_SEPARATOR = ",";

@Inject
private WatchedEntityFactory watchedEntityFactory;

Expand Down Expand Up @@ -89,10 +93,18 @@ public void onEvent(Event event, Object source, Object data)
}
WatchedLocationReference docRef =
watchedEntityFactory.createWatchedLocationReference(taskChangedEvent.getDocument().getDocumentReference());
// In order to receive notifications, watch the task page for the newly assigned user.
watchTask(docRef, (String) taskChangedEvent.getCurrentValue());
// In order to stop receiving notifications, unwatch the task page for the unassigned user.
unwatchTask(docRef, (String) taskChangedEvent.getPreviousValue());
Set<String> oldUsers = null == taskChangedEvent.getPreviousValue() ? Set.of()
: Set.of(((String) taskChangedEvent.getPreviousValue()).split(USER_SEPARATOR));
Set<String> newUsers = null == taskChangedEvent.getCurrentValue() ? Set.of()
: Set.of(((String) taskChangedEvent.getCurrentValue()).split(USER_SEPARATOR));
// In order to receive notifications, watch the task page for the newly assigned users.
Set<String> tempSet = new HashSet<>(newUsers);
tempSet.removeAll(oldUsers);
tempSet.forEach(username -> watchTask(docRef, username));
// In order to stop receiving notifications, unwatch the task page for the unassigned users.
tempSet = new HashSet<>(oldUsers);
tempSet.removeAll(newUsers);
tempSet.forEach(username -> unwatchTask(docRef, username));
}

private boolean hasTaskNotificationPreferenceEnabled(DocumentReference user)
Expand All @@ -104,9 +116,8 @@ private boolean hasTaskNotificationPreferenceEnabled(DocumentReference user)
preference -> preference.isNotificationEnabled() && TaskChangedEvent.class.getCanonicalName()
.equals(preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE)));
} catch (NotificationException e) {
logger.warn(
"Failed to retrieve the notification preferences for user [{}]. Cause: [{}].",
user, ExceptionUtils.getRootCauseMessage(e));
logger.warn("Failed to retrieve the notification preferences for user [{}]. Cause: [{}].", user,
ExceptionUtils.getRootCauseMessage(e));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,75 +79,14 @@
</property>
<property>
<notificationTemplate>#template('notification/macros.vm')

#set ($mainIcon = 'list')
#set ($smallIcon = '')

#macro (getGenericFieldDescription $customEventInfo $eventText)
## The notification text will be available in `$eventText` after calling this macro.
#set ($localizationParams = [
$customEventInfo['currentValue'],
$customEventInfo['previousValue']
])
#set ($localizationId = "taskmanager.events.taskChangedEvent.details.${customEventInfo['type']}" )
#set ($eventText = $services.localization.render($localizationId, 'xhtml/1.0', $localizationParams))
#end

#macro (getAssigneeDescription $customEventInfo $eventText)
#if ("$!customEventInfo['currentValue']" == '')
#if ($customEventInfo['previousValue'] == $xwiki.getUser().getUser().getFullName())
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.you.unassigned')
#else
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.none')
#end
#elseif ($customEventInfo['currentValue'] == $xwiki.getUser().getUser().getFullName())
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.you.assigned')
#end
#set ($localizationParams = [
'__currentUser__',
'__previousUser__'
])
#set ($localizationId = "taskmanager.events.taskChangedEvent.details.${customEventInfo['type']}" )
#set ($eventText = $services.localization.render($localizationId, 'xhtml/1.0', $localizationParams) )
#set ($eventText = $eventText.replace('__currentUser__', $!xwiki.getUserName($customEventInfo['currentValue'])))
#set ($eventText = $eventText.replace('__previousUser__', $!xwiki.getUserName($customEventInfo['previousValue'])))
#end

#macro (getDueDateDescription $customEventInfo $eventText)
## Send different messages if the due date was extended or reduced.
## The date is displayed using the format configured in datemacro.
#set ($displayDateFormat = $services.datemacro.configuration.displayDateFormat)
#set ($displayDateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern($displayDateFormat))
#if ($customEventInfo['previousValue'])
#if (!$customEventInfo['currentValue'])
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.none')
#elseif ($customEventInfo['previousValue'] &lt; $customEventInfo['currentValue'])
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.later')
#else
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.earlier')
#end
#set ($customEventInfo['previousValue'] =
$!escapetool.xml($displayDateFormatter.print(
$xwiki.jodatime.getDateTime($customEventInfo['previousValue'])
))
)
#end
#if ($customEventInfo['currentValue'])
#set ($customEventInfo['currentValue'] =
$!escapetool.xml($displayDateFormatter.print(
$xwiki.jodatime.getDateTime($customEventInfo['currentValue'])
))
)
#end
#getGenericFieldDescription($customEventInfo $eventText)
#end
#template('taskManagerProNotificationRendererCommons.vm')

#macro (displayEventDetails $event)
#set ($customEventInfo = $jsontool.fromString($event.getBody()))
#set ($diffUrl = $xwiki.getURL($event.document, 'view', "viewer=changes&amp;rev2=${event.documentVersion}"))
#set ($eventText = '')
#if ($customEventInfo['type'] == 'assignee')
#getAssigneeDescription($customEventInfo $eventText)
#getAssigneeDescription($customEventInfo $eventText '')
#elseif ($customEventInfo['type'] == 'duedate')
#getDueDateDescription($customEventInfo $eventText)
#else
Expand Down Expand Up @@ -264,75 +203,14 @@
</property>
<property>
<htmlTemplate>#template('notification/email/macros.vm')

#set ($mainIcon = 'list')
#set ($smallIcon = '')

#macro (getGenericFieldDescription $customEventInfo $eventText)
## The notification text will be available in `$eventText` after calling this macro.
#set ($localizationParams = [
$customEventInfo['currentValue'],
$customEventInfo['previousValue']
])
#set ($localizationId = "taskmanager.events.taskChangedEvent.details.${customEventInfo['type']}" )
#set ($eventText = $services.localization.render($localizationId, 'xhtml/1.0', $localizationParams))
#end

#macro (getAssigneeDescription $customEventInfo $eventText)
#if ("$!customEventInfo['currentValue']" == '')
#if ($customEventInfo['previousValue'] == $xwiki.getUser().getUser().getFullName())
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.you.unassigned')
#else
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.none')
#end
#elseif ($customEventInfo['currentValue'] == $xwiki.getUser().getUser().getFullName())
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.you.assigned')
#end
#set ($localizationParams = [
'__currentUser__',
'__previousUser__'
])
#set ($localizationId = "taskmanager.events.taskChangedEvent.details.${customEventInfo['type']}" )
#set ($eventText = $services.localization.render($localizationId, 'xhtml/1.0', $localizationParams) )
#set ($eventText = $eventText.replace('__currentUser__', $!xwiki.getUserName($customEventInfo['currentValue'])))
#set ($eventText = $eventText.replace('__previousUser__', $!xwiki.getUserName($customEventInfo['previousValue'])))
#end

#macro (getDueDateDescription $customEventInfo $eventText)
## Send different messages if the due date was extended or reduced.
## The date is displayed using the format configured in datemacro.
#set ($displayDateFormat = $services.datemacro.configuration.displayDateFormat)
#set ($displayDateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern($displayDateFormat))
#if ($customEventInfo['previousValue'])
#if (!$customEventInfo['currentValue'])
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.none')
#elseif ($customEventInfo['previousValue'] &lt; $customEventInfo['currentValue'])
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.later')
#else
#set ($customEventInfo['type'] = $customEventInfo['type'] + '.earlier')
#end
#set ($customEventInfo['previousValue'] =
$!escapetool.xml($displayDateFormatter.print(
$xwiki.jodatime.getDateTime($customEventInfo['previousValue'])
))
)
#end
#if ($customEventInfo['currentValue'])
#set ($customEventInfo['currentValue'] =
$!escapetool.xml($displayDateFormatter.print(
$xwiki.jodatime.getDateTime($customEventInfo['currentValue'])
))
)
#end
#getGenericFieldDescription($customEventInfo $eventText)
#end
#template('taskManagerProNotificationRendererCommons.vm')

#macro (displayTaskChangedEventDetails $event)
#set ($customEventInfo = $jsontool.fromString($event.getBody()))
#set ($diffUrl = $xwiki.getURL($event.document, 'view', "viewer=changes&amp;rev2=${event.documentVersion}"))
#set ($eventText = '')
#if ($customEventInfo['type'] == 'assignee')
#getAssigneeDescription($customEventInfo $eventText)
#getAssigneeDescription($customEventInfo $eventText 'email')
#elseif ($customEventInfo['type'] == 'duedate')
#getDueDateDescription($customEventInfo $eventText)
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ taskmanager.events.taskChangedEvent.details.duedate.earlier=Deadline reduced fro
taskmanager.events.taskChangedEvent.details.assignee.you.assigned=You were assigned
taskmanager.events.taskChangedEvent.details.assignee.you.unassigned=You were unassigned
taskmanager.events.taskChangedEvent.details.assignee.none=Nobody is assigned
taskmanager.events.taskChangedEvent.details.assignee=Assignee changed from {1} to {0}
taskmanager.events.taskChangedEvent.details.assignee=Assignee changed
taskmanager.events.taskChangedEvent.details.assignee.assigned=Assigned: {0}
taskmanager.events.taskChangedEvent.details.assignee.unassigned=Unassigned: {0}
taskmanager.events.taskChangedEvent.details.severity=Priority changed from {1} to {0}
taskmanager.events.taskChangedEvent.details.project=This task was assigned to project {0}
taskmanager.events.taskChangedEvent.details.progress=Progress changed from {1} to {0}
Expand Down