Skip to content

Commit 252c149

Browse files
vitormattosnickvergessen
authored andcommitted
Add test scenario to validate the @ALL in mention
Check if non moderators can use `@all` when autocomplete mentions Signed-off-by: Vitor Mattos <[email protected]>
1 parent 6ecae1c commit 252c149

File tree

20 files changed

+278
-15
lines changed

20 files changed

+278
-15
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
1616
1717
]]></description>
1818

19-
<version>18.0.0-dev.1</version>
19+
<version>18.0.0-dev.2</version>
2020
<licence>agpl</licence>
2121

2222
<author>Daniel Calviño Sánchez</author>

appinfo/routes/routesRoomController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,7 @@
108108
['name' => 'Room#setSIPEnabled', 'url' => '/api/{apiVersion}/room/{token}/webinar/sip', 'verb' => 'PUT', 'requirements' => $requirementsWithToken],
109109
/** @see \OCA\Talk\Controller\RoomController::setMessageExpiration() */
110110
['name' => 'Room#setMessageExpiration', 'url' => '/api/{apiVersion}/room/{token}/message-expiration', 'verb' => 'POST', 'requirements' => $requirementsWithToken],
111+
/** @see \OCA\Talk\Controller\RoomController::setCanMentionEveryone() */
112+
['name' => 'Room#setCanMentionEveryone', 'url' => '/api/{apiVersion}/room/{token}/can-mention-everyone', 'verb' => 'PUT', 'requirements' => $requirementsWithToken],
111113
],
112114
];

docs/capabilities.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,6 @@
121121
* `config => call => supported-reactions` - A list of emojis supported as call reactions. If the list is absent or empty, clients should not show the emoji reaction option in calls.
122122
* `config => chat => typing-privacy` - User defined numeric value to enable 1 or disable 0 the typing indicator to other users
123123
* `typing-privacy` - Support toggle typing privacy
124+
125+
## 18
126+
* `can-mention-everyone` - Allow non moderators to mention everyone using `@all`

docs/constants.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
* `0` No lobby
3131
* `1` Lobby for non moderators
3232

33+
### Can mention everyone
34+
* `0` Moderators only
35+
* `1` Everyone (default)
36+
3337
### SIP states
3438
* `0` Disabled
3539
* `1` Enabled (Each participant needs a unique PIN)

