Skip to content

Commit

Permalink
fresh session if missing
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed May 24, 2023
1 parent 929b517 commit 2e5dd34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
26 changes: 14 additions & 12 deletions lib/RelatedResourceProviders/TalkRelatedResourceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

use Exception;
use OCA\Circles\CirclesManager;
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Member;
use OCA\RelatedResources\Db\TalkRoomRequest;
Expand All @@ -48,27 +49,21 @@
use OCP\IURLGenerator;
use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;

class TalkRelatedResourceProvider implements IRelatedResourceProvider {
use TArrayTools;


private const PROVIDER_ID = 'talk';

private IURLGenerator $urlGenerator;
private IL10N $l10n;
private TalkRoomRequest $talkRoomRequest;
private ?CirclesManager $circlesManager = null;


public function __construct(
IURLGenerator $urlGenerator,
IL10N $l10n,
TalkRoomRequest $talkRoomRequest
private IURLGenerator $urlGenerator,
private IL10N $l10n,
private TalkRoomRequest $talkRoomRequest,
private LoggerInterface $logger
) {
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
$this->talkRoomRequest = $talkRoomRequest;
try {
$this->circlesManager = Server::get(CirclesManager::class);
} catch (ContainerExceptionInterface | AutoloadNotAllowedException $e) {
Expand Down Expand Up @@ -129,7 +124,14 @@ public function improveRelatedResource(IRelatedResource $entry): void {
return;
}

$current = $this->circlesManager->getCurrentFederatedUser();
try {
$current = $this->circlesManager->getCurrentFederatedUser();
} catch (FederatedUserNotFoundException $e) {
$this->circlesManager->startSession(); // enforce new session if not available
$current = $this->circlesManager->getCurrentFederatedUser();
$this->logger->info('session restarted', ['current' => $current]);
}

if (!$current->isLocal() || $current->getUserType() !== Member::TYPE_USER) {
return;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/Service/RelatedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

use Exception;
use OCA\Circles\CirclesManager;
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Member;
use OCA\RelatedResources\Exceptions\CacheNotFoundException;
Expand Down Expand Up @@ -429,7 +430,13 @@ private function strictMatching(RelatedResource $current, array $result): array
* @return IRelatedResource[]
*/
private function filterUnavailableResults(array $result): array {
$current = $this->circlesManager->getCurrentFederatedUser();
try {
$current = $this->circlesManager->getCurrentFederatedUser();
} catch (FederatedUserNotFoundException $e) {
$this->circlesManager->startSession(); // it should not happen at this point, but we log if it does
$current = $this->circlesManager->getCurrentFederatedUser();
$this->logger->warning('session restarted while filtering results', ['current' => $current]);
}

return array_filter($result, function (IRelatedResource $res) use ($current): bool {
$all = array_values(array_unique(array_merge($res->getVirtualGroup(), $res->getRecipients())));
Expand Down

0 comments on commit 2e5dd34

Please sign in to comment.