Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raised max nc version, refactored php code #15

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
<bugs>https://github.com/nextmcloud/nmc_user/issues</bugs>
<repository>https://github.com/nextmcloud/nmc_user/nmcloud_oidc</repository>
<dependencies>
<nextcloud min-version="22" max-version="25"/>
<nextcloud min-version="22" max-version="27"/>
</dependencies>
</info>
14 changes: 0 additions & 14 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

use OCA\NmcSpica\Listener\BeforeTemplateRenderedListener;
use OCA\NmcSpica\Listener\TokenObtainedEventListener;
use OCA\NmcSpica\Service\SpicaMailService;
use OCA\NmcSpica\Service\TokenService;
use OCA\NmcSpica\SpicaAddressBook;
use OCA\UserOIDC\Event\TokenObtainedEvent;
Expand All @@ -36,9 +35,7 @@
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Services\IInitialState;
use OCP\Contacts\IManager;
use OCP\IConfig;

class Application extends App implements IBootstrap {
public const APP_ID = 'nmc_spica';
Expand Down Expand Up @@ -66,12 +63,9 @@ public function register(IRegistrationContext $context): void {

public function boot(IBootContext $context): void {
$context->injectFn(function (
IInitialState $initialState,
TokenService $tokenService,
IManager $contactsManager,
SpicaAddressBook $spicaAddressBook,
SpicaMailService $unreadService,
IConfig $config,
$userId
) {

Expand All @@ -89,14 +83,6 @@ public function boot(IBootContext $context): void {
if ($token !== null && $token->isExpired()) {
$tokenService->reauthenticate();
}

$initialState->provideLazyInitialState('unread-counter', function () use ($unreadService) {
return $unreadService->getUnreadCounter();
});

$initialState->provideLazyInitialState('mail-url', function () use ($config) {
return $config->getAppValue(self::APP_ID, self::APP_CONFIG_WEBMAIL_URL, '');
});
});
}
}
38 changes: 38 additions & 0 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,42 @@
*/
namespace OCA\NmcSpica\Listener;

use OCA\NmcSpica\AppInfo\Application;
use OCA\NmcSpica\Service\SpicaMailService;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\IInitialStateService;

/** @template-implements IEventListener<Event|BeforeTemplateRenderedEvent> */
class BeforeTemplateRenderedListener implements IEventListener {

/** @var IConfig */
private $config;

/** @var IInitialStateService */
private $initialState;

/** @var SpicaMailService */
private $spicaMailService;

/**
* BeforeTemplateRenderedListener constructor.
*
* @param IInitialStateService $initialState
*/
public function __construct(
IConfig $config,
IInitialStateService $initialState,
SpicaMailService $spicaMailService
) {
$this->config = $config;
$this->initialState = $initialState;
$this->spicaMailService = $spicaMailService;
}

public function handle(Event $event): void {

if (!($event instanceof BeforeTemplateRenderedEvent)) {
Expand All @@ -29,6 +57,16 @@ public function handle(Event $event): void {
return;
}

$this->initialState->provideLazyInitialState(Application::APP_ID, 'unread-counter', function () {
$unreadCounter = $this->spicaMailService->getUnreadCounter();
return $unreadCounter;
});

$this->initialState->provideLazyInitialState(Application::APP_ID, 'mail-url', function () {
$mailUrl = $this->config->getAppValue(Application::APP_ID, Application::APP_CONFIG_WEBMAIL_URL, '');
return $mailUrl;
});

// show email button only to logged in users
\OCP\Util::addScript("nmc_spica", "nmc_spica");
\OCP\Util::addStyle('nmc_spica', 'nmc_spica');
Expand Down