docs/conversation.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
| `isCustomAvatar` | bool | v4 | | Flag if the conversation has a custom avatar (only available with `avatar` capability) |
108108
| `callStartTime` | int | v4 | | Timestamp when the call was started (only available with `recording-v1` capability) |
109109
| `callRecording` | int | v4 | | Type of call recording (see [Constants - Call recording status](constants.md#call-recording-status)) (only available with `recording-v1` capability) |
110+
| `canMentionEveryone` | int | v4 | | Flag if non moderators can mention everyone (see [Constants - Can mention everyone](constants.md#can-mention-everyone)) (only available with `can-mention-everyone` capability) |
110111

111112
## Creating a new conversation
112113

@@ -425,3 +426,21 @@ Get all (for moderators and in case of "free selection") or the assigned breakou
425426
+ `400 Bad Request` When the conversation is a breakout room
426427
+ `403 Forbidden` When the current user is not a moderator/owner or the conversation is not a public conversation
427428
+ `404 Not Found` When the conversation could not be found for the participant
429+
430+
## Change the permission to mention everyone using `@all`
431+
* Required capability: `can-mention-everyone`
432+
* Method: `PUT`
433+
* Endpoint: `/room/{token}/can-mention-everyone`
434+
* Data:
435+
436+
| field | type | Description |
437+
|----------|------|---------------------------------------------------------------------------|
438+
| `config` | int | See [Constants - Can mention everyone](constants.md#can-mention-everyone) |
439+
440+
* Response:
441+
- Status code:
442+
+ `200 OK`
443+
+ `400 Bad Request` Error: `config`: When the provided config value is invalid
444+
+ `400 Bad Request` Error: `room`: When the conversation is a one-to-one conversation
445+
+ `403 Forbidden` When the current user is not a moderator/owner or the conversation is not a one-to-one conversation
446+
+ `404 Not Found` When the conversation could not be found for the participant

lib/Chat/ChatManager.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function sendMessage(Room $chat, Participant $participant, string $actorT
297297
}
298298
}
299299

300-
$alreadyNotifiedUsers = $this->notifier->notifyMentionedUsers($chat, $comment, $alreadyNotifiedUsers, $silent);
300+
$alreadyNotifiedUsers = $this->notifier->notifyMentionedUsers($chat, $comment, $alreadyNotifiedUsers, $silent, $participant);
301301
if (!empty($alreadyNotifiedUsers)) {
302302
$userIds = array_column($alreadyNotifiedUsers, 'id');
303303
$this->participantService->markUsersAsMentioned($chat, $userIds, (int) $comment->getId(), $usersDirectlyMentioned);
@@ -756,6 +756,14 @@ public function addConversationNotify(array $results, string $search, Room $room
756756
} else {
757757
$roomDisplayName = $room->getDisplayName('');
758758
}
759+
switch ($room->getCanMentionEveryone()) {
760+
case Room::CAN_MENTION_EVERYONE_ALL:
761+
break;
762+
case Room::CAN_MENTION_EVERYONE_MODERATORS:
763+
if (!$participant->hasModeratorPermissions(true)) {
764+
return $results;
765+
}
766+
}
759767
if ($search === '' || $this->searchIsPartOfConversationNameOrAtAll($search, $roomDisplayName)) {
760768
array_unshift($results, [
761769
'id' => 'all',

lib/Chat/Notifier.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,17 @@ public function __construct(
9292
* @param IComment $comment
9393
* @param array[] $alreadyNotifiedUsers
9494
* @psalm-param array<int, array{id: string, type: string, reason: string}> $alreadyNotifiedUsers
95+
* @param Participant $participant
9596
* @return string[] Users that were mentioned
9697
* @psalm-return array<int, array{id: string, type: string, reason: string, sourceId?: string, attendee?: Attendee}>
9798
*/
98-
public function notifyMentionedUsers(Room $chat, IComment $comment, array $alreadyNotifiedUsers, bool $silent): array {
99-
$usersToNotify = $this->getUsersToNotify($chat, $comment, $alreadyNotifiedUsers);
99+
public function notifyMentionedUsers(Room $chat,
100+
IComment $comment,
101+
array $alreadyNotifiedUsers,
102+
bool $silent,
103+
Participant $participant
104+
): array {
105+
$usersToNotify = $this->getUsersToNotify($chat, $comment, $alreadyNotifiedUsers, $participant);
100106

101107
if (!$usersToNotify) {
102108
return $alreadyNotifiedUsers;
@@ -139,13 +145,18 @@ public function notifyMentionedUsers(Room $chat, IComment $comment, array $alrea
139145
* @param IComment $comment
140146
* @param array $alreadyNotifiedUsers
141147
* @psalm-param array<int, array{id: string, type: string, reason?: string}> $alreadyNotifiedUsers
148+
* @param Participant $participant
142149
* @return array
143150
* @psalm-return array<int, array{id: string, type: string, reason?: string, sourceId?: string, attendee?: Attendee}>
144151
*/
145-
private function getUsersToNotify(Room $chat, IComment $comment, array $alreadyNotifiedUsers): array {
152+
private function getUsersToNotify(Room $chat,
153+
IComment $comment,
154+
array $alreadyNotifiedUsers,
155+
Participant $participant
156+
): array {
146157
$usersToNotify = $this->getMentionedUsers($comment);
147158
$usersToNotify = $this->getMentionedGroupMembers($chat, $comment, $usersToNotify);
148-
$usersToNotify = $this->addMentionAllToList($chat, $usersToNotify);
159+
$usersToNotify = $this->addMentionAllToList($chat, $usersToNotify, $participant);
149160
$usersToNotify = $this->removeAlreadyNotifiedUsers($usersToNotify, $alreadyNotifiedUsers);
150161

151162
return $usersToNotify;
@@ -177,7 +188,7 @@ private function removeAlreadyNotifiedUsers(array $usersToNotify, array $already
177188
* @return array
178189
* @psalm-return array<int, array{id: string, type: string, reason: string, sourceId?: string, attendee?: Attendee}>
179190
*/
180-
private function addMentionAllToList(Room $chat, array $list): array {
191+
private function addMentionAllToList(Room $chat, array $list, Participant $participant): array {
181192
$usersToNotify = array_filter($list, static function (array $entry): bool {
182193
return $entry['type'] !== Attendee::ACTOR_USERS || $entry['id'] !== 'all';
183194
});
@@ -186,6 +197,15 @@ private function addMentionAllToList(Room $chat, array $list): array {
186197
return $usersToNotify;
187198
}
188199

200+
switch ($chat->getCanMentionEveryone()) {
201+
case Room::CAN_MENTION_EVERYONE_ALL:
202+
break;
203+
case Room::CAN_MENTION_EVERYONE_MODERATORS:
204+
if (!$participant->hasModeratorPermissions(true)) {
205+
return $usersToNotify;
206+
}
207+
}
208+
189209
$attendees = $this->participantService->getActorsByType($chat, Attendee::ACTOR_USERS);
190210
foreach ($attendees as $attendee) {
191211
$alreadyAddedToNotify = array_filter($list, static function ($user) use ($attendee): bool {

lib/Controller/RoomController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,4 +1491,15 @@ public function setMessageExpiration(int $seconds): DataResponse {
14911491

14921492
return new DataResponse();
14931493
}
1494+
1495+
#[NoAdminRequired]
1496+
#[RequireLoggedInModeratorParticipant]
1497+
public function setCanMentionEveryone(int $config): DataResponse {
1498+
try {
1499+
$this->roomService->setCanMentionEveryone($this->room, $config);
1500+
} catch (\InvalidArgumentException $e) {
1501+
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
1502+
}
1503+
return new DataResponse();
1504+
}
14941505
}

lib/Manager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public function createRoomObjectFromData(array $data): Room {
162162
'breakout_room_mode' => 0,
163163
'breakout_room_status' => 0,
164164
'call_recording' => 0,
165+
'can_mention_everyone' => 1,
165166
], $data));
166167
}
167168

@@ -228,7 +229,8 @@ public function createRoomObject(array $row): Room {
228229
(string) $row['object_id'],
229230
(int) $row['breakout_room_mode'],
230231
(int) $row['breakout_room_status'],
231-
(int) $row['call_recording']
232+
(int) $row['call_recording'],
233+
(int) $row['can_mention_everyone'],
232234
);
233235
}
234236

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Vitor Mattos <[email protected]>
7+
*
8+
* @author Vitor Mattos <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\Talk\Migration;
28+
29+
use Closure;
30+
use OCP\DB\ISchemaWrapper;
31+
use OCP\DB\Types;
32+
use OCP\Migration\IOutput;
33+
use OCP\Migration\SimpleMigrationStep;
34+
35+
class Version18000Date20230505122109 extends SimpleMigrationStep {
36+
37+
/**
38+
* @param IOutput $output
39+
* @param Closure(): ISchemaWrapper $schemaClosure
40+
* @param array $options
41+
* @return null|ISchemaWrapper
42+
*/
43+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
44+
/** @var ISchemaWrapper $schema */
45+
$schema = $schemaClosure();
46+
47+
$table = $schema->getTable('talk_rooms');
48+
if (!$table->hasColumn('can_mention_everyone')) {
49+
$table->addColumn('can_mention_everyone', Types::INTEGER, [
50+
'default' => 1,
51+
]);
52+
return $schema;
53+
}
54+
return null;
55+
}
56+
}

0 commit comments

Comments
 (0)