summaryrefslogtreecommitdiffstats
path: root/apps/user_status/lib
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2021-10-14 08:19:40 +0000
committerChristopher Ng <chrng8@gmail.com>2021-10-19 04:59:35 +0000
commit309354852f12ae88d5eef05d311d6ebcba8ee762 (patch)
tree640c4e2394ba2a868d8d1cb6b5271fd1271bbdab /apps/user_status/lib
parent7215148a242815a5064ce5d00a387c634dc936f3 (diff)
downloadnextcloud-server-309354852f12ae88d5eef05d311d6ebcba8ee762.tar.gz
nextcloud-server-309354852f12ae88d5eef05d311d6ebcba8ee762.zip
Profile backend
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/user_status/lib')
-rw-r--r--apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php32
1 files changed, 30 insertions, 2 deletions
diff --git a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php
index 86e151affdf..24090188170 100644
--- a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php
+++ b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php
@@ -24,17 +24,27 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
namespace OCA\UserStatus\Listener;
use OCA\UserStatus\AppInfo\Application;
use OCA\UserStatus\Service\JSDataService;
+use OCP\Accounts\IAccountManager;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IInitialStateService;
+use OCP\IUserSession;
class BeforeTemplateRenderedListener implements IEventListener {
+ use \OC\Profile\TProfileHelper;
+
+ /** @var IAccountManager */
+ private $accountManager;
+
+ /** @var IUserSession */
+ private $userSession;
/** @var IInitialStateService */
private $initialState;
@@ -45,11 +55,19 @@ class BeforeTemplateRenderedListener implements IEventListener {
/**
* BeforeTemplateRenderedListener constructor.
*
+ * @param IAccountManager $accountManager
+ * @param IUserSession $userSession
* @param IInitialStateService $initialState
* @param JSDataService $jsDataService
*/
- public function __construct(IInitialStateService $initialState,
- JSDataService $jsDataService) {
+ public function __construct(
+ IAccountManager $accountManager,
+ IUserSession $userSession,
+ IInitialStateService $initialState,
+ JSDataService $jsDataService
+ ) {
+ $this->accountManager = $accountManager;
+ $this->userSession = $userSession;
$this->initialState = $initialState;
$this->jsDataService = $jsDataService;
}
@@ -58,6 +76,12 @@ class BeforeTemplateRenderedListener implements IEventListener {
* @inheritDoc
*/
public function handle(Event $event): void {
+ $user = $this->userSession->getUser();
+ if ($user === null) {
+ return;
+ }
+ $account = $this->accountManager->getAccount($user);
+
if (!($event instanceof BeforeTemplateRenderedEvent)) {
// Unrelated
return;
@@ -71,6 +95,10 @@ class BeforeTemplateRenderedListener implements IEventListener {
return $this->jsDataService;
});
+ $this->initialState->provideLazyInitialState(Application::APP_ID, 'profileEnabled', function () use ($account) {
+ return ['profileEnabled' => $this->isProfileEnabled($account)];
+ });
+
\OCP\Util::addScript('user_status', 'user-status-menu');
\OCP\Util::addStyle('user_status', 'user-status-menu');
}