Skip to content

Commit

Permalink
Add unread mail dashboard widget
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed Nov 24, 2020
1 parent 9669b1b commit b59ac14
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 23 deletions.
6 changes: 4 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
use OCA\Mail\Contracts\IMailSearch;
use OCA\Mail\Contracts\IMailTransmission;
use OCA\Mail\Contracts\IUserPreferences;
use OCA\Mail\Dashboard\MailWidget;
use OCA\Mail\Dashboard\ImportantMailWidget;
use OCA\Mail\Dashboard\UnreadMailWidget;
use OCA\Mail\Events\DraftSavedEvent;
use OCA\Mail\Events\MailboxesSynchronizedEvent;
use OCA\Mail\Events\SynchronizationEvent;
Expand Down Expand Up @@ -113,7 +114,8 @@ public function register(IRegistrationContext $context): void {
$context->registerMiddleWare(ErrorMiddleware::class);
$context->registerMiddleWare(ProvisioningMiddleware::class);

$context->registerDashboardWidget(MailWidget::class);
$context->registerDashboardWidget(ImportantMailWidget::class);
$context->registerDashboardWidget(UnreadMailWidget::class);
$context->registerSearchProvider(Provider::class);

// bypass Horde Translation system
Expand Down
52 changes: 52 additions & 0 deletions lib/Dashboard/ImportantMailWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020 Richard Steinmetz <richard@steinmetz.cloud>
*
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Mail\Dashboard;

use OCA\Mail\AppInfo\Application;
use OCA\Mail\Service\AccountService;
use OCP\AppFramework\Services\IInitialState;
use OCP\Dashboard\IWidget;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Util;

class ImportantMailWidget extends MailWidget {

/**
* @inheritDoc
*/
public function getId(): string {
return 'mail';
}

/**
* @inheritDoc
*/
public function getTitle(): string {
return $this->l10n->t('Important mail');
}
}
19 changes: 3 additions & 16 deletions lib/Dashboard/MailWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down Expand Up @@ -34,10 +35,10 @@
use OCP\IURLGenerator;
use OCP\Util;

class MailWidget implements IWidget {
abstract class MailWidget implements IWidget {

/** @var IL10N */
private $l10n;
protected $l10n;

/** @var IURLGenerator */
private $urlGenerator;
Expand All @@ -63,20 +64,6 @@ public function __construct(IL10N $l10n,
$this->userId = $userId;
}

/**
* @inheritDoc
*/
public function getId(): string {
return Application::APP_ID;
}

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

/**
* @inheritDoc
*/
Expand Down
52 changes: 52 additions & 0 deletions lib/Dashboard/UnreadMailWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020 Richard Steinmetz <richard@steinmetz.cloud>
*
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Mail\Dashboard;

use OCA\Mail\AppInfo\Application;
use OCA\Mail\Service\AccountService;
use OCP\AppFramework\Services\IInitialState;
use OCP\Dashboard\IWidget;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Util;

class UnreadMailWidget extends MailWidget {

/**
* @inheritDoc
*/
public function getId(): string {
return 'mail-unread';
}

/**
* @inheritDoc
*/
public function getTitle(): string {
return $this->l10n->t('Unread mail');
}
}
7 changes: 5 additions & 2 deletions lib/Listener/DashboardPanelListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -28,7 +29,8 @@

namespace OCA\Mail\Listener;

use OCA\Mail\Dashboard\MailWidget;
use OCA\Mail\Dashboard\ImportantMailWidget;
use OCA\Mail\Dashboard\UnreadMailWidget;
use OCP\Dashboard\RegisterWidgetEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand All @@ -43,6 +45,7 @@ public function handle(Event $event): void {
return;
}

$event->registerWidget(MailWidget::class);
$event->registerWidget(ImportantMailWidget::class);
$event->registerWidget(UnreadMailWidget::class);
}
}
8 changes: 7 additions & 1 deletion src/views/Dashboard.vue → src/components/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export default {
DashboardWidgetItem,
EmptyContent,
},
props: {
query: {
type: String,
required: true,
},
},
data() {
return {
messages: [],
Expand Down Expand Up @@ -113,7 +119,7 @@ export default {
})
await Promise.all(inboxes.map(async(mailbox) => {
const messages = await fetchEnvelopes(mailbox.databaseId, 'is:important', undefined, 10)
const messages = await fetchEnvelopes(mailbox.databaseId, this.query, undefined, 10)
this.messages = this.messages !== null ? [...this.messages, ...messages] : messages
this.fetchedAccounts++
}))
Expand Down
10 changes: 8 additions & 2 deletions src/main-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { getRequestToken } from '@nextcloud/auth'
import { generateFilePath } from '@nextcloud/router'

import Nextcloud from './mixins/Nextcloud'
import Dashboard from './views/Dashboard'
import DashboardImportant from './views/DashboardImportant'
import DashboardUnread from './views/DashboardUnread'

// eslint-disable-next-line camelcase
__webpack_nonce__ = btoa(getRequestToken())
Expand All @@ -38,7 +39,12 @@ document.addEventListener('DOMContentLoaded', function() {
const register = OCA?.Dashboard?.register || (() => {})

register('mail', (el) => {
const View = Vue.extend(Dashboard)
const View = Vue.extend(DashboardImportant)
new View().$mount(el)
})

register('mail-unread', (el) => {
const View = Vue.extend(DashboardUnread)
new View().$mount(el)
})
})
36 changes: 36 additions & 0 deletions src/views/DashboardImportant.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
- @copyright Copyright (c) 2020 Richard Steinmetz <richard@steinmetz.cloud>
-
- @author Richard Steinmetz <richard@steinmetz.cloud>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero 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 Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->

<template>
<Dashboard query="is:important" />
</template>

<script>
import Dashboard from '../components/Dashboard'
export default {
name: 'DashboardImportant',
components: {
Dashboard,
},
}
</script>
36 changes: 36 additions & 0 deletions src/views/DashboardUnread.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
- @copyright Copyright (c) 2020 Richard Steinmetz <richard@steinmetz.cloud>
-
- @author Richard Steinmetz <richard@steinmetz.cloud>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero 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 Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->

<template>
<Dashboard query="is:unread" />
</template>

<script>
import Dashboard from '../components/Dashboard'
export default {
name: 'DashboardUnread',
components: {
Dashboard,
},
}
</script>

0 comments on commit b59ac14

Please sign in to comment.