From 92e79281b5ab345aa5c61e2d293ef72d78865df6 Mon Sep 17 00:00:00 2001 From: Christian Lorang Date: Fri, 30 Oct 2026 14:25:18 +0100 Subject: [PATCH] chore: refactor last deprecated config methods Signed-off-by: Christian Lorang --- lib/Chat/Changelog/Manager.php | 16 ++-- lib/Config.php | 74 +++++++++---------- lib/Controller/CallController.php | 9 +-- lib/Controller/SettingsController.php | 11 ++- lib/Federation/Proxy/TalkV1/ProxyRequest.php | 6 +- lib/Notification/Listener.php | 5 +- lib/Service/ConversationUnarchiveService.php | 8 +- lib/Service/NoteToSelfService.php | 15 ++-- lib/Service/RecordingService.php | 6 +- lib/Service/SampleConversationsService.php | 9 ++- lib/Settings/Admin/AdminSettings.php | 6 +- psalm.xml | 8 -- tests/php/Controller/CallControllerTest.php | 5 +- .../php/Controller/SettingsControllerTest.php | 4 + .../Controller/SignalingControllerTest.php | 9 ++- tests/php/Recording/BackendNotifierTest.php | 2 - .../ConversationUnarchiveServiceTest.php | 24 +++--- tests/php/Service/RecordingServiceTest.php | 8 +- .../php/Settings/Admin/AdminSettingsTest.php | 5 ++ 19 files changed, 125 insertions(+), 105 deletions(-) diff --git a/lib/Chat/Changelog/Manager.php b/lib/Chat/Changelog/Manager.php index f705aaac6af..14c95eda3b9 100644 --- a/lib/Chat/Changelog/Manager.php +++ b/lib/Chat/Changelog/Manager.php @@ -8,16 +8,17 @@ namespace OCA\Talk\Chat\Changelog; +use OCA\Talk\AppInfo\Application; use OCA\Talk\Chat\ChatManager; +use OCA\Talk\Config; use OCA\Talk\Manager as RoomManager; -use OCP\IConfig; +use OCP\Config\IUserConfig; use OCP\IL10N; -use OCP\PreConditionNotMetException; class Manager { public function __construct( - private readonly IConfig $config, + private readonly IUserConfig $userConfig, private readonly RoomManager $roomManager, private readonly ChatManager $chatManager, private readonly IL10N $l, @@ -25,7 +26,7 @@ public function __construct( } public function getChangelogForUser(string $userId): int { - return (int)$this->config->getUserValue($userId, 'spreed', 'changelog', '0'); + return $this->userConfig->getValueInt($userId, Application::APP_ID, Config::CHANGELOG); } public function updateChangelog(string $userId): void { @@ -37,12 +38,7 @@ public function updateChangelog(string $userId): void { return; } - try { - $this->config->setUserValue($userId, 'spreed', 'changelog', (string)$shouldHaveReceived, (string)$hasReceivedLog); - } catch (PreConditionNotMetException) { - // Parallel request won the race - return; - } + $this->userConfig->setValueInt($userId, Application::APP_ID, Config::CHANGELOG, $shouldHaveReceived); $room = $this->roomManager->getChangelogRoom($userId); diff --git a/lib/Config.php b/lib/Config.php index 619502c502b..4778fc6ba95 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -172,10 +172,11 @@ public function getAllowedTalkGroupIds(): array { * @return Participant::PRIVACY_* */ public function getUserReadPrivacy(string $userId): int { - return match ((int)$this->config->getUserValue( + return match ($this->userConfig->getValueInt( $userId, - 'spreed', UserPreference::READ_STATUS_PRIVACY, - (string)Participant::PRIVACY_PUBLIC)) { + Application::APP_ID, + UserPreference::READ_STATUS_PRIVACY, + Participant::PRIVACY_PUBLIC)) { Participant::PRIVACY_PUBLIC => Participant::PRIVACY_PUBLIC, default => Participant::PRIVACY_PRIVATE, }; @@ -185,10 +186,11 @@ public function getUserReadPrivacy(string $userId): int { * @return Participant::PRIVACY_* */ public function getUserTypingPrivacy(string $userId): int { - return match ((int)$this->config->getUserValue( + return match ($this->userConfig->getValueInt( $userId, - 'spreed', UserPreference::TYPING_PRIVACY, - (string)Participant::PRIVACY_PUBLIC)) { + Application::APP_ID, + UserPreference::TYPING_PRIVACY, + Participant::PRIVACY_PUBLIC)) { Participant::PRIVACY_PUBLIC => Participant::PRIVACY_PUBLIC, default => Participant::PRIVACY_PRIVATE, }; @@ -312,18 +314,18 @@ public function getRecordingConsentConfig(): int { } public function getRecordingFolder(string $userId): string { - return $this->config->getUserValue( + return $this->userConfig->getValueString( $userId, - 'spreed', + Application::APP_ID, UserPreference::RECORDING_FOLDER, $this->getAttachmentFolder($userId) . '/Recording' ); } public function getLiveTranscriptionTargetLanguageId(?string $userId = null): string { - return $this->config->getUserValue( + return $this->userConfig->getvalueString( $userId, - 'spreed', + Application::APP_ID, UserPreference::LIVE_TRANSCRIPTION_TARGET_LANGUAGE_ID, '' ); @@ -395,7 +397,7 @@ public function getDefaultPermissions(): int { public function getAttachmentFolder(string $userId): string { $defaultAttachmentFolder = $this->appConfig->getAppValueString(self::DEFAULT_ATTACHMENT_FOLDER); - return $this->config->getUserValue($userId, 'spreed', UserPreference::ATTACHMENT_FOLDER, $defaultAttachmentFolder); + return $this->userConfig->getValueString($userId, Application::APP_ID, UserPreference::ATTACHMENT_FOLDER, $defaultAttachmentFolder); } /** @@ -730,7 +732,7 @@ private function getSignalingTicketV1(?string $userId): string { if (empty($userId)) { $secret = $this->appConfig->getAppValueString(self::SIGNALING_TICKET_SECRET); } else { - $secret = $this->config->getUserValue($userId, 'spreed', 'signaling_ticket_secret'); + $secret = $this->userConfig->getValueString($userId, Application::APP_ID, self::SIGNALING_TICKET_SECRET); } if (empty($secret)) { // Create secret lazily on first access. @@ -739,7 +741,7 @@ private function getSignalingTicketV1(?string $userId): string { if (empty($userId)) { $this->appConfig->setAppValueString(self::SIGNALING_TICKET_SECRET, $secret); } else { - $this->config->setUserValue($userId, 'spreed', 'signaling_ticket_secret', $secret); + $this->userConfig->setValueString($userId, Application::APP_ID, self::SIGNALING_TICKET_SECRET, $secret); } } @@ -914,7 +916,7 @@ public function validateSignalingTicket(?string $userId, #[SensitiveParameter] s if (empty($userId)) { $secret = $this->appConfig->getAppValueString(self::SIGNALING_TICKET_SECRET); } else { - $secret = $this->config->getUserValue($userId, 'spreed', 'signaling_ticket_secret'); + $secret = $this->userConfig->getValueString($userId, Application::APP_ID, self::SIGNALING_TICKET_SECRET); } if (empty($secret)) { return false; @@ -948,10 +950,7 @@ public function getGridVideosLimitEnforced(): bool { */ public function getCallsStartWithoutMedia(?string $userId): bool { if ($userId !== null) { - $userSetting = $this->config->getUserValue($userId, 'spreed', UserPreference::CALLS_START_WITHOUT_MEDIA); - if ($userSetting === 'yes' || $userSetting === 'no') { - return $userSetting === 'yes'; - } + return $this->userConfig->getValueBool($userId, Application::APP_ID, UserPreference::CALLS_START_WITHOUT_MEDIA); } return $this->appConfig->getAppValueBool(self::CALLS_START_WITHOUT_MEDIA); @@ -965,8 +964,7 @@ public function getCallsStartWithoutMedia(?string $userId): bool { */ public function getBlurVirtualBackground(?string $userId): bool { if ($userId !== null) { - $userSetting = $this->config->getUserValue($userId, 'spreed', UserPreference::BLUR_VIRTUAL_BACKGROUND); - return $userSetting === 'yes'; + return $this->userConfig->getValueBool($userId, Application::APP_ID, UserPreference::BLUR_VIRTUAL_BACKGROUND); } return false; } @@ -979,10 +977,10 @@ public function getBlurVirtualBackground(?string $userId): bool { */ public function getConversationsListStyle(?string $userId): string { if ($userId !== null) { - $userSetting = $this->config->getUserValue( + $userSetting = $this->userConfig->getValueString( $userId, - 'spreed', - UserPreference::CONVERSATIONS_LIST_STYLE, + Application::APP_ID, + UserPreference::CONVERSATIONS_LIST_STYLE ); if (in_array($userSetting, [UserPreference::CONVERSATION_LIST_STYLE_TWO_LINES, UserPreference::CONVERSATION_LIST_STYLE_COMPACT], true)) { @@ -1006,10 +1004,10 @@ public function getConversationsListStyle(?string $userId): string { */ public function getChatStyle(?string $userId): string { if ($userId !== null) { - $userSetting = $this->config->getUserValue( + $userSetting = $this->userConfig->getValueString( $userId, - 'spreed', - UserPreference::CHAT_STYLE, + Application::APP_ID, + UserPreference::CHAT_STYLE ); if (in_array($userSetting, [UserPreference::CHAT_STYLE_SPLIT, UserPreference::CHAT_STYLE_UNIFIED], true)) { @@ -1033,10 +1031,10 @@ public function getChatStyle(?string $userId): string { */ public function getConversationsSortOrder(?string $userId): string { if ($userId !== null) { - $userSetting = $this->config->getUserValue( + $userSetting = $this->userConfig->getValueString( $userId, - 'spreed', - UserPreference::CONVERSATIONS_SORT_ORDER, + Application::APP_ID, + UserPreference::CONVERSATIONS_SORT_ORDER ); if (in_array($userSetting, [UserPreference::CONVERSATIONS_SORT_ORDER_ACTIVITY, UserPreference::CONVERSATIONS_SORT_ORDER_ALPHABETICAL], true)) { @@ -1055,10 +1053,10 @@ public function getConversationsSortOrder(?string $userId): string { */ public function getConversationsGroupMode(?string $userId): string { if ($userId !== null) { - $userSetting = $this->config->getUserValue( + $userSetting = $this->userConfig->getValueString( $userId, - 'spreed', - UserPreference::CONVERSATIONS_GROUP_MODE, + Application::APP_ID, + UserPreference::CONVERSATIONS_GROUP_MODE ); if (in_array($userSetting, [ @@ -1081,10 +1079,10 @@ public function getConversationsGroupMode(?string $userId): string { */ public function getConversationsUnarchive(?string $userId): string { if ($userId !== null) { - $userSetting = $this->config->getUserValue( + $userSetting = $this->userConfig->getValueString( $userId, - 'spreed', - UserPreference::CONVERSATIONS_UNARCHIVE, + Application::APP_ID, + UserPreference::CONVERSATIONS_UNARCHIVE ); if (in_array($userSetting, [ @@ -1107,10 +1105,10 @@ public function getConversationsUnarchive(?string $userId): string { */ public function getConversationsTagsShowUnread(?string $userId): string { if ($userId !== null) { - $userSetting = $this->config->getUserValue( + $userSetting = $this->userConfig->getValueString( $userId, - 'spreed', - UserPreference::CONVERSATIONS_TAGS_SHOW_UNREAD, + Application::APP_ID, + UserPreference::CONVERSATIONS_TAGS_SHOW_UNREAD ); if (in_array($userSetting, [ diff --git a/lib/Controller/CallController.php b/lib/Controller/CallController.php index f4e660e3c86..7af35279bbd 100644 --- a/lib/Controller/CallController.php +++ b/lib/Controller/CallController.php @@ -8,12 +8,12 @@ namespace OCA\Talk\Controller; +use OCA\Talk\AppInfo\Application; use OCA\Talk\AuditLog\Operation; use OCA\Talk\Authenticator; use OCA\Talk\Config; use OCA\Talk\Exceptions\DialOutFailedException; use OCA\Talk\Exceptions\ParticipantNotFoundException; -use OCA\Talk\Manager; use OCA\Talk\Middleware\Attribute\FederationSupported; use OCA\Talk\Middleware\Attribute\RequireCallEnabled; use OCA\Talk\Middleware\Attribute\RequireFederatedParticipant; @@ -45,8 +45,8 @@ use OCP\AppFramework\Http\Response; use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Config\IUserConfig; use OCP\EventDispatcher\IEventDispatcher; -use OCP\IConfig; use OCP\IRequest; use OCP\IUserManager; use OCP\Log\Audit\CriticalActionPerformedEvent; @@ -59,15 +59,14 @@ class CallController extends AEnvironmentAwareOCSController { public function __construct( string $appName, IRequest $request, - private readonly Manager $manager, private readonly ConsentService $consentService, private readonly ParticipantService $participantService, private readonly PhoneNumberMapper $phoneNumberMapper, private readonly RoomService $roomService, private readonly IUserManager $userManager, private readonly ITimeFactory $timeFactory, - private readonly IConfig $serverConfig, private readonly IAppConfig $appConfig, + private readonly IUserConfig $userConfig, private readonly Config $talkConfig, private readonly Authenticator $federationAuthenticator, private readonly SIPDialOutService $dialOutService, @@ -205,7 +204,7 @@ public function downloadParticipantsForCall(string $format = 'csv'): DataDownloa $timezone = 'UTC'; if ($this->participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS) { - $timezone = $this->serverConfig->getUserValue($this->participant->getAttendee()->getActorId(), 'core', 'timezone', 'UTC'); + $timezone = $this->userConfig->getValueString($this->participant->getAttendee()->getActorId(), Application::APP_ID, 'timezone', 'UTC'); } try { diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 20576ffc14d..76122fd8e7b 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -8,6 +8,7 @@ namespace OCA\Talk\Controller; +use OCA\Talk\AppInfo\Application; use OCA\Talk\AuditLog\Operation; use OCA\Talk\Config; use OCA\Talk\Settings\BeforePreferenceSetEventListener; @@ -18,6 +19,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\AppFramework\Services\IAppConfig; +use OCP\Config\IUserConfig; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroup; @@ -33,6 +35,7 @@ public function __construct( IRequest $request, private readonly IConfig $config, private readonly IAppConfig $appConfig, + private readonly IUserConfig $userConfig, private readonly IGroupManager $groupManager, private readonly BeforePreferenceSetEventListener $preferenceListener, private readonly ?string $userId, @@ -60,7 +63,13 @@ public function setUserSetting(string $key, string|int|null $value): DataRespons return new DataResponse(null, Http::STATUS_BAD_REQUEST); } - $this->config->setUserValue($this->userId, 'spreed', $key, $value); + if (is_string($value)) { + $this->userConfig->setValueString($this->userId, Application::APP_ID, $key, $value); + } + + if (is_int($value)) { + $this->userConfig->setValueInt($this->userId, Application::APP_ID, $key, $value); + } return new DataResponse(null); } diff --git a/lib/Federation/Proxy/TalkV1/ProxyRequest.php b/lib/Federation/Proxy/TalkV1/ProxyRequest.php index e2fdaed68e8..f24009c820d 100644 --- a/lib/Federation/Proxy/TalkV1/ProxyRequest.php +++ b/lib/Federation/Proxy/TalkV1/ProxyRequest.php @@ -19,6 +19,7 @@ use OCA\Talk\Participant; use OCA\Talk\Settings\UserPreference; use OCP\AppFramework\Http; +use OCP\Config\IUserConfig; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IConfig; @@ -30,6 +31,7 @@ class ProxyRequest { public function __construct( private readonly IConfig $config, + private readonly IUserConfig $userConfig, private readonly IClientService $clientService, private readonly LoggerInterface $logger, private readonly IFactory $l10nFactory, @@ -39,11 +41,11 @@ public function __construct( } public function overwrittenRemoteTalkHash(string $hash): string { - $typingIndicator = $this->config->getUserValue( + $typingIndicator = $this->userConfig->getValueInt( $this->userSession->getUser()?->getUID(), Application::APP_ID, UserPreference::TYPING_PRIVACY, - Participant::PRIVACY_PRIVATE, + Participant::PRIVACY_PRIVATE ); return sha1(json_encode([ 'remoteHash' => $hash, diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php index 0769b4dc03e..f6fe16c264f 100644 --- a/lib/Notification/Listener.php +++ b/lib/Notification/Listener.php @@ -22,6 +22,8 @@ use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Config\IUserConfig; +use OCP\Config\ValueType; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\IConfig; @@ -43,6 +45,7 @@ class Listener implements IEventListener { public function __construct( private readonly IConfig $serverConfig, + private readonly IUserConfig $userConfig, private readonly IDBConnection $connection, private readonly IManager $notificationManager, private readonly Notifier $notificationProvider, @@ -304,7 +307,7 @@ protected function sendCallNotifications(Room $room, array $silentFor = []): voi } else { $fallbackLang = $this->serverConfig->getSystemValueString('default_language', 'en'); /** @psalm-var array $userLanguages */ - $userLanguages = $this->serverConfig->getUserValueForUsers('core', 'lang', array_map(strval(...), array_keys($users))); + $userLanguages = $this->userConfig->getValuesByUsers('core', 'lang', ValueType::STRING, array_map(strval(...), array_keys($users))); } } diff --git a/lib/Service/ConversationUnarchiveService.php b/lib/Service/ConversationUnarchiveService.php index 200b9a73fb8..4ea3ecaf641 100644 --- a/lib/Service/ConversationUnarchiveService.php +++ b/lib/Service/ConversationUnarchiveService.php @@ -8,6 +8,7 @@ namespace OCA\Talk\Service; +use OCA\Talk\AppInfo\Application; use OCA\Talk\Chat\ChatManager; use OCA\Talk\Config; use OCA\Talk\Federation\Proxy\TalkV1\UserConverter; @@ -18,7 +19,8 @@ use OCA\Talk\Room; use OCA\Talk\Settings\UserPreference; use OCP\Comments\IComment; -use OCP\IConfig; +use OCP\Config\IUserConfig; +use OCP\Config\ValueType; /** * Unarchive conversations for users who opted in via the @@ -33,8 +35,8 @@ class ConversationUnarchiveService { public function __construct( private readonly AttendeeMapper $attendeeMapper, private readonly ParticipantService $participantService, - private readonly IConfig $serverConfig, private readonly Config $talkConfig, + private readonly IUserConfig $userConfig, private readonly UserConverter $userConverter, ) { } @@ -46,7 +48,7 @@ public function unarchiveAfterMessage(Room $room, IComment $comment, ?IComment $ } $userIds = array_map(static fn (Attendee $attendee): string => $attendee->getActorId(), $archivedAttendees); - $modes = $this->serverConfig->getUserValueForUsers('spreed', UserPreference::CONVERSATIONS_UNARCHIVE, $userIds); + $modes = $this->userConfig->getValuesByUsers(Application::APP_ID, UserPreference::CONVERSATIONS_UNARCHIVE, ValueType::STRING, $userIds); $senderUserId = $comment->getActorType() === Attendee::ACTOR_USERS ? $comment->getActorId() : null; $mentions = $this->getMentions($comment); diff --git a/lib/Service/NoteToSelfService.php b/lib/Service/NoteToSelfService.php index ccb2bcf8cfd..7d98717d246 100644 --- a/lib/Service/NoteToSelfService.php +++ b/lib/Service/NoteToSelfService.php @@ -8,11 +8,12 @@ namespace OCA\Talk\Service; +use OCA\Talk\AppInfo\Application; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; use OCA\Talk\Room; -use OCP\IConfig; +use OCP\Config\IUserConfig; use OCP\IL10N; use OCP\IUser; use OCP\IUserManager; @@ -21,7 +22,7 @@ class NoteToSelfService { public function __construct( - private readonly IConfig $config, + private readonly IUserConfig $userConfig, private readonly IUserManager $userManager, private readonly Manager $manager, private readonly RoomService $roomService, @@ -59,7 +60,7 @@ public function initialCreateNoteToSelfForUser(string $userId): void { // Prefixing with zz, so that casting to int does not give a random roomId for other requests $randomLock = 'zz' . $this->secureRandom->generate(3); - $this->config->setUserValue($userId, 'spreed', 'note_to_self', $randomLock); + $this->userConfig->setValueString($userId, Application::APP_ID, 'note_to_self', $randomLock); $currentUser = $this->userManager->get($userId); if (!$currentUser instanceof IUser) { @@ -79,15 +80,15 @@ protected function createNoteToSelfConversation(IUser $user, string|int $previou ); try { - $this->config->setUserValue($user->getUID(), 'spreed', 'note_to_self', (string)$room->getId(), (string)$previousValue); + $this->userConfig->setValueString($user->getUID(), Application::APP_ID, 'note_to_self', (string)$room->getId()); } catch (PreConditionNotMetException) { // This process didn't win the race for creating the conversation, so fetch the other one $this->roomService->deleteRoom($room); // This is a little trick to bypass local caching - $values = $this->config->getUserValueForUsers('spreed', 'note_to_self', [$user->getUID()]); + $values = $this->userConfig->getValuesByUsers(Application::APP_ID, 'note_to_self', userIds: [$user->getUID()]); if (isset($values[$user->getUID()])) { - return $this->manager->getRoomById($values[$user->getUID()]); + return $this->manager->getRoomById($values[$user->getUID()]['note_to_self']); } // Failed to read parallel note-to-self creation @@ -113,6 +114,6 @@ protected function createNoteToSelfConversation(IUser $user, string|int $previou } protected function getNoteToSelfConversationId(string $userId): int { - return (int)$this->config->getUserValue($userId, 'spreed', 'note_to_self', '0'); + return $this->userConfig->getValueInt($userId, Application::APP_ID, 'note_to_self', 0); } } diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index d11612661a8..27794cd0652 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -23,6 +23,7 @@ use OCA\Talk\Settings\UserPreference; use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Config\IUserConfig; use OCP\Constants; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; @@ -31,7 +32,6 @@ use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; -use OCP\IConfig; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Log\Audit\CriticalActionPerformedEvent; @@ -83,8 +83,8 @@ public function __construct( private readonly Manager $roomManager, private readonly ITimeFactory $timeFactory, private readonly Config $config, - private readonly IConfig $serverConfig, private readonly IAppConfig $appConfig, + private readonly IUserConfig $userConfig, private readonly RoomService $roomService, private readonly ShareManager $shareManager, private readonly ChatManager $chatManager, @@ -676,7 +676,7 @@ private function getRecordingFolder(string $owner, string $token): Folder { 'userId' => $owner, ]); - $this->serverConfig->setUserValue($owner, 'spreed', UserPreference::ATTACHMENT_FOLDER, '/'); + $this->userConfig->setValueString($owner, Application::APP_ID, UserPreference::ATTACHMENT_FOLDER, '/'); } } catch (NotFoundException) { /** @var Folder */ diff --git a/lib/Service/SampleConversationsService.php b/lib/Service/SampleConversationsService.php index a8e6b820140..94980bd3865 100644 --- a/lib/Service/SampleConversationsService.php +++ b/lib/Service/SampleConversationsService.php @@ -8,6 +8,7 @@ namespace OCA\Talk\Service; +use OCA\Talk\AppInfo\Application; use OCA\Talk\Chat\ChatManager; use OCA\Talk\Chat\ReactionManager; use OCA\Talk\Config; @@ -15,10 +16,10 @@ use OCA\Talk\Room; use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Config\IUserConfig; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; -use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; @@ -28,8 +29,8 @@ class SampleConversationsService { public function __construct( - private readonly IConfig $config, private readonly IAppConfig $appConfig, + private readonly IUserConfig $userConfig, private readonly IUserManager $userManager, private readonly ChatManager $chatManager, private readonly ReactionManager $reactionManager, @@ -49,12 +50,12 @@ public function initialCreateSamples(string $userId): void { return; } - $created = $this->config->getUserValue($userId, 'spreed', 'samples_created'); + $created = $this->userConfig->getValueString($userId, Application::APP_ID, 'samples_created'); if ($created !== '') { return; } - $this->config->setUserValue($userId, 'spreed', 'samples_created', $this->timeFactory->now()->format(\DateTime::ATOM)); + $this->userConfig->setValueString($userId, Application::APP_ID, 'samples_created', $this->timeFactory->now()->format(\DateTime::ATOM)); $user = $this->userManager->get($userId); if (!$user instanceof IUser) { diff --git a/lib/Settings/Admin/AdminSettings.php b/lib/Settings/Admin/AdminSettings.php index 15137df3177..afed6251b53 100644 --- a/lib/Settings/Admin/AdminSettings.php +++ b/lib/Settings/Admin/AdminSettings.php @@ -14,6 +14,7 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Services\IInitialState; +use OCP\Config\IUserConfig; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; @@ -33,6 +34,7 @@ public function __construct( private readonly Config $talkConfig, private readonly IConfig $serverConfig, private readonly IAppConfig $appConfig, + private readonly IUserConfig $userConfig, private readonly IInitialState $initialState, private readonly ICacheFactory $memcacheFactory, private readonly IGroupManager $groupManager, @@ -398,11 +400,11 @@ protected function initRequestSignalingServerTrial(): void { ['code' => 'ZW', 'name' => $this->l10n->t('Zimbabwe')], ]; - $userLanguage = $this->serverConfig->getUserValue($this->currentUser->getUID(), 'core', 'lang', 'en'); + $userLanguage = $this->userConfig->getValueString($this->currentUser->getUID(), 'core', 'lang', 'en'); if ($userLanguage === 'de_DE') { // hardcode de_DE to de because this is a quirk in Nextcloud itself $userLanguage = 'de'; } - $userLocale = $this->serverConfig->getUserValue($this->currentUser->getUID(), 'core', 'locale', 'en_US'); + $userLocale = $this->userConfig->getValueString($this->currentUser->getUID(), 'core', 'locale', 'en_US'); $guessCountry = 'US'; if (str_contains($userLocale, '_')) { $guessCountry = substr($userLocale, strrpos($userLocale, '_') + 1); diff --git a/psalm.xml b/psalm.xml index 76d77fa802a..4ece4951b2e 100644 --- a/psalm.xml +++ b/psalm.xml @@ -34,14 +34,6 @@ - - - - - - - - diff --git a/tests/php/Controller/CallControllerTest.php b/tests/php/Controller/CallControllerTest.php index 0a348bc3761..a9dcfada045 100644 --- a/tests/php/Controller/CallControllerTest.php +++ b/tests/php/Controller/CallControllerTest.php @@ -15,6 +15,7 @@ use OCA\Talk\Service\ParticipantService; use OCP\AppFramework\Http\DataDownloadResponse; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Config\IUserConfig; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\Log\Audit\CriticalActionPerformedEvent; @@ -26,6 +27,7 @@ class CallControllerTest extends TestCase { private IEventDispatcher&MockObject $dispatcher; private ITimeFactory&MockObject $timeFactory; private IConfig&MockObject $serverConfig; + private IUserConfig&MockObject $userConfig; private Room&MockObject $room; private CallController $controller; @@ -35,6 +37,7 @@ protected function setUp(): void { $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->serverConfig = $this->createMock(IConfig::class); + $this->userConfig = $this->createMock(IUserConfig::class); $this->room = $this->createMock(Room::class); $arguments = []; @@ -69,7 +72,7 @@ public function testDownloadParticipantsForCallLogsCriticalAction(): void { $this->room->method('getName')->willReturn('Team call'); $this->participantService->method('getParticipantsJoinedCurrentCall') ->willReturn([$this->createParticipant('alice'), $this->createParticipant('bob')]); - $this->serverConfig->method('getUserValue')->willReturn('UTC'); + $this->userConfig->method('getValueString')->willReturn('UTC'); $this->timeFactory->method('getDateTime')->willReturn(new \DateTime('2026-10-16')); $this->controller->setRoom($this->room); $this->controller->setParticipant($this->createParticipant('moderator')); diff --git a/tests/php/Controller/SettingsControllerTest.php b/tests/php/Controller/SettingsControllerTest.php index ce4044c1549..5394dbf5d1b 100644 --- a/tests/php/Controller/SettingsControllerTest.php +++ b/tests/php/Controller/SettingsControllerTest.php @@ -12,6 +12,7 @@ use OCA\Talk\Controller\SettingsController; use OCA\Talk\Settings\BeforePreferenceSetEventListener; use OCP\AppFramework\Services\IAppConfig; +use OCP\Config\IUserConfig; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroup; @@ -25,6 +26,7 @@ class SettingsControllerTest extends TestCase { protected IConfig&MockObject $config; protected IAppConfig&MockObject $appConfig; + protected IUserConfig&MockObject $userConfig; protected IGroupManager&MockObject $groupManager; protected IEventDispatcher&MockObject $dispatcher; protected SettingsController $controller; @@ -34,6 +36,7 @@ public function setUp(): void { $this->config = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); + $this->userConfig = $this->createMock(IUserConfig::class); $this->groupManager = $this->createMock(IGroupManager::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->controller = new SettingsController( @@ -41,6 +44,7 @@ public function setUp(): void { $this->createMock(IRequest::class), $this->config, $this->appConfig, + $this->userConfig, $this->groupManager, $this->createMock(BeforePreferenceSetEventListener::class), 'admin', diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php index db9f3f3323b..8c206cac230 100644 --- a/tests/php/Controller/SignalingControllerTest.php +++ b/tests/php/Controller/SignalingControllerTest.php @@ -9,6 +9,7 @@ namespace OCA\Talk\Tests\php\Controller; use OC\AppFramework\Services\AppConfig; +use OCA\Talk\AppInfo\Application; use OCA\Talk\Authenticator; use OCA\Talk\Chat\CommentsManager; use OCA\Talk\Config; @@ -91,6 +92,7 @@ class SignalingControllerTest extends TestCase { protected ?Config $config = null; protected IAppConfig $appConfig; protected ?string $userId = null; + protected ?IUserConfig $userConfig = null; protected ?ISecureRandom $secureRandom = null; protected ?IEventDispatcher $dispatcher = null; @@ -109,12 +111,13 @@ public function setUp(): void { $groupManager = $this->createMock(IGroupManager::class); $this->serverConfig = \OCP\Server::get(IConfig::class); $this->appConfig = $this->getRealAppConfig(); - $this->serverConfig->setUserValue($this->userId, 'spreed', 'signaling_ticket_secret', 'the-user-ticket-secret'); + $this->userConfig = \OCP\Server::get(IUserConfig::class); + $this->userConfig->setValueString($this->userId, Application::APP_ID, Config::SIGNALING_TICKET_SECRET, 'the-user-ticket-secret'); $this->appConfig->setAppValueArray(Config::SIGNALING_SERVERS, ['servers' => [], 'secret' => self::SIGNALING_SECRET]); $this->userManager = $this->createMock(IUserManager::class); $this->dispatcher = \OCP\Server::get(IEventDispatcher::class); $urlGenerator = $this->createMock(IURLGenerator::class); - $this->config = new Config($this->serverConfig, $this->appConfig, $this->createMock(IUserConfig::class), $this->secureRandom, $groupManager, $this->userManager, $urlGenerator, $timeFactory, $this->dispatcher, $this->createMock(IFilenameValidator::class)); + $this->config = new Config($this->serverConfig, $this->appConfig, $this->userConfig, $this->secureRandom, $groupManager, $this->userManager, $urlGenerator, $timeFactory, $this->dispatcher, $this->createMock(IFilenameValidator::class)); $this->serverSession = $this->createMock(ISession::class); $this->session = $this->createMock(TalkSession::class); $this->dbConnection = \OCP\Server::get(IDBConnection::class); @@ -1482,7 +1485,7 @@ private function sipBridgeChecksum(string $data, string $random): string { private function setUpSIPBridgeConfig(): void { $this->appConfig = $this->createMock(IAppConfig::class); - $this->appConfig->method('getAppValueString')->with(Config::SIP_BRIDGE_SHARED_SECRET)->willReturn(self::SIP_BRIDGE_SECRET); + $this->appConfig->setAppValueString(Config::SIP_BRIDGE_SHARED_SECRET, self::SIP_BRIDGE_SECRET); $this->userId = null; $this->recreateSignalingController(); } diff --git a/tests/php/Recording/BackendNotifierTest.php b/tests/php/Recording/BackendNotifierTest.php index 6b0b008854b..16f96a3f06c 100644 --- a/tests/php/Recording/BackendNotifierTest.php +++ b/tests/php/Recording/BackendNotifierTest.php @@ -128,8 +128,6 @@ public function setUp(): void { } public function tearDown(): void { - $config = \OCP\Server::get(IConfig::class); - $config->deleteAppValue('spreed', 'recording_servers'); parent::tearDown(); } diff --git a/tests/php/Service/ConversationUnarchiveServiceTest.php b/tests/php/Service/ConversationUnarchiveServiceTest.php index cf7611d0ee9..d35addeb63e 100644 --- a/tests/php/Service/ConversationUnarchiveServiceTest.php +++ b/tests/php/Service/ConversationUnarchiveServiceTest.php @@ -9,6 +9,7 @@ namespace OCA\Talk\Tests\php\Service; use OC\Comments\Comment; +use OCA\Talk\AppInfo\Application; use OCA\Talk\Chat\ChatManager; use OCA\Talk\Config; use OCA\Talk\Federation\Proxy\TalkV1\UserConverter; @@ -21,7 +22,8 @@ use OCA\Talk\Service\ParticipantService; use OCA\Talk\Settings\UserPreference; use OCP\Comments\IComment; -use OCP\IConfig; +use OCP\Config\IUserConfig; +use OCP\Config\ValueType; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -29,8 +31,8 @@ class ConversationUnarchiveServiceTest extends TestCase { protected AttendeeMapper&MockObject $attendeeMapper; protected ParticipantService&MockObject $participantService; - protected IConfig&MockObject $serverConfig; protected Config&MockObject $talkConfig; + protected IUserConfig&MockObject $userConfig; protected UserConverter&MockObject $userConverter; protected ConversationUnarchiveService $service; @@ -39,14 +41,14 @@ public function setUp(): void { $this->attendeeMapper = $this->createMock(AttendeeMapper::class); $this->participantService = $this->createMock(ParticipantService::class); - $this->serverConfig = $this->createMock(IConfig::class); $this->talkConfig = $this->createMock(Config::class); + $this->userConfig = $this->createMock(IUserConfig::class); $this->userConverter = $this->createMock(UserConverter::class); $this->service = new ConversationUnarchiveService( $this->attendeeMapper, $this->participantService, - $this->serverConfig, $this->talkConfig, + $this->userConfig, $this->userConverter, ); } @@ -90,8 +92,8 @@ public function testNoArchivedAttendees(): void { $this->attendeeMapper->method('getArchivedActorsByType') ->with(42, Attendee::ACTOR_USERS) ->willReturn([]); - $this->serverConfig->expects($this->never()) - ->method('getUserValueForUsers'); + $this->userConfig->expects($this->never()) + ->method('getValuesByUsers'); $this->participantService->expects($this->never()) ->method('unarchiveAttendeesByIds'); @@ -135,8 +137,8 @@ public function testUnarchiveAfterMessage(array $modes, array $mentions, ?string $this->createAttendee(1, 'alice'), $this->createAttendee(2, 'bob'), ]); - $this->serverConfig->method('getUserValueForUsers') - ->with('spreed', UserPreference::CONVERSATIONS_UNARCHIVE, ['alice', 'bob']) + $this->userConfig->method('getValuesByUsers') + ->with(Application::APP_ID, UserPreference::CONVERSATIONS_UNARCHIVE, ValueType::STRING, ['alice', 'bob']) ->willReturn($modes); $parent = null; @@ -164,7 +166,7 @@ public static function dataOwnMessage(): array { public function testOwnMessageKeepsArchived(string $mode): void { $this->attendeeMapper->method('getArchivedActorsByType') ->willReturn([$this->createAttendee(1, 'alice'), $this->createAttendee(2, 'bob')]); - $this->serverConfig->method('getUserValueForUsers') + $this->userConfig->method('getValuesByUsers') ->willReturn(['alice' => $mode, 'bob' => $mode]); // Only bob is unarchived, even when the sender mentions themselves @@ -194,7 +196,7 @@ public static function dataParsedMentions(): array { public function testParsedMentions(string $message, array $expectedAttendeeIds): void { $this->attendeeMapper->method('getArchivedActorsByType') ->willReturn([$this->createAttendee(2, 'bob')]); - $this->serverConfig->method('getUserValueForUsers') + $this->userConfig->method('getValuesByUsers') ->willReturn(['bob' => UserPreference::CONVERSATIONS_UNARCHIVE_MENTION]); $this->participantService->expects($this->once()) @@ -232,7 +234,7 @@ public static function dataSharedObject(): array { public function testSharedObject(string $mode, array $message, array $expectedAttendeeIds): void { $this->attendeeMapper->method('getArchivedActorsByType') ->willReturn([$this->createAttendee(2, 'bob')]); - $this->serverConfig->method('getUserValueForUsers') + $this->userConfig->method('getValuesByUsers') ->willReturn(['bob' => $mode]); $this->participantService->expects($this->once()) diff --git a/tests/php/Service/RecordingServiceTest.php b/tests/php/Service/RecordingServiceTest.php index e1e883a4d62..1d140ecef11 100644 --- a/tests/php/Service/RecordingServiceTest.php +++ b/tests/php/Service/RecordingServiceTest.php @@ -30,6 +30,7 @@ function is_uploaded_file($filename) { use OCA\Talk\Service\RoomService; use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Config\IUserConfig; use OCP\Constants; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; @@ -38,7 +39,6 @@ function is_uploaded_file($filename) { use OCP\Files\IRootFolder; use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; -use OCP\IConfig; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Log\Audit\CriticalActionPerformedEvent; @@ -62,8 +62,8 @@ class RecordingServiceTest extends TestCase { protected ParticipantService&MockObject $participantService; protected IRootFolder&MockObject $rootFolder; protected Config&MockObject $config; - protected IConfig&MockObject $serverConfig; protected IAppConfig&MockObject $appConfig; + protected IUserConfig&MockObject $userConfig; protected IManager&MockObject $notificationManager; protected Manager&MockObject $roomManager; protected ITimeFactory&MockObject $timeFactory; @@ -90,8 +90,8 @@ public function setUp(): void { $this->roomManager = $this->createMock(Manager::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->config = $this->createMock(Config::class); - $this->serverConfig = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); + $this->userConfig = $this->createMock(IUserConfig::class); $this->roomService = $this->createMock(RoomService::class); $this->shareManager = $this->createMock(ShareManager::class); $this->chatManager = $this->createMock(ChatManager::class); @@ -112,8 +112,8 @@ public function setUp(): void { $this->roomManager, $this->timeFactory, $this->config, - $this->serverConfig, $this->appConfig, + $this->userConfig, $this->roomService, $this->shareManager, $this->chatManager, diff --git a/tests/php/Settings/Admin/AdminSettingsTest.php b/tests/php/Settings/Admin/AdminSettingsTest.php index 7853e43e138..b1cb778f1fd 100644 --- a/tests/php/Settings/Admin/AdminSettingsTest.php +++ b/tests/php/Settings/Admin/AdminSettingsTest.php @@ -14,6 +14,7 @@ use OCA\Talk\Settings\Admin\AdminSettings; use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Services\IInitialState; +use OCP\Config\IUserConfig; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; @@ -29,6 +30,7 @@ class AdminSettingsTest extends TestCase { protected Config&MockObject $talkConfig; protected IConfig&MockObject $serverConfig; protected IAppConfig&MockObject $appConfig; + protected IUserConfig&MockObject $userConfig; protected IInitialState&MockObject $initialState; protected ICacheFactory&MockObject $cacheFactory; protected IGroupManager&MockObject $groupManager; @@ -45,6 +47,7 @@ public function setUp(): void { $this->talkConfig = $this->createMock(Config::class); $this->serverConfig = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); + $this->userConfig = $this->createMock(IUserConfig::class); $this->initialState = $this->createMock(IInitialState::class); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->groupManager = $this->createMock(IGroupManager::class); @@ -67,6 +70,7 @@ protected function getAdminSettings(array $methods = []): AdminSettings { $this->talkConfig, $this->serverConfig, $this->appConfig, + $this->userConfig, $this->initialState, $this->cacheFactory, $this->groupManager, @@ -83,6 +87,7 @@ protected function getAdminSettings(array $methods = []): AdminSettings { $this->talkConfig, $this->serverConfig, $this->appConfig, + $this->userConfig, $this->initialState, $this->cacheFactory, $this->groupManager,