From eac8129118d3427c98d8c6b6304e81480fa387d3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 26 Sep 2024 16:44:08 +0200 Subject: [PATCH] fix(archive): Improve archive preference handling Signed-off-by: Joas Schilling --- lib/Controller/RoomController.php | 3 +++ lib/Service/ParticipantService.php | 26 ++++++++++++++++++++++---- openapi-full.json | 1 + openapi.json | 1 + src/types/openapi/openapi-full.ts | 5 ++++- src/types/openapi/openapi.ts | 5 ++++- 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index d8b47b9604f..69039a22ec5 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -1546,6 +1546,9 @@ public function setPassword(string $password): DataResponse { /** * Archive a conversation * + * - Turns off call notifications + * - Reduces chat notifications in group and public rooms when it was "default" resulting in "always" + * * @return DataResponse * * 200: Conversation was archived diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 16e9db52ad4..04a37050d41 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -299,18 +299,36 @@ public function updateNotificationCalls(Participant $participant, int $level): v } /** - * @param Participant $participant + * @return Participant::NOTIFY_* */ + protected function getDefaultGroupNotification(): int { + $config = (int)$this->serverConfig->getAppValue('spreed', 'default_group_notification', (string)Participant::NOTIFY_MENTION); + return max(Participant::NOTIFY_DEFAULT, min($config, Participant::NOTIFY_NEVER)); + } + public function archiveConversation(Participant $participant): void { $attendee = $participant->getAttendee(); $attendee->setArchived(true); $attendee->setLastAttendeeActivity($this->timeFactory->getTime()); + + $room = $participant->getRoom(); + if ($room->getType() === Room::TYPE_PUBLIC || $room->getType() === Room::TYPE_GROUP) { + // Turn of call notifications by default + if ($attendee->getNotificationCalls() === Participant::NOTIFY_CALLS_ON) { + $attendee->setNotificationCalls(Participant::NOTIFY_CALLS_OFF); + } + + // Reduce notifications when it was "Always" via the default + // Otherwise we respect the attendees selection + if ($attendee->getNotificationLevel() === Participant::NOTIFY_DEFAULT + && $this->getDefaultGroupNotification() !== Participant::NOTIFY_NEVER) { + $attendee->setNotificationCalls(Participant::NOTIFY_MENTION); + } + } + $this->attendeeMapper->update($attendee); } - /** - * @param Participant $participant - */ public function unarchiveConversation(Participant $participant): void { $attendee = $participant->getAttendee(); $attendee->setArchived(false); diff --git a/openapi-full.json b/openapi-full.json index 6fe5a4e43db..6957600600f 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -15814,6 +15814,7 @@ "post": { "operationId": "room-archive-conversation", "summary": "Archive a conversation", + "description": "- Turns off call notifications - Reduces chat notifications in group and public rooms when it was \"default\" resulting in \"always\"", "tags": [ "room" ], diff --git a/openapi.json b/openapi.json index fcab24e35c5..4910a601007 100644 --- a/openapi.json +++ b/openapi.json @@ -15948,6 +15948,7 @@ "post": { "operationId": "room-archive-conversation", "summary": "Archive a conversation", + "description": "- Turns off call notifications - Reduces chat notifications in group and public rooms when it was \"default\" resulting in \"always\"", "tags": [ "room" ], diff --git a/src/types/openapi/openapi-full.ts b/src/types/openapi/openapi-full.ts index 8cbdba663d4..4d5f8da745a 100644 --- a/src/types/openapi/openapi-full.ts +++ b/src/types/openapi/openapi-full.ts @@ -1231,7 +1231,10 @@ export type paths = { }; get?: never; put?: never; - /** Archive a conversation */ + /** + * Archive a conversation + * @description - Turns off call notifications - Reduces chat notifications in group and public rooms when it was "default" resulting in "always" + */ post: operations["room-archive-conversation"]; /** Unarchive a conversation */ delete: operations["room-unarchive-conversation"]; diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 594f0479e2e..1f31c46ceb8 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -1233,7 +1233,10 @@ export type paths = { }; get?: never; put?: never; - /** Archive a conversation */ + /** + * Archive a conversation + * @description - Turns off call notifications - Reduces chat notifications in group and public rooms when it was "default" resulting in "always" + */ post: operations["room-archive-conversation"]; /** Unarchive a conversation */ delete: operations["room-unarchive-conversation"];