mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-18 05:20:50 +01:00
Also check the expiration on all other renderings
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
23351fa096
commit
da768a715d
7 changed files with 56 additions and 7 deletions
|
|
@ -466,7 +466,7 @@ class ChatController extends AEnvironmentAwareController {
|
|||
$this->preloadShares($comments);
|
||||
|
||||
$i = 0;
|
||||
$now = $this->timeFactory->getDateTime('now', new \DateTimeZone('UTC'));
|
||||
$now = $this->timeFactory->getDateTime();
|
||||
$messages = $commentIdToIndex = $parentIds = [];
|
||||
foreach ($comments as $comment) {
|
||||
$id = (int) $comment->getId();
|
||||
|
|
@ -475,7 +475,8 @@ class ChatController extends AEnvironmentAwareController {
|
|||
|
||||
$expireDate = $message->getComment()->getExpireDate();
|
||||
if ($expireDate instanceof \DateTime && $expireDate < $now) {
|
||||
$message->setVisibility(false);
|
||||
$commentIdToIndex[$id] = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$message->getVisibility()) {
|
||||
|
|
@ -528,6 +529,12 @@ class ChatController extends AEnvironmentAwareController {
|
|||
continue;
|
||||
}
|
||||
|
||||
$expireDate = $message->getComment()->getExpireDate();
|
||||
if ($expireDate instanceof \DateTime && $expireDate < $now) {
|
||||
$commentIdToIndex[$id] = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
$loadedParents[$parentId] = [
|
||||
'id' => (int) $parentId,
|
||||
'deleted' => true,
|
||||
|
|
@ -852,6 +859,12 @@ class ChatController extends AEnvironmentAwareController {
|
|||
|
||||
$this->messageParser->parseMessage($message);
|
||||
|
||||
$now = $this->timeFactory->getDateTime();
|
||||
$expireDate = $message->getComment()->getExpireDate();
|
||||
if ($expireDate instanceof \DateTime && $expireDate < $now) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$message->getVisibility()) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -655,6 +655,12 @@ class RoomController extends AEnvironmentAwareController {
|
|||
return [];
|
||||
}
|
||||
|
||||
$now = $this->timeFactory->getDateTime();
|
||||
$expireDate = $message->getComment()->getExpireDate();
|
||||
if ($expireDate instanceof \DateTime && $expireDate < $now) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $message->toArray($this->getResponseFormat());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ use OCA\Talk\Participant;
|
|||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\AvatarService;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Comments\IComment;
|
||||
use OCP\Dashboard\IAPIWidget;
|
||||
use OCP\Dashboard\IButtonWidget;
|
||||
|
|
@ -56,6 +57,7 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
|
|||
protected AvatarService $avatarService;
|
||||
protected ParticipantService $participantService;
|
||||
protected MessageParser $messageParser;
|
||||
protected ITimeFactory $timeFactory;
|
||||
|
||||
public function __construct(
|
||||
IUserSession $userSession,
|
||||
|
|
@ -65,7 +67,8 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
|
|||
Manager $manager,
|
||||
AvatarService $avatarService,
|
||||
ParticipantService $participantService,
|
||||
MessageParser $messageParser
|
||||
MessageParser $messageParser,
|
||||
ITimeFactory $timeFactory
|
||||
) {
|
||||
$this->userSession = $userSession;
|
||||
$this->talkConfig = $talkConfig;
|
||||
|
|
@ -75,6 +78,7 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
|
|||
$this->avatarService = $avatarService;
|
||||
$this->participantService = $participantService;
|
||||
$this->messageParser = $messageParser;
|
||||
$this->timeFactory = $timeFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -183,7 +187,11 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
|
|||
if ($lastMessage instanceof IComment) {
|
||||
$message = $this->messageParser->createMessage($room, $participant, $room->getLastMessage(), $this->l10n);
|
||||
$this->messageParser->parseMessage($message);
|
||||
if ($message->getVisibility()) {
|
||||
|
||||
$now = $this->timeFactory->getDateTime();
|
||||
$expireDate = $message->getComment()->getExpireDate();
|
||||
if ((!$expireDate instanceof \DateTime || $expireDate >= $now)
|
||||
&& $message->getVisibility()) {
|
||||
$placeholders = $replacements = [];
|
||||
|
||||
foreach ($message->getMessageParameters() as $placeholder => $parameter) {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ use OCA\Talk\Participant;
|
|||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCA\Talk\Webinary;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\Comments\NotFoundException;
|
||||
use OCP\HintException;
|
||||
|
|
@ -68,6 +69,7 @@ class Notifier implements INotifier {
|
|||
protected INotificationManager $notificationManager;
|
||||
protected ICommentsManager $commentManager;
|
||||
protected MessageParser $messageParser;
|
||||
protected ITimeFactory $timeFactory;
|
||||
protected Definitions $definitions;
|
||||
protected AddressHandler $addressHandler;
|
||||
|
||||
|
|
@ -87,6 +89,7 @@ class Notifier implements INotifier {
|
|||
INotificationManager $notificationManager,
|
||||
CommentsManager $commentManager,
|
||||
MessageParser $messageParser,
|
||||
ITimeFactory $timeFactory,
|
||||
Definitions $definitions,
|
||||
AddressHandler $addressHandler) {
|
||||
$this->lFactory = $lFactory;
|
||||
|
|
@ -100,6 +103,7 @@ class Notifier implements INotifier {
|
|||
$this->notificationManager = $notificationManager;
|
||||
$this->commentManager = $commentManager;
|
||||
$this->messageParser = $messageParser;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->definitions = $definitions;
|
||||
$this->addressHandler = $addressHandler;
|
||||
}
|
||||
|
|
@ -385,6 +389,12 @@ class Notifier implements INotifier {
|
|||
throw new AlreadyProcessedException();
|
||||
}
|
||||
|
||||
$now = $this->timeFactory->getDateTime();
|
||||
$expireDate = $message->getComment()->getExpireDate();
|
||||
if ($expireDate instanceof \DateTime && $expireDate < $now) {
|
||||
throw new AlreadyProcessedException();
|
||||
}
|
||||
|
||||
if ($message->getMessageType() === ChatManager::VERB_MESSAGE_DELETED) {
|
||||
throw new AlreadyProcessedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use OCA\Talk\Model\Attendee;
|
|||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCA\Talk\Webinary;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Comments\IComment;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
|
|
@ -47,6 +48,7 @@ class MessageSearch implements IProvider {
|
|||
protected ParticipantService $participantService;
|
||||
protected ChatManager $chatManager;
|
||||
protected MessageParser $messageParser;
|
||||
protected ITimeFactory $timeFactory;
|
||||
protected IURLGenerator $url;
|
||||
protected IL10N $l;
|
||||
|
||||
|
|
@ -55,6 +57,7 @@ class MessageSearch implements IProvider {
|
|||
ParticipantService $participantService,
|
||||
ChatManager $chatManager,
|
||||
MessageParser $messageParser,
|
||||
ITimeFactory $timeFactory,
|
||||
IURLGenerator $url,
|
||||
IL10N $l
|
||||
) {
|
||||
|
|
@ -62,6 +65,7 @@ class MessageSearch implements IProvider {
|
|||
$this->participantService = $participantService;
|
||||
$this->chatManager = $chatManager;
|
||||
$this->messageParser = $messageParser;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->url = $url;
|
||||
$this->l = $l;
|
||||
}
|
||||
|
|
@ -194,8 +198,13 @@ class MessageSearch implements IProvider {
|
|||
$messageStr = '…' . mb_substr($messageStr, $matchPosition - 10);
|
||||
}
|
||||
|
||||
$now = $this->timeFactory->getDateTime();
|
||||
$expireDate = $message->getComment()->getExpireDate();
|
||||
if ($expireDate instanceof \DateTime && $expireDate < $now) {
|
||||
throw new UnauthorizedException('Expired');
|
||||
}
|
||||
|
||||
if (!$message->getVisibility()) {
|
||||
$commentIdToIndex[$id] = null;
|
||||
throw new UnauthorizedException('Not visible');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\SpreedCheats\Controller;
|
||||
|
||||
use OCA\Talk\BackgroundJob\ExpireChatMessages;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IDBConnection;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ use OCA\Talk\Notification\Notifier;
|
|||
use OCA\Talk\Participant;
|
||||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Comments\IComment;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
|
|
@ -72,6 +73,8 @@ class NotifierTest extends TestCase {
|
|||
protected $commentsManager;
|
||||
/** @var MessageParser|MockObject */
|
||||
protected $messageParser;
|
||||
/** @var ITimeFactory|MockObject */
|
||||
protected $timeFactory;
|
||||
/** @var Definitions|MockObject */
|
||||
protected $definitions;
|
||||
protected ?Notifier $notifier = null;
|
||||
|
|
@ -92,6 +95,7 @@ class NotifierTest extends TestCase {
|
|||
$this->notificationManager = $this->createMock(INotificationManager::class);
|
||||
$this->commentsManager = $this->createMock(CommentsManager::class);
|
||||
$this->messageParser = $this->createMock(MessageParser::class);
|
||||
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
||||
$this->definitions = $this->createMock(Definitions::class);
|
||||
$this->addressHandler = $this->createMock(AddressHandler::class);
|
||||
|
||||
|
|
@ -107,6 +111,7 @@ class NotifierTest extends TestCase {
|
|||
$this->notificationManager,
|
||||
$this->commentsManager,
|
||||
$this->messageParser,
|
||||
$this->timeFactory,
|
||||
$this->definitions,
|
||||
$this->addressHandler
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue