Browse Source
Make the room_id not mandatory to define the expire time
Signed-off-by: Vitor Mattos <vitor@php.rio>
pull/7571/head
Vitor Mattos
3 years ago
No known key found for this signature in database
GPG Key ID: B7AB4B76A7CA7318
7 changed files with
15 additions and
43 deletions
-
lib/BackgroundJob/ExpireChatMessages.php
-
lib/Chat/ChatManager.php
-
lib/Service/RoomService.php
-
tests/integration/features/bootstrap/FeatureContext.php
-
tests/integration/features/chat/message-expiration.feature
-
tests/integration/spreedcheats/appinfo/routes.php
-
tests/integration/spreedcheats/lib/Controller/ApiController.php
|
|
|
@ -53,19 +53,9 @@ class ExpireChatMessages extends TimedJob { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param array $argument |
|
|
|
* @inheritDoc |
|
|
|
*/ |
|
|
|
protected function run($argument): void { |
|
|
|
$this->chatManager->deleteExpiredMessages($argument['room_id']); |
|
|
|
|
|
|
|
try { |
|
|
|
$room = $this->roomManager->getRoomById($argument['room_id']); |
|
|
|
if ($room->getMessageExpiration() === 0) { |
|
|
|
// FIXME check if there are still messages to expire in the database
|
|
|
|
$this->jobList->remove(ExpireChatMessages::class, $argument); |
|
|
|
} |
|
|
|
} catch (RoomNotFoundException $e) { |
|
|
|
$this->jobList->remove(ExpireChatMessages::class, $argument); |
|
|
|
} |
|
|
|
$this->chatManager->deleteExpiredMessages(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -711,7 +711,7 @@ class ChatManager { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public function deleteExpiredMessages(int $roomId): void { |
|
|
|
public function deleteExpiredMessages(?int $roomId = null): void { |
|
|
|
$this->commentsManager->deleteCommentsExpiredAtObject('chat', (string) $roomId); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -549,7 +549,9 @@ class RoomService { |
|
|
|
$update->executeStatement(); |
|
|
|
$room->setMessageExpiration($seconds); |
|
|
|
if ($seconds > 0) { |
|
|
|
$this->jobList->add(ExpireChatMessages::class, ['room_id' => $room->getId()]); |
|
|
|
if (!$this->jobList->has(ExpireChatMessages::class, null)) { |
|
|
|
$this->jobList->add(ExpireChatMessages::class, null); |
|
|
|
} |
|
|
|
$this->addMessageExpirationSystemMessage($room, $participant, $seconds, 'message_expiration_enabled'); |
|
|
|
} else { |
|
|
|
$this->addMessageExpirationSystemMessage($room, $participant, $seconds, 'message_expiration_disabled'); |
|
|
|
|
|
|
|
@ -2589,15 +2589,15 @@ class FeatureContext implements Context, SnippetAcceptingContext { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @When apply message expiration job to room :identifier |
|
|
|
* @When apply message expiration job |
|
|
|
*/ |
|
|
|
public function applyMessageExpirationJobToRoom($identifier): void { |
|
|
|
public function applyMessageExpirationJob(): void { |
|
|
|
$currentUser = $this->currentUser; |
|
|
|
$this->setCurrentUser('admin'); |
|
|
|
$this->sendRequest('GET', '/apps/spreedcheats/get_message_expiration_job/' . self::$identifierToToken[$identifier]); |
|
|
|
$this->sendRequest('GET', '/apps/spreedcheats/get_message_expiration_job'); |
|
|
|
$response = $this->getDataFromResponse($this->response); |
|
|
|
Assert::assertIsArray($response, 'Room ' . $identifier . 'not found'); |
|
|
|
Assert::assertArrayHasKey('id', $response, 'Job not found by identifier "' . $identifier . '"'); |
|
|
|
Assert::assertIsArray($response, 'Job not found'); |
|
|
|
Assert::assertArrayHasKey('id', $response, 'Job not found'); |
|
|
|
$this->runOcc(['background-job:execute', $response['id']]); |
|
|
|
$this->setCurrentUser($currentUser); |
|
|
|
} |
|
|
|
|
|
|
|
@ -19,7 +19,7 @@ Feature: room/message-expiration |
|
|
|
| id | type | messageExpiration | |
|
|
|
| room | 3 | 3 | |
|
|
|
And wait for 3 seconds |
|
|
|
And apply message expiration job to room "room" |
|
|
|
And apply message expiration job |
|
|
|
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 | [] | | |
|
|
|
@ -26,6 +26,6 @@ declare(strict_types=1); |
|
|
|
return [ |
|
|
|
'ocs' => [ |
|
|
|
['name' => 'Api#resetSpreed', 'url' => '/', 'verb' => 'DELETE'], |
|
|
|
['name' => 'Api#getMessageExpirationJob', 'url' => '/get_message_expiration_job/{token}', 'verb' => 'GET'], |
|
|
|
['name' => 'Api#getMessageExpirationJob', 'url' => '/get_message_expiration_job', 'verb' => 'GET'], |
|
|
|
], |
|
|
|
]; |
|
|
|
@ -110,19 +110,12 @@ class ApiController extends OCSController { |
|
|
|
* |
|
|
|
* @return DataResponse |
|
|
|
*/ |
|
|
|
public function getMessageExpirationJob($token): DataResponse { |
|
|
|
$roomId = $this->getRoomIdByToken($token); |
|
|
|
if (!$roomId) { |
|
|
|
return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
|
|
} |
|
|
|
public function getMessageExpirationJob(): DataResponse { |
|
|
|
$query = $this->db->getQueryBuilder(); |
|
|
|
$query->select('id') |
|
|
|
->from('jobs') |
|
|
|
->where( |
|
|
|
$query->expr()->andX( |
|
|
|
$query->expr()->eq('class', $query->createNamedParameter(ExpireChatMessages::class)), |
|
|
|
$query->expr()->eq('argument', $query->createNamedParameter(json_encode(['room_id' => $roomId]))) |
|
|
|
) |
|
|
|
$query->expr()->eq('class', $query->createNamedParameter(ExpireChatMessages::class)) |
|
|
|
); |
|
|
|
$result = $query->executeQuery(); |
|
|
|
$job = $result->fetchOne(); |
|
|
|
@ -131,17 +124,4 @@ class ApiController extends OCSController { |
|
|
|
} |
|
|
|
return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
|
|
} |
|
|
|
|
|
|
|
private function getRoomIdByToken(string $token): ?int { |
|
|
|
$query = $this->db->getQueryBuilder(); |
|
|
|
$query->select('id') |
|
|
|
->from('talk_rooms') |
|
|
|
->where($query->expr()->eq('token', $query->createNamedParameter($token))); |
|
|
|
|
|
|
|
$result = $query->executeQuery(); |
|
|
|
$roomId = (int) $result->fetchOne(); |
|
|
|
$result->closeCursor(); |
|
|
|
|
|
|
|
return $roomId; |
|
|
|
} |
|
|
|
} |