Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
SystemKeeper committed Sep 20, 2024
1 parent bd8b8a6 commit ea59952
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 0 deletions.
4 changes: 4 additions & 0 deletions appinfo/routes/routesRoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,9 @@
['name' => 'Room#getCapabilities', 'url' => '/api/{apiVersion}/room/{token}/capabilities', 'verb' => 'GET', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::setMentionPermissions() */
['name' => 'Room#setMentionPermissions', 'url' => '/api/{apiVersion}/room/{token}/mention-permissions', 'verb' => 'PUT', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::archiveConversation() */
['name' => 'Room#archiveConversation', 'url' => '/api/{apiVersion}/room/{token}/archive', 'verb' => 'POST', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::unarchiveConversation() */
['name' => 'Room#unarchiveConversation', 'url' => '/api/{apiVersion}/room/{token}/archive', 'verb' => 'DELETE', 'requirements' => $requirementsWithToken],
],
];
40 changes: 40 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,46 @@ public function setPassword(string $password): DataResponse {
return new DataResponse();
}

/**
* Archive a conversation
*
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST, array<empty>, array{}>
*
* 200: Conversation was archived
* 400: Archiving is not possible
*/
#[NoAdminRequired]
#[RequireLoggedInParticipant]
public function archiveConversation(): DataResponse {
try {
$this->participantService->archiveConversation($this->participant);
} catch (\InvalidArgumentException $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}

return new DataResponse();
}

/**
* Unarchive a conversation
*
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST, array<empty>, array{}>
*
* 200: Conversation was unarchived
* 400: Unarchiving is not possible
*/
#[NoAdminRequired]
#[RequireLoggedInParticipant]
public function unarchiveConversation(): DataResponse {
try {
$this->participantService->unarchiveConversation($this->participant);
} catch (\InvalidArgumentException $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}

return new DataResponse();
}

/**
* Join a room
*
Expand Down
40 changes: 40 additions & 0 deletions lib/Migration/Version21000Date20240919222538.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version21000Date20240919222538 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable('talk_attendees');
if (!$table->hasColumn('archived')) {
$table->addColumn('archived', Types::BOOLEAN, [
'default' => 0,
'notnull' => false,
]);
}

return $schema;
}
}
4 changes: 4 additions & 0 deletions lib/Model/Attendee.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* @method void setReadPrivacy(int $readPrivacy)
* @method int getReadPrivacy()
* @method void setPermissions(int $permissions)
* @method void setArchived(bool $archived)
* @method bool isArchived()
* @internal
* @method int getPermissions()
* @method void setAccessToken(string $accessToken)
Expand Down Expand Up @@ -108,6 +110,7 @@ class Attendee extends Entity {
protected bool $favorite = false;
protected int $notificationLevel = 0;
protected int $notificationCalls = 0;
protected bool $archived = false;
protected int $lastJoinedCall = 0;
protected int $lastReadMessage = 0;
protected int $lastMentionMessage = 0;
Expand All @@ -131,6 +134,7 @@ public function __construct() {
$this->addType('pin', 'string');
$this->addType('participantType', 'int');
$this->addType('favorite', 'bool');
$this->addType('archived', 'bool');
$this->addType('notificationLevel', 'int');
$this->addType('notificationCalls', 'int');
$this->addType('lastJoinedCall', 'int');
Expand Down
1 change: 1 addition & 0 deletions lib/Model/AttendeeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ public function createAttendeeFromRow(array $row): Attendee {
'state' => (int)$row['state'],
'unread_messages' => (int)$row['unread_messages'],
'last_attendee_activity' => (int)$row['last_attendee_activity'],
'archived' => (bool)$row['archived'],
]);
}
}
1 change: 1 addition & 0 deletions lib/Model/SelectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function selectAttendeesTable(IQueryBuilder $query, string $alias = 'a'):
->addSelect($alias . 'state')
->addSelect($alias . 'unread_messages')
->addSelect($alias . 'last_attendee_activity')
->addSelect($alias . 'archived')
->selectAlias($alias . 'id', 'a_id');
}

Expand Down
20 changes: 20 additions & 0 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,26 @@ public function updateNotificationCalls(Participant $participant, int $level): v
$this->attendeeMapper->update($attendee);
}

/**
* @param Participant $participant
*/
public function archiveConversation(Participant $participant): void {
$attendee = $participant->getAttendee();
$attendee->setArchived(true);
$attendee->setLastAttendeeActivity($this->timeFactory->getTime());
$this->attendeeMapper->update($attendee);
}

/**
* @param Participant $participant
*/
public function unarchiveConversation(Participant $participant): void {
$attendee = $participant->getAttendee();
$attendee->setArchived(false);
$attendee->setLastAttendeeActivity($this->timeFactory->getTime());
$this->attendeeMapper->update($attendee);
}

/**
* @param RoomService $roomService
* @param Room $room
Expand Down
2 changes: 2 additions & 0 deletions lib/Service/RoomFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public function formatRoomV4(
'breakoutRoomStatus' => BreakoutRoom::STATUS_STOPPED,
'recordingConsent' => $this->talkConfig->recordingConsentRequired() === RecordingService::CONSENT_REQUIRED_OPTIONAL ? $room->getRecordingConsent() : $this->talkConfig->recordingConsentRequired(),
'mentionPermissions' => Room::MENTION_PERMISSIONS_EVERYONE,
'isArchived' => false,
];

if ($room->isFederatedConversation()) {
Expand Down Expand Up @@ -223,6 +224,7 @@ public function formatRoomV4(
'breakoutRoomMode' => $room->getBreakoutRoomMode(),
'breakoutRoomStatus' => $room->getBreakoutRoomStatus(),
'mentionPermissions' => $room->getMentionPermissions(),
'isArchived' => $attendee->isArchived(),
]);

if ($room->isFederatedConversation()) {
Expand Down
39 changes: 39 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4828,6 +4828,45 @@ public function userSetsMentionPermissionsOfTheRoom(string $user, string $identi
$this->assertStatusCode($this->response, $statusCode);
}

/**
* @When /^user "([^"]*)" (unarchives|archives) room "([^"]*)" with (\d+) \((v4)\)$/
*
* @param string $user
* @param string $identifier
* @param string $action
* @param int $statusCode
* @param string $apiVersion
*/
public function userArchivesConversation(string $user, string $identifier, string $action, int $statusCode, string $apiVersion): void {
$httpMethod = "POST";

if ($action === 'unarchives') {
$httpMethod = "DELETE";
}

$this->setCurrentUser($user);
$this->sendRequest(
$httpMethod, '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/archive',
);
$this->assertStatusCode($this->response, $statusCode);
}

/**
* @When /^user "([^"]*)" unarchives room "([^"]*)" with (\d+) \((v4)\)$/
*
* @param string $user
* @param string $identifier
* @param int $statusCode
* @param string $apiVersion
*/
public function userUnarchivesConversation(string $user, string $identifier, int $statusCode, string $apiVersion): void {
$this->setCurrentUser($user);
$this->sendRequest(
'DELETE', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/archive',
);
$this->assertStatusCode($this->response, $statusCode);
}

/**
* @param string $verb
* @param string $fullUrl
Expand Down
3 changes: 3 additions & 0 deletions tests/php/Chat/ChatManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ public function testDeleteMessage(): void {
'state' => Invitation::STATE_ACCEPTED,
'unread_messages' => 0,
'last_attendee_activity' => 0,
'archived' => 0,
]);
$chat = $this->createMock(Room::class);
$chat->expects($this->any())
Expand Down Expand Up @@ -490,6 +491,7 @@ public function testDeleteMessageFileShare(): void {
'state' => Invitation::STATE_ACCEPTED,
'unread_messages' => 0,
'last_attendee_activity' => 0,
'archived' => 0,
]);
$chat = $this->createMock(Room::class);
$chat->expects($this->any())
Expand Down Expand Up @@ -574,6 +576,7 @@ public function testDeleteMessageFileShareNotFound(): void {
'state' => Invitation::STATE_ACCEPTED,
'unread_messages' => 0,
'last_attendee_activity' => 0,
'archived' => 0,
]);
$chat = $this->createMock(Room::class);
$chat->expects($this->any())
Expand Down

0 comments on commit ea59952

Please sign in to comment.