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

Refactor code to improve unread marker logic #18637

Merged
merged 56 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
1c98457
Pass client's lastReadTime to server
MonilBhavsar May 7, 2023
5189784
Listen for new messages
MonilBhavsar May 7, 2023
8895b61
Mark comments as read
MonilBhavsar May 7, 2023
7f13144
Add and update logic to set new marker
MonilBhavsar May 8, 2023
87ef4b3
Update more logic and fix active chat case
MonilBhavsar May 8, 2023
3ce360e
Pass correct report actions
MonilBhavsar May 8, 2023
3931f71
if reportActions exist, use onyx local data to render the messages
gedu May 9, 2023
05cc1be
Merge branch 'main' into monil-fixNewMarkerLine
MonilBhavsar May 10, 2023
f39a674
Don't set lastReadTime optimistically
MonilBhavsar May 10, 2023
9a7ef68
handling the unread line on report list
gedu May 10, 2023
e022a7a
using the reportsActions from onyx
gedu May 10, 2023
9132bc2
Merge branch 'main' into monil-fixNewMarkerLine
gedu May 10, 2023
a79ac80
style updated
gedu May 10, 2023
15377c7
Some more updates to logic to fix 2 1:1 and switch cases
MonilBhavsar May 10, 2023
279e1a2
Attempt to fix unread marker logic
MonilBhavsar May 10, 2023
bc15e03
Merge branch 'monil-fixNewMarkerLine' of https://github.com/Expensify…
gedu May 11, 2023
0843bae
Clean up, and handling unread cases
gedu May 15, 2023
e8712d5
Merge branch 'main' into monil-fixNewMarkerLine
MonilBhavsar May 17, 2023
1d899ca
Revert to another approach
MonilBhavsar May 19, 2023
52cf638
Merge branch 'main' into monil-fixNewMarkerLine
MonilBhavsar May 19, 2023
41602a4
Updated marking report as read
gedu May 19, 2023
eea32eb
Merge branch 'monil-fixNewMarkerLine' of github.com:gedu/App into mon…
gedu May 19, 2023
1cf3101
Fix openReport call
MonilBhavsar May 19, 2023
009063d
Add hook to track active chat
MonilBhavsar May 19, 2023
347538c
Donot render marker when active on chat
MonilBhavsar May 22, 2023
9c286f7
Donot render marker line for sender
MonilBhavsar May 22, 2023
685467e
updated to handle marking message as unread
gedu May 22, 2023
1775100
updated FAB button and handle when the user scroll up unread
gedu May 22, 2023
287771e
Pass lastReadTime to server when marking message as read
MonilBhavsar May 22, 2023
cc49a2d
Merge branch 'monil-fixNewMarkerLine' of github.com:gedu/App into mon…
MonilBhavsar May 22, 2023
04ab84f
Marking read message after skipped by scroll
gedu May 22, 2023
f5cfa42
Merge branch 'monil-fixNewMarkerLine' of github.com:gedu/App into mon…
gedu May 22, 2023
0bb23c5
small clean up
gedu May 22, 2023
fc555c4
Merge branch 'main' into monil-geduFixNewMarkerLine
MonilBhavsar May 31, 2023
a5aebac
Merge branch 'main' into monil-fixNewMarkerLine
gedu Jun 22, 2023
eff076f
Merge branch 'main' into monil-fixNewMarkerLine
gedu Jun 30, 2023
7afcf3c
clean up
gedu Jun 30, 2023
b9da5e2
Merge branch 'main' into monil-fixNewMarkerLine
gedu Jul 31, 2023
4cb33db
Return early if user is inactive on chat
MonilBhavsar Aug 1, 2023
668209e
Remove unecessary code
MonilBhavsar Aug 1, 2023
cbb485a
Don't set floating button if marker is null
MonilBhavsar Aug 1, 2023
1026e4e
Fixed tests
gedu Aug 1, 2023
0a5b0d6
Use accountID and pass correct param
MonilBhavsar Aug 2, 2023
78ec995
Merge branch 'monil-fixNewMarkerLine' of github.com:gedu/App into mon…
MonilBhavsar Aug 2, 2023
619d754
cleaning the userActiveSince value
gedu Aug 3, 2023
6e248ab
fixed comments
gedu Aug 4, 2023
36c762b
Merge branch 'main' into monil-fixNewMarkerLine
gedu Aug 4, 2023
d6ebe9e
removed unused var
gedu Aug 4, 2023
c86812a
fixed comments
gedu Aug 8, 2023
f16ed18
clean ups
gedu Aug 8, 2023
9c84668
Merge branch 'main' into monil-fixNewMarkerLine
gedu Aug 10, 2023
827612c
fixed marking unread twice in a row
gedu Aug 10, 2023
a2da574
Merge branch 'main' into monil-fixNewMarkerLine
gedu Aug 11, 2023
7388fbf
removed console logs
gedu Aug 11, 2023
f6bd06a
Merge branch 'main' into monil-geduFixNewMarkerLine
MonilBhavsar Aug 15, 2023
5d3edd4
Cleanup
MonilBhavsar Aug 15, 2023
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
39 changes: 33 additions & 6 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ Onyx.connect({
},
});

