Browse Source
			
			
			feat(retention): Allow defining a default retention for event and phone conversations
			
				
		feat(retention): Allow defining a default retention for event and phone conversations
	
		
	
			
				Signed-off-by: Joas Schilling <coding@schilljs.com>pull/15018/head
				
				  
				  No known key found for this signature in database
				  
				  	
						GPG Key ID: F72FA5B49FFA96B0
				  	
				  
				
			
		
		
		
	
				 38 changed files with 727 additions and 29 deletions
			
			
		- 
					4appinfo/info.xml
 - 
					2appinfo/routes/routesRoomController.php
 - 
					3docs/capabilities.md
 - 
					2docs/settings.md
 - 
					65lib/BackgroundJob/ExpireObjectRooms.php
 - 
					5lib/Capabilities.php
 - 
					32lib/Controller/RoomController.php
 - 
					2lib/Listener/CalDavEventListener.php
 - 
					33lib/Manager.php
 - 
					3lib/Notification/Notifier.php
 - 
					2lib/ResponseDefinitions.php
 - 
					7lib/Room.php
 - 
					2lib/Service/AvatarService.php
 - 
					11lib/Service/RoomService.php
 - 
					14openapi-administration.json
 - 
					14openapi-backend-recording.json
 - 
					14openapi-backend-signaling.json
 - 
					14openapi-backend-sipbridge.json
 - 
					14openapi-bots.json
 - 
					14openapi-federation.json
 - 
					139openapi-full.json
 - 
					139openapi.json
 - 
					2src/__mocks__/capabilities.ts
 - 
					5src/components/CallView/shared/EmptyCallView.vue
 - 
					4src/components/ConversationIcon.vue
 - 
					3src/components/LeftSidebar/CallPhoneDialog/CallPhoneDialog.vue
 - 
					6src/components/TopBar/CallButton.vue
 - 
					5src/constants.ts
 - 
					4src/types/openapi/openapi-administration.ts
 - 
					4src/types/openapi/openapi-backend-recording.ts
 - 
					4src/types/openapi/openapi-backend-signaling.ts
 - 
					4src/types/openapi/openapi-backend-sipbridge.ts
 - 
					4src/types/openapi/openapi-bots.ts
 - 
					4src/types/openapi/openapi-federation.ts
 - 
					72src/types/openapi/openapi-full.ts
 - 
					72src/types/openapi/openapi.ts
 - 
					18tests/php/CapabilitiesTest.php
 - 
					10tests/php/Listener/CalDavEventListenerTest.php
 
@ -0,0 +1,65 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
declare(strict_types=1); | 
				
			|||
/** | 
				
			|||
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | 
				
			|||
 * SPDX-License-Identifier: AGPL-3.0-or-later | 
				
			|||
 */ | 
				
			|||
 | 
				
			|||
namespace OCA\Talk\BackgroundJob; | 
				
			|||
 | 
				
			|||
use OCA\Talk\Manager; | 
				
			|||
use OCA\Talk\Room; | 
				
			|||
use OCA\Talk\Service\RoomService; | 
				
			|||
use OCP\AppFramework\Services\IAppConfig; | 
				
			|||
use OCP\AppFramework\Utility\ITimeFactory; | 
				
			|||
use OCP\BackgroundJob\IJob; | 
				
			|||
use OCP\BackgroundJob\TimedJob; | 
				
			|||
use Psr\Log\LoggerInterface; | 
				
			|||
 | 
				
			|||
class ExpireObjectRooms extends TimedJob { | 
				
			|||
 | 
				
			|||
	public function __construct( | 
				
			|||
		ITimeFactory $timeFactory, | 
				
			|||
		protected Manager $manager, | 
				
			|||
		protected RoomService $roomService, | 
				
			|||
		protected LoggerInterface $logger, | 
				
			|||
		protected IAppConfig $appConfig, | 
				
			|||
	) { | 
				
			|||
		parent::__construct($timeFactory); | 
				
			|||
		$this->setInterval(60 * 60 * 24); | 
				
			|||
		$this->setTimeSensitivity(IJob::TIME_INSENSITIVE); | 
				
			|||
 | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	#[\Override]
 | 
				
			|||
	protected function run($argument): void { | 
				
			|||
		$phoneRetention = $this->appConfig->getAppValueInt('retention_phone_rooms', 7); | 
				
			|||
		if ($phoneRetention !== 0) { | 
				
			|||
			$this->executeRetention(Room::OBJECT_TYPE_PHONE_TEMPORARY, $phoneRetention); | 
				
			|||
		} | 
				
			|||
 | 
				
			|||
		$eventRetention = $this->appConfig->getAppValueInt('retention_event_rooms', 28); | 
				
			|||
		if ($eventRetention !== 0) { | 
				
			|||
			$this->executeRetention(Room::OBJECT_TYPE_EVENT, $eventRetention); | 
				
			|||
		} | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	protected function executeRetention(string $objectType, int $retention): void { | 
				
			|||
		$now = $this->time->getTime(); | 
				
			|||
		$minimumLastActivity = $now - $retention * 24 * 3600; | 
				
			|||
		$rooms = $this->manager->getExpiringRoomsForObjectType($objectType, $minimumLastActivity); | 
				
			|||
 | 
				
			|||
		$numDeletedRooms = 0; | 
				
			|||
		foreach ($rooms as $room) { | 
				
			|||
			$this->roomService->deleteRoom($room); | 
				
			|||
			$numDeletedRooms++; | 
				
			|||
		} | 
				
			|||
 | 
				
			|||
		$this->logger->info('Deleted {numDeletedRooms} {objectType} rooms because they did not have activity since {minimumLastActivity} days', [ | 
				
			|||
			'objectType' => $objectType, | 
				
			|||
			'numDeletedRooms' => $numDeletedRooms, | 
				
			|||
			'minimumLastActivity' => $retention, | 
				
			|||
		]); | 
				
			|||
	} | 
				
			|||
} | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue