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

Fix: Update the read marker position even if it is not displayed #7461

Merged
merged 5 commits into from
Apr 3, 2023

Conversation

nimau
Copy link
Contributor

@nimau nimau commented Mar 29, 2023

This PR fixes #7420

The current implementation only updates the read marker if we are able to display the read marker view and we have identified some cases where the read marker is not updated because its view cannot be displayed:

  • when it is placed on a reaction (or potentially any event that relates to another one)
  • when it is placed on a redaction
  • when it is placed on an event displayed in a collapsed cell (e.g. a room member update)

Also, relatesTo events can be problematic as they can cause the user to jump backwards in the timeline, even if the current read marker timestamp is more recent than the related event.

To fix these issues:

  • When checking the visibility of the "jump to unread" banner, we now ask for the read marker to be updated when we are supposed to render it.
  • Also, the read marker update was linked to the read receipt update. To prevent setting the read marker on an incorrect event (such as reaction, redaction ...), the read marker update is now performed separately from the read receipt.

Pull Request Checklist

  • I read the contributing guide
  • UI change has been tested on both light and dark themes, in portrait and landscape orientations and on iPhone and iPad simulators
  • Accessibility has been taken into account.
  • Pull request is based on the develop branch
  • Pull request contains a changelog file in ./changelog.d
  • You've made a self review of your PR
  • Pull request includes screenshots or videos of UI changes
  • Pull request includes a sign off

@codecov
Copy link

codecov bot commented Mar 29, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01 ⚠️

Comparison is base (45668e6) 12.30% compared to head (f63efbe) 12.29%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7461      +/-   ##
===========================================
- Coverage    12.30%   12.29%   -0.01%     
===========================================
  Files         1645     1645              
  Lines       163052   163135      +83     
  Branches     66936    66982      +46     
===========================================
+ Hits         20059    20064       +5     
- Misses      142344   142421      +77     
- Partials       649      650       +1     
Flag Coverage Δ
uitests 55.24% <ø> (+<0.01%) ⬆️
unittests 6.19% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
Riot/Modules/Room/MXKRoomViewController.m 0.00% <0.00%> (ø)
Riot/Modules/Room/RoomViewController.m 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Riot/Modules/Room/MXKRoomViewController.m Outdated Show resolved Hide resolved
Riot/Modules/Room/MXKRoomViewController.m Outdated Show resolved Hide resolved
Riot/Modules/Room/MXKRoomViewController.m Outdated Show resolved Hide resolved
Riot/Modules/Room/RoomViewController.m Outdated Show resolved Hide resolved
@nimau
Copy link
Contributor Author

nimau commented Mar 29, 2023

@giomfo I've updated this PR to reflect your comments.

Riot/Modules/Room/MXKRoomViewController.m Outdated Show resolved Hide resolved
Riot/Modules/Room/MXKRoomViewController.m Outdated Show resolved Hide resolved
Copy link
Member

@giomfo giomfo left a comment

Choose a reason for hiding this comment

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

SGTM, let go for an actual Review by leaving the Draft status

@@ -7946,6 +7955,9 @@ -(void)reloadRoomWihtEventId:(NSString *)eventId

// Give the data source ownership to the room view controller.
self.hasRoomDataSourceOwnership = YES;

// Force the read marker update if needed (this
Copy link
Member

Choose a reason for hiding this comment

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

the comment seems truncated

@nimau nimau marked this pull request as ready for review March 30, 2023 08:43
@nimau nimau requested review from a team and stefanceriu and removed request for a team March 30, 2023 08:43
Copy link
Member

@stefanceriu stefanceriu left a comment

Choose a reason for hiding this comment

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

Looks good to me but of course statically checking it is prone to errors. I would be great if any of this would be testable..

contentBottomOffsetY = _bubblesTableView.contentSize.height;
}
// Be a bit less retrictive, consider visible an event at the bottom even if is partially hidden.
contentBottomOffsetY += 8;
Copy link
Member

Choose a reason for hiding this comment

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

This 8 is a bit magical, maybe you should move it to a constant at the top of the file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I moved this value to a new constant: kCellVisibilityMinimumHeight

- (void)updateReadMarkerEvent
{
// Compute the content offset corresponding to the line displayed at the table bottom (just above the toolbar).
CGFloat contentBottomOffsetY = _bubblesTableView.contentOffset.y + (_bubblesTableView.frame.size.height - _bubblesTableView.adjustedContentInset.bottom);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need any special handling for when the keyboard is displayed or better yet do we need to tweak the ContentInsetAdjustmentBehavior?

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’m not sure. I used the same mechanism as the one used to find the event to acknowledge because the read marker was updated in the same process as the acknowledgement.

cell = visibleCells[index];

// Check whether the cell is actually visible
if (cell && (cell.frame.origin.y < contentBottomOffsetY))
Copy link
Member

Choose a reason for hiding this comment

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

This code would be a lot cleaner with early bail outs e.g.:

if (!cell || cell.frame.origin.y > contentBottomOffsetY) {
    continue
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. It's done.

while (componentIndex --)
{
component = bubbleComponents[componentIndex];
if (![cell isKindOfClass:MXKRoomBubbleTableViewCell.class])
Copy link
Member

Choose a reason for hiding this comment

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

Can we combine this check with the previous isKindOfClass:MXKTableViewCell.class and maybe use the casted version from then on? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, it should be much easier to understand now.

Riot/Modules/Room/RoomViewController.m Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Mar 31, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@nimau nimau requested a review from stefanceriu April 3, 2023 11:56
Copy link
Member

@stefanceriu stefanceriu left a comment

Choose a reason for hiding this comment

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

👍

@nimau nimau merged commit eeb0abe into develop Apr 3, 2023
@nimau nimau deleted the nimau/7420-readmarker branch April 3, 2023 12:34
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.

The read marker is stuck when it is placed on a reaction
3 participants