Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m

]]></description>

<version>13.0.0-dev.1</version>
<version>13.0.0-dev.2</version>
<licence>agpl</licence>

<author>Daniel Calviño Sánchez</author>
Expand Down
9 changes: 9 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,15 @@
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'Room#setPublishingAllowed',
'url' => '/api/{apiVersion}/room/{token}/publishing-allowed',
'verb' => 'PUT',
'requirements' => [
'apiVersion' => 'v(4)',
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'Room#getParticipants',
'url' => '/api/{apiVersion}/room/{token}/participants',
Expand Down
4 changes: 4 additions & 0 deletions docs/constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ title: Constants
* `0` No lobby
* `1` Lobby for non moderators

### Publishing allowed
* `0` Everyone
* `1` Moderators

## Participants

### Participant types
Expand Down
18 changes: 18 additions & 0 deletions docs/conversation.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
`hasPassword` | bool | v1 | | Flag if the conversation has a password
`hasCall` | bool | v1 | | Flag if the conversation has an active call
`callFlag` | int | v3 | | Combined flag of all participants in the current call (see [constants list](constants.md#participant-in-call-flag), only available with `conversation-call-flags` capability)
`publishingAllowed` | int | v4 | Flag about which kind of participants are allowed to publish in a call (see [constants list](constants.md#publishing-allowed))
`canStartCall` | bool | v1 | | Flag if the user can start a new call in this conversation (joining is always possible) (only available with `start-call-flag` capability)
`canDeleteConversation` | bool | v2 | | Flag if the user can delete the conversation for everyone (not possible without moderator permissions or in one-to-one conversations)
`canLeaveConversation` | bool | v2 | | Flag if the user can leave the conversation (not possible for the last user with moderator permissions)
Expand Down Expand Up @@ -247,6 +248,23 @@
+ `403 Forbidden` When the conversation is not a public conversation
+ `404 Not Found` When the conversation could not be found for the participant

## Set publishing allowed for a conversation

* Method: `PUT`
* Endpoint: `/room/{token}/publishing-allowed`
* Data:

field | type | Description
---|---|---
`state` | int | New state for the conversation, see [constants list](constants.md#publishing-allowed)

* Response:
- Status code:
+ `200 OK`
+ `400 Bad Request` When the conversation type does not support setting publishing allowed (only group and public conversations without an on-going call)
+ `403 Forbidden` When the current user is not a moderator/owner
+ `404 Not Found` When the conversation could not be found for the participant

## Add conversation to favorites

* Required capability: `favorites`
Expand Down
18 changes: 18 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ protected function formatRoomV4(Room $room, ?Participant $currentParticipant, ar
'lastCommonReadMessage' => 0,
'listable' => Room::LISTABLE_NONE,
'callFlag' => Participant::FLAG_DISCONNECTED,
'publishingAllowed' => Room::PUBLISHING_ALLOWED_EVERYONE,
];

$lastActivity = $room->getLastActivity();
Expand Down Expand Up @@ -435,6 +436,7 @@ protected function formatRoomV4(Room $room, ?Participant $currentParticipant, ar
'lobbyTimer' => $lobbyTimer,
'sipEnabled' => $room->getSIPEnabled(),
'listable' => $room->getListable(),
'publishingAllowed' => $room->getPublishingAllowed(),
]);
}

Expand Down Expand Up @@ -465,6 +467,7 @@ protected function formatRoomV4(Room $room, ?Participant $currentParticipant, ar
'publishingPermissions' => $attendee->getPublishingPermissions(),
'description' => $room->getDescription(),
'listable' => $room->getListable(),
'publishingAllowed' => $room->getPublishingAllowed(),
]);

if ($currentParticipant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
Expand Down Expand Up @@ -1265,6 +1268,21 @@ public function setPassword(string $password): DataResponse {
return new DataResponse();
}

/**
* @PublicPage
* @RequireLoggedInModeratorParticipant
*
* @param int $state
* @return DataResponse
*/
public function setPublishingAllowed(int $state): DataResponse {
if (!$this->room->setPublishingAllowed($state)) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}

return new DataResponse();
}

/**
* @PublicPage
* @UseSession
Expand Down
3 changes: 2 additions & 1 deletion lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ public function createRoomObject(array $row): Room {
$lastMessage,
$lobbyTimer,
(string) $row['object_type'],
(string) $row['object_id']
(string) $row['object_id'],
(int) $row['publishing_allowed']
);
}

Expand Down
58 changes: 58 additions & 0 deletions lib/Migration/Version13000Date20210901132118.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Daniel Calviño Sánchez <[email protected]>
*
* @author Daniel Calviño Sánchez <[email protected]>
*
* @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\Migration;

use Closure;
use Doctrine\DBAL\Types\Types;
use OCA\Talk\Room;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version13000Date20210901132118 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @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_rooms');
if (!$table->hasColumn('publishing_allowed')) {
$table->addColumn('publishing_allowed', Types::INTEGER, [
'default' => Room::PUBLISHING_ALLOWED_EVERYONE,
]);

return $schema;
}

return null;
}
}
1 change: 1 addition & 0 deletions lib/Model/SelectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function selectRoomsTable(IQueryBuilder $query, string $alias = 'r'): voi
->addSelect($alias . 'object_id')
->addSelect($alias . 'listable')
->addSelect($alias . 'server_url')
->addSelect($alias . 'publishing_allowed')
->selectAlias($alias . 'id', 'r_id');
}

Expand Down
63 changes: 62 additions & 1 deletion lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class Room {
public const START_CALL_USERS = 1;
public const START_CALL_MODERATORS = 2;

public const PUBLISHING_ALLOWED_EVERYONE = 0;
public const PUBLISHING_ALLOWED_MODERATORS = 1;

public const PARTICIPANT_REMOVED = 'remove';
public const PARTICIPANT_LEFT = 'leave';

Expand All @@ -116,6 +119,8 @@ class Room {
public const EVENT_AFTER_LOBBY_STATE_SET = self::class . '::postSetLobbyState';
public const EVENT_BEFORE_SIP_ENABLED_SET = self::class . '::preSetSIPEnabled';
public const EVENT_AFTER_SIP_ENABLED_SET = self::class . '::postSetSIPEnabled';
public const EVENT_BEFORE_PUBLISHING_ALLOWED_SET = self::class . '::preSetPublishingAllowed';
public const EVENT_AFTER_PUBLISHING_ALLOWED_SET = self::class . '::postSetPublishingAllowed';
public const EVENT_BEFORE_USERS_ADD = self::class . '::preAddUsers';
public const EVENT_AFTER_USERS_ADD = self::class . '::postAddUsers';
public const EVENT_BEFORE_PARTICIPANT_TYPE_SET = self::class . '::preSetParticipantType';
Expand Down Expand Up @@ -198,6 +203,8 @@ class Room {
private $objectType;
/** @var string */
private $objectId;
/** @var int */
private $publishingAllowed;

/** @var string */
protected $currentUser;
Expand Down Expand Up @@ -229,7 +236,8 @@ public function __construct(Manager $manager,
?IComment $lastMessage,
?\DateTime $lobbyTimer,
string $objectType,
string $objectId) {
string $objectId,
int $publishingAllowed) {
$this->manager = $manager;
$this->db = $db;
$this->dispatcher = $dispatcher;
Expand All @@ -256,6 +264,7 @@ public function __construct(Manager $manager,
$this->lobbyTimer = $lobbyTimer;
$this->objectType = $objectType;
$this->objectId = $objectId;
$this->publishingAllowed = $publishingAllowed;
}

public function getId(): int {
Expand Down Expand Up @@ -373,6 +382,10 @@ public function getObjectId(): string {
return $this->objectId;
}

public function getPublishingAllowed(): int {
return $this->publishingAllowed;
}

public function hasPassword(): bool {
return $this->password !== '';
}
Expand Down Expand Up @@ -1034,6 +1047,54 @@ public function setSIPEnabled(int $newSipEnabled): bool {
return true;
}

/**
* @param int $newState New publishing allowed value from
* self::PUBLISHING_ALLOWED_*
* Also it can be set only on rooms of type
* `self::GROUP_CALL` and `self::PUBLIC_CALL` if there
* is no on-going call.
* @return bool True when the change was valid, false otherwise
*/
public function setPublishingAllowed(int $newState): bool {
$oldState = $this->getPublishingAllowed();
if ($newState === $oldState) {
return true;
}

if (!in_array($this->getType(), [
self::GROUP_CALL,
self::PUBLIC_CALL
], true)) {
return false;
}

if ($this->getCallFlag() !== Participant::FLAG_DISCONNECTED) {
return false;
}

if (!in_array($newState, [
Room::PUBLISHING_ALLOWED_EVERYONE,
Room::PUBLISHING_ALLOWED_MODERATORS,
], true)) {
return false;
}

$event = new ModifyRoomEvent($this, 'publishing_allowed', $newState, $oldState);
$this->dispatcher->dispatch(self::EVENT_BEFORE_PUBLISHING_ALLOWED_SET, $event);

$query = $this->db->getQueryBuilder();
$query->update('talk_rooms')
->set('publishing_allowed', $query->createNamedParameter($newState, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();

$this->publishingAllowed = $newState;

$this->dispatcher->dispatch(self::EVENT_AFTER_PUBLISHING_ALLOWED_SET, $event);

return true;
}

/**
* @param string $password
* @return array
Expand Down
Loading