Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Mattos <vitor@php.rio>2022-07-22 15:24:08 +0300
committerVitor Mattos <vitor@php.rio>2022-07-22 15:24:08 +0300
commit19d57f5ab6b6338b2e19374e036926a546181c2d (patch)
tree9beeb90a48724c9e8baaed6c21ee629a9a6b2758
parentc36cab3f5540ae6550480fb5d587c12e1e7a1bb6 (diff)
Expire shared link when expire message
Signed-off-by: Vitor Mattos <vitor@php.rio>
-rw-r--r--lib/Chat/ChatManager.php2
-rw-r--r--lib/Chat/SystemMessage/Listener.php29
-rw-r--r--tests/integration/features/chat/message-expiration.feature16
3 files changed, 47 insertions, 0 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index 64d5ceba9..08359f004 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -176,6 +176,8 @@ class ChatManager {
$comment->setVerb(self::VERB_SYSTEM);
}
+ $this->setMessageExpiration($chat, $comment);
+
$event = new ChatEvent($chat, $comment, $shouldSkipLastMessageUpdate);
$this->dispatcher->dispatch(self::EVENT_BEFORE_SYSTEM_MESSAGE_SEND, $event);
try {
diff --git a/lib/Chat/SystemMessage/Listener.php b/lib/Chat/SystemMessage/Listener.php
index 61859a1f0..ef012cb3f 100644
--- a/lib/Chat/SystemMessage/Listener.php
+++ b/lib/Chat/SystemMessage/Listener.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace OCA\Talk\Chat\SystemMessage;
+use DateInterval;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Events\AddParticipantsEvent;
use OCA\Talk\Events\AttendeesAddedEvent;
@@ -91,6 +92,7 @@ class Listener implements IEventListener {
$dispatcher->addListener(Room::EVENT_AFTER_USERS_ADD, self::class . '::addSystemMessageUserAdded');
$dispatcher->addListener(Room::EVENT_AFTER_USER_REMOVE, self::class . '::sendSystemMessageUserRemoved');
$dispatcher->addListener(Room::EVENT_AFTER_PARTICIPANT_TYPE_SET, self::class . '::sendSystemMessageAboutPromoteOrDemoteModerator');
+ $dispatcher->addListener('OCP\Share::preShare', self::class . '::setShareExpiration');
$dispatcher->addListener('OCP\Share::postShare', self::class . '::fixMimeTypeOfVoiceMessage');
$dispatcher->addListener(RoomShareProvider::EVENT_SHARE_FILE_AGAIN, self::class . '::fixMimeTypeOfVoiceMessage');
$dispatcher->addListener(Room::EVENT_AFTER_SET_MESSAGE_EXPIRATION, self::class . '::afterSetMessageExpiration');
@@ -330,6 +332,33 @@ class Listener implements IEventListener {
* @param GenericEvent|Event $event
* @return void
*/
+ public static function setShareExpiration($event): void {
+ /** @var IShare $share */
+ $share = $event->getSubject();
+
+ if ($share->getShareType() !== IShare::TYPE_ROOM) {
+ return;
+ }
+
+ $listener = Server::get(self::class);
+ $manager = Server::get(Manager::class);
+
+ $room = $manager->getRoomByToken($share->getSharedWith());
+
+ $messageExpiration = $room->getMessageExpiration();
+ if (!$messageExpiration) {
+ return;
+ }
+
+ $dateTime = $listener->timeFactory->getDateTime();
+ $dateTime->add(DateInterval::createFromDateString($messageExpiration . ' seconds'));
+ $share->setExpirationDate($dateTime);
+ }
+
+ /**
+ * @param GenericEvent|Event $event
+ * @return void
+ */
public static function fixMimeTypeOfVoiceMessage($event): void {
/** @var IShare $share */
$share = $event->getSubject();
diff --git a/tests/integration/features/chat/message-expiration.feature b/tests/integration/features/chat/message-expiration.feature
index 00fbbf8c5..93f56933c 100644
--- a/tests/integration/features/chat/message-expiration.feature
+++ b/tests/integration/features/chat/message-expiration.feature
@@ -23,3 +23,19 @@ Feature: room/message-expiration
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant1 | participant1-displayname | Message 1 | [] | |
+
+ Scenario: Expire shared file
+ Given user "participant1" creates room "room2" (v4)
+ | roomType | 3 |
+ | roomName | room2 |
+ And user "participant1" set the message expiration to 3 of room "room2" with 200 (v4)
+ When user "participant1" shares "welcome.txt" with room "room2"
+ And user "participant1" sees the following messages in room "room2" with 200
+ | room | actorType | actorId | actorDisplayName | message | messageParameters |
+ | room2 | users | participant1 | participant1-displayname | {file} | "IGNORE" |
+ And wait for 3 seconds
+ And apply message expiration job manually
+ Then user "participant1" sees the following messages in room "room2" with 200
+ | room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
+ And user "participant1" gets last share
+ And the OCS status code should be 404