Browse Source

Rename text

Signed-off-by: Vitor Mattos <vitor@php.rio>
pull/7327/head
Vitor Mattos 3 years ago
parent
commit
af34125e66
No known key found for this signature in database GPG Key ID: B7AB4B76A7CA7318
  1. 4
      appinfo/routes/routesRoomController.php
  2. 2
      docs/capabilities.md
  3. 10
      docs/conversation.md
  4. 2
      lib/BackgroundJob/ExpireChatMessages.php
  5. 2
      lib/Capabilities.php
  6. 10
      lib/Chat/ChatManager.php
  7. 8
      lib/Controller/RoomController.php
  8. 42
      lib/Events/ChangeExpireDateEvent.php
  9. 2
      lib/Manager.php
  10. 4
      lib/Migration/Version15000Date20220506005058.php
  11. 2
      lib/Model/SelectHelper.php
  12. 18
      lib/Room.php
  13. 19
      lib/Service/RoomService.php
  14. 2
      lib/Share/Helper/ShareAPIController.php
  15. 28
      tests/integration/features/bootstrap/FeatureContext.php
  16. 16
      tests/integration/features/chat/expire-date.feature
  17. 2
      tests/integration/spreedcheats/appinfo/routes.php
  18. 6
      tests/integration/spreedcheats/lib/Controller/ApiController.php
  19. 4
      tests/php/CapabilitiesTest.php

4
appinfo/routes/routesRoomController.php

