mirror of
https://github.com/nextcloud/spreed.git
synced 2025-08-16 15:27:59 +00:00
Move dismiss stored notification to specific endpoint
Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
@ -36,5 +36,7 @@ return [
|
||||
['name' => 'Recording#stop', 'url' => '/api/{apiVersion}/recording/{token}', 'verb' => 'DELETE', 'requirements' => $requirements],
|
||||
/** @see \OCA\Talk\Controller\RecordingController::store() */
|
||||
['name' => 'Recording#store', 'url' => '/api/{apiVersion}/recording/{token}/store', 'verb' => 'POST', 'requirements' => $requirements],
|
||||
/** @see \OCA\Talk\Controller\RecordingController::notificationDismiss() */
|
||||
['name' => 'Recording#notificationDismiss', 'url' => '/api/{apiVersion}/recording/{token}/notification', 'verb' => 'DELETE', 'requirements' => $requirements],
|
||||
],
|
||||
];
|
||||
|
@ -72,3 +72,20 @@
|
||||
+ `401 Unauthorized` When the validation as SIP bridge failed
|
||||
+ `404 Not Found` Room not found
|
||||
+ `429 Too Many Request` Brute force protection
|
||||
|
||||
## Dismiss store call recording notification
|
||||
|
||||
* Required capability: `recording-v1`
|
||||
* Method: `DELETE`
|
||||
* Endpoint: `/recording/{token}/notification`
|
||||
* Data:
|
||||
|
||||
| field | type | Description |
|
||||
| ---------- | ------ | --------------------------------------------------------- |
|
||||
| `dateTime` | string | The date time that notification was created. |
|
||||
|
||||
* Response:
|
||||
- Status code:
|
||||
+ `200 OK`
|
||||
+ `403 Forbidden` When the user is not a moderator/owner.
|
||||
+ `404 Not Found` Room not found
|
||||
|
@ -100,4 +100,21 @@ class RecordingController extends AEnvironmentAwareController {
|
||||
}
|
||||
return new DataResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @RequireModeratorParticipant
|
||||
*/
|
||||
public function notificationDismiss(string $token, string $dateTime): DataResponse {
|
||||
try {
|
||||
$this->recordingService->notificationDismiss(
|
||||
$token,
|
||||
$this->participant->getAttendee()->getActorId(),
|
||||
$dateTime
|
||||
);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
return new DataResponse();
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,7 @@ use OCA\Talk\Webinary;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\Comments\NotFoundException;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\HintException;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
@ -61,7 +59,6 @@ use OCP\Share\IShare;
|
||||
|
||||
class Notifier implements INotifier {
|
||||
protected IFactory $lFactory;
|
||||
private IDBConnection $db;
|
||||
protected IURLGenerator $url;
|
||||
protected Config $config;
|
||||
protected IUserManager $userManager;
|
||||
@ -83,7 +80,6 @@ class Notifier implements INotifier {
|
||||
protected array $participants = [];
|
||||
|
||||
public function __construct(IFactory $lFactory,
|
||||
IDBConnection $db,
|
||||
IURLGenerator $url,
|
||||
Config $config,
|
||||
IUserManager $userManager,
|
||||
@ -99,7 +95,6 @@ class Notifier implements INotifier {
|
||||
Definitions $definitions,
|
||||
AddressHandler $addressHandler) {
|
||||
$this->lFactory = $lFactory;
|
||||
$this->db = $db;
|
||||
$this->url = $url;
|
||||
$this->config = $config;
|
||||
$this->userManager = $userManager;
|
||||
@ -304,6 +299,7 @@ class Notifier implements INotifier {
|
||||
Participant $participant,
|
||||
IL10N $l
|
||||
): INotification {
|
||||
$parameters = $notification->getSubjectParameters();
|
||||
$shareAction = $notification->createAction()
|
||||
->setParsedLabel($l->t('Share to chat'))
|
||||
->setPrimary(true)
|
||||
@ -327,10 +323,11 @@ class Notifier implements INotifier {
|
||||
->setParsedLabel($l->t('Dismiss'))
|
||||
->setLink(
|
||||
$this->urlGenerator->linkToRouteAbsolute(
|
||||
'ocs.notifications.Endpoint.deleteNotification',
|
||||
'ocs.spreed.Recording.notificationDismiss',
|
||||
[
|
||||
'apiVersion' => 'v2',
|
||||
'id' => $this->getNotificationId($notification),
|
||||
'apiVersion' => 'v1',
|
||||
'token' => $room->getToken(),
|
||||
'dateTime' => $notification->getDateTime()->format('U'),
|
||||
]
|
||||
),
|
||||
IAction::TYPE_DELETE
|
||||
@ -352,27 +349,6 @@ class Notifier implements INotifier {
|
||||
return $notification;
|
||||
}
|
||||
|
||||
public function getNotificationId(INotification $notification): int {
|
||||
$sql = $this->db->getQueryBuilder();
|
||||
$sql->select('notification_id')
|
||||
->from('notifications')
|
||||
->andWhere($sql->expr()->eq('app',
|
||||
$sql->createNamedParameter($notification->getApp())))
|
||||
->andWhere($sql->expr()->eq('object_id',
|
||||
$sql->createNamedParameter($notification->getObjectId())))
|
||||
->andWhere($sql->expr()->eq('object_type',
|
||||
$sql->createNamedParameter($notification->getObjectType())))
|
||||
->andWhere($sql->expr()->eq('subject',
|
||||
$sql->createNamedParameter($notification->getSubject())))
|
||||
->andWhere($sql->expr()->eq('timestamp',
|
||||
$sql->createNamedParameter($notification->getDateTime()->format('U')),
|
||||
IQueryBuilder::PARAM_INT))
|
||||
->setMaxResults(1);
|
||||
|
||||
$statement = $sql->executeQuery();
|
||||
return (int) $statement->fetchOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HintException
|
||||
*/
|
||||
|
@ -29,6 +29,7 @@ use InvalidArgumentException;
|
||||
use OC\User\NoUserException;
|
||||
use OCA\Talk\Config;
|
||||
use OCA\Talk\Exceptions\ParticipantNotFoundException;
|
||||
use OCA\Talk\Manager;
|
||||
use OCA\Talk\Participant;
|
||||
use OCA\Talk\Room;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
@ -52,6 +53,7 @@ class RecordingService {
|
||||
private ParticipantService $participantService,
|
||||
private IRootFolder $rootFolder,
|
||||
private IManager $notificationManager,
|
||||
private Manager $roomManager,
|
||||
private ITimeFactory $timeFactory,
|
||||
private Config $config,
|
||||
private RoomService $roomService
|
||||
@ -172,4 +174,15 @@ class RecordingService {
|
||||
]);
|
||||
$this->notificationManager->notify($notification);
|
||||
}
|
||||
|
||||
public function notificationDismiss(string $roomToken, string $userId, string $dateTime): void {
|
||||
$room = $this->roomManager->getRoomByToken($roomToken);
|
||||
$notification = $this->notificationManager->createNotification();
|
||||
$notification->setApp('spreed')
|
||||
->setObject('chat', (string) $room->getToken())
|
||||
->setSubject('record_file_stored')
|
||||
->setDateTime($this->timeFactory->getDateTime('@' . $dateTime))
|
||||
->setUser($userId);
|
||||
$this->notificationManager->markProcessed($notification);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Comments\IComment;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
@ -54,8 +53,6 @@ use Test\TestCase;
|
||||
class NotifierTest extends TestCase {
|
||||
/** @var IFactory|MockObject */
|
||||
protected $lFactory;
|
||||
/** @var IFactory|MockObject */
|
||||
protected $db;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
protected $url;
|
||||
/** @var Config|MockObject */
|
||||
@ -90,7 +87,6 @@ class NotifierTest extends TestCase {
|
||||
parent::setUp();
|
||||
|
||||
$this->lFactory = $this->createMock(IFactory::class);
|
||||
$this->db = $this->createMock(IDBConnection::class);
|
||||
$this->url = $this->createMock(IURLGenerator::class);
|
||||
$this->config = $this->createMock(Config::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
@ -108,7 +104,6 @@ class NotifierTest extends TestCase {
|
||||
|
||||
$this->notifier = new Notifier(
|
||||
$this->lFactory,
|
||||
$this->db,
|
||||
$this->url,
|
||||
$this->config,
|
||||
$this->userManager,
|
||||
|
@ -36,6 +36,7 @@ function is_uploaded_file($filename) {
|
||||
namespace OCA\Talk\Tests\php\Service;
|
||||
|
||||
use OCA\Talk\Config;
|
||||
use OCA\Talk\Manager;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCA\Talk\Service\RecordingService;
|
||||
use OCA\Talk\Service\RoomService;
|
||||
@ -57,6 +58,8 @@ class RecordingServiceTest extends TestCase {
|
||||
private $config;
|
||||
/** @var IManager|MockObject */
|
||||
private $notificationManager;
|
||||
/** @var Manager|MockObject */
|
||||
private $roomManager;
|
||||
/** @var ITimeFactory|MockObject */
|
||||
private $timeFactory;
|
||||
/** @var RoomService|MockObject */
|
||||
@ -71,6 +74,7 @@ class RecordingServiceTest extends TestCase {
|
||||
$this->participantService = $this->createMock(ParticipantService::class);
|
||||
$this->rootFolder = $this->createMock(IRootFolder::class);
|
||||
$this->notificationManager = $this->createMock(IManager::class);
|
||||
$this->roomManager = $this->createMock(Manager::class);
|
||||
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
||||
$this->config = $this->createMock(Config::class);
|
||||
$this->roomService = $this->createMock(RoomService::class);
|
||||
@ -80,6 +84,7 @@ class RecordingServiceTest extends TestCase {
|
||||
$this->participantService,
|
||||
$this->rootFolder,
|
||||
$this->notificationManager,
|
||||
$this->roomManager,
|
||||
$this->timeFactory,
|
||||
$this->config,
|
||||
$this->roomService
|
||||
|
Reference in New Issue
Block a user