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

Place the new marker when a chat becomes visible #2737

Merged
merged 8 commits into from
May 11, 2021
Merged

Conversation

Gonals
Copy link
Contributor

@Gonals Gonals commented May 7, 2021

@tgolen, @marcaaron, since we were all working on this.

Details

I decided to put the code on onVisibilityChange in ReportActionsView because that way we keep all the "similar" logic in the same file and I think it is really easy to understand and follow what's going on.
BUT, it could totally go here in updateReportWithNewAction too and it works just as well and it is also a logical place for it to be so... 🤷. If anyone has a strong preference, I'm fine with either.

Fixed Issues

https://github.com/Expensify/Expensify/issues/163167

Tests/ QA Steps

In web:

  • Open a chat that does NOT have the New marker in place and move to a different tab.
  • Receive two messages in the chat (wait for the notifications)
  • Go back to the .cash tab. The new marker should be over the oldest of the new messages.
  • Open a chat that DOES have the new marker (or place it marking a comment as unread) and move to a different tab.
  • Receive a message in the chat (wait for the notification)
  • Go back to the .cash tab. The New marker should be in the same place it was before.

In web and all the other platforms:

  • Open a chat that does NOT have the New marker in place and minimize the window/app.
  • Receive two messages in the chat (wait for the notifications)
  • Go back to the .cash tab. The new marker should be over the oldest of the new messages.
  • Open a chat that DOES have the new marker (or place it marking a comment as unread) and minimize the window/app.
  • Receive a message in the chat (wait for the notification)
  • Go back to the .cash tab. The New marker should be in the same place it was before.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Taking screenshots of the marker won't mean much.

@Gonals Gonals requested review from tgolen and marcaaron May 7, 2021 14:31
@Gonals Gonals self-assigned this May 7, 2021
@Gonals Gonals requested a review from a team as a code owner May 7, 2021 14:31
@Gonals Gonals removed the request for review from a team May 7, 2021 14:31
@MelvinBot MelvinBot requested a review from Dal-Papa May 7, 2021 14:31
@Gonals Gonals changed the title Alberto newer marker Place the new marker when a chat becomes visible May 7, 2021
@Gonals Gonals removed the request for review from Dal-Papa May 7, 2021 15:08
Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

I guess my one question is do we need to hook into the visibility event? Doesn't this mean we will only set the new marker when the user becomes active.

I think this works, but I might expect this to work like this:

  1. User is not active
  2. New comments appear
  3. We should reset the new marker because they are not active

That would probably require adding similar logic to the code that handles the new actions here (which I think is the "event" we are reacting to here and maybe not the user becoming active):

https://github.com/Expensify/Expensify.cash/blob/a22e73de0086c2694026d545e15a8862af3990d5/src/pages/home/report/ReportActionsView.js#L155-L182

But maybe I'm missing something about why we would prefer to do it this way.

src/pages/home/report/ReportActionsView.js Outdated Show resolved Hide resolved
@tgolen
Copy link
Contributor

tgolen commented May 7, 2021

Heh, @marcaaron I think that's the same thing I suggested to Alberto when he originally asked me about this.

@Gonals maybe since both Marc and I had that same instinct, it might be a good reason to go with that solution over this one. Do you know how much more complex that solution would be? I do like that this PR is nice and simple, and I don't have too good of a sense over how complex the other solution would be.

@Gonals
Copy link
Contributor Author

Gonals commented May 10, 2021

... All your questions are already answered in the body of the PR!!!

  • Yep, we can totally move this to trigger when the message comes in. It works equally fine and the code is just as simple. I just went with the onVisibility to keep similar logic in the same file, but that was what made me lean towards that solution xD

Moving the code to the other place!

@Gonals
Copy link
Contributor Author

Gonals commented May 10, 2021

All comments addressed!

src/libs/actions/Report.js Outdated Show resolved Hide resolved

// When a new message comes in, if the New marker is not already set (newMarkerSequenceNumber === 0) and, set the
// marker above the incoming message.
if (lodashGet(allReports, reportID).newMarkerSequenceNumber === 0 && updatedReportObject.unreadActionCount > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's very possible that this report does not yet exist. And if lodashGet(allReports, reportID) is undefined then we will try and fail to access newMarkerSequenceNumber.

In the case that it doesn't exist I think we would treat that as the same as having a newMarkerSequenceNumber === 0 so we should do this instead...

Suggested change
if (lodashGet(allReports, reportID).newMarkerSequenceNumber === 0 && updatedReportObject.unreadActionCount > 0) {
if (lodashGet(allReports, [reportID, 'newMarkerSequenceNumber'], 0) === 0 && updatedReportObject.unreadActionCount > 0) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! That makes sense. Good catch!

tgolen
tgolen previously approved these changes May 10, 2021
Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

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

I like it with Marc's suggested change.

@marcaaron marcaaron merged commit 5d5b2fb into main May 11, 2021
@marcaaron marcaaron deleted the alberto-newerMarker branch May 11, 2021 17:37
@OSBotify
Copy link
Contributor

🚀 Deployed to staging in version: 1.0.41-12🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production in version: 1.0.44-0🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

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.

4 participants