@ -102,7 +102,7 @@ return [
['name' => 'Room#setLobby', 'url' => '/api/{apiVersion}/room/{token}/webinar/lobby', 'verb' => 'PUT', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::setSIPEnabled() */
['name' => 'Room#setSIPEnabled', 'url' => '/api/{apiVersion}/room/{token}/webinar/sip', 'verb' => 'PUT', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::setExpireInterval() */
['name' => 'Room#setExpireInterval', 'url' => '/api/{apiVersion}/room/{token}/message-expire-interval', 'verb' => 'POST', 'requirements' => $requirements],
/** @see \OCA\Talk\Controller\RoomController::setMessageExpiration() */
['name' => 'Room#setMessageExpiration', 'url' => '/api/{apiVersion}/room/{token}/message-expiration', 'verb' => 'POST', 'requirements' => $requirements],
],
];

2
docs/capabilities.md

@ -97,7 +97,7 @@ title: Capabilities
* `unified-search` - When the extended attributes of unified search results are there
* `chat-permission` - When permission 128 is required to post chat messages, reaction or share items to the conversation
* `silent-send` - Whether the chat API allows to send chat messages without triggering notifications
* `message-expire` - Message expiration time for a conversation
* `message-expiration` - Message expiration time for a conversation
* `sip-support-nopin` - Whether SIP can be configured to not require a custom attendee PIN
* `send-call-notification` - When the API allows to resend call notifications for individual users that did not join yet
* `silent-call` - Allow to start calls without sending notification

10
docs/conversation.md

@ -51,7 +51,7 @@
`participantFlags` | int | v1 | | "In call" flags of the user's session making the request (only available with `in-call-flags` capability)
`readOnly` | int | v1 | | Read-only state for the current user (only available with `read-only-rooms` capability)
`listable` | int | v3 | | Listable scope for the room (only available with `listable-rooms` capability)
`expireDate` | int | v4 | | The expire date time in seconds in this chat. Zero if disabled. (only available with `message-expire` capability)
`messageExpiration` | int | v4 | | The message expiration time in seconds in this chat. Zero if disabled. (only available with `message-expiration` capability)
`count` | int | v1 | v2 | **Removed:** Count the users on the [Get list of participants in a conversation](participant.md#get-list-of-participants-in-a-conversation) endpoint
`numGuests` | int | v1 | v2 | **Removed:** Count the guests on the [Get list of participants in a conversation](participant.md#get-list-of-participants-in-a-conversation) endpoin
`lastPing` | int | v1 | | Timestamp of the user's session making the request
@ -337,16 +337,16 @@
+ `401 Unauthorized` When the participant is a guest
+ `404 Not Found` When the conversation could not be found for the participant
## Set expire date for messages in a conversation
## Set message expiration
* Required capability: `message-expire`
* Required capability: `message-expiration`
* Method: `POST`
* Endpoint: `/room/{token}/message-expire`
* Endpoint: `/room/{token}/message-expiration`
* Data:
field | type | Description
---|---|---
`seconds` | int | The messages expire time in seconds. If is zero, messages will not be deleted automatically.
`seconds` | int | The messages expiration in seconds. If is zero, messages will not be deleted automatically.
* Response:
- Status code:

2
lib/BackgroundJob/ApplyExpireDate.php → lib/BackgroundJob/ExpireChatMessages.php

@ -30,7 +30,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\TimedJob;
class ApplyExpireDate extends TimedJob {
class ExpireChatMessages extends TimedJob {
private ChatManager $chatManager;
public function __construct(ITimeFactory $timeFactory,

2
lib/Capabilities.php

@ -135,7 +135,7 @@ class Capabilities implements IPublicCapability {
];
if ($this->serverConfig->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron') {
$capabilities['features'][] = 'message-expire';
$capabilities['features'][] = 'message-expiration';
}
if ($this->commentsManager->supportReactions()) {

10
lib/Chat/ChatManager.php

@ -263,7 +263,7 @@ class ChatManager {
if ($referenceId !== '') {
$comment->setReferenceId($referenceId);
}
$this->setExpireDate($chat, $comment);
$this->setMessageExpiration($chat, $comment);
$event = new ChatParticipantEvent($chat, $comment, $participant, $silent);
$this->dispatcher->dispatch(self::EVENT_BEFORE_MESSAGE_SEND, $event);
@ -309,14 +309,14 @@ class ChatManager {
return $comment;
}
private function setExpireDate(Room $room, IComment $comment): void {
$expireInterval = $room->getExpireInterval();
if (!$expireInterval) {
private function setMessageExpiration(Room $room, IComment $comment): void {
$messageExpiration = $room->getMessageExpiration();
if (!$messageExpiration) {
return;
}
$dateTime = $this->timeFactory->getDateTime();
$dateTime->add(DateInterval::createFromDateString($expireInterval . ' seconds'));
$dateTime->add(DateInterval::createFromDateString($messageExpiration . ' seconds'));
$comment->setExpireDate($dateTime);
}

8
lib/Controller/RoomController.php

@ -400,7 +400,7 @@ class RoomController extends AEnvironmentAwareController {
'lastCommonReadMessage' => 0,
'listable' => Room::LISTABLE_NONE,
'callFlag' => Participant::FLAG_DISCONNECTED,
'expireDate' => 0,
'messageExpiration' => 0,
];
$lastActivity = $room->getLastActivity();
@ -467,7 +467,7 @@ class RoomController extends AEnvironmentAwareController {
'defaultPermissions' => $room->getDefaultPermissions(),
'description' => $room->getDescription(),
'listable' => $room->getListable(),
'expireInterval' => $this->roomService->getExpireInterval($room),
'messageExpiration' => $this->roomService->getMessageExpiration($room),
]);
if ($currentParticipant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
@ -1713,11 +1713,11 @@ class RoomController extends AEnvironmentAwareController {
* @PublicPage
* @RequireModeratorParticipant
*/
public function setExpireInterval(int $seconds): DataResponse {
public function setMessageExpiration(int $seconds): DataResponse {
if ($seconds < 0) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$this->roomService->setExpireInterval($this->room, $this->getParticipant(), $seconds);
$this->roomService->setMessageExpiration($this->room, $this->getParticipant(), $seconds);
return new DataResponse();
}
}

42
lib/Events/ChangeExpireDateEvent.php

@ -1,42 +0,0 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Vitor Mattos <vitor@php.rio>
*
* @author Vitor Mattos <vitor@php.rio>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Talk\Events;
use OCA\Talk\Room;
class ChangeExpireDateEvent extends RoomEvent {
private int $seconds;
public function __construct(Room $room,
int $seconds
) {
parent::__construct($room);
$this->seconds = $seconds;
}
public function getExpireDateSeconds(): int {
return $this->seconds;
}
}

2
lib/Manager.php

@ -165,7 +165,7 @@ class Manager {
(int) $row['type'],
(int) $row['read_only'],
(int) $row['listable'],
(int) $row['message_expire'],
(int) $row['message_expiration'],
(int) $row['lobby_state'],
(int) $row['sip_enabled'],
$assignedSignalingServer,

4
lib/Migration/Version15000Date20220506005058.php

@ -45,8 +45,8 @@ class Version15000Date20220506005058 extends SimpleMigrationStep {
$schema = $schemaClosure();
$table = $schema->getTable('talk_rooms');
if (!$table->hasColumn('message_expire')) {
$table->addColumn('message_expire', Types::INTEGER, [
if (!$table->hasColumn('message_expiration')) {
$table->addColumn('message_expiration', Types::INTEGER, [
'default' => 0,
]);
return $schema;

2
lib/Model/SelectHelper.php

@ -51,7 +51,7 @@ class SelectHelper {
->addSelect($alias . 'object_type')
->addSelect($alias . 'object_id')
->addSelect($alias . 'listable')
->addSelect($alias . 'message_expire')
->addSelect($alias . 'message_expiration')
->addSelect($alias . 'remote_server')
->addSelect($alias . 'remote_token')
->selectAlias($alias . 'id', 'r_id');

18
lib/Room.php

@ -147,8 +147,8 @@ class Room {
public const EVENT_BEFORE_SESSION_LEAVE_CALL = self::class . '::preSessionLeaveCall';
public const EVENT_AFTER_SESSION_LEAVE_CALL = self::class . '::postSessionLeaveCall';
public const EVENT_BEFORE_SIGNALING_PROPERTIES = self::class . '::beforeSignalingProperties';
public const EVENT_BEFORE_SET_EXPIRE_DATE = self::class . '::beforeSetExpireInterval';
public const EVENT_AFTER_SET_EXPIRE_DATE = self::class . '::afterSetExpireInterval';
public const EVENT_BEFORE_SET_EXPIRE_DATE = self::class . '::beforeSetMessageExpiration';
public const EVENT_AFTER_SET_EXPIRE_DATE = self::class . '::afterSetMessageExpiration';
public const DESCRIPTION_MAXIMUM_LENGTH = 500;
@ -162,7 +162,7 @@ class Room {
private int $type;
private int $readOnly;
private int $listable;
private int $expireInterval;
private int $messageExpiration;
private int $lobbyState;
private int $sipEnabled;
private ?int $assignedSignalingServer;
@ -196,7 +196,7 @@ class Room {
int $type,
int $readOnly,
int $listable,
int $expireInterval,
int $messageExpiration,
int $lobbyState,
int $sipEnabled,
?int $assignedSignalingServer,
@ -226,7 +226,7 @@ class Room {
$this->type = $type;
$this->readOnly = $readOnly;
$this->listable = $listable;
$this->expireInterval = $expireInterval;
$this->messageExpiration = $messageExpiration;
$this->lobbyState = $lobbyState;
$this->sipEnabled = $sipEnabled;
$this->assignedSignalingServer = $assignedSignalingServer;
@ -288,12 +288,12 @@ class Room {
$this->listable = $newState;
}
public function getExpireInterval(): int {
return $this->expireInterval;
public function getMessageExpiration(): int {
return $this->messageExpiration;
}
public function setExpireInterval(int $expireInterval): void {
$this->expireInterval = $expireInterval;
public function setMessageExpiration(int $messageExpiration): void {
$this->messageExpiration = $messageExpiration;
}
public function getLobbyState(): int {

19
lib/Service/RoomService.php

@ -24,10 +24,9 @@ declare(strict_types=1);
namespace OCA\Talk\Service;
use InvalidArgumentException;
use OCA\Talk\BackgroundJob\ApplyExpireDate;
use OCA\Talk\BackgroundJob\ExpireChatMessages;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\CommentsManager;
use OCA\Talk\Events\ChangeExpireDateEvent;
use OCA\Talk\Events\ModifyLobbyEvent;
use OCA\Talk\Events\ModifyRoomEvent;
use OCA\Talk\Events\VerifyRoomPasswordEvent;
@ -543,21 +542,21 @@ class RoomService {
];
}
public function setExpireInterval(Room $room, Participant $participant, int $seconds): void {
$event = new ChangeExpireDateEvent($room, $seconds);
public function setMessageExpiration(Room $room, Participant $participant, int $seconds): void {
$event = new ModifyRoomEvent($room, 'messageExpiration', $seconds, null, $participant);
$this->dispatcher->dispatch(Room::EVENT_BEFORE_SET_EXPIRE_DATE, $event);
$update = $this->db->getQueryBuilder();
$update->update('talk_rooms')
->set('message_expire', $update->createNamedParameter($seconds, IQueryBuilder::PARAM_INT))
->set('message_expiration', $update->createNamedParameter($seconds, IQueryBuilder::PARAM_INT))
->where($update->expr()->eq('id', $update->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)));
$update->executeStatement();
$room->setExpireInterval($seconds);
$room->setMessageExpiration($seconds);
if ($seconds > 0) {
$this->jobList->add(ApplyExpireDate::class, ['room_id' => $room->getId()]);
$this->jobList->add(ExpireChatMessages::class, ['room_id' => $room->getId()]);
$this->expireDateSystemMessage($room, $participant, $seconds, 'message_expire_enabled');
} else {
$this->jobList->remove(ApplyExpireDate::class, ['room_id' => $room->getId()]);
$this->jobList->remove(ExpireChatMessages::class, ['room_id' => $room->getId()]);
$this->expireDateSystemMessage($room, $participant, $seconds, 'message_expire_disabled');
}
@ -578,7 +577,7 @@ class RoomService {
);
}
public function getExpireInterval(Room $room): int {
return $room->getExpireInterval();
public function getMessageExpiration(Room $room): int {
return $room->getMessageExpiration();
}
}

2
lib/Share/Helper/ShareAPIController.php

@ -102,7 +102,7 @@ class ShareAPIController {
* @param IShare $share
* @param string $shareWith
* @param int $permissions
* @param string $expireDate
* @param string $messageExpiration
* @throws OCSNotFoundException
*/
public function createShare(IShare $share, string $shareWith, int $permissions, string $expireDate): void {

28
tests/integration/features/bootstrap/FeatureContext.php

@ -339,6 +339,9 @@ class FeatureContext implements Context, SnippetAcceptingContext {
if (isset($expectedRoom['unreadMentionDirect'])) {
$data['unreadMentionDirect'] = (int) $room['unreadMentionDirect'];
}
if (isset($expectedRoom['messageExpiration'])) {
$data['messageExpiration'] = (int) $room['messageExpiration'];
}
if (isset($expectedRoom['participants'])) {
throw new \Exception('participants key needs to be checked via participants endpoint');
}
@ -2568,27 +2571,16 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
* @Given user :user set the expire interval to :expireInterval of room :identifier with :statusCode (:apiVersion)
* @Given user :user set the message expiration to :messageExpiration of room :identifier with :statusCode (:apiVersion)
*/
public function userSetTheExpireIntervalToWith(string $user, int $expireInterval, string $identifier, int $statusCode, string $apiVersion = 'v4'): void {
public function userSetTheMessageExpirationToXWithStatusCode(string $user, int $messageExpiration, string $identifier, int $statusCode, string $apiVersion = 'v4'): void {
$this->setCurrentUser($user);
$this->sendRequest('POST', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/message-expire-interval', [
'seconds' => $expireInterval
$this->sendRequest('POST', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/message-expiration', [
'seconds' => $messageExpiration,
]);
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Given user :user check if expire interval of room :identifier is :expireInterval (:apiVersion)
*/
public function userCheckIfExpireIntervalOfRoomIsX(string $user, string $identifier, int $expireInterval, string $apiVersion = 'v4') {
$this->setCurrentUser($user);
$this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier]);
$room = $this->getDataFromResponse($this->response);
Assert::assertEquals($expireInterval, $room['expireInterval']);
}
/**
* @When wait for :seconds seconds
*/
@ -2597,12 +2589,12 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
* @When apply expire date job to room :identifier
* @When apply message expiration job to room :identifier
*/
public function applyExpireDateJobToRoom($identifier): void {
public function applyMessageExpirationJobToRoom($identifier): void {
$currentUser = $this->currentUser;
$this->setCurrentUser('admin');
$this->sendRequest('GET', '/apps/spreedcheats/get_message_expire_job/' . self::$identifierToToken[$identifier]);
$this->sendRequest('GET', '/apps/spreedcheats/get_message_expiration_job/' . self::$identifierToToken[$identifier]);
$response = $this->getDataFromResponse($this->response);
Assert::assertIsArray($response, 'Room ' . $identifier . 'not found');
Assert::assertArrayHasKey('id', $response, 'Job not found by identifier "' . $identifier . '"');

16
tests/integration/features/chat/expire-date.feature

@ -4,20 +4,22 @@ Feature: room/expire-date
Given user "participant2" exists
Given user "participant3" exists
Scenario: Enable expire date and check after expire
Scenario: Enable message expiration and check after expire
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" sends message "Message 1" to room "room" with 201
And user "participant1" set the expire interval to -1 of room "room" with 400 (v4)
And user "participant2" set the expire interval to 3 of room "room" with 403 (v4)
And user "participant3" set the expire interval to 3 of room "room" with 404 (v4)
And user "participant1" set the expire interval to 3 of room "room" with 200 (v4)
And user "participant1" set the message expiration to -1 of room "room" with 400 (v4)
And user "participant2" set the message expiration to 3 of room "room" with 403 (v4)
And user "participant3" set the message expiration to 3 of room "room" with 404 (v4)
And user "participant1" set the message expiration to 3 of room "room" with 200 (v4)
And user "participant1" sends message "Message 2" to room "room" with 201
And user "participant1" check if expire interval of room "room" is 3 (v4)
Then user "participant1" is participant of the following rooms (v4)
| id | type | messageExpiration |
| room | 3 | 3 |
And wait for 3 seconds
And apply expire date job to room "room"
And apply message expiration job to room "room"
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 | [] | |

2
tests/integration/spreedcheats/appinfo/routes.php

@ -26,6 +26,6 @@ declare(strict_types=1);
return [
'ocs' => [
['name' => 'Api#resetSpreed', 'url' => '/', 'verb' => 'DELETE'],
['name' => 'Api#getExpireDateJob', 'url' => '/get_message_expire_job/{token}', 'verb' => 'GET'],
['name' => 'Api#getMessageExpirationJob', 'url' => '/get_message_expiration_job/{token}', 'verb' => 'GET'],
],
];

6
tests/integration/spreedcheats/lib/Controller/ApiController.php

@ -25,7 +25,7 @@ declare(strict_types=1);
namespace OCA\SpreedCheats\Controller;
use OCA\Talk\BackgroundJob\ApplyExpireDate;
use OCA\Talk\BackgroundJob\ExpireChatMessages;
use OCP\AppFramework\Http;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Http\DataResponse;
@ -110,7 +110,7 @@ class ApiController extends OCSController {
*
* @return DataResponse
*/
public function getExpireDateJob($token): DataResponse {
public function getMessageExpirationJob($token): DataResponse {
$roomId = $this->getRoomIdByToken($token);
if (!$roomId) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
@ -120,7 +120,7 @@ class ApiController extends OCSController {
->from('jobs')
->where(
$query->expr()->andX(
$query->expr()->eq('class', $query->createNamedParameter(ApplyExpireDate::class)),
$query->expr()->eq('class', $query->createNamedParameter(ExpireChatMessages::class)),
$query->expr()->eq('argument', $query->createNamedParameter(json_encode(['room_id' => (int) $roomId])))
)
);

4
tests/php/CapabilitiesTest.php

@ -59,7 +59,7 @@ class CapabilitiesTest extends TestCase {
$this->commentsManager = $this->createMock(CommentsManager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->commentsManager->expects($this->any())
->method('supportReactions')
->willReturn(true);
@ -121,7 +121,7 @@ class CapabilitiesTest extends TestCase {
'silent-send',
'silent-call',
'send-call-notification',
'message-expire',
'message-expiration',
'reactions',
];
}

Loading…
Cancel
Save