Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2021-07-02 18:22:10 +0300
committerGitHub <noreply@github.com>2021-07-02 18:22:10 +0300
commitd1996c97220408f4ebc9b54c0ca1f3f8e6e1b831 (patch)
tree8e730b00f881a7b39c5b1d1fbba63df9e44b5294
parentf4ba6d8b35f7351a9f5b89b3bf0286c3d37f4f48 (diff)
parenta8ee2220f326853cc2c21eefd7f22e6f4fdeb758 (diff)
Merge pull request #5270 from nextcloud/enhancement/toggle-auto-tagging-classified-messages
Toggle auto tagging for classified messages
-rw-r--r--lib/Controller/PageController.php1
-rw-r--r--lib/Listener/NewMessageClassificationListener.php13
-rw-r--r--src/components/AppSettingsMenu.vue43
-rw-r--r--src/main.js5
-rw-r--r--templates/index.php1
-rw-r--r--tests/Unit/Controller/PageControllerTest.php4
6 files changed, 64 insertions, 3 deletions
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index cff03a324..554ab07ef 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -158,6 +158,7 @@ class PageController extends Controller {
'external-avatars' => $this->preferences->getPreference('external-avatars', 'true'),
'reply-mode' => $this->preferences->getPreference('reply-mode', 'top'),
'collect-data' => $this->preferences->getPreference('collect-data', 'true'),
+ 'tag-classified-messages' => $this->preferences->getPreference('tag-classified-messages', 'true'),
]);
$this->initialStateService->provideInitialState(
'prefill_displayName',
diff --git a/lib/Listener/NewMessageClassificationListener.php b/lib/Listener/NewMessageClassificationListener.php
index fb499a569..d370d9b9d 100644
--- a/lib/Listener/NewMessageClassificationListener.php
+++ b/lib/Listener/NewMessageClassificationListener.php
@@ -27,6 +27,7 @@ namespace OCA\Mail\Listener;
use Horde_Imap_Client;
use OCA\Mail\Contracts\IMailManager;
+use OCA\Mail\Contracts\IUserPreferences;
use OCA\Mail\Db\Tag;
use OCA\Mail\Db\TagMapper;
use OCA\Mail\Events\NewMessagesSynchronized;
@@ -58,14 +59,19 @@ class NewMessageClassificationListener implements IEventListener {
/** @var IMailManager */
private $mailManager;
+ /** @var IUserPreferences */
+ private $preferences;
+
public function __construct(ImportanceClassifier $classifier,
TagMapper $tagMapper,
LoggerInterface $logger,
- IMailManager $mailManager) {
+ IMailManager $mailManager,
+ IUserPreferences $preferences) {
$this->classifier = $classifier;
$this->logger = $logger;
$this->tagMapper = $tagMapper;
$this->mailManager = $mailManager;
+ $this->preferences = $preferences;
}
public function handle(Event $event): void {
@@ -73,6 +79,11 @@ class NewMessageClassificationListener implements IEventListener {
return;
}
+ $allowTagging = $this->preferences->getPreference('tag-classified-messages');
+ if ($allowTagging === "false") {
+ return;
+ }
+
foreach (self::EXEMPT_FROM_CLASSIFICATION as $specialUse) {
if ($event->getMailbox()->isSpecialUse($specialUse)) {
// Nothing to do then
diff --git a/src/components/AppSettingsMenu.vue b/src/components/AppSettingsMenu.vue
index 2307fbae6..301487d4c 100644
--- a/src/components/AppSettingsMenu.vue
+++ b/src/components/AppSettingsMenu.vue
@@ -18,6 +18,20 @@
<label for="data-collection-toggle">{{ optOutSettingsText }}</label>
</p>
+ <p v-if="toggleAutoTagging" class="app-settings">
+ <span class="icon-loading-small" />
+ {{ autoTaggingText }}
+ </p>
+ <p v-else class="app-settings">
+ <input
+ id="auto-tagging-toggle"
+ class="checkbox"
+ type="checkbox"
+ :checked="useAutoTagging"
+ @change="onToggleAutoTagging">
+ <label for="auto-tagging-toggle">{{ autoTaggingText }}</label>
+ </p>
+
<p v-if="loadingAvatarSettings" class="app-settings avatar-settings">
<span class="icon-loading-small" />
{{ t('mail', 'Use Gravatar and favicon avatars') }}
@@ -63,8 +77,10 @@
</template>
<script>
-import Logger from '../logger'
import { generateUrl } from '@nextcloud/router'
+import { showError } from '@nextcloud/dialogs'
+
+import Logger from '../logger'
import KeyboardShortcuts from '../views/KeyboardShortcuts'
export default {
@@ -82,6 +98,9 @@ export default {
replySettingsText: t('mail', 'Put my text to the bottom of a reply instead of on top of it.'),
loadingReplySettings: false,
displayKeyboardShortcuts: false,
+ // eslint-disable-next-line
+ autoTaggingText: t('mail', 'Automatically classify importance of new email'),
+ toggleAutoTagging: false,
}
},
computed: {
@@ -94,6 +113,11 @@ export default {
useDataCollection() {
return this.$store.getters.getPreference('collect-data', 'true') === 'true'
},
+ useAutoTagging() {
+ const b = this.$store.getters.getPreference('tag-classified-messages', 'true') === 'true'
+ console.info('TAGGING?????', b)
+ return b
+ },
},
methods: {
onToggleButtonReplies(e) {
@@ -135,6 +159,23 @@ export default {
this.loadingOptOutSettings = false
})
},
+ async onToggleAutoTagging(e) {
+ this.toggleAutoTagging = true
+
+ try {
+ await this.$store
+ .dispatch('savePreference', {
+ key: 'tag-classified-messages',
+ value: e.target.checked ? 'true' : 'false',
+ })
+ } catch (error) {
+ Logger.error('could not save preferences', { error })
+
+ showError(t('mail', 'Could not update preference'))
+ } finally {
+ this.toggleAutoTagging = false
+ }
+ },
registerProtocolHandler() {
if (window.navigator.registerProtocolHandler) {
const url
diff --git a/src/main.js b/src/main.js
index 16df5cf0f..b98b49bed 100644
--- a/src/main.js
+++ b/src/main.js
@@ -76,6 +76,11 @@ store.commit('savePreference', {
key: 'collect-data',
value: getPreferenceFromPage('collect-data'),
})
+store.commit('savePreference', {
+ key: 'tag-classified-messages',
+ value: getPreferenceFromPage('tag-classified-messages'),
+})
+console.info('TTTTTTTTTTT', getPreferenceFromPage('tag-classified-messages'))
const accountSettings = loadState('mail', 'account-settings')
const accounts = loadState('mail', 'accounts', [])
diff --git a/templates/index.php b/templates/index.php
index aae405924..c4edb35c3 100644
--- a/templates/index.php
+++ b/templates/index.php
@@ -32,3 +32,4 @@ script('mail', 'mail');
<input type="hidden" id="config-installed-version" value="<?php p($_['app-version']); ?>">
<input type="hidden" id="external-avatars" value="<?php p($_['external-avatars']); ?>">
<input type="hidden" id="collect-data" value="<?php p($_['collect-data']); ?>">
+<input type="hidden" id="tag-classified-messages" value="<?php p($_['tag-classified-messages']); ?>">
diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php
index 90f6a0741..0d9b95015 100644
--- a/tests/Unit/Controller/PageControllerTest.php
+++ b/tests/Unit/Controller/PageControllerTest.php
@@ -126,13 +126,14 @@ class PageControllerTest extends TestCase {
$account1 = $this->createMock(Account::class);
$account2 = $this->createMock(Account::class);
$mailbox = $this->createMock(Mailbox::class);
- $this->preferences->expects($this->exactly(4))
+ $this->preferences->expects($this->exactly(5))
->method('getPreference')
->willReturnMap([
['account-settings', '[]', json_encode([])],
['external-avatars', 'true', 'true'],
['reply-mode', 'top', 'bottom'],
['collect-data', 'true', 'true'],
+ ['tag-classified-messages', 'true', 'true'],
]);
$this->accountService->expects($this->once())
->method('findByUserId')
@@ -237,6 +238,7 @@ class PageControllerTest extends TestCase {
'reply-mode' => 'bottom',
'app-version' => '1.2.3',
'collect-data' => 'true',
+ 'tag-classified-messages' => 'true',
]);
$csp = new ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');