Skip to content
Draft
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
107 changes: 54 additions & 53 deletions lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public function __construct(
* @return string[]
*/
public function getAllowedTalkGroupIds(): array {
$groups = $this->config->getAppValue('spreed', 'allowed_groups', '[]');
$groups = json_decode($groups, true);
return \is_array($groups) ? $groups : [];
$groups = $this->appConfig->getAppValueArray('allowed_groups');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document the types and included changed defaults in the settings.md

@miaulalala miaulalala Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the setter didn't change?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we should use the same type in get and set, otherwise this is "based on assumptions that might change".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, fair enough. I just figured your comment in #17171 (comment) was meant to point me towards using getArrayValue

if (empty($groups)) {
return [];
}
return $groups;
}

/**
Expand Down Expand Up @@ -98,9 +100,11 @@ public function getUserTypingPrivacy(string $userId): int {
* @return string[]
*/
public function getSIPGroups(): array {
$groups = $this->config->getAppValue('spreed', 'sip_bridge_groups', '[]');
$groups = json_decode($groups, true);
return \is_array($groups) ? $groups : [];
$groups = $this->appConfig->getAppValueArray('sip_bridge_groups');
if (empty($groups)) {
return [];
}
return $groups;
}

public function isSIPConfigured(): bool {
Expand All @@ -113,7 +117,7 @@ public function isSIPConfigured(): bool {
*/
public function isFederationEnabled(): bool {
// TODO: Set to default true once implementation is complete
return $this->config->getAppValue('spreed', 'federation_enabled', 'no') === 'yes';
return $this->appConfig->getAppValueBool('federation_enabled');
}

public function isFederationEnabledForUserId(IUser $user): bool {
Expand All @@ -127,15 +131,15 @@ public function isFederationEnabledForUserId(IUser $user): bool {
}

public function isBreakoutRoomsEnabled(): bool {
return $this->config->getAppValue('spreed', 'breakout_rooms', 'yes') === 'yes';
return $this->appConfig->getAppValueBool('breakout_rooms', true);
}

public function getDialInInfo(): string {
return $this->config->getAppValue('spreed', 'sip_bridge_dialin_info');
return $this->appConfig->getAppValueString('sip_bridge_dialin_info');
}

public function getSIPSharedSecret(): string {
return $this->config->getAppValue('spreed', 'sip_bridge_shared_secret');
return $this->appConfig->getAppValueString('sip_bridge_shared_secret');
}

public function canUserEnableSIP(IUser $user): bool {
Expand Down Expand Up @@ -165,37 +169,33 @@ public function canUserDialOutSIP(IUser $user): bool {
}

public function isSIPDialOutEnabled(): bool {
return $this->config->getAppValue('spreed', 'sip_dialout', 'no') !== 'no';
return $this->appConfig->getAppValueBool('sip_dialout');
}

public function getRecordingServers(): array {
$config = $this->config->getAppValue('spreed', 'recording_servers');
$recording = json_decode($config, true);

if (!is_array($recording) || !isset($recording['servers'])) {
$recording = $this->appConfig->getAppValueArray('recording_servers');
if (empty($recording) || !isset($recording['servers'])) {
return [];
}

return $recording['servers'];
}

public function getRecordingSecret(): string {
$config = $this->config->getAppValue('spreed', 'recording_servers');
$recording = json_decode($config, true);

if (!is_array($recording)) {
$config = $this->appConfig->getAppValueArray('recording_servers');
if (!isset($config['secret'])) {
return '';
}

return $recording['secret'];
return $config['secret'];
}

public function isRecordingEnabled(): bool {
if ($this->getSignalingMode() === self::SIGNALING_INTERNAL) {
return false;
}

if ($this->config->getAppValue('spreed', 'call_recording', 'yes') !== 'yes') {
if (!$this->appConfig->getAppValueBool('call_recording', true)) {
return false;
}

Expand Down Expand Up @@ -226,7 +226,7 @@ public function recordingConsentRequired(): int {
* @return RecordingService::CONSENT_REQUIRED_*
*/
public function getRecordingConsentConfig(): int {
return match ((int)$this->config->getAppValue('spreed', 'recording_consent', (string)RecordingService::CONSENT_REQUIRED_NO)) {
return match ($this->appConfig->getAppValueInt('recording_consent', RecordingService::CONSENT_REQUIRED_NO)) {
RecordingService::CONSENT_REQUIRED_YES => RecordingService::CONSENT_REQUIRED_YES,
RecordingService::CONSENT_REQUIRED_OPTIONAL => RecordingService::CONSENT_REQUIRED_OPTIONAL,
default => RecordingService::CONSENT_REQUIRED_NO,
Expand Down Expand Up @@ -265,9 +265,11 @@ public function isDisabledForUser(IUser $user): bool {
* @return string[]
*/
public function getAllowedConversationsGroupIds(): array {
$groups = $this->config->getAppValue('spreed', 'start_conversations', '[]');
$groups = json_decode($groups, true);
return \is_array($groups) ? $groups : [];
$groups = $this->appConfig->getAppValueArray('start_conversations');
if (empty($groups)) {
return [];
}
return $groups;
}

public function isNotAllowedToCreateConversations(IUser $user): bool {
Expand All @@ -286,7 +288,7 @@ public function isNotAllowedToCreateConversations(IUser $user): bool {
*/
public function getDefaultPermissions(): int {
// Admin configured default permissions
$configurableDefault = $this->config->getAppValue('spreed', 'default_permissions');
$configurableDefault = $this->appConfig->getAppValueString('default_permissions');
if ($configurableDefault !== '') {
return min(Attendee::PERMISSIONS_MAX_CUSTOM, max(Attendee::PERMISSIONS_DEFAULT, (int)$configurableDefault));
}
Expand All @@ -296,7 +298,7 @@ public function getDefaultPermissions(): int {
}

public function getAttachmentFolder(string $userId): string {
$defaultAttachmentFolder = $this->config->getAppValue('spreed', 'default_attachment_folder', '/Talk');
$defaultAttachmentFolder = $this->appConfig->getAppValueString('default_attachment_folder', '/Talk');
return $this->config->getUserValue($userId, 'spreed', UserPreference::ATTACHMENT_FOLDER, $defaultAttachmentFolder);
}

Expand Down Expand Up @@ -355,7 +357,7 @@ protected function getWebSocketDomainForSignalingServer(string $url): string {
* @return string[]
*/
public function getStunServers(): array {
$config = $this->config->getAppValue('spreed', 'stun_servers', json_encode(['stun.nextcloud.com:443']));
$config = $this->appConfig->getAppValueString('stun_servers', json_encode(['stun.nextcloud.com:443']));
$servers = json_decode($config, true);

if (!is_array($servers) || empty($servers)) {
Expand All @@ -377,11 +379,9 @@ public function getStunServers(): array {
* @return array
*/
public function getTurnServers(bool $withEvent = true): array {
$config = $this->config->getAppValue('spreed', 'turn_servers');
$servers = json_decode($config, true);

if ($servers === null || empty($servers) || !is_array($servers)) {
$servers = [];
$servers = $this->appConfig->getAppValueArray('turn_servers');
if (empty($servers)) {
return [];
}

if ($withEvent) {
Expand Down Expand Up @@ -428,7 +428,7 @@ public function getTurnSettings(): array {
];
}

return $turnSettings;
return $turnSettings ?? [];
}

public function getSignalingMode(bool $cleanExternalSignaling = true): string {
Expand All @@ -438,7 +438,7 @@ public function getSignalingMode(bool $cleanExternalSignaling = true): string {
self::SIGNALING_CLUSTER_CONVERSATION,
];

$mode = $this->config->getAppValue('spreed', 'signaling_mode', null);
$mode = $this->appConfig->getAppValueString('signaling_mode');
if ($mode === self::SIGNALING_INTERNAL) {
return self::SIGNALING_INTERNAL;
}
Expand All @@ -462,9 +462,8 @@ public function getSignalingMode(bool $cleanExternalSignaling = true): string {
* @return array
*/
public function getSignalingServers(): array {
$config = $this->config->getAppValue('spreed', 'signaling_servers');
$signaling = json_decode($config, true);
if (!is_array($signaling) || !isset($signaling['servers'])) {
$signaling = $this->appConfig->getAppValueArray('signaling_servers');
if (empty($signaling) || !isset($signaling['servers'])) {
return [];
}

Expand All @@ -475,7 +474,10 @@ public function getSignalingServers(): array {
* @return string
*/
public function getSignalingSecret(): string {
$config = $this->config->getAppValue('spreed', 'signaling_servers');
$config = $this->appConfig->getAppValueString('signaling_servers');
if ($config === '') {
return '';
}
$signaling = json_decode($config, true);

if (!is_array($signaling)) {
Expand All @@ -486,7 +488,7 @@ public function getSignalingSecret(): string {
}

public function getHideSignalingWarning(): bool {
return $this->config->getAppValue('spreed', 'hide_signaling_warning', 'no') === 'yes';
return $this->appConfig->getAppValueBool('hide_signaling_warning');
}

/**
Expand All @@ -510,7 +512,7 @@ public function getSignalingTicket(int $version, ?string $userId, ?string $cloud
*/
private function getSignalingTicketV1(?string $userId): string {
if (empty($userId)) {
$secret = $this->config->getAppValue('spreed', 'signaling_ticket_secret');
$secret = $this->appConfig->getAppValueString('signaling_ticket_secret');
} else {
$secret = $this->config->getUserValue($userId, 'spreed', 'signaling_ticket_secret');
}
Expand All @@ -519,7 +521,7 @@ private function getSignalingTicketV1(?string $userId): string {
// TODO(fancycode): Is there a possibility for a race condition?
$secret = $this->secureRandom->generate(255);
if (empty($userId)) {
$this->config->setAppValue('spreed', 'signaling_ticket_secret', $secret);
$this->appConfig->setAppValueString('signaling_ticket_secret', $secret);
} else {
$this->config->setUserValue($userId, 'spreed', 'signaling_ticket_secret', $secret);
}
Expand All @@ -535,7 +537,7 @@ private function getSignalingTicketV1(?string $userId): string {
}

private function ensureSignalingTokenKeys(string $alg): void {
$secret = $this->config->getAppValue('spreed', 'signaling_token_privkey_' . strtolower($alg));
$secret = $this->appConfig->getAppValueString('signaling_token_privkey_' . strtolower($alg));
if ($secret) {
return;
}
Expand Down Expand Up @@ -569,12 +571,12 @@ private function ensureSignalingTokenKeys(string $alg): void {
throw new \Exception('Unsupported algorithm ' . $alg);
}

$this->config->setAppValue('spreed', 'signaling_token_privkey_' . strtolower($alg), $secret);
$this->config->setAppValue('spreed', 'signaling_token_pubkey_' . strtolower($alg), $public);
$this->appConfig->setAppValueString('signaling_token_privkey_' . strtolower($alg), $secret);
$this->appConfig->setAppValueString('signaling_token_pubkey_' . strtolower($alg), $public);
}

public function getSignalingTokenAlgorithm(): string {
return $this->config->getAppValue('spreed', 'signaling_token_alg', 'ES256');
return $this->appConfig->getAppValueString('signaling_token_alg', 'ES256');
}

public function getSignalingTokenPrivateKey(?string $alg = null): string {
Expand All @@ -583,7 +585,7 @@ public function getSignalingTokenPrivateKey(?string $alg = null): string {
}
$this->ensureSignalingTokenKeys($alg);

return $this->config->getAppValue('spreed', 'signaling_token_privkey_' . strtolower($alg));
return $this->appConfig->getAppValueString('signaling_token_privkey_' . strtolower($alg));
}

public function getSignalingTokenPublicKey(?string $alg = null): string {
Expand All @@ -592,7 +594,7 @@ public function getSignalingTokenPublicKey(?string $alg = null): string {
}
$this->ensureSignalingTokenKeys($alg);

return $this->config->getAppValue('spreed', 'signaling_token_pubkey_' . strtolower($alg));
return $this->appConfig->getAppValueString('signaling_token_pubkey_' . strtolower($alg));
}

public function deriveSignalingTokenPublicKey(string $privateKey, string $alg): string {
Expand Down Expand Up @@ -678,8 +680,7 @@ private function getSignalingTicketV2(?string $userId, ?string $cloudId): string

$alg = $this->getSignalingTokenAlgorithm();
$secret = $this->getSignalingTokenPrivateKey($alg);
$token = JWT::encode($data, $secret, $alg);
return $token;
return JWT::encode($data, $secret, $alg);
}

/**
Expand All @@ -689,7 +690,7 @@ private function getSignalingTicketV2(?string $userId, ?string $cloudId): string
*/
public function validateSignalingTicket(?string $userId, string $ticket): bool {
if (empty($userId)) {
$secret = $this->config->getAppValue('spreed', 'signaling_ticket_secret');
$secret = $this->appConfig->getAppValueString('signaling_ticket_secret');
} else {
$secret = $this->config->getUserValue($userId, 'spreed', 'signaling_ticket_secret');
}
Expand All @@ -710,11 +711,11 @@ public function validateSignalingTicket(?string $userId, string $ticket): bool {
}

public function getGridVideosLimit(): int {
return (int)$this->config->getAppValue('spreed', 'grid_videos_limit', '19'); // 5*4 - self
return $this->appConfig->getAppValueInt('grid_videos_limit', 19); // 5*4 - self
}

public function getGridVideosLimitEnforced(): bool {
return $this->config->getAppValue('spreed', 'grid_videos_limit_enforced', 'no') === 'yes';
return $this->appConfig->getAppValueBool('grid_videos_limit_enforced');
}

/**
Expand Down
Loading
Loading