Skip to content
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
14 changes: 12 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* Mail
*
Expand Down Expand Up @@ -35,7 +36,9 @@
use OCA\Mail\Contracts\ITrustedSenderService;
use OCA\Mail\Contracts\IUserPreferences;
use OCA\Mail\Dashboard\ImportantMailWidget;
use OCA\Mail\Dashboard\ImportantMailWidgetV2;
use OCA\Mail\Dashboard\UnreadMailWidget;
use OCA\Mail\Dashboard\UnreadMailWidgetV2;
use OCA\Mail\Events\BeforeImapClientCreated;
use OCA\Mail\Events\BeforeMessageSentEvent;
use OCA\Mail\Events\DraftMessageCreatedEvent;
Expand Down Expand Up @@ -81,6 +84,7 @@
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Dashboard\IAPIWidgetV2;
use OCP\IServerContainer;
use OCP\User\Events\UserDeletedEvent;
use OCP\Util;
Expand Down Expand Up @@ -138,8 +142,14 @@ public function register(IRegistrationContext $context): void {
$context->registerMiddleWare(ErrorMiddleware::class);
$context->registerMiddleWare(ProvisioningMiddleware::class);

$context->registerDashboardWidget(ImportantMailWidget::class);
$context->registerDashboardWidget(UnreadMailWidget::class);
if (interface_exists(IAPIWidgetV2::class)) {
$context->registerDashboardWidget(ImportantMailWidgetV2::class);
$context->registerDashboardWidget(UnreadMailWidgetV2::class);
} else {
$context->registerDashboardWidget(ImportantMailWidget::class);
$context->registerDashboardWidget(UnreadMailWidget::class);
}

$context->registerSearchProvider(Provider::class);

$context->registerNotifierService(Notifier::class);
Expand Down
53 changes: 53 additions & 0 deletions lib/Dashboard/ImportantMailWidgetV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud>
*
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Mail\Dashboard;

/**
* Requires Nextcloud >= 27.1.0
*/
class ImportantMailWidgetV2 extends MailWidgetV2 {
/**
* @inheritDoc
*/
public function getId(): string {
return 'mail';
}

/**
* @inheritDoc
*/
public function getTitle(): string {
return $this->l10n->t('Important mail');
}

/**
* @inheritDoc
*/
public function getSearchFilter(): string {
return 'is:important';
}
}
12 changes: 6 additions & 6 deletions lib/Dashboard/MailWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
use OCP\Util;

abstract class MailWidget implements IAPIWidget, IIconWidget, IOptionWidget {
private IURLGenerator $urlGenerator;
private IUserManager $userManager;
private AccountService $accountService;
private IMailSearch $mailSearch;
private IInitialState $initialState;
private ?string $userId;
protected IURLGenerator $urlGenerator;
protected IUserManager $userManager;
protected AccountService $accountService;
protected IMailSearch $mailSearch;
protected IInitialState $initialState;
protected ?string $userId;
protected IL10N $l10n;

public function __construct(IL10N $l10n,
Expand Down
76 changes: 76 additions & 0 deletions lib/Dashboard/MailWidgetV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud>
*
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Mail\Dashboard;

use OCP\Dashboard\IAPIWidgetV2;
use OCP\Dashboard\IButtonWidget;
use OCP\Dashboard\Model\WidgetButton;
use OCP\Dashboard\Model\WidgetItems;

/**
* Requires Nextcloud >= 27.1.0
*/
abstract class MailWidgetV2 extends MailWidget implements IAPIWidgetV2, IButtonWidget {

/**
* @inheritDoc
*/
public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems {
$items = $this->getItems($userId, $since, $limit);
return new WidgetItems(
$items,
empty($items) ? $this->l10n->t('No message found yet') : '',
);
}

/**
* @inheritDoc
*/
public function load(): void {
// No assets need to be loaded anymore as the widget is rendered from the API
}

/**
* @inheritDoc
*/
public function getWidgetButtons(string $userId): array {
$buttons = [];

if ($this->userId !== null) {
$accounts = $this->accountService->findByUserId($this->userId);
if (empty($accounts)) {
$buttons[] = new WidgetButton(
WidgetButton::TYPE_SETUP,
$this->urlGenerator->linkToRouteAbsolute('mail.page.setup'),
$this->l10n->t('Set up an account'),
);
}
}

return $buttons;
}
}
53 changes: 53 additions & 0 deletions lib/Dashboard/UnreadMailWidgetV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud>
*
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Mail\Dashboard;

/**
* Requires Nextcloud >= 27.1.0
*/
class UnreadMailWidgetV2 extends MailWidgetV2 {
/**
* @inheritDoc
*/
public function getId(): string {
return 'mail-unread';
}

/**
* @inheritDoc
*/
public function getTitle(): string {
return $this->l10n->t('Unread mail');
}

/**
* @inheritDoc
*/
public function getSearchFilter(): string {
return 'is:unread';
}
}
25 changes: 22 additions & 3 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.13.1@086b94371304750d1c673315321a55d15fc59015">
<files psalm-version="5.14.1@b9d355e0829c397b9b3b47d0c0ed042a8a70284d">
<file src="lib/AppInfo/Application.php">
<MissingDependency>
<code>ImportantMailWidgetV2</code>
<code>UnreadMailWidgetV2</code>
</MissingDependency>
<UndefinedClass>
<code>IAPIWidgetV2</code>
</UndefinedClass>
</file>
<file src="lib/Cache/Cache.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$d = &$this->_data[$mailbox]]]></code>
Expand All @@ -13,9 +22,19 @@
<code><![CDATA[$slicemap = &$this->_slicemap[$mailbox]]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="lib/Rector/ServerGetRector.php">
<file src="lib/Dashboard/ImportantMailWidgetV2.php">
<MissingDependency>
<code>MailWidgetV2</code>
</MissingDependency>
</file>
<file src="lib/Dashboard/MailWidgetV2.php">
<UndefinedClass>
<code>AbstractRector</code>
<code>IAPIWidgetV2</code>
</UndefinedClass>
</file>
<file src="lib/Dashboard/UnreadMailWidgetV2.php">
<MissingDependency>
<code>MailWidgetV2</code>
</MissingDependency>
</file>
</files>