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

Use custom ListModel for getting mails #8308

Open
wants to merge 5 commits into
base: dev-mail
Choose a base branch
from

Conversation

paw-hub
Copy link
Contributor

@paw-hub paw-hub commented Jan 17, 2025

This removes MailViewModel having to keep track of MailSetEntry<->Mail, and it removes a lot of legacy code for getting Mail vs MailSetEntry, as all of the implementation details for getting mails are now in MailListModel. Additionally, everyone uses mailsets, so the legacy code is no longer necessary.

Closes #8247

This removes MailViewModel having to keep track of MailSetEntry<->Mail,
and it removes a lot of legacy code for getting Mail vs MailSetEntry, as
all of the implementation details for getting mails are now in
MailListModel. Additionally, everyone uses mailsets, so the legacy code
is no longer necessary.

Closes #8247

Co-authored-by: hrb-hub <[email protected]>
@paw-hub paw-hub force-pushed the 8247-refactor-non-conversation-list branch from c502aad to 3356e4b Compare January 17, 2025 15:46
Comment on lines 55 to 62
sortCompare: (item1, item2) => {
// Mail set entry ID has the timestamp and mail element ID
const item1Id = getElementId(item1.mailSetEntry)
const item2Id = getElementId(item2.mailSetEntry)

// Sort in reverse order to ensure newer mails are first
return compare(customIdToUint8array(item2Id), customIdToUint8array(item1Id))
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're currently awaiting a response if this is a good enough check or if the limited 1024 ms precision would necessitate checking the mail's receivedDate separately. If not, we can check them separately as was written before.

Do not merge this until this is resolved.

@hrb-hub hrb-hub linked an issue Jan 17, 2025 that may be closed by this pull request
Copy link
Contributor

@charlag charlag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't look at all of it yet but great work!

src/common/misc/ListModel.ts Outdated Show resolved Hide resolved
src/mail-app/mail/model/MailListModel.ts Outdated Show resolved Hide resolved
const items = await this.loadMails(lastFetchedId, count)
return {
items,
complete: items.length < count,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

complete condition was different before because of inbox rules, should we take that into account?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Oops!

}

async handleEntityUpdate(update: EntityUpdateData) {
if (isUpdateForTypeRef(MailFolderTypeRef, update)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking… we could pass labels in also directly now. We should think about it, would be a good point to do it now.

const newMailData = await this.entityClient.load(MailTypeRef, [update.instanceListId, update.instanceId])
// Updating the mail in-place does not require waiting for the underlying list model to finish.
// We use Object.assign here to ensure references to the mail now have the new mail data
Object.assign(mailItem.mail, newMailData)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this optimization is worth it. What if new mail has fewer fields assigned than the old one (probably not possible yet but could). I prefer to not mutate globally-referenced instances without reason (even though that's the case for mails right now).

I also don't understand how it would trigger a list update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an optimization. We had an issue where mails were not always being updated (for example marking mails as read/unread).

Maybe we can look at this one together.

}

onSingleExclusiveSelection(mail: Mail) {
this.listModel.onSingleExclusiveSelection(assertNotNull(this.getLoadedMail(mail)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we pass around LoadedMail now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoadedMail is sort of an internal detail as we needed some sort of tuple for Mail/MailSetEntry. Do we want to expose this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial understanding was that we would have two list models (with maybe similar interfaces?): one for individual mail set entries and one for conversations.

I don't have any issue with exposing it btw.

src/mail-app/mail/model/MailListModel.ts Outdated Show resolved Hide resolved
Also tweak the timestamp check slightly; we can return the difference,
since all sort cares about is if it is >0 or <0, not =1 or =-1

If this check is not necessary, this commit can be dropped.
@paw-hub paw-hub force-pushed the 8247-refactor-non-conversation-list branch from 79415a6 to 6f711f6 Compare January 17, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor non-conversation list using custom type support from
2 participants