diff --git a/appinfo/info.xml b/appinfo/info.xml
index 03275c4b4e9..015aaff799f 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
]]>
- 18.0.0-dev.1
+ 18.0.0-dev.2
agpl
Daniel Calviño Sánchez
diff --git a/appinfo/routes/routesRoomController.php b/appinfo/routes/routesRoomController.php
index 7542b88841f..ebe169686a6 100644
--- a/appinfo/routes/routesRoomController.php
+++ b/appinfo/routes/routesRoomController.php
@@ -108,5 +108,7 @@
['name' => 'Room#setSIPEnabled', 'url' => '/api/{apiVersion}/room/{token}/webinar/sip', 'verb' => 'PUT', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::setMessageExpiration() */
['name' => 'Room#setMessageExpiration', 'url' => '/api/{apiVersion}/room/{token}/message-expiration', 'verb' => 'POST', 'requirements' => $requirementsWithToken],
+ /** @see \OCA\Talk\Controller\RoomController::setCanMentionEveryone() */
+ ['name' => 'Room#setCanMentionEveryone', 'url' => '/api/{apiVersion}/room/{token}/can-mention-everyone', 'verb' => 'PUT', 'requirements' => $requirementsWithToken],
],
];
diff --git a/docs/capabilities.md b/docs/capabilities.md
index f299a979790..dace0b35f4e 100644
--- a/docs/capabilities.md
+++ b/docs/capabilities.md
@@ -121,3 +121,6 @@
* `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.
* `config => chat => typing-privacy` - User defined numeric value to enable 1 or disable 0 the typing indicator to other users
* `typing-privacy` - Support toggle typing privacy
+
+## 18
+* `can-mention-everyone` - Allow non moderators to mention everyone using `@all`
diff --git a/docs/constants.md b/docs/constants.md
index 729fa33fbe8..2def64e630b 100644
--- a/docs/constants.md
+++ b/docs/constants.md
@@ -30,6 +30,10 @@
* `0` No lobby
* `1` Lobby for non moderators
+### Can mention everyone
+* `0` Moderators only
+* `1` Everyone (default)
+
### SIP states
* `0` Disabled
* `1` Enabled (Each participant needs a unique PIN)
diff --git a/docs/conversation.md b/docs/conversation.md
index 3bfdf3dcb36..23cbffb2f33 100644
--- a/docs/conversation.md
+++ b/docs/conversation.md
@@ -107,6 +107,7 @@
| `isCustomAvatar` | bool | v4 | | Flag if the conversation has a custom avatar (only available with `avatar` capability) |
| `callStartTime` | int | v4 | | Timestamp when the call was started (only available with `recording-v1` capability) |
| `callRecording` | int | v4 | | Type of call recording (see [Constants - Call recording status](constants.md#call-recording-status)) (only available with `recording-v1` capability) |
+| `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) |
## Creating a new conversation
@@ -425,3 +426,21 @@ Get all (for moderators and in case of "free selection") or the assigned breakou
+ `400 Bad Request` When the conversation is a breakout room
+ `403 Forbidden` When the current user is not a moderator/owner or the conversation is not a public conversation
+ `404 Not Found` When the conversation could not be found for the participant
+
+## Change the permission to mention everyone using `@all`
+* Required capability: `can-mention-everyone`
+* Method: `PUT`
+* Endpoint: `/room/{token}/can-mention-everyone`
+* Data:
+
+| field | type | Description |
+|----------|------|---------------------------------------------------------------------------|
+| `config` | int | See [Constants - Can mention everyone](constants.md#can-mention-everyone) |
+
+* Response:
+ - Status code:
+ + `200 OK`
+ + `400 Bad Request` Error: `config`: When the provided config value is invalid
+ + `400 Bad Request` Error: `room`: When the conversation is a one-to-one conversation
+ + `403 Forbidden` When the current user is not a moderator/owner or the conversation is not a one-to-one conversation
+ + `404 Not Found` When the conversation could not be found for the participant
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index 1de8610ecc1..75f2111b11a 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -297,7 +297,7 @@ public function sendMessage(Room $chat, Participant $participant, string $actorT
}
}
- $alreadyNotifiedUsers = $this->notifier->notifyMentionedUsers($chat, $comment, $alreadyNotifiedUsers, $silent);
+ $alreadyNotifiedUsers = $this->notifier->notifyMentionedUsers($chat, $comment, $alreadyNotifiedUsers, $silent, $participant);
if (!empty($alreadyNotifiedUsers)) {
$userIds = array_column($alreadyNotifiedUsers, 'id');
$this->participantService->markUsersAsMentioned($chat, $userIds, (int) $comment->getId(), $usersDirectlyMentioned);
@@ -756,6 +756,14 @@ public function addConversationNotify(array $results, string $search, Room $room
} else {
$roomDisplayName = $room->getDisplayName('');
}
+ switch ($room->getCanMentionEveryone()) {
+ case Room::CAN_MENTION_EVERYONE_ALL:
+ break;
+ case Room::CAN_MENTION_EVERYONE_MODERATORS:
+ if (!$participant->hasModeratorPermissions(true)) {
+ return $results;
+ }
+ }
if ($search === '' || $this->searchIsPartOfConversationNameOrAtAll($search, $roomDisplayName)) {
array_unshift($results, [
'id' => 'all',
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php
index ec4bcb3e84d..211d1e49799 100644
--- a/lib/Chat/Notifier.php
+++ b/lib/Chat/Notifier.php
@@ -92,11 +92,17 @@ public function __construct(
* @param IComment $comment
* @param array[] $alreadyNotifiedUsers
* @psalm-param array $alreadyNotifiedUsers
+ * @param Participant $participant
* @return string[] Users that were mentioned
* @psalm-return array
*/
- public function notifyMentionedUsers(Room $chat, IComment $comment, array $alreadyNotifiedUsers, bool $silent): array {
- $usersToNotify = $this->getUsersToNotify($chat, $comment, $alreadyNotifiedUsers);
+ public function notifyMentionedUsers(Room $chat,
+ IComment $comment,
+ array $alreadyNotifiedUsers,
+ bool $silent,
+ Participant $participant
+ ): array {
+ $usersToNotify = $this->getUsersToNotify($chat, $comment, $alreadyNotifiedUsers, $participant);
if (!$usersToNotify) {
return $alreadyNotifiedUsers;
@@ -139,13 +145,18 @@ public function notifyMentionedUsers(Room $chat, IComment $comment, array $alrea
* @param IComment $comment
* @param array $alreadyNotifiedUsers
* @psalm-param array $alreadyNotifiedUsers
+ * @param Participant $participant
* @return array
* @psalm-return array
*/
- private function getUsersToNotify(Room $chat, IComment $comment, array $alreadyNotifiedUsers): array {
+ private function getUsersToNotify(Room $chat,
+ IComment $comment,
+ array $alreadyNotifiedUsers,
+ Participant $participant
+ ): array {
$usersToNotify = $this->getMentionedUsers($comment);
$usersToNotify = $this->getMentionedGroupMembers($chat, $comment, $usersToNotify);
- $usersToNotify = $this->addMentionAllToList($chat, $usersToNotify);
+ $usersToNotify = $this->addMentionAllToList($chat, $usersToNotify, $participant);
$usersToNotify = $this->removeAlreadyNotifiedUsers($usersToNotify, $alreadyNotifiedUsers);
return $usersToNotify;
@@ -177,7 +188,7 @@ private function removeAlreadyNotifiedUsers(array $usersToNotify, array $already
* @return array
* @psalm-return array
*/
- private function addMentionAllToList(Room $chat, array $list): array {
+ private function addMentionAllToList(Room $chat, array $list, Participant $participant): array {
$usersToNotify = array_filter($list, static function (array $entry): bool {
return $entry['type'] !== Attendee::ACTOR_USERS || $entry['id'] !== 'all';
});
@@ -186,6 +197,15 @@ private function addMentionAllToList(Room $chat, array $list): array {
return $usersToNotify;
}
+ switch ($chat->getCanMentionEveryone()) {
+ case Room::CAN_MENTION_EVERYONE_ALL:
+ break;
+ case Room::CAN_MENTION_EVERYONE_MODERATORS:
+ if (!$participant->hasModeratorPermissions(true)) {
+ return $usersToNotify;
+ }
+ }
+
$attendees = $this->participantService->getActorsByType($chat, Attendee::ACTOR_USERS);
foreach ($attendees as $attendee) {
$alreadyAddedToNotify = array_filter($list, static function ($user) use ($attendee): bool {
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index dae1542ceec..1fe79bd1680 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -1491,4 +1491,15 @@ public function setMessageExpiration(int $seconds): DataResponse {
return new DataResponse();
}
+
+ #[NoAdminRequired]
+ #[RequireLoggedInModeratorParticipant]
+ public function setCanMentionEveryone(int $config): DataResponse {
+ try {
+ $this->roomService->setCanMentionEveryone($this->room, $config);
+ } catch (\InvalidArgumentException $e) {
+ return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
+ }
+ return new DataResponse();
+ }
}
diff --git a/lib/Manager.php b/lib/Manager.php
index 1ab1c4e2728..abadce53dd0 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -162,6 +162,7 @@ public function createRoomObjectFromData(array $data): Room {
'breakout_room_mode' => 0,
'breakout_room_status' => 0,
'call_recording' => 0,
+ 'can_mention_everyone' => 1,
], $data));
}
@@ -228,7 +229,8 @@ public function createRoomObject(array $row): Room {
(string) $row['object_id'],
(int) $row['breakout_room_mode'],
(int) $row['breakout_room_status'],
- (int) $row['call_recording']
+ (int) $row['call_recording'],
+ (int) $row['can_mention_everyone'],
);
}
diff --git a/lib/Migration/Version18000Date20230505122109.php b/lib/Migration/Version18000Date20230505122109.php
new file mode 100644
index 00000000000..96678763698
--- /dev/null
+++ b/lib/Migration/Version18000Date20230505122109.php
@@ -0,0 +1,56 @@
+
+ *
+ * @author Vitor Mattos
+ *
+ * @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 .
+ *
+ */
+
+namespace OCA\Talk\Migration;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\DB\Types;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+class Version18000Date20230505122109 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_rooms');
+ if (!$table->hasColumn('can_mention_everyone')) {
+ $table->addColumn('can_mention_everyone', Types::INTEGER, [
+ 'default' => 1,
+ ]);
+ return $schema;
+ }
+ return null;
+ }
+}
diff --git a/lib/Model/SelectHelper.php b/lib/Model/SelectHelper.php
index 611d86753ad..92547144871 100644
--- a/lib/Model/SelectHelper.php
+++ b/lib/Model/SelectHelper.php
@@ -58,6 +58,7 @@ public function selectRoomsTable(IQueryBuilder $query, string $alias = 'r'): voi
->addSelect($alias . 'breakout_room_mode')
->addSelect($alias . 'breakout_room_status')
->addSelect($alias . 'call_recording')
+ ->addSelect($alias . 'can_mention_everyone')
->selectAlias($alias . 'id', 'r_id');
}
diff --git a/lib/Room.php b/lib/Room.php
index b0b8b36221b..7c1a2b7c8ce 100644
--- a/lib/Room.php
+++ b/lib/Room.php
@@ -101,6 +101,9 @@ class Room {
public const PARTICIPANT_REMOVED_ALL = 'remove_all';
public const PARTICIPANT_LEFT = 'leave';
+ public const CAN_MENTION_EVERYONE_MODERATORS = 0;
+ public const CAN_MENTION_EVERYONE_ALL = 1;
+
public const EVENT_AFTER_ROOM_CREATE = self::class . '::createdRoom';
public const EVENT_BEFORE_ROOM_DELETE = self::class . '::preDeleteRoom';
public const EVENT_AFTER_ROOM_DELETE = self::class . '::postDeleteRoom';
@@ -160,6 +163,8 @@ class Room {
public const EVENT_AFTER_SET_CALL_RECORDING = self::class . '::afterSetCallRecording';
public const EVENT_BEFORE_AVATAR_SET = self::class . '::preSetAvatar';
public const EVENT_AFTER_AVATAR_SET = self::class . '::postSetAvatar';
+ public const EVENT_BEFORE_SET_CAN_MENTION_EVERYONE = self::class . '::preCanMentionEveryone';
+ public const EVENT_AFTER_SET_CAN_MENTION_EVERYONE = self::class . '::postCanMentionEveryone';
public const DESCRIPTION_MAXIMUM_LENGTH = 500;
@@ -197,6 +202,7 @@ class Room {
private int $breakoutRoomMode;
private int $breakoutRoomStatus;
private int $callRecording;
+ private int $canMentionEveryone;
protected ?string $currentUser = null;
protected ?Participant $participant = null;
@@ -235,6 +241,7 @@ public function __construct(
int $breakoutRoomMode,
int $breakoutRoomStatus,
int $callRecording,
+ int $canMentionEveryone,
) {
$this->manager = $manager;
$this->db = $db;
@@ -269,6 +276,7 @@ public function __construct(
$this->breakoutRoomMode = $breakoutRoomMode;
$this->breakoutRoomStatus = $breakoutRoomStatus;
$this->callRecording = $callRecording;
+ $this->canMentionEveryone = $canMentionEveryone;
}
public function getId(): int {
@@ -656,4 +664,12 @@ public function getCallRecording(): int {
public function setCallRecording(int $callRecording): void {
$this->callRecording = $callRecording;
}
+
+ public function setCanMentionEveryone(int $canMentionEveryone): void {
+ $this->canMentionEveryone = $canMentionEveryone;
+ }
+
+ public function getCanMentionEveryone(): int {
+ return $this->canMentionEveryone;
+ }
}
diff --git a/lib/Service/RoomFormatter.php b/lib/Service/RoomFormatter.php
index f0b83413141..b457ac35367 100644
--- a/lib/Service/RoomFormatter.php
+++ b/lib/Service/RoomFormatter.php
@@ -139,6 +139,7 @@ public function formatRoomV4(
'isCustomAvatar' => $this->avatarService->isCustomAvatar($room),
'breakoutRoomMode' => BreakoutRoom::MODE_NOT_CONFIGURED,
'breakoutRoomStatus' => BreakoutRoom::STATUS_STOPPED,
+ 'canMentionEveryone' => Room::CAN_MENTION_EVERYONE_ALL,
];
$lastActivity = $room->getLastActivity();
@@ -215,6 +216,7 @@ public function formatRoomV4(
'messageExpiration' => $room->getMessageExpiration(),
'breakoutRoomMode' => $room->getBreakoutRoomMode(),
'breakoutRoomStatus' => $room->getBreakoutRoomStatus(),
+ 'canMentionEveryone' => $room->getCanMentionEveryone(),
]);
if ($currentParticipant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php
index 4776236c25e..eea6329b94d 100644
--- a/lib/Service/RoomService.php
+++ b/lib/Service/RoomService.php
@@ -851,4 +851,37 @@ public function deleteRoom(Room $room): void {
));
}
}
+
+ public function setCanMentionEveryone(Room $room, int $config): void {
+ $allowedValues = [
+ Room::CAN_MENTION_EVERYONE_MODERATORS,
+ Room::CAN_MENTION_EVERYONE_ALL
+ ];
+ if (!in_array($config, $allowedValues)) {
+ throw new InvalidArgumentException('config');
+ }
+ if ($room->getType() !== Room::TYPE_GROUP
+ && $room->getType() !== Room::TYPE_PUBLIC
+ ) {
+ throw new InvalidArgumentException('room');
+ }
+
+ $old = $room->getCanMentionEveryone();
+ if ($old === $config) {
+ return;
+ }
+
+ $event = new ModifyRoomEvent($room, 'canMentionEveryone', $config, $old);
+ $this->dispatcher->dispatch(Room::EVENT_BEFORE_SET_CAN_MENTION_EVERYONE, $event);
+
+ $update = $this->db->getQueryBuilder();
+ $update->update('talk_rooms')
+ ->set('can_mention_everyone', $update->createNamedParameter($config, IQueryBuilder::PARAM_INT))
+ ->where($update->expr()->eq('id', $update->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)));
+ $update->executeStatement();
+
+ $room->setCanMentionEveryone($config);
+
+ $this->dispatcher->dispatch(Room::EVENT_AFTER_SET_CAN_MENTION_EVERYONE, $event);
+ }
}
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index 97c842e9f08..cc260903146 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -3154,6 +3154,22 @@ public function userSetTheMessageExpirationToXWithStatusCode(string $user, int $
$this->assertStatusCode($this->response, $statusCode);
}
+ /**
+ * @Given /^user "([^"]*)" set can mention everyone to (all|moderators) of room "([^"]*)" with (\d+)(?: \((v4)\))?$/
+ */
+ public function userSetMentionEveryoneOfRoomWithStatus(string $user, string $who, string $identifier, int $statusCode, string $apiVersion = 'v1'): void {
+ if ($who === 'all') {
+ $config = 1;
+ } elseif ($who === 'moderators') {
+ $config = 0;
+ }
+ $this->setCurrentUser($user);
+ $this->sendRequest('PUT', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/can-mention-everyone', [
+ 'config' => $config,
+ ]);
+ $this->assertStatusCode($this->response, $statusCode);
+ }
+
/**
* @When wait for :seconds (second|seconds)
*/
diff --git a/tests/integration/features/chat/mentions.feature b/tests/integration/features/chat/mentions.feature
index 2c039f95cf5..97baf0cfa11 100644
--- a/tests/integration/features/chat/mentions.feature
+++ b/tests/integration/features/chat/mentions.feature
@@ -623,3 +623,22 @@ Feature: chat/mentions
And user "participant3" is participant of the following rooms (v4)
| id | unreadMention | unreadMentionDirect |
| group room | 0 | 0 |
+
+ Scenario: Toggle the usage of @all and try to use mentions
+ Given user "participant1" creates room "room" (v4)
+ | roomType | 2 |
+ | roomName | room |
+ And user "participant1" adds user "participant2" to room "room" with 200 (v4)
+ And user "participant2" joins room "room" with 200 (v4)
+ # default
+ Then user "participant2" gets the following candidate mentions in room "room" for "all" with 200
+ | id | label | source |
+ | all | room | calls |
+ # moderators
+ When user "participant1" set can mention everyone to moderators of room "room" with 200 (v4)
+ Then user "participant2" gets the following candidate mentions in room "room" for "all" with 200
+ # all
+ When user "participant1" set can mention everyone to all of room "room" with 200 (v4)
+ Then user "participant2" gets the following candidate mentions in room "room" for "all" with 200
+ | id | label | source |
+ | all | room | calls |
diff --git a/tests/integration/features/chat/notifications.feature b/tests/integration/features/chat/notifications.feature
index 527f6201d68..2738da41aef 100644
--- a/tests/integration/features/chat/notifications.feature
+++ b/tests/integration/features/chat/notifications.feature
@@ -479,3 +479,19 @@ Feature: chat/notifications
When user "participant1" sets lobby state for room "room" to "non moderators" with 200 (v4)
Then user "participant2" has the following notifications
| app | object_type | object_id | subject |
+
+ Scenario: Toggle the usage of @all in a group by non moderators
+ Given user "participant1" creates room "room" (v4)
+ | roomType | 2 |
+ | roomName | room |
+ And user "participant1" set can mention everyone to moderators of room "room" with 200 (v4)
+ And user "participant1" adds user "participant2" to room "room" with 200 (v4)
+ And user "participant2" joins room "room" with 200 (v4)
+ When user "participant2" sends message "Hi @all" to room "room" with 201
+ Then user "participant1" has the following notifications
+ | app | object_type | object_id | subject |
+ And user "participant1" set can mention everyone to all of room "room" with 200 (v4)
+ And user "participant2" sends message "Bye @all" to room "room" with 201
+ Then user "participant1" has the following notifications
+ | app | object_type | object_id | subject |
+ | spreed | chat | room/Bye @all | participant2-displayname mentioned everyone in conversation room |
diff --git a/tests/php/Chat/ChatManagerTest.php b/tests/php/Chat/ChatManagerTest.php
index e0f3c9dd786..c16e092fb72 100644
--- a/tests/php/Chat/ChatManagerTest.php
+++ b/tests/php/Chat/ChatManagerTest.php
@@ -707,7 +707,7 @@ public function dataAddConversationNotify(): array {
],
[
'',
- ['getDisplayName' => 'test'],
+ ['getDisplayName' => 'test', 'getCanMentionEveryone' => 1],
['getAttendee' => Attendee::fromRow([
'actor_type' => Attendee::ACTOR_USERS,
'actor_id' => 'user',
@@ -716,7 +716,7 @@ public function dataAddConversationNotify(): array {
],
[
'all',
- ['getDisplayName' => 'test'],
+ ['getDisplayName' => 'test', 'getCanMentionEveryone' => 1],
['getAttendee' => Attendee::fromRow([
'actor_type' => Attendee::ACTOR_USERS,
'actor_id' => 'user',
@@ -725,12 +725,21 @@ public function dataAddConversationNotify(): array {
],
[
'here',
- ['getDisplayName' => 'test'],
+ ['getDisplayName' => 'test', 'getCanMentionEveryone' => 1],
['getAttendee' => Attendee::fromRow([
'actor_type' => Attendee::ACTOR_GUESTS,
'actor_id' => 'guest',
])],
[['id' => 'all', 'label' => 'test', 'source' => 'calls']]
+ ],
+ [
+ 'here',
+ ['getDisplayName' => 'test', 'getCanMentionEveryone' => 0],
+ ['getAttendee' => Attendee::fromRow([
+ 'actor_type' => Attendee::ACTOR_GUESTS,
+ 'actor_id' => 'guest',
+ ])],
+ []
]
];
}
diff --git a/tests/php/Chat/NotifierTest.php b/tests/php/Chat/NotifierTest.php
index dc2088b1995..0529d569118 100644
--- a/tests/php/Chat/NotifierTest.php
+++ b/tests/php/Chat/NotifierTest.php
@@ -170,7 +170,8 @@ public function testNotifyMentionedUsers(string $message, array $alreadyNotified
$room = $this->getRoom();
$comment = $this->newComment('108', 'users', 'testUser', new \DateTime('@' . 1000000016), $message);
$notifier = $this->getNotifier([]);
- $actual = $notifier->notifyMentionedUsers($room, $comment, $alreadyNotifiedUsers, false);
+ $participant = $this->createMock(Participant::class);
+ $actual = $notifier->notifyMentionedUsers($room, $comment, $alreadyNotifiedUsers, false, $participant);
$this->assertEqualsCanonicalizing($expectedReturn, $actual);
}
@@ -322,13 +323,20 @@ public function testRemovePendingNotificationsForChatOnly(): void {
/**
* @dataProvider dataAddMentionAllToList
*/
- public function testAddMentionAllToList(array $usersToNotify, array $participants, array $return): void {
+ public function testAddMentionAllToList(array $usersToNotify, array $participants, $canNotifyAll, array $return): void {
$room = $this->createMock(Room::class);
$this->participantService
->method('getActorsByType')
->willReturn($participants);
+ $participant = $this->createMock(Participant::class);
+ $participant->expects($this->any())
+ ->method('hasModeratorPermissions')
+ ->willReturn($canNotifyAll);
+ $room->expects($this->any())
+ ->method('getCanMentionEveryone')
+ ->willReturn($canNotifyAll ? 1 : 0);
- $actual = self::invokePrivate($this->getNotifier(), 'addMentionAllToList', [$room, $usersToNotify]);
+ $actual = self::invokePrivate($this->getNotifier(), 'addMentionAllToList', [$room, $usersToNotify, $participant]);
$this->assertCount(count($return), $actual);
foreach ($actual as $key => $value) {
$this->assertIsArray($value);
@@ -345,6 +353,7 @@ public function dataAddMentionAllToList(): array {
'not notify' => [
[],
[],
+ false,
[],
],
'preserve notify list and do not notify all' => [
@@ -352,6 +361,7 @@ public function dataAddMentionAllToList(): array {
['id' => 'user1', 'type' => Attendee::ACTOR_USERS, 'reason' => 'direct'],
],
[],
+ false,
[
['id' => 'user1', 'type' => Attendee::ACTOR_USERS, 'reason' => 'direct'],
],
@@ -365,11 +375,26 @@ public function dataAddMentionAllToList(): array {
Attendee::fromRow(['actor_id' => 'user1', 'actor_type' => Attendee::ACTOR_USERS]),
Attendee::fromRow(['actor_id' => 'user2', 'actor_type' => Attendee::ACTOR_USERS]),
],
+ true,
[
['id' => 'user1', 'type' => Attendee::ACTOR_USERS, 'reason' => 'direct'],
['id' => 'user2', 'type' => Attendee::ACTOR_USERS, 'reason' => 'all'],
],
],
+ 'can not mention all' => [
+ [
+ ['id' => 'user1', 'type' => Attendee::ACTOR_USERS, 'reason' => 'direct'],
+ ['id' => 'all', 'type' => Attendee::ACTOR_USERS, 'reason' => 'direct'],
+ ],
+ [
+ Attendee::fromRow(['actor_id' => 'user1', 'actor_type' => Attendee::ACTOR_USERS]),
+ Attendee::fromRow(['actor_id' => 'user2', 'actor_type' => Attendee::ACTOR_USERS]),
+ ],
+ false,
+ [
+ ['id' => 'user1', 'type' => Attendee::ACTOR_USERS, 'reason' => 'direct'],
+ ],
+ ],
];
}
diff --git a/tests/php/Service/RoomServiceTest.php b/tests/php/Service/RoomServiceTest.php
index 9334f2d716f..d5c1e9e8636 100644
--- a/tests/php/Service/RoomServiceTest.php
+++ b/tests/php/Service/RoomServiceTest.php
@@ -396,7 +396,8 @@ public function testVerifyPassword(): void {
'',
0,
0,
- 0
+ 0,
+ 0,
);
$verificationResult = $service->verifyPassword($room, '1234');