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

Add unread mail dashboard widget #4124

Merged
merged 1 commit into from
Nov 25, 2020
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
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
44 changes: 44 additions & 0 deletions lib/Dashboard/ImportantMailWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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;

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
44 changes: 44 additions & 0 deletions lib/Dashboard/UnreadMailWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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;

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
11 changes: 9 additions & 2 deletions src/main-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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 @@ -25,7 +26,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 +40,12 @@ document.addEventListener('DOMContentLoaded', function() {
const register = OCA?.Dashboard?.register || (() => {})

register('mail', (el) => {
ChristophWurst marked this conversation as resolved.
Show resolved Hide resolved
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>