Make use of notification setting when sending out due date notifications
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -24,14 +24,18 @@
|
|||||||
namespace OCA\Deck\Notification;
|
namespace OCA\Deck\Notification;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use OCA\Deck\AppInfo\Application;
|
||||||
use OCA\Deck\Db\Acl;
|
use OCA\Deck\Db\Acl;
|
||||||
|
use OCA\Deck\Db\AssignedUsersMapper;
|
||||||
use OCA\Deck\Db\Board;
|
use OCA\Deck\Db\Board;
|
||||||
use OCA\Deck\Db\BoardMapper;
|
use OCA\Deck\Db\BoardMapper;
|
||||||
use OCA\Deck\Db\CardMapper;
|
use OCA\Deck\Db\CardMapper;
|
||||||
|
use OCA\Deck\Db\User;
|
||||||
|
use OCA\Deck\Service\ConfigService;
|
||||||
use OCA\Deck\Service\PermissionService;
|
use OCA\Deck\Service\PermissionService;
|
||||||
use OCP\Comments\IComment;
|
use OCP\Comments\IComment;
|
||||||
|
use OCP\IConfig;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
use OCP\IUser;
|
|
||||||
use OCP\Notification\IManager;
|
use OCP\Notification\IManager;
|
||||||
|
|
||||||
class NotificationHelper {
|
class NotificationHelper {
|
||||||
@@ -40,8 +44,12 @@ class NotificationHelper {
|
|||||||
protected $cardMapper;
|
protected $cardMapper;
|
||||||
/** @var BoardMapper */
|
/** @var BoardMapper */
|
||||||
protected $boardMapper;
|
protected $boardMapper;
|
||||||
|
/** @var AssignedUsersMapper */
|
||||||
|
protected $assignedUsersMapper;
|
||||||
/** @var PermissionService */
|
/** @var PermissionService */
|
||||||
protected $permissionService;
|
protected $permissionService;
|
||||||
|
/** @var IConfig */
|
||||||
|
protected $config;
|
||||||
/** @var IManager */
|
/** @var IManager */
|
||||||
protected $notificationManager;
|
protected $notificationManager;
|
||||||
/** @var IGroupManager */
|
/** @var IGroupManager */
|
||||||
@@ -54,14 +62,18 @@ class NotificationHelper {
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
CardMapper $cardMapper,
|
CardMapper $cardMapper,
|
||||||
BoardMapper $boardMapper,
|
BoardMapper $boardMapper,
|
||||||
|
AssignedUsersMapper $assignedUsersMapper,
|
||||||
PermissionService $permissionService,
|
PermissionService $permissionService,
|
||||||
|
IConfig $config,
|
||||||
IManager $notificationManager,
|
IManager $notificationManager,
|
||||||
IGroupManager $groupManager,
|
IGroupManager $groupManager,
|
||||||
$userId
|
$userId
|
||||||
) {
|
) {
|
||||||
$this->cardMapper = $cardMapper;
|
$this->cardMapper = $cardMapper;
|
||||||
$this->boardMapper = $boardMapper;
|
$this->boardMapper = $boardMapper;
|
||||||
|
$this->assignedUsersMapper = $assignedUsersMapper;
|
||||||
$this->permissionService = $permissionService;
|
$this->permissionService = $permissionService;
|
||||||
|
$this->config = $config;
|
||||||
$this->notificationManager = $notificationManager;
|
$this->notificationManager = $notificationManager;
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
$this->currentUser = $userId;
|
$this->currentUser = $userId;
|
||||||
@@ -83,18 +95,24 @@ class NotificationHelper {
|
|||||||
// TODO: Once assigning users is possible, those should be notified instead of all users of the board
|
// TODO: Once assigning users is possible, those should be notified instead of all users of the board
|
||||||
$boardId = $this->cardMapper->findBoardId($card->getId());
|
$boardId = $this->cardMapper->findBoardId($card->getId());
|
||||||
$board = $this->getBoard($boardId);
|
$board = $this->getBoard($boardId);
|
||||||
/** @var IUser $user */
|
/** @var User $user */
|
||||||
foreach ($this->permissionService->findUsers($boardId) as $user) {
|
foreach ($this->permissionService->findUsers($boardId) as $user) {
|
||||||
$notification = $this->notificationManager->createNotification();
|
$notificationSetting = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'board:' . $boardId . ':notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_DEFAULT);
|
||||||
$notification
|
if (
|
||||||
->setApp('deck')
|
$notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL ||
|
||||||
->setUser((string) $user->getUID())
|
($notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED && $this->assignedUsersMapper->isUserAssigned($card->getId(), $user->getUID()))
|
||||||
->setObject('card', $card->getId())
|
) {
|
||||||
->setSubject('card-overdue', [
|
$notification = $this->notificationManager->createNotification();
|
||||||
$card->getTitle(), $board->getTitle()
|
$notification
|
||||||
])
|
->setApp('deck')
|
||||||
->setDateTime(new DateTime($card->getDuedate()));
|
->setUser((string)$user->getUID())
|
||||||
$this->notificationManager->notify($notification);
|
->setObject('card', $card->getId())
|
||||||
|
->setSubject('card-overdue', [
|
||||||
|
$card->getTitle(), $board->getTitle()
|
||||||
|
])
|
||||||
|
->setDateTime(new DateTime($card->getDuedate()));
|
||||||
|
$this->notificationManager->notify($notification);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->cardMapper->markNotified($card);
|
$this->cardMapper->markNotified($card);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user