Skip to content
Open
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
47 changes: 43 additions & 4 deletions lib/Service/RecordingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCA\Talk\Recording\BackendNotifier;
use OCA\Talk\Room;
use OCA\Talk\Settings\UserPreference;
use OCP\Activity\IManager as IActivityManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Constants;
Expand Down Expand Up @@ -94,6 +95,7 @@ public function __construct(
private readonly IUserManager $userManager,
private readonly IEventDispatcher $eventDispatcher,
private readonly ISecureRandom $secureRandom,
private readonly IActivityManager $activityManager,
) {
}

Expand Down Expand Up @@ -157,7 +159,10 @@ public function store(Room $room, string $owner, array $file): void {

try {
$recordingFolder = $this->getRecordingFolder($owner, $room->getToken());
$fileNode = $recordingFolder->newFile($fileName, $resource);
$fileNode = $this->runAsActor(
$owner,
static fn (): File => $recordingFolder->newFile($fileName, $resource),
);
} catch (NoUserException) {
throw new InvalidArgumentException('owner_invalid');
} catch (NotPermittedException) {
Expand Down Expand Up @@ -431,9 +436,12 @@ public function storeTranscript(string $owner, string $roomToken, int $recording
}

try {
$fileNode = $recordingFolder->newFile(
$transcriptFileName,
$output . "\n\n$warning\n",
$fileNode = $this->runAsActor(
$owner,
static fn (): File => $recordingFolder->newFile(
$transcriptFileName,
$output . "\n\n$warning\n",
),
);
$this->systemTagMapper->assignGeneratedByAITag((string)$fileNode->getId(), 'files');
$this->notifyStoredTranscript($room, $participant, $fileNode, $aiTask);
Expand Down Expand Up @@ -623,6 +631,37 @@ private function validateMimeTypeAndExtension(string $fileName, string $mimeType
* @throws NoUserException
*/
private function getRecordingFolder(string $owner, string $token): Folder {
return $this->runAsActor(
$owner,
fn (): Folder => $this->getRecordingFolderInternal($owner, $token),
);
}

/**
* Run the callback with the activity actor set to the given user.
*
* Recordings are stored by a background job, outside of any session, so
* without this the folder and the file are attributed to nobody and the
* activity stream renders them as coming from a "remote account".
*
* @template T
* @param callable():T $callback
* @return T
*/
private function runAsActor(string $userId, callable $callback) {
$this->activityManager->setCurrentUserId($userId);
try {
return $callback();
} finally {
$this->activityManager->setCurrentUserId(null);
}
}

/**
* @throws NotPermittedException
* @throws NoUserException
*/
private function getRecordingFolderInternal(string $owner, string $token): Folder {
$userFolder = $this->rootFolder->getUserFolder($owner);
$recordingRootFolderName = $this->config->getRecordingFolder($owner);
try {
Expand Down