From a94236483e26785dcaf97fb10e863f82348eb068 Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Tue, 11 May 2021 08:22:51 +0200 Subject: Let apps toggle an unread counter on app icons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Louis Chemineau Signed-off-by: Julius Härtl --- lib/private/NavigationManager.php | 12 +++++++++++- lib/public/INavigationManager.php | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index 97bb8f85894..2ffd25df9b8 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -49,6 +49,8 @@ class NavigationManager implements INavigationManager { protected $entries = []; protected $closureEntries = []; protected $activeEntry; + protected $unreadCounters = []; + /** @var bool */ protected $init = false; /** @var IAppManager|AppManager */ @@ -97,7 +99,11 @@ class NavigationManager implements INavigationManager { if (!isset($entry['type'])) { $entry['type'] = 'link'; } - $this->entries[$entry['id']] = $entry; + + $id = $entry['id']; + $entry['unread'] = isset($this->unreadCounters[$id]) ? $this->unreadCounters[$id] : 0; + + $this->entries[$id] = $entry; } /** @@ -319,4 +325,8 @@ class NavigationManager implements INavigationManager { } return false; } + + public function setUnreadCounter(string $id, int $unreadCounter): void { + $this->unreadCounters[$id] = $unreadCounter; + } } diff --git a/lib/public/INavigationManager.php b/lib/public/INavigationManager.php index 189342b4cc4..71979042811 100644 --- a/lib/public/INavigationManager.php +++ b/lib/public/INavigationManager.php @@ -90,4 +90,13 @@ interface INavigationManager { * @since 14.0.0 */ public function getAll(string $type = self::TYPE_APPS): array; + + /** + * Set an unread counter for navigation entries + * + * @param string $id id of the navigation entry + * @param int $unreadCounter Number of unread entries (0 to hide the counter which is the default) + * @since 22.0.0 + */ + public function setUnreadCounter(string $id, int $unreadCounter): void; } -- cgit v1.2.3