diff options
-rw-r--r-- | docs/call.md | 1 | ||||
-rw-r--r-- | docs/capabilities.md | 1 | ||||
-rw-r--r-- | lib/Capabilities.php | 1 | ||||
-rw-r--r-- | lib/Controller/CallController.php | 4 | ||||
-rw-r--r-- | lib/Events/SilentModifyParticipantEvent.php | 27 | ||||
-rw-r--r-- | lib/Notification/Listener.php | 12 | ||||
-rw-r--r-- | lib/Service/ParticipantService.php | 9 | ||||
-rw-r--r-- | tests/integration/features/bootstrap/FeatureContext.php | 16 | ||||
-rw-r--r-- | tests/integration/features/callapi/notifications.feature | 68 | ||||
-rw-r--r-- | tests/php/CapabilitiesTest.php | 1 |
10 files changed, 132 insertions, 8 deletions
diff --git a/docs/call.md b/docs/call.md index 0dc3d788a..92fadce89 100644 --- a/docs/call.md +++ b/docs/call.md @@ -38,6 +38,7 @@ field | type | Description ---|---|--- `flags` | int | Flags what streams are provided by the participant (see [Constants - Participant in-call flag](constants.md#participant-in-call-flag)) + `silent` | bool | Disable start call notifications for group/public calls * Response: - Status code: diff --git a/docs/capabilities.md b/docs/capabilities.md index 92ddc828c..ce4507633 100644 --- a/docs/capabilities.md +++ b/docs/capabilities.md @@ -99,5 +99,6 @@ title: Capabilities * `silent-send` - Whether the chat API allows to send chat messages without triggering notifications * `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 * `config => call => enabled` - Whether calling is enabled on the instance or not * `config => signaling => session-ping-limit` - Number of sessions the HPB is allowed to ping in the same request diff --git a/lib/Capabilities.php b/lib/Capabilities.php index 1623b6249..57650a54d 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -105,6 +105,7 @@ class Capabilities implements IPublicCapability { 'unified-search', 'chat-permission', 'silent-send', + 'silent-call', 'send-call-notification', ], 'config' => [ diff --git a/lib/Controller/CallController.php b/lib/Controller/CallController.php index 26797eae5..f55b62bc7 100644 --- a/lib/Controller/CallController.php +++ b/lib/Controller/CallController.php @@ -111,7 +111,7 @@ class CallController extends AEnvironmentAwareController { * @param int|null $forcePermissions * @return DataResponse */ - public function joinCall(?int $flags = null, ?int $forcePermissions = null): DataResponse { + public function joinCall(?int $flags = null, ?int $forcePermissions = null, bool $silent = false): DataResponse { $this->participantService->ensureOneToOneRoomIsFilled($this->room); $session = $this->participant->getSession(); @@ -128,7 +128,7 @@ class CallController extends AEnvironmentAwareController { $this->roomService->setPermissions($this->room, 'call', Attendee::PERMISSIONS_MODIFY_SET, $forcePermissions, true); } - $this->participantService->changeInCall($this->room, $this->participant, $flags); + $this->participantService->changeInCall($this->room, $this->participant, $flags, false, $silent); return new DataResponse(); } diff --git a/lib/Events/SilentModifyParticipantEvent.php b/lib/Events/SilentModifyParticipantEvent.php new file mode 100644 index 000000000..1ac9d3806 --- /dev/null +++ b/lib/Events/SilentModifyParticipantEvent.php @@ -0,0 +1,27 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2022 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; + +class SilentModifyParticipantEvent extends ModifyParticipantEvent { +} diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php index f6913e67a..7ab0d5274 100644 --- a/lib/Notification/Listener.php +++ b/lib/Notification/Listener.php @@ -28,6 +28,7 @@ use OCA\Talk\Events\AddParticipantsEvent; use OCA\Talk\Events\JoinRoomUserEvent; use OCA\Talk\Events\RoomEvent; use OCA\Talk\Events\SendCallNotificationEvent; +use OCA\Talk\Events\SilentModifyParticipantEvent; use OCA\Talk\Model\Attendee; use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; @@ -90,7 +91,8 @@ class Listener implements IEventListener { $listener = static function (RoomEvent $event): void { $listener = Server::get(self::class); - $listener->checkCallNotifications($event->getRoom()); + $silent = $event instanceof SilentModifyParticipantEvent; + $listener->checkCallNotifications($event->getRoom(), $silent); }; $dispatcher->addListener(Room::EVENT_BEFORE_SESSION_JOIN_CALL, $listener); @@ -188,10 +190,12 @@ class Listener implements IEventListener { /** * Call notification: "{user} wants to talk with you" - * - * @param Room $room */ - public function checkCallNotifications(Room $room): void { + public function checkCallNotifications(Room $room, bool $silent = false): void { + if ($silent) { + $this->shouldSendCallNotification = false; + return; + } if ($room->getActiveSince() instanceof \DateTime) { // Call already active => No new notifications $this->shouldSendCallNotification = false; diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 274ed2986..852e33d7f 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -43,6 +43,7 @@ use OCA\Talk\Events\RemoveParticipantEvent; use OCA\Talk\Events\RemoveUserEvent; use OCA\Talk\Events\RoomEvent; use OCA\Talk\Events\SendCallNotificationEvent; +use OCA\Talk\Events\SilentModifyParticipantEvent; use OCA\Talk\Exceptions\ForbiddenException; use OCA\Talk\Exceptions\InvalidPasswordException; use OCA\Talk\Exceptions\ParticipantNotFoundException; @@ -947,7 +948,7 @@ class ParticipantService { $this->dispatcher->dispatch(Room::EVENT_AFTER_END_CALL_FOR_EVERYONE, $event); } - public function changeInCall(Room $room, Participant $participant, int $flags, bool $endCallForEveryone = false): void { + public function changeInCall(Room $room, Participant $participant, int $flags, bool $endCallForEveryone = false, bool $silent = false): void { $session = $participant->getSession(); if (!$session instanceof Session) { return; @@ -962,7 +963,11 @@ class ParticipantService { } if ($flags !== Participant::FLAG_DISCONNECTED) { - $event = new ModifyParticipantEvent($room, $participant, 'inCall', $flags, $session->getInCall()); + if ($silent) { + $event = new SilentModifyParticipantEvent($room, $participant, 'inCall', $flags, $session->getInCall(), $silent); + } else { + $event = new ModifyParticipantEvent($room, $participant, 'inCall', $flags, $session->getInCall(), $silent); + } $this->dispatcher->dispatch(Room::EVENT_BEFORE_SESSION_JOIN_CALL, $event); } else { if ($endCallForEveryone) { diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index ed3088b02..6e741187f 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -1342,6 +1342,22 @@ class FeatureContext implements Context, SnippetAcceptingContext { } /** + * @Then /^user "([^"]*)" pings (user|guest) "([^"]*)" to join call "([^"]*)" with (\d+) \((v4)\)$/ + * + * @param string $user + * @param string $actorType + * @param string $actorId + * @param string $identifier + * @param int $statusCode + * @param string $apiVersion + */ + public function userPingsAttendeeInRoomTo(string $user, string $actorType, string $actorId, string $identifier, int $statusCode, string $apiVersion): void { + $this->setCurrentUser($user); + $this->sendRequest('POST', '/apps/spreed/api/' . $apiVersion . '/call/' . self::$identifierToToken[$identifier] . '/ring/' . self::$userToAttendeeId[$actorType . 's'][$actorId]); + $this->assertStatusCode($this->response, $statusCode); + } + + /** * @Then /^user "([^"]*)" leaves call "([^"]*)" with (\d+) \((v4)\)$/ * * @param string $user diff --git a/tests/integration/features/callapi/notifications.feature b/tests/integration/features/callapi/notifications.feature new file mode 100644 index 000000000..b1d13c051 --- /dev/null +++ b/tests/integration/features/callapi/notifications.feature @@ -0,0 +1,68 @@ +Feature: chat/notifications + + Background: + Given user "participant1" exists + Given user "participant2" exists + + Scenario: Normal call notification + When user "participant1" creates room "room" (v4) + | roomType | 2 | + | roomName | room | + And user "participant1" adds user "participant2" to room "room" with 200 (v4) + Given user "participant1" joins room "room" with 200 (v4) + Given user "participant2" joins room "room" with 200 (v4) + Given user "participant1" joins call "room" with 200 (v4) + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | call | room | A group call has started in room | + Given user "participant2" joins call "room" with 200 (v4) + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + + Scenario: Missed call notification + When user "participant1" creates room "room" (v4) + | roomType | 2 | + | roomName | room | + And user "participant1" adds user "participant2" to room "room" with 200 (v4) + Given user "participant1" joins room "room" with 200 (v4) + Given user "participant2" joins room "room" with 200 (v4) + Given user "participant1" joins call "room" with 200 (v4) + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | call | room | A group call has started in room | + Given user "participant1" leaves call "room" with 200 (v4) + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | call | room | You missed a group call in room | + + Scenario: Silent call does not trigger notifications + When user "participant1" creates room "room" (v4) + | roomType | 2 | + | roomName | room | + And user "participant1" adds user "participant2" to room "room" with 200 (v4) + Given user "participant1" joins room "room" with 200 (v4) + Given user "participant2" joins room "room" with 200 (v4) + Given user "participant1" joins call "room" with 200 (v4) + | silent | true | + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + Given user "participant1" leaves call "room" with 200 (v4) + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + + Scenario: Silent call with dedicated ping does trigger notifications + When user "participant1" creates room "room" (v4) + | roomType | 2 | + | roomName | room | + And user "participant1" adds user "participant2" to room "room" with 200 (v4) + Given user "participant1" joins room "room" with 200 (v4) + Given user "participant2" joins room "room" with 200 (v4) + Given user "participant1" loads attendees attendee ids in room "room" (v4) + Given user "participant1" joins call "room" with 200 (v4) + | silent | true | + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + Given user "participant1" pings user "participant2" to join call "room" with 200 (v4) + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | call | room | A group call has started in room | diff --git a/tests/php/CapabilitiesTest.php b/tests/php/CapabilitiesTest.php index f046e7457..b52318918 100644 --- a/tests/php/CapabilitiesTest.php +++ b/tests/php/CapabilitiesTest.php @@ -109,6 +109,7 @@ class CapabilitiesTest extends TestCase { 'unified-search', 'chat-permission', 'silent-send', + 'silent-call', 'send-call-notification', 'reactions', ]; |