Skip to content

Commit

Permalink
feat(calls): Add appconfig and user preference for default setting of…
Browse files Browse the repository at this point in the history
… media

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Oct 7, 2024
1 parent b681d0e commit bd1c758
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,4 @@

## 20.1
* `archived-conversations` (local) - Conversations can be marked as archived which will hide them from the conversation list by default
* `config => call => start-without-media` (local) - Boolean, whether media should be disabled when starting or joining a conversation
1 change: 1 addition & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Legend:
| `changelog` | string<br>`yes` or `no` | `yes` | No | | Whether the changelog conversation is updated with new features on major releases |
| `has_reference_id` | string<br>`yes` or `no` | `no` | Yes | | Indicator whether the clients can use the reference value to identify their message, will be automatically set to `yes` when the repair steps are executed |
| `hide_signaling_warning` | string<br>`yes` or `no` | `no` | No | 🖌️ | Flag that allows to suppress the warning that an HPB should be configured |
| `calls_start_without_media` | string<br>`yes` or `no` | `no` | Yes | | Whether participants start with enabled or disabled audio and video by default |
| `breakout_rooms` | string<br>`yes` or `no` | `yes` | Yes | | Whether or not breakout rooms are allowed (Will only prevent creating new breakout rooms. Existing conversations are not modified.) |
| `call_recording` | string<br>`yes` or `no` | `yes` | Yes | | Enable call recording |
| `call_recording_transcription` | string<br>`yes` or `no` | `no` | No | | Whether call recordings should automatically be transcripted when a transcription provider is enabled. |
Expand Down
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
use OCA\Talk\Search\MessageSearch;
use OCA\Talk\Search\UnifiedSearchCSSLoader;
use OCA\Talk\Search\UnifiedSearchFilterPlugin;
use OCA\Talk\Settings\BeforePreferenceSetEventListener;
use OCA\Talk\Settings\Personal;
use OCA\Talk\SetupCheck\BackgroundBlurLoading;
use OCA\Talk\SetupCheck\FederationLockCache;
Expand All @@ -124,6 +125,7 @@
use OCP\Collaboration\AutoComplete\AutoCompleteFilterEvent;
use OCP\Collaboration\Resources\IProviderManager;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
use OCP\Config\BeforePreferenceSetEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationProvider;
use OCP\Federation\ICloudFederationProviderManager;
Expand Down Expand Up @@ -177,6 +179,7 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeTemplateRenderedEvent::class, PublicShareTemplateLoader::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, PublicShareAuthTemplateLoader::class);
$context->registerEventListener(LoadSidebar::class, FilesTemplateLoader::class);
$context->registerEventListener(BeforePreferenceSetEvent::class, BeforePreferenceSetEventListener::class);

// Activity listeners
$context->registerEventListener(AttendeesAddedEvent::class, ActivityListener::class);
Expand Down
2 changes: 2 additions & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Capabilities implements IPublicCapability {
'call' => [
'predefined-backgrounds',
'can-upload-background',
'start-without-media',
],
'chat' => [
'read-privacy',
Expand Down Expand Up @@ -196,6 +197,7 @@ public function getCapabilities(): array {
'sip-enabled' => $this->talkConfig->isSIPConfigured(),
'sip-dialout-enabled' => $this->talkConfig->isSIPDialOutEnabled(),
'can-enable-sip' => false,
'start-without-media' => $this->talkConfig->getCallsStartWithoutMedia($user?->getUID()),
],
'chat' => [
'max-length' => ChatManager::MAX_CHAT_LENGTH,
Expand Down
15 changes: 15 additions & 0 deletions lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\Talk\Federation\Authenticator;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Service\RecordingService;
use OCA\Talk\Settings\UserPreference;
use OCA\Talk\Vendor\Firebase\JWT\JWT;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
Expand Down Expand Up @@ -662,4 +663,18 @@ public function getGridVideosLimit(): int {
public function getGridVideosLimitEnforced(): bool {
return $this->config->getAppValue('spreed', 'grid_videos_limit_enforced', 'no') === 'yes';
}

/**
* User setting falling back to admin defined app config
*
* @param ?string $userId
* @return bool
*/
public function getCallsStartWithoutMedia(?string $userId): bool {
if ($userId !== null && $this->config->getUserValue($userId, 'spreed', UserPreference::CALLS_START_WITHOUT_MEDIA) === 'no') {
return false;
}

return $this->appConfig->getAppValueBool('calls_start_without_media');
}
}
3 changes: 3 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,9 @@ public function getCapabilities(): DataResponse {
if (isset($data['config']['chat']['typing-privacy'])) {
$data['config']['chat']['typing-privacy'] = Participant::PRIVACY_PRIVATE;
}
if (isset($data['config']['call']['start-without-media'])) {
$data['config']['call']['start-without-media'] = $this->talkConfig->getCallsStartWithoutMedia($this->userId);
}

if ($response->getHeaders()['X-Nextcloud-Talk-Hash']) {
$headers['X-Nextcloud-Talk-Proxy-Hash'] = $response->getHeaders()['X-Nextcloud-Talk-Hash'];
Expand Down
1 change: 1 addition & 0 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@
* sip-enabled: bool,
* sip-dialout-enabled: bool,
* can-enable-sip: bool,
* start-without-media: bool,
* },
* chat: array{
* max-length: int,
Expand Down
51 changes: 51 additions & 0 deletions lib/Settings/BeforePreferenceSetEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\Settings;

use OCA\Talk\AppInfo\Application;
use OCA\Talk\Participant;
use OCP\Config\BeforePreferenceSetEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<Event>
*/
class BeforePreferenceSetEventListener implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof BeforePreferenceSetEvent)) {
// Unrelated
return;
}

if ($event->getAppId() !== Application::APP_ID) {
return;
}

$event->setValid($this->validatePreference(
$event->getConfigKey(),
$event->getConfigValue(),
));
}

protected function validatePreference(string $key, string $value): bool {
// "boolean" yes/no
if ($key === UserPreference::CALLS_START_WITHOUT_MEDIA
|| $key === UserPreference::PLAY_SOUNDS) {
return $value === 'yes' || $value === 'no';
}

// "privacy" 0/1
if ($key === UserPreference::TYPING_PRIVACY
|| $key === UserPreference::READ_STATUS_PRIVACY) {
return $value === (string)Participant::PRIVACY_PRIVATE || $value === (string)Participant::PRIVACY_PUBLIC;
}
return false;
}
}
16 changes: 16 additions & 0 deletions lib/Settings/UserPreference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\Settings;

class UserPreference {
public const CALLS_START_WITHOUT_MEDIA = 'calls_start_without_media';
public const PLAY_SOUNDS = 'play_sounds';
public const TYPING_PRIVACY = 'typing_privacy';
public const READ_STATUS_PRIVACY = 'read_status_privacy';
}
2 changes: 2 additions & 0 deletions tests/php/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function testGetCapabilitiesGuest(): void {
'sip-enabled' => false,
'sip-dialout-enabled' => false,
'can-enable-sip' => false,
'start-without-media' => false,
'predefined-backgrounds' => [
'1_office.jpg',
'2_home.jpg',
Expand Down Expand Up @@ -252,6 +253,7 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea
'sip-enabled' => false,
'sip-dialout-enabled' => false,
'can-enable-sip' => false,
'start-without-media' => false,
'predefined-backgrounds' => [
'1_office.jpg',
'2_home.jpg',
Expand Down

0 comments on commit bd1c758

Please sign in to comment.