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

Try to select sticky mail if in list #7792

Merged
merged 1 commit into from
Nov 6, 2024
Merged

Conversation

paw-hub
Copy link
Contributor

@paw-hub paw-hub commented Oct 22, 2024

Fix the sticky mail selection behavior so that if we are on the list, it will visually show that mail being selected. If not, don't try to go to that list.

Fixes #7585

@paw-hub paw-hub force-pushed the 7585-notification-select branch 3 times, most recently from f878653 to 75647a0 Compare October 22, 2024 14:17
@wrdhub wrdhub linked an issue Oct 23, 2024 that may be closed by this pull request
6 tasks
@@ -340,7 +354,7 @@ export class MailViewModel {
this._folder = folder
this.listStreamSubscription?.end(true)
this.listStreamSubscription = this.listModel!.stateStream.map((state) => this.onListStateChange(state))
this.listModel!.loadInitial()
this.listModel!.loadInitial().then(noOp)
Copy link
Contributor

Choose a reason for hiding this comment

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

why is then(noOp) needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't, but my cursed IDE setup complains since loadInitial is async.

Maybe .then() would suffice, but we do .then(noOp) way, way more often.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove the change, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

there's a magical comment that you can ask IDE to insert that suppresses it

private async resetOrInitializeList() {
if (this.listModel == null) {
// If we don't have a list, load the inbox so that it won't be empty on mobile.
this.setListId(await this.getFolderForUserInbox())
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't it a race to set list id after doing async?

Copy link
Contributor Author

@paw-hub paw-hub Nov 5, 2024

Choose a reason for hiding this comment

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

We were already doing this, I think?

if (!isSameId(this.stickyMailId, fullMailId)) return
// Make sure that we display *something* in the list, otherwise it'll be empty on mobile
// We could try to open the location of the mail, but it might have been moved around soon after
this.setListId(await this.getFolderForUserInbox())
}

Copy link
Contributor

Choose a reason for hiding this comment

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

ah that's also not good maybe

@@ -230,12 +235,21 @@ export class MailViewModel {
}

private async loadExplicitMailTarget(listId: Id, mailId: Id, onMissingTargetEmail: () => unknown) {
// shouldStop returning true guarantees we won't load anything if the mail is not in the list already, so
// this will be synchronous
const listMail = await this.listModel?.loadAndSelect(mailId, () => true)
Copy link
Contributor

Choose a reason for hiding this comment

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

it should stop if we get called with another id

Copy link
Contributor

Choose a reason for hiding this comment

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

I misread it, you are trying to select it without loading anything. So this will only select the mail if it's already in the list.

@paw-hub paw-hub force-pushed the 7585-notification-select branch 2 times, most recently from d777f07 to 73e9551 Compare November 5, 2024 14:16
@@ -230,12 +235,21 @@ export class MailViewModel {
}

private async loadExplicitMailTarget(listId: Id, mailId: Id, onMissingTargetEmail: () => unknown) {
// shouldStop returning true guarantees we won't load anything if the mail is not in the list already, so
// this will be synchronous
const listMail = await this.listModel?.loadAndSelect(mailId, () => true)
Copy link
Contributor

Choose a reason for hiding this comment

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

I misread it, you are trying to select it without loading anything. So this will only select the mail if it's already in the list.

const cached = await this.cacheStorage.get(MailTypeRef, listId, mailId)
if (cached) {
console.log(TAG, "opening cached mail", mailId)
await this.resetOrInitializeList([listId, mailId])
Copy link
Contributor

Choose a reason for hiding this comment

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

I am confused, above we call loadAndSelect() and this function is supposed to deselect?

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 will never get called if loadAndSelect() actually did anything, and it won't do anything if the mail is not currently loaded in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, if our list does not contain the mail, then we don't want to change lists, but we also do not want to show a different mail being selected to the one that we are viewing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's say we already have a correct folder loaded and then we click on notification. Let's say the email is already in the list. Wouldn't we loadAndSelect() to select it and then resetOrInitializeList() which will deselect it?

Copy link
Contributor Author

@paw-hub paw-hub Nov 5, 2024

Choose a reason for hiding this comment

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

This shouldn't happen because we check if the return value of loadAndSelect is null immediately after calling it.

const listMail = await this.listModel?.loadAndSelect(mailId, () => true)
if (listMail) {
	console.log(TAG, "opening mail from list", mailId)
	return
}

loadAndSelect is unfortunately undocumented, but the return value is the element, if something was selected, or null if not.

return foundItem ?? null

In this case, if we have the correct folder loaded and this function does select something, we will return that value. As such, we won't deselect since we check this return value and return early if so (after logging to console).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhhh yes sorry!

Fix the sticky mail selection behavior so that if we are on the list, it
will visually show that mail being selected. If not, don't try to go to
that list.

Fixes #7585
@paw-hub paw-hub force-pushed the 7585-notification-select branch from 73e9551 to 5be1b32 Compare November 6, 2024 08:33
@paw-hub paw-hub merged commit 5be1b32 into dev-mail Nov 6, 2024
1 check passed
@paw-hub paw-hub deleted the 7585-notification-select branch November 6, 2024 08:59
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.

Opening a mail from the notification does not highlight mail in list
4 participants