Notifications: remove pending notifications if duedate is changed
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
committed by
Julius Härtl
parent
f8c9bc1c7c
commit
6a575baadd
@@ -23,21 +23,31 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
use OC\Notification\Notification;
|
|
||||||
use OCP\AppFramework\Db\Entity;
|
use OCP\AppFramework\Db\Entity;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
use OCP\Notification\IManager;
|
||||||
|
|
||||||
|
|
||||||
class CardMapper extends DeckMapper implements IPermissionMapper {
|
class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||||
|
|
||||||
|
/** @var LabelMapper */
|
||||||
private $labelMapper;
|
private $labelMapper;
|
||||||
|
/** @var IUserManager */
|
||||||
private $userManager;
|
private $userManager;
|
||||||
|
/** @var Manager */
|
||||||
|
private $notificationManager;
|
||||||
|
|
||||||
public function __construct(IDBConnection $db, LabelMapper $labelMapper, IUserManager $userManager) {
|
public function __construct(
|
||||||
|
IDBConnection $db,
|
||||||
|
LabelMapper $labelMapper,
|
||||||
|
IUserManager $userManager,
|
||||||
|
IManager $notificationManager
|
||||||
|
) {
|
||||||
parent::__construct($db, 'deck_cards', '\OCA\Deck\Db\Card');
|
parent::__construct($db, 'deck_cards', '\OCA\Deck\Db\Card');
|
||||||
$this->labelMapper = $labelMapper;
|
$this->labelMapper = $labelMapper;
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
|
$this->notificationManager = $notificationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert(Entity $entity) {
|
public function insert(Entity $entity) {
|
||||||
@@ -55,10 +65,13 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
$existing = $this->find($entity->getId());
|
$existing = $this->find($entity->getId());
|
||||||
if ($existing->getDuedate() !== $entity->getDuedate())
|
if ($existing->getDuedate() !== $entity->getDuedate())
|
||||||
$entity->setNotified(false);
|
$entity->setNotified(false);
|
||||||
|
// remove pending notifications
|
||||||
|
$notification = $this->notificationManager->createNotification();
|
||||||
|
$notification
|
||||||
|
->setApp('deck')
|
||||||
|
->setObject('card', $entity->getId());
|
||||||
|
$this->notificationManager->markProcessed($notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: also remove pending notifications
|
|
||||||
|
|
||||||
return parent::update($entity);
|
return parent::update($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +88,7 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
public function find($id) {
|
public function find($id) {
|
||||||
$sql = 'SELECT * FROM `*PREFIX*deck_cards` ' .
|
$sql = 'SELECT * FROM `*PREFIX*deck_cards` ' .
|
||||||
'WHERE `id` = ?';
|
'WHERE `id` = ?';
|
||||||
|
/** @var Card $card */
|
||||||
$card = $this->findEntity($sql, [$id]);
|
$card = $this->findEntity($sql, [$id]);
|
||||||
$labels = $this->labelMapper->findAssignedLabelsForCard($card->id);
|
$labels = $this->labelMapper->findAssignedLabelsForCard($card->id);
|
||||||
$card->setLabels($labels);
|
$card->setLabels($labels);
|
||||||
|
|||||||
@@ -52,11 +52,13 @@ class NotificationHelper {
|
|||||||
CardMapper $cardMapper,
|
CardMapper $cardMapper,
|
||||||
BoardMapper $boardMapper,
|
BoardMapper $boardMapper,
|
||||||
IManager $notificationManager,
|
IManager $notificationManager,
|
||||||
|
IGroupManager $groupManager,
|
||||||
$userId
|
$userId
|
||||||
) {
|
) {
|
||||||
$this->cardMapper = $cardMapper;
|
$this->cardMapper = $cardMapper;
|
||||||
$this->boardMapper = $boardMapper;
|
$this->boardMapper = $boardMapper;
|
||||||
$this->notificationManager = $notificationManager;
|
$this->notificationManager = $notificationManager;
|
||||||
|
$this->groupManager = $groupManager;
|
||||||
$this->currentUser = $userId;
|
$this->currentUser = $userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +102,6 @@ class NotificationHelper {
|
|||||||
$this->notificationManager->notify($notification);
|
$this->notificationManager->notify($notification);
|
||||||
}
|
}
|
||||||
if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
|
if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
|
||||||
$this->groupManager = \OC::$server->getGroupManager();
|
|
||||||
$group = $this->groupManager->get($acl->getParticipant());
|
$group = $this->groupManager->get($acl->getParticipant());
|
||||||
foreach ($group->getUsers() as $user) {
|
foreach ($group->getUsers() as $user) {
|
||||||
$notification = $this->generateBoardShared($board, $user->getUID());
|
$notification = $this->generateBoardShared($board, $user->getUID());
|
||||||
@@ -139,7 +140,7 @@ class NotificationHelper {
|
|||||||
$users[] = $acl->getParticipant();
|
$users[] = $acl->getParticipant();
|
||||||
}
|
}
|
||||||
if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
|
if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
|
||||||
$group = \OC::$server->getGroupManager()->get($acl->getParticipant());
|
$group = $this->groupManager->get($acl->getParticipant());
|
||||||
/** @var IUser $user */
|
/** @var IUser $user */
|
||||||
foreach ($group->getUsers() as $user) {
|
foreach ($group->getUsers() as $user) {
|
||||||
$users[] = $user->getUID();
|
$users[] = $user->getUID();
|
||||||
|
|||||||
Reference in New Issue
Block a user