Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,11 +1267,6 @@ function updateLastReadActionID(reportID, sequenceNumber) {
// (sequenceNumber - 1) || reportMaxSequenceNumbers[reportID] because the first expression results in 0 which is falsy.
const lastReadSequenceNumber = _.isNumber(sequenceNumber) ? (sequenceNumber - 1) : reportMaxSequenceNumbers[reportID];

// We call this method in many cases where there's nothing to update because we already updated it, so we avoid
// doing an unnecessary server call if the last read is the same one we had already
if (lastReadSequenceNumbers[reportID] === lastReadSequenceNumber) {
return;
}
setLocalLastRead(reportID, lastReadSequenceNumber);

// Mark the report as not having any unread items
Expand Down
13 changes: 5 additions & 8 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ReportActionsView extends React.Component {

this.renderItem = this.renderItem.bind(this);
this.renderCell = this.renderCell.bind(this);
this.scrollToListBottom = this.scrollToListBottom.bind(this);
this.scrollToBottomAndUpdateLastRead = this.scrollToBottomAndUpdateLastRead.bind(this);
this.onVisibilityChange = this.onVisibilityChange.bind(this);
this.recordTimeToMeasureItemLayout = this.recordTimeToMeasureItemLayout.bind(this);
this.loadMoreChats = this.loadMoreChats.bind(this);
Expand Down Expand Up @@ -140,8 +140,7 @@ class ReportActionsView extends React.Component {
if (!ReportActionComposeFocusManager.isFocused()) {
return;
}

this.scrollToListBottom();
ReportScrollManager.scrollToBottom();
Comment on lines -144 to +143

@parasharrajat parasharrajat Jan 4, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just noticed, Why aren't we calling scrollToBottomAndUpdateLastRead here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is explained in the issue description:

Remove updateLastReadActionID on keyboardDidShow ( not instructed. I have tested it on android: updateLastReadActionID is being called each time user open keyboard. if user open a room and he is on a room, updateLastReadActionID is called automatically, whether he is viewing old message (scroll at the top) or not. So, when scroll at the top and user open keyboard updateLastReadActionID is unnecessary. )

I think the assumption is that we are already updating the last read when the report opens and so it is unnecessary to do it again when the keyboard opens. Feels fine to me but maybe there's some reason why we are setting it when the keyboard opens? I would guess the original intention is to just scroll to the bottom. But the excess calls to the API are because those two behaviors were stuck together before.

@parasharrajat parasharrajat Jan 4, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't remember why it was added so it seems fine. But let's add proper tests so that QA can test the unread/read behavior properly.

All scenarios should be tested when messages are marked read.

  1. When we switch between reports.
  2. When we resize the window on Desktop from mobile to Web.
  3. etc...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CC @K4tsuki See ⬆️

});

this.updateUnreadIndicatorPosition(this.props.report.unreadActionCount);
Expand Down Expand Up @@ -211,7 +210,7 @@ class ReportActionsView extends React.Component {
// leave the user positioned where they are now in the list.
const lastAction = CollectionUtils.lastItem(this.props.reportActions);
if (lastAction && (lastAction.actorEmail === this.props.session.email)) {
this.scrollToListBottom();
ReportScrollManager.scrollToBottom();
}

if (lodashGet(lastAction, 'actorEmail', '') !== lodashGet(this.props.session, 'email', '')) {
Expand Down Expand Up @@ -311,7 +310,6 @@ class ReportActionsView extends React.Component {
return Math.ceil(availableHeight / minimumReportActionHeight);
}


/**
* Updates and sorts the report actions by sequence number
*
Expand Down Expand Up @@ -380,7 +378,7 @@ class ReportActionsView extends React.Component {
* items have been rendered. If the number of actions has changed since it was last rendered, then
* scroll the list to the end. As a report can contain non-message actions, we should confirm that list data exists.
*/
scrollToListBottom() {
scrollToBottomAndUpdateLastRead() {
ReportScrollManager.scrollToBottom();
Report.updateLastReadActionID(this.props.reportID);
}
Expand All @@ -397,7 +395,6 @@ class ReportActionsView extends React.Component {
Report.setNewMarkerPosition(this.props.reportID, oldestUnreadSequenceNumber);
}


/**
* Show/hide the new MarkerBadge when user is scrolling back/forth in the history of messages.
*/
Expand Down Expand Up @@ -557,7 +554,7 @@ class ReportActionsView extends React.Component {
<MarkerBadge
active={this.state.isMarkerActive}
count={this.state.localUnreadActionCount}
onClick={this.scrollToListBottom}
onClick={this.scrollToBottomAndUpdateLastRead}
onClose={this.hideMarker}
/>
<InvertedFlatList
Expand Down