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;
|
||||
|
||||
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);
|
||||
|
||||
@@ -52,11 +52,13 @@ class NotificationHelper {
|
||||
CardMapper $cardMapper,
|
||||
BoardMapper $boardMapper,
|
||||
IManager $notificationManager,
|
||||
IGroupManager $groupManager,
|
||||
$userId
|
||||
) {
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->boardMapper = $boardMapper;
|
||||
$this->notificationManager = $notificationManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->currentUser = $userId;
|
||||
}
|
||||
|
||||
@@ -100,7 +102,6 @@ class NotificationHelper {
|
||||
$this->notificationManager->notify($notification);
|
||||
}
|
||||
if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
|
||||
$this->groupManager = \OC::$server->getGroupManager();
|
||||
$group = $this->groupManager->get($acl->getParticipant());
|
||||
foreach ($group->getUsers() as $user) {
|
||||
$notification = $this->generateBoardShared($board, $user->getUID());
|
||||
@@ -139,7 +140,7 @@ class NotificationHelper {
|
||||
$users[] = $acl->getParticipant();
|
||||
}
|
||||
if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
|
||||
$group = \OC::$server->getGroupManager()->get($acl->getParticipant());
|
||||
$group = $this->groupManager->get($acl->getParticipant());
|
||||
/** @var IUser $user */
|
||||
foreach ($group->getUsers() as $user) {
|
||||
$users[] = $user->getUID();
|
||||
|
||||
Reference in New Issue
Block a user