Skip to content

Commit

Permalink
feat(snooze): Disable snooze on AJAX cron
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Merkel <[email protected]>
  • Loading branch information
JohannesGGE committed Aug 16, 2023
1 parent 5c8d239 commit 49725af
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,16 @@ public function index(): TemplateResponse {
);
}

// Disable scheduled send in frontend if ajax cron is used because it is unreliable
// Disable snooze and scheduled send in frontend if ajax cron is used because it is unreliable
$cronMode = $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax');
$this->initialStateService->provideInitialState(
'disable-scheduled-send',
$cronMode === 'ajax',
);
$this->initialStateService->provideInitialState(
'disable-snooze',
$cronMode === 'ajax',
);

$this->initialStateService->provideInitialState(
'allow-new-accounts',
Expand Down
6 changes: 5 additions & 1 deletion src/components/Envelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
</template>
{{ t('mail', 'Edit tags') }}
</ActionButton>
<ActionButton
<ActionButton v-if="!isSnoozeDisabled"
:close-after-click="false"
@click="showSnoozeOptions">
<template #icon>
Expand Down Expand Up @@ -384,6 +384,7 @@ import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput'
import CalendarClock from 'vue-material-design-icons/CalendarClock'
import AlarmIcon from 'vue-material-design-icons/Alarm'
import moment from '@nextcloud/moment'
import { mapGetters } from 'vuex'
export default {
name: 'Envelope',
Expand Down Expand Up @@ -475,6 +476,9 @@ export default {
}
},
computed: {
...mapGetters([
'isSnoozeDisabled',
]),
messageLongDate() {
return messageDateTime(new Date(this.data.dateInt))
},
Expand Down
7 changes: 6 additions & 1 deletion src/components/MenuEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
</template>
{{ t('mail', 'Move message') }}
</ActionButton>
<ActionButton :close-after-click="false"
<ActionButton v-if="!isSnoozeDisabled"
:close-after-click="false"
@click="snoozeActionsOpen = true">
<template #icon>
<AlarmIcon :title="t('mail', 'Snooze')"
Expand Down Expand Up @@ -293,6 +294,7 @@ import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput'
import AlarmIcon from 'vue-material-design-icons/Alarm'
import logger from '../logger'
import moment from '@nextcloud/moment'
import { mapGetters } from 'vuex'
export default {
name: 'MenuEnvelope',
Expand Down Expand Up @@ -374,6 +376,9 @@ export default {
}
},
computed: {
...mapGetters([
'isSnoozeDisabled',
]),
account() {
const accountId = this.envelope.accountId ?? this.mailbox.accountId
return this.$store.getters.getAccount(accountId)
Expand Down
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const accounts = loadState('mail', 'accounts', [])
const tags = loadState('mail', 'tags', [])
const outboxMessages = loadState('mail', 'outbox-messages')
const disableScheduledSend = loadState('mail', 'disable-scheduled-send')
const disableSnooze = loadState('mail', 'disable-snooze')
const googleOauthUrl = loadState('mail', 'google-oauth-url', null)
const microsoftOauthUrl = loadState('mail', 'microsoft-oauth-url', null)

Expand All @@ -128,6 +129,7 @@ tags.forEach(tag => store.commit('addTag', { tag }))
outboxMessages.forEach(message => store.commit('outbox/addMessage', { message }))

store.commit('setScheduledSendingDisabled', disableScheduledSend)
store.commit('setSnoozeDisabled', disableSnooze)
store.commit('setGoogleOauthUrl', googleOauthUrl)
store.commit('setMicrosoftOauthUrl', microsoftOauthUrl)

Expand Down
1 change: 1 addition & 0 deletions src/store/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const getters = {
return state.tagList.map(tagId => state.tags[tagId])
},
isScheduledSendingDisabled: (state) => state.isScheduledSendingDisabled,
isSnoozeDisabled: (state) => state.isSnoozeDisabled,
googleOauthUrl: (state) => state.googleOauthUrl,
microsoftOauthUrl: (state) => state.microsoftOauthUrl,
getActiveSieveScript: (state) => (accountId) => state.sieveScript[accountId],
Expand Down
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default new Store({
tags: {},
tagList: [],
isScheduledSendingDisabled: false,
isSnoozeDisabled: false,
currentUserPrincipal: undefined,
googleOauthUrl: null,
sieveScript: {},
Expand Down
3 changes: 3 additions & 0 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ export default {
setScheduledSendingDisabled(state, value) {
state.isScheduledSendingDisabled = value
},
setSnoozeDisabled(state, value) {
state.isSnoozeDisabled = value
},
setActiveSieveScript(state, { accountId, scriptData }) {
Vue.set(state.sieveScript, accountId, scriptData)
},
Expand Down
2 changes: 0 additions & 2 deletions tests/Integration/Db/MailAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public function testToAPI() {
'quotaPercentage' => 10,
'trashRetentionDays' => 60,
'junkMailboxId' => null,
'moveJunk' => false,
'snoozeMailboxId' => null
], $a->toJson());
}
Expand Down Expand Up @@ -115,7 +114,6 @@ public function testMailAccountConstruct() {
'quotaPercentage' => null,
'trashRetentionDays' => 60,
'junkMailboxId' => null,
'moveJunk' => false,
'snoozeMailboxId' => null,
];
$a = new MailAccount($expected);
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function testIndex(): void {
->method('getLoginCredentials')
->willReturn($loginCredentials);

$this->initialState->expects($this->exactly(13))
$this->initialState->expects($this->exactly(14))
->method('provideInitialState')
->withConsecutive(
['debug', true],
Expand All @@ -288,6 +288,7 @@ public function testIndex(): void {
['prefill_email', '[email protected]'],
['outbox-messages', []],
['disable-scheduled-send', false],
['disable-snooze', false],
['allow-new-accounts', true],
['enabled_thread_summary', false],
['smime-certificates', []],
Expand Down

0 comments on commit 49725af

Please sign in to comment.