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
1 change: 1 addition & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public function index(): TemplateResponse {
'search-priority-body' => $this->preferences->getPreference($this->currentUserId, 'search-priority-body', 'false'),
'start-mailbox-id' => $this->preferences->getPreference($this->currentUserId, 'start-mailbox-id'),
'follow-up-reminders' => $this->preferences->getPreference($this->currentUserId, 'follow-up-reminders', 'true'),
'sort-favorites' => $this->preferences->getPreference($this->currentUserId, 'sort-favorites', 'false'),
]);
$this->initialStateService->provideInitialState(
'prefill_displayName',
Expand Down
33 changes: 33 additions & 0 deletions src/components/AppSettingsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
:label="t('mail', 'Show all messages in thread')"
:description="t('mail', 'When off, only the selected message will be shown')" />
</NcFormBox>
<NcFormBox>
<NcFormBoxSwitch
v-model="sortFavorites"
:label="t('mail', 'Sort favorites up')"
:disabled="loadingSortFavorites"
:description="t('mail', 'When on, favorite messages will be sorted to the top of folders')" />
</NcFormBox>
<NcRadioGroup v-model="layoutMode" :label="t('mail', 'Layout')">
<NcRadioGroupButton :label="t('mail', 'Vertical split')" value="vertical-split">
<template #icon>
Expand Down Expand Up @@ -348,6 +355,7 @@ export default {
internalAddressText: t('mail', 'Highlight external addresses'),
toggleAutoTagging: false,
loadingFollowUpReminders: false,
loadingSortFavorites: false,
displaySmimeCertificateModal: false,
sortOrder: 'newest',
showSettings: false,
Expand Down Expand Up @@ -384,6 +392,16 @@ export default {
return this.getAccounts.filter((account) => account && account.emailAddress)
},

sortFavorites: {
get() {
return this.mainStore.getPreference('sort-favorites', 'false') === 'true'
},

set(value) {
this.onToggleSortFavorites(value)
},
},

searchPriorityBody: {
get() {
return this.mainStore.getPreference('search-priority-body', 'false') === 'true'
Expand Down Expand Up @@ -564,6 +582,21 @@ export default {
}
},

async onToggleSortFavorites(enabled) {
this.loadingSortFavorites = true

try {
await this.mainStore.savePreference({
key: 'sort-favorites',
value: enabled ? 'true' : 'false',
})
} catch (error) {
Logger.error('could not save preferences', { error })
} finally {
this.loadingSortFavorites = false
}
},

onToggleCollectData(collect) {
this.loadingOptOutSettings = true

Expand Down
24 changes: 20 additions & 4 deletions src/components/MailboxThread.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,14 @@ export default {
return envelopes.length > 0
},

sortFavorites() {
return this.mainStore.getPreference('sort-favorites', 'false') === 'true'
},

hasFavoriteEnvelopes() {
if (!this.sortFavorites) {
return false
}
const envelopes = this.mainStore.getEnvelopes(
this.unifiedInbox.databaseId,
this.appendToSearch(this.favoriteQuery),
Expand Down Expand Up @@ -424,6 +431,14 @@ export default {
}
},

sortFavorites(enabled) {
if (enabled) {
this.searchQuery = this.searchQuery ? 'not:starred' : this.searchQuery + ' not:starred'
} else if (this.searchQuery.includes('not:starred')) {
this.searchQuery = this.searchQuery.replace('not:starred', '')
}
},

async hasFollowUpEnvelopes(value) {
if (!value) {
return
Expand All @@ -444,8 +459,9 @@ export default {
},

async mounted() {
// TODO: check the user preference
this.searchQuery = 'not:starred'
if (this.sortFavorites) {
this.searchQuery = 'not:starred'
}
setTimeout(this.saveStartMailbox, START_MAILBOX_DEBOUNCE)
if (this.isThreadShown) {
await this.fetchEnvelopes()
Expand Down Expand Up @@ -495,8 +511,8 @@ export default {
if (this.searchQuery === undefined) {
return str
}
// Todo: adjust once we have the user prefeference
if (str === this.favoriteQuery && this.searchQuery.includes('not:starred')) {

if (this.sortFavorites && str === this.favoriteQuery && this.searchQuery.includes('not:starred')) {
return this.searchQuery.replace('not:starred', str)
}
return this.searchQuery + ' ' + str
Expand Down
4 changes: 4 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export default function initAfterAppCreation() {
key: 'search-priority-body',
value: preferences['search-priority-body'],
})
mainStore.savePreferenceMutation({
key: 'sort-favorites',
value: preferences['sort-favorites'],
})
const startMailboxId = preferences['start-mailbox-id']
mainStore.savePreferenceMutation({
key: 'start-mailbox-id',
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function testIndex(): void {
$account1 = $this->createMock(Account::class);
$account2 = $this->createMock(Account::class);
$mailbox = $this->createMock(Mailbox::class);
$this->preferences->expects($this->exactly(12))
$this->preferences->expects($this->exactly(13))
->method('getPreference')
->willReturnMap([
[$this->userId, 'account-settings', '[]', json_encode([])],
Expand All @@ -185,6 +185,7 @@ public function testIndex(): void {
[$this->userId, 'follow-up-reminders', 'true', 'true'],
[$this->userId, 'internal-addresses', 'false', 'false'],
[$this->userId, 'smime-sign-aliases', '[]', '[]'],
[$this->userId, 'sort-favorites', 'false', 'false'],
]);
$this->accountService->expects($this->once())
->method('findByUserId')
Expand Down Expand Up @@ -334,6 +335,7 @@ public function testIndex(): void {
'layout-mode' => 'vertical-split',
'layout-message-view' => 'threaded',
'follow-up-reminders' => 'true',
'sort-favorites' => 'false'
]],
['prefill_displayName', 'Jane Doe'],
['prefill_email', '[email protected]'],
Expand Down
Loading