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

fix(Snooze): Sort snooze mailbox as specialUse #8774

Merged
merged 1 commit into from
Aug 21, 2023
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
7 changes: 6 additions & 1 deletion src/imap/MailboxSorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import clone from 'lodash/fp/clone'

const specialRolesOrder = ['all', 'inbox', 'flagged', 'drafts', 'sent', 'archive', 'junk', 'trash']

export const sortMailboxes = (mailboxes) => {
export const sortMailboxes = (mailboxes, account) => {
const c = clone(mailboxes)
c.sort((f1, f2) => {
if (f1.specialUse.length && f2.specialUse.length) {
Expand All @@ -39,6 +39,11 @@ export const sortMailboxes = (mailboxes) => {
return -1
} else if (f2.specialUse.length) {
return 1
} else if (f1.databaseId === account.snoozeMailboxId) {
// Sort Snoozed mailbox to specialRole mailboxes.
// Because this mailbox does not have specialUse,
// we need to check the databaseId for snoozeMailboxId
return -1
} else {
return f1.name.localeCompare(f2.name)
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default {
)

// Save the mailboxes to the store, but only keep IDs in the account's mailboxes list
const mailboxes = sortMailboxes(account.mailboxes || [])
const mailboxes = sortMailboxes(account.mailboxes || [], account)
Vue.set(account, 'mailboxes', [])
Vue.set(account, 'aliases', account.aliases ?? [])
mailboxes.map(addMailboxToState(state, account))
Expand Down
45 changes: 39 additions & 6 deletions src/tests/unit/imap/MailboxSorter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ describe('mailboxSorter', () => {
const mb1 = {
name: 'Inbox 1',
specialUse: [],
databaseId: 1,
}
const mb2 = {
name: 'Inbox 2',
specialUse: [],
databaseId: 2,
}
const mailboxes = [mb2, mb1]

const sorted = sortMailboxes(mailboxes)
const account = {
snoozeMailboxId: 0,
}

const sorted = sortMailboxes(mailboxes, account)

expect(sorted).toEqual([mb1, mb2])
})
Expand All @@ -42,14 +48,20 @@ describe('mailboxSorter', () => {
const mb1 = {
name: 'Inbox 1',
specialUse: [],
databaseId: 1,
}
const mb2 = {
name: 'Inbox 2',
specialUse: ['inbox'],
databaseId: 2,
}
const mailboxes = [mb1, mb2]

const sorted = sortMailboxes(mailboxes)
const account = {
snoozeMailboxId: 0,
}

const sorted = sortMailboxes(mailboxes, account)

expect(sorted).toEqual([mb2, mb1])
})
Expand All @@ -58,14 +70,20 @@ describe('mailboxSorter', () => {
const mb1 = {
name: 'Inbox 1',
specialUse: ['inbox'],
databaseId: 1,
}
const mb2 = {
name: 'Inbox 2',
specialUse: ['inbox'],
databaseId: 2,
}
const mailboxes = [mb1, mb2]

const sorted = sortMailboxes(mailboxes)
const account = {
snoozeMailboxId: 0,
}

const sorted = sortMailboxes(mailboxes, account)

expect(sorted).toEqual([mb1, mb2])
})
Expand All @@ -74,31 +92,46 @@ describe('mailboxSorter', () => {
const mb1 = {
name: 'Drafts',
specialUse: ['drafts'],
databaseId: 2,
}
const mb2 = {
name: 'Inbox',
specialUse: ['inbox'],
databaseId: 1,
}
const mb3 = {
name: 'Other 2',
specialUse: [],
databaseId: 3,
}
const mb4 = {
name: 'Other 1',
specialUse: [],
databaseId: 4,
}
const mb5 = {
name: 'Sent',
specialUse: ['sent'],
databaseId: 5,
}
const mb6 = {
name: 'Sent2',
specialUse: ['sent'],
databaseId: 6,
}
const mb7 = {
name: 'Snoozed',
specialUse: [],
databaseId: 7,
}
const mailboxes = [mb1, mb2, mb3, mb4, mb5, mb6, mb7]

const account = {
snoozeMailboxId: 7,
}
const mailboxes = [mb1, mb2, mb3, mb4, mb5, mb6]

const sorted = sortMailboxes(mailboxes)
const sorted = sortMailboxes(mailboxes, account)

expect(sorted).toEqual([mb2, mb1, mb5, mb6, mb4, mb3])
expect(sorted).toEqual([mb2, mb1, mb5, mb6, mb7, mb4, mb3])
})
})
Loading