From f5fa40a3007226e96163123ea731467471ec6479 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Fri, 13 Dec 2024 15:21:30 +0100 Subject: [PATCH] feat(conversations): add backend support of compact list - int<0,1> was chosen if we further want to extend with other appearance types Signed-off-by: Maksim Sukharev --- docs/capabilities.md | 1 + docs/constants.md | 4 ++++ docs/settings.md | 1 + lib/Capabilities.php | 2 ++ lib/Config.php | 17 +++++++++++++++++ lib/Controller/RoomController.php | 3 +++ lib/Federation/Proxy/TalkV1/ProxyRequest.php | 5 ++++- lib/ResponseDefinitions.php | 1 + .../BeforePreferenceSetEventListener.php | 5 +++++ lib/Settings/UserPreference.php | 1 + tests/php/CapabilitiesTest.php | 2 ++ 11 files changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/capabilities.md b/docs/capabilities.md index 87802a453c7..9de00305b65 100644 --- a/docs/capabilities.md +++ b/docs/capabilities.md @@ -171,3 +171,4 @@ * `config => conversations => force-passwords` - Whether passwords are enforced for public rooms * `conversation-creation-password` - Whether the endpoints for creating public conversations or making a conversation public support setting a password * `call-notification-state-api` (local) - Whether the endpoints exists for checking if a call notification should be dismissed +* `config => conversations => list-style` - Whether conversation list should appear in certain way diff --git a/docs/constants.md b/docs/constants.md index 91c2bfe421e..65086e0c35f 100644 --- a/docs/constants.md +++ b/docs/constants.md @@ -51,6 +51,10 @@ * `0` Everyone (default) - All participants can mention using `@all` * `1` Moderators - Only moderators can mention using `@all` +### Conversation list style +* `two-lines` Normal (default) - two-line elements (with display name and last message) +* `compact` Compact - one-line elements (with display name) + ## Participants ### Participant types diff --git a/docs/settings.md b/docs/settings.md index e95738b25a3..535d5cf13a7 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -32,6 +32,7 @@ Instead, the server API `POST /ocs/v2.php/apps/provisioning_api/api/v1/config/us | `play_sounds` | | `'yes'` | `'yes'` and `'no'` | | `calls_start_without_media` | `config => call => start-without-media` | `''` falling back to app config with the same name | `'yes'` and `'no'` | | `blur_virtual_background` | `config => call => blur-virtual-background` | `'no'` | `'yes'` and `'no'` | +| `conversations_list_style` | `config => conversations => list-style` | `'two-lines'` | One of the constants from the [constants list](constants.md#conversation-list-style) | ## Set SIP settings diff --git a/lib/Capabilities.php b/lib/Capabilities.php index b8817a629f2..9dce742b2f3 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -153,6 +153,7 @@ class Capabilities implements IPublicCapability { ], 'conversations' => [ 'can-create', + 'list-style', ], 'federation' => [ 'enabled', @@ -229,6 +230,7 @@ public function getCapabilities(): array { 'conversations' => [ 'can-create' => $user instanceof IUser && !$this->talkConfig->isNotAllowedToCreateConversations($user), 'force-passwords' => $this->talkConfig->isPasswordEnforced(), + 'list-style' => $this->talkConfig->getConversationsListStyle($user?->getUID()), ], 'federation' => [ 'enabled' => false, diff --git a/lib/Config.php b/lib/Config.php index 491d898def1..ceb86b005e9 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -695,6 +695,23 @@ public function getBlurVirtualBackground(?string $userId): bool { return false; } + /** + * User setting for conversations list style + * + * @param ?string $userId + * @return string + */ + public function getConversationsListStyle(?string $userId): string { + if ($userId !== null) { + $userSetting = $this->config->getUserValue($userId, 'spreed', UserPreference::CONVERSATIONS_LIST_STYLE); + if (!empty($userSetting)) { + return $userSetting; + } + return 'two-lines'; + } + return 'two-lines'; + } + /** * User setting falling back to admin defined app config */ diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 70b353c7b06..75b370b382c 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -2539,6 +2539,9 @@ public function getCapabilities(): DataResponse { if (isset($data['config']['call']['blur-virtual-background'])) { $data['config']['call']['blur-virtual-background'] = $this->talkConfig->getBlurVirtualBackground($this->userId); } + if (isset($data['config']['conversations']['list-style'])) { + $data['config']['conversations']['list-style'] = $this->talkConfig->getConversationsListStyle($this->userId); + } if ($response->getHeaders()['X-Nextcloud-Talk-Hash']) { $headers['X-Nextcloud-Talk-Proxy-Hash'] = $response->getHeaders()['X-Nextcloud-Talk-Hash']; diff --git a/lib/Federation/Proxy/TalkV1/ProxyRequest.php b/lib/Federation/Proxy/TalkV1/ProxyRequest.php index 55ce4642c05..5a597dbd979 100644 --- a/lib/Federation/Proxy/TalkV1/ProxyRequest.php +++ b/lib/Federation/Proxy/TalkV1/ProxyRequest.php @@ -44,7 +44,10 @@ public function overwrittenRemoteTalkHash(string $hash): string { ], 'call' => [ 'blur-virtual-background', - ] + ], + 'conversations' => [ + 'list-style', + ], ], ] ])); diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index 60da06cf6cb..fd5b7e14b8c 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -362,6 +362,7 @@ * conversations: array{ * can-create: bool, * force-passwords: bool, + * list-style: string, * }, * federation: array{ * enabled: bool, diff --git a/lib/Settings/BeforePreferenceSetEventListener.php b/lib/Settings/BeforePreferenceSetEventListener.php index 1fe87fdb1d5..275aea8c9df 100644 --- a/lib/Settings/BeforePreferenceSetEventListener.php +++ b/lib/Settings/BeforePreferenceSetEventListener.php @@ -76,6 +76,11 @@ public function validatePreference(string $userId, string $key, string|int|null return $valid; } + // "list-style" 'two-lines' / 'compact' + if ($key === UserPreference::CONVERSATIONS_LIST_STYLE) { + return $value === 'two-lines' || $value === 'compact'; + } + return false; } diff --git a/lib/Settings/UserPreference.php b/lib/Settings/UserPreference.php index 6c729ae0f11..2c9ca3d44d0 100644 --- a/lib/Settings/UserPreference.php +++ b/lib/Settings/UserPreference.php @@ -11,6 +11,7 @@ class UserPreference { public const BLUR_VIRTUAL_BACKGROUND = 'blur_virtual_background'; public const CALLS_START_WITHOUT_MEDIA = 'calls_start_without_media'; + public const CONVERSATIONS_LIST_STYLE = 'conversations_list_style'; public const PLAY_SOUNDS = 'play_sounds'; public const TYPING_PRIVACY = 'typing_privacy'; public const READ_STATUS_PRIVACY = 'read_status_privacy'; diff --git a/tests/php/CapabilitiesTest.php b/tests/php/CapabilitiesTest.php index 2669e433e88..35f795b985a 100644 --- a/tests/php/CapabilitiesTest.php +++ b/tests/php/CapabilitiesTest.php @@ -153,6 +153,7 @@ public function testGetCapabilitiesGuest(): void { 'conversations' => [ 'can-create' => false, 'force-passwords' => false, + 'list-style' => 'two-lines', ], 'federation' => [ 'enabled' => false, @@ -286,6 +287,7 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea 'conversations' => [ 'can-create' => $canCreate, 'force-passwords' => false, + 'list-style' => 'two-lines', ], 'federation' => [ 'enabled' => false,