Notifications: remove pending notifications if duedate is changed

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-10-02 19:20:09 +02:00
committed by Julius Härtl
parent f8c9bc1c7c
commit 6a575baadd
2 changed files with 22 additions and 7 deletions

View File

@@ -23,21 +23,31 @@
namespace OCA\Deck\Db;
use OC\Notification\Notification;
use OCP\AppFramework\Db\Entity;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Notification\IManager;
class CardMapper extends DeckMapper implements IPermissionMapper {
/** @var LabelMapper */
private $labelMapper;
/** @var IUserManager */
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');
$this->labelMapper = $labelMapper;
$this->userManager = $userManager;
$this->notificationManager = $notificationManager;
}
public function insert(Entity $entity) {
@@ -55,10 +65,13 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
$existing = $this->find($entity->getId());
if ($existing->getDuedate() !== $entity->getDuedate())
$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);
}
@@ -75,6 +88,7 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
public function find($id) {
$sql = 'SELECT * FROM `*PREFIX*deck_cards` ' .
'WHERE `id` = ?';
/** @var Card $card */
$card = $this->findEntity($sql, [$id]);
$labels = $this->labelMapper->findAssignedLabelsForCard($card->id);
$card->setLabels($labels);