-
Notifications
You must be signed in to change notification settings - Fork 547
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
Conversation
f878653
to
75647a0
Compare
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
tutanota/src/mail-app/mail/view/MailViewModel.ts
Lines 159 to 164 in 82f2217
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()) | |
} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
d777f07
to
73e9551
Compare
@@ -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) |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
73e9551
to
5be1b32
Compare
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