@ -65,6 +65,10 @@ class NavigationManager implements INavigationManager {
private $groupManager;
/** @var IConfig */
private $config;
/** The default app for the current user (cached for the `add` function) */
private ?string $defaultApp;
/** User defined app order (cached for the `add` function) */
private array $customAppOrder;
public function __construct(IAppManager $appManager,
IURLGenerator $urlGenerator,
@ -78,6 +82,8 @@ class NavigationManager implements INavigationManager {
$this->userSession = $userSession;
$this->groupManager = $groupManager;
$this->config = $config;
$this->defaultApp = null;
}
/**
@ -102,6 +108,12 @@ class NavigationManager implements INavigationManager {
$id = $entry['id'];
$entry['unread'] = $this->unreadCounters[$id] ?? 0;
if ($entry['type'] === 'link') {
// This is the default app that will always be shown first
$entry['default'] = ($entry['app'] ?? false) === $this->defaultApp;
// Set order from user defined app order
$entry['order'] = $this->customAppOrder[$id]['order'] ?? $entry['order'] ?? 100;
}
$this->entries[$id] = $entry;
}
@ -218,6 +230,12 @@ class NavigationManager implements INavigationManager {
]);
}
if ($this->appManager === 'null') {
return;
}
$this->defaultApp = $this->appManager->getDefaultAppForUser($this->userSession->getUser(), false);
if ($this->userSession->isLoggedIn()) {
// Profile
$this->add([
@ -311,22 +329,15 @@ class NavigationManager implements INavigationManager {
}
}
if ($this->appManager === 'null') {
return;
}
if ($this->userSession->isLoggedIn()) {
$user = $this->userSession->getUser();
$apps = $this->appManager->getEnabledAppsForUser($user);
$customOrders = json_decode($this->config->getUserValue($user->getUID(), 'core', 'apporder', '[]'), true, flags:JSON_THROW_ON_ERROR);
$this->customAppOrder = json_decode($this->config->getUserValue($user->getUID(), 'core', 'apporder', '[]'), true, flags:JSON_THROW_ON_ERROR);
} else {
$apps = $this->appManager->getInstalledApps();
$customOrders = [];
$this-> customApp Order = [];
}
// The default app of the current user without fallbacks
$defaultApp = $this->appManager->getDefaultAppForUser($this->userSession->getUser(), false);
foreach ($apps as $app) {
if (!$this->userSession->isLoggedIn() & & !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
continue;
@ -352,7 +363,7 @@ class NavigationManager implements INavigationManager {
}
$l = $this->l10nFac->get($app);
$id = $nav['id'] ?? $app . ($key === 0 ? '' : $key);
$order = $customOrders[$app][$key] ?? $ nav['order'] ?? 100;
$order = $nav['order'] ?? 100;
$type = $nav['type'];
$route = !empty($nav['route']) ? $this->urlGenerator->linkToRoute($nav['route']) : '';
$icon = $nav['icon'] ?? 'app.svg';
@ -382,12 +393,8 @@ class NavigationManager implements INavigationManager {
// Localized name of the navigation entry
'name' => $l->t($nav['name']),
], $type === 'link' ? [
// This is the default app that will always be shown first
'default' => $defaultApp === $id,
// App that registered this navigation entry (not necessarly the same as the id)
'app' => $app,
// The key used to identify this entry in the navigations entries
'key' => $key,
] : []
));
}