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

Jumping to an unread message did not keep scroll location #534

Merged
merged 4 commits into from
Jul 4, 2024

Conversation

laevandus
Copy link
Contributor

@laevandus laevandus commented Jul 2, 2024

🔗 Issue Link

Resolves PBE-5003

🎯 Goal

Fix an issue where scroll location was not kept after jumping to a message

🛠 Implementation

  • Set the scroll location to the unread message when the message list has changed (unread message lookup only works on the loaded message list)

Note: In general, the ChatChannelViewModel would benefit from the state layer API a lot since then we would not have cases where we call load more messages, wait for completion handler AND then also need to wait when the delegate callback comes (delay comes from database observer).

🧪 Testing

Chewbacca has some test channels useful here.

Verification checks

  1. Is scroll to last button shown or hidden correctly?
  2. Is the scrolled message visible after jumping to it?
  3. Unread messages should be marked as read when reaching the most recent message after jumping to the first unread message.

Case 1: Jumping to unread message

  1. Scroll up in a channel and press and hold on a message
  2. Mark the message as unread
  3. Go to channel list
  4. Go back to the channel
  5. Tap on the x unread messages button > we should jump to the first unread message

Case 2: Jumping to some other message

  1. Scroll to an old message, quote it
  2. Open the channel again and tap on the quoted message > we jump to that message

🎨 Changes

I marked the message "A" as unread.

Before After
img img

☑️ Checklist

  • I have signed the Stream CLA (required)
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Affected documentation updated (docusaurus, tutorial, CMS (task created)

@laevandus laevandus requested a review from a team as a code owner July 2, 2024 08:04
@@ -230,8 +230,8 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
} else if diff < 0 && scrollDirection == .down {
scrollDirection = .up
}
utils.messageCachingUtils.scrollOffset = offsetValue
Copy link
Contributor Author

@laevandus laevandus Jul 2, 2024

Choose a reason for hiding this comment

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

Here we had an issue where if you scroll extra slowly, the scroll direction argument in the view model is incorrect. Makes the check for load more older/newer messages incorrect in the view model.

Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

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

there's still one issue here - when you mark unread an older message (e.g. unread count > 30), and you come back, sometimes it marks the chat as read.

@laevandus laevandus marked this pull request as draft July 2, 2024 10:13
@laevandus laevandus force-pushed the fix/jump-to-unread branch 2 times, most recently from dbb9afa to e8bfae0 Compare July 2, 2024 12:15
@laevandus laevandus marked this pull request as ready for review July 3, 2024 07:08
@laevandus laevandus force-pushed the fix/jump-to-unread branch from 543a51b to ebe8904 Compare July 3, 2024 11:11
Copy link

sonarqubecloud bot commented Jul 3, 2024

Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

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

Works well now ✅

@laevandus laevandus merged commit 68fb16a into develop Jul 4, 2024
10 checks passed
@laevandus laevandus deleted the fix/jump-to-unread branch July 4, 2024 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ✅ QAed swiftui-repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants