Skip to content

Commit

Permalink
fix(frontend): revert return format of getCollectivesForUser
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz authored and mejo- committed Nov 7, 2023
1 parent 8324725 commit eb8dc30
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
13 changes: 4 additions & 9 deletions lib/Service/CollectiveHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ public function __construct(CollectiveMapper $collectiveMapper,
* @param bool $getLevel
* @param bool $getUserSettings
*
* @return array<int, CollectiveInfo>
* @return CollectiveInfo[]
* @throws NotFoundException
* @throws NotPermittedException
* @throws MissingDependencyException
*
* The array key of the returned result is the collective id.
*/
public function getCollectivesForUser(string $userId, bool $getLevel = true, bool $getUserSettings = true): array {
$collectiveInfos = [];
Expand All @@ -62,7 +60,7 @@ public function getCollectivesForUser(string $userId, bool $getLevel = true, boo
$userPageOrder = ($settings ? $settings->getSetting('page_order') : null) ?? Collective::defaultPageOrder;
$userShowRecentPages = ($settings ? $settings->getSetting('show_recent_pages') : null) ?? Collective::defaultShowRecentPages;
}
$collectiveInfos[$c->getId()] = new CollectiveInfo(
$collectiveInfos[] = new CollectiveInfo(
$c,
$circle->getSanitizedName(),
$level,
Expand All @@ -77,12 +75,10 @@ public function getCollectivesForUser(string $userId, bool $getLevel = true, boo
/**
* @param string $userId
*
* @return array<int, CollectiveInfo>
* @return CollectiveInfo[]
* @throws NotFoundException
* @throws NotPermittedException
* @throws MissingDependencyException
*
* The array key of the returned result is the collective id.
*/
public function getCollectivesTrashForUser(string $userId): array {
$collectiveInfos = [];
Expand All @@ -91,11 +87,10 @@ public function getCollectivesTrashForUser(string $userId): array {
return $circle->getSingleId();
}, $circles);
$circles = array_combine($cids, $circles);
/** @var Collective[] $collectives */
$collectives = $this->collectiveMapper->findTrashByCircleIdsAndUser($cids, $userId);
foreach ($collectives as $c) {
$cid = $c->getCircleId();
$collectiveInfos[$c->getId()] = new CollectiveInfo(
$collectiveInfos[] = new CollectiveInfo(
$c,
$circles[$cid]->getSanitizedName(),
$this->circleHelper->getLevel($cid, $userId)
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/CollectiveService.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getCollectiveWithShare(int $id, string $userId): CollectiveInfo
/**
* @param string $userId
*
* @return array<int, CollectiveInfo>
* @return CollectiveInfo[]
* @throws NotFoundException
* @throws NotPermittedException
* @throws MissingDependencyException
Expand Down
9 changes: 6 additions & 3 deletions lib/Service/RecentPagesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ public function forUser(IUser $user, int $limit = 10): array {
$mimeTypeMd = $this->mimeTypeLoader->getId('text/markdown');

$expressions = [];
$collectivesMap = [];
foreach ($collectives as $collective) {
$value = sprintf($appData . '/collectives/%d/%%', $collective->getId());
$expressions[] = $qb->expr()->like('f.path', $qb->createNamedParameter($value, IQueryBuilder::PARAM_STR));
$collectivesMap[$collective->getId()] = $collective;
}
unset($collectives);

$qb->select('p.*', 'f.mtime as timestamp', 'f.name as filename', 'f.path as path')
->from('filecache', 'f')
Expand All @@ -71,7 +74,7 @@ public function forUser(IUser $user, int $limit = 10): array {
$pages = [];
while ($row = $r->fetch()) {
$collectiveId = (int)explode('/', $row['path'], 4)[2];
if (!isset($collectives[$collectiveId])) {
if (!isset($collectivesMap[$collectiveId])) {
continue;
}

Expand All @@ -81,7 +84,7 @@ public function forUser(IUser $user, int $limit = 10): array {
unset($splitPath);

// prepare link and title
$pathParts = [$collectives[$collectiveId]->getName()];
$pathParts = [$collectivesMap[$collectiveId]->getName()];
if ($internalPath !== '' && $internalPath !== '.') {
$pathParts = array_merge($pathParts, explode('/', $internalPath));
}
Expand All @@ -97,7 +100,7 @@ public function forUser(IUser $user, int $limit = 10): array {
// not returning a PageInfo instance because it would be either incomplete or too expensive to build completely
$recentPage = new RecentPage();
$recentPage
->setCollectiveName($this->collectiveService->getCollectiveNameWithEmoji($collectives[$collectiveId]))
->setCollectiveName($this->collectiveService->getCollectiveNameWithEmoji($collectivesMap[$collectiveId]))
->setTitle($title)
->setPageUrl($url)
->setTimestamp($row['timestamp']);
Expand Down

0 comments on commit eb8dc30

Please sign in to comment.