summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitor Mattos <vitor@php.rio>2022-07-12 08:09:41 -0300
committerVitor Mattos <vitor@php.rio>2022-07-12 08:13:02 -0300
commit92093bff12cf3e5812d6702f5182d0c890f4dd31 (patch)
tree4cd30a7f2d0d463c5cac5b6fb2740e728efe2b73
parentc7e1b5b807cf9a4bc26291ffee98e18d5947c929 (diff)
Change point of execution of ExpireChatMessage
Change job from trigged when as necessary to run all times that cron.php will be executed Signed-off-by: Vitor Mattos <vitor@php.rio>
-rw-r--r--appinfo/info.xml1
-rw-r--r--lib/Service/RoomService.php26
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php26
-rw-r--r--tests/integration/features/chat/message-expiration.feature13
4 files changed, 2 insertions, 64 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 6f7c7603d..a59f2d245 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -62,6 +62,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
<job>OCA\Talk\BackgroundJob\CheckReferenceIdColumn</job>
<job>OCA\Talk\BackgroundJob\CheckHostedSignalingServer</job>
<job>OCA\Talk\BackgroundJob\CheckMatterbridges</job>
+ <job>OCA\Talk\BackgroundJob\ExpireChatMessages</job>
</background-jobs>
<repair-steps>
diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php
index 5b63c687d..f633c8126 100644
--- a/lib/Service/RoomService.php
+++ b/lib/Service/RoomService.php
@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace OCA\Talk\Service;
use InvalidArgumentException;
-use OCA\Talk\BackgroundJob\ExpireChatMessages;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Events\ModifyLobbyEvent;
use OCA\Talk\Events\ModifyRoomEvent;
@@ -550,36 +549,11 @@ class RoomService {
$room->setMessageExpiration($seconds);
- $this->toggleJobExpireMesssageIfNecessary($seconds);
$this->addMessageExpirationSystemMessage($room, $participant, $seconds);
$this->dispatcher->dispatch(Room::EVENT_AFTER_SET_MESSAGE_EXPIRATION, $event);
}
- private function toggleJobExpireMesssageIfNecessary(int $seconds): void {
- if ($seconds > 0) {
- if (!$this->jobList->has(ExpireChatMessages::class, null)) {
- $this->jobList->add(ExpireChatMessages::class, null);
- }
- return;
- }
- $this->disableExpireMessageJobIfNecesary();
- }
-
- private function disableExpireMessageJobIfNecesary(): void {
- $qb = $this->db->getQueryBuilder();
- $qb->select($qb->func()->count('*', 'total'))
- ->from('talk_rooms')
- ->where($qb->expr()->gt('message_expiration', $qb->createNamedParameter(0)));
- $result = $qb->executeQuery();
- $count = (int) $result->fetchOne();
- $result->closeCursor();
-
- if (!$count) {
- $this->jobList->remove(ExpireChatMessages::class, null);
- }
- }
-
private function addMessageExpirationSystemMessage(Room $room, Participant $participant, int $seconds): void {
if ($seconds > 0) {
$message = 'message_expiration_enabled';
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index 07c94e047..e7d53ffe7 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -2588,32 +2588,6 @@ class FeatureContext implements Context, SnippetAcceptingContext {
sleep($seconds);
}
- /**
- * @When apply message expiration job
- */
- public function applyMessageExpirationJob(): void {
- $currentUser = $this->currentUser;
- $this->setCurrentUser('admin');
- $this->sendRequest('GET', '/apps/spreedcheats/get_message_expiration_job');
- $response = $this->getDataFromResponse($this->response);
- Assert::assertIsArray($response, 'Job not found');
- Assert::assertArrayHasKey('id', $response, 'Job not found');
- $this->runOcc(['background-job:execute', $response['id']]);
- $this->setCurrentUser($currentUser);
- }
-
- /**
- * @When message expiration job don't exists
- */
- public function messageExpirationJobDontExists(): void {
- $currentUser = $this->currentUser;
- $this->setCurrentUser('admin');
- $this->sendRequest('GET', '/apps/spreedcheats/get_message_expiration_job');
- $response = $this->getDataFromResponse($this->response);
- Assert::assertEmpty($response, 'Job found');
- $this->setCurrentUser($currentUser);
- }
-
/*
* Requests
*/
diff --git a/tests/integration/features/chat/message-expiration.feature b/tests/integration/features/chat/message-expiration.feature
index 2282ded80..00fbbf8c5 100644
--- a/tests/integration/features/chat/message-expiration.feature
+++ b/tests/integration/features/chat/message-expiration.feature
@@ -19,18 +19,7 @@ Feature: room/message-expiration
| id | type | messageExpiration |
| room | 3 | 3 |
And wait for 3 seconds
- And apply message expiration job
+ And apply message expiration job manually
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: Toggle message expiration job
- Given user "participant1" creates room "room" (v4)
- | roomType | 3 |
- | roomName | room |
- And user "participant1" adds user "participant2" to room "room" with 200 (v4)
- And user "participant1" set the message expiration to 10 of room "room" with 200 (v4)
- And apply message expiration job
- And user "participant1" set the message expiration to 0 of room "room" with 200 (v4)
- Then message expiration job don't exists