-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace OCA\Text\Controller; | ||
|
||
use OCA\Text\Service\SessionService; | ||
use \OCP\AppFramework\ApiController; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\Collaboration\Collaborators\ISearch; | ||
use \OCP\IRequest; | ||
use OCP\IUserManager; | ||
use OCP\IUserSession; | ||
use OCP\Share\IShare; | ||
|
||
class UserApiController extends ApiController { | ||
private ISearch $collaboratorSearch; | ||
private IUserSession $userSession; | ||
private IUserManager $userManager; | ||
private SessionService $sessionService; | ||
|
||
public function __construct($appName, IRequest $request, SessionService $sessionService, ISearch $ISearch, IUserManager $userManager, IUserSession $userSession) { | ||
parent::__construct($appName, $request); | ||
|
||
$this->sessionService = $sessionService; | ||
$this->collaboratorSearch = $ISearch; | ||
$this->userSession = $userSession; | ||
$this->userManager = $userManager; | ||
$this->sessionService = $sessionService; | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @PublicPage | ||
*/ | ||
public function index(int $documentId, int $sessionId, string $sessionToken, string $filter, int $limit = 5): DataResponse { | ||
if (!$this->sessionService->isValidSession($documentId, $sessionId, $sessionToken)) { | ||
return new DataResponse([], 403); | ||
} | ||
|
||
$sessions = $this->sessionService->getAllSessions($documentId); | ||
|
||
$users = []; | ||
|
||
// Add joined users to the autocomplete list | ||
foreach ($sessions as $session) { | ||
$sessionUserId = $session['userId']; | ||
if ($sessionUserId !== null && !isset($users[$sessionUserId])) { | ||
$users[$sessionUserId] = $this->userManager->getDisplayName($sessionUserId); | ||
} | ||
} | ||
|
||
$currentSession = $this->sessionService->getSession($documentId, $sessionId, $sessionToken); | ||
if ($currentSession->getUserId() !== null) { | ||
// Add other users to the autocomplete list | ||
[$result] = $this->collaboratorSearch->search($filter, [IShare::TYPE_USER], false, $limit, 0); | ||
|
||
foreach ($result['users'] as ['label' => $label, 'value' => $value]) { | ||
if (isset($value['shareWith'])) { | ||
$id = $value['shareWith']; | ||
$users[$id] = $label; | ||
} | ||
} | ||
|
||
$user = $this->userSession->getUser(); | ||
$users[$user->getUID()] = $user->getDisplayName(); | ||
} | ||
|
||
return new DataResponse($users); | ||
} | ||
} |