const currentReportData = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
callback: (data, key) => {
if (!key || !data) {
return;
}
const reportID = CollectionUtils.extractCollectionItemID(key);
currentReportData[reportID] = data;
},
});

let isNetworkOffline = false;
Onyx.connect({
key: ONYXKEYS.NETWORK,
Expand Down Expand Up @@ -373,6 +385,10 @@ function addComment(reportID, text) {
addActions(reportID, text);
}

function reportActionsExist(reportID) {
return allReportActions[reportID] !== undefined;
}

/**
* Gets the latest page of report actions and updates the last read message
* If a chat with the passed reportID is not found, we will create a chat based on the passed participantList
Expand All @@ -388,11 +404,13 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p
const optimisticReportData = {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
isLoadingReportActions: true,
isLoadingMoreReportActions: false,
lastReadTime: DateUtils.getDBTime(),
},
value: reportActionsExist(reportID)
? {}
: {
isLoadingReportActions: true,
isLoadingMoreReportActions: false,
reportName: lodashGet(allReports, [reportID, 'reportName'], CONST.REPORT.DEFAULT_REPORT_NAME),
},
};
const reportSuccessData = {
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -515,6 +533,8 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p
}
}

params.clientLastReadTime = lodashGet(currentReportData, [reportID, 'lastReadTime'], '');

if (isFromDeepLink) {
// eslint-disable-next-line rulesdir/no-api-side-effects-method
API.makeRequestWithSideEffects('OpenReport', params, onyxData).finally(() => {
Expand Down Expand Up @@ -715,18 +735,20 @@ function expandURLPreview(reportID, reportActionID) {
* @param {String} reportID
*/
function readNewestAction(reportID) {
const lastReadTime = DateUtils.getDBTime();
API.write(
'ReadNewestAction',
{
reportID,
lastReadTime,
},
{
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
lastReadTime: DateUtils.getDBTime(),
lastReadTime,
},
},
],
Expand Down Expand Up @@ -1729,6 +1751,10 @@ function openReportFromDeepLink(url, isAuthenticated) {
});
}

function getCurrentUserAccountID() {
return currentUserAccountID;
}

/**
* Leave a report by setting the state to submitted and closed
*
Expand Down Expand Up @@ -1928,6 +1954,7 @@ export {
hasAccountIDEmojiReacted,
shouldShowReportActionNotification,
leaveRoom,
getCurrentUserAccountID,
setLastOpenedPublicRoom,
flagComment,
openLastOpenedPublicRoom,
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ class ReportScreen extends React.Component {
if (this.props.report.reportID && this.props.report.reportID === getReportID(this.props.route)) {
return;
}

Report.openReport(reportIDFromPath);
}

Expand Down
Loading
Loading