From 0c7c71d46fecc8cde46f009d8ccb472316786ef8 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 3 Jun 2024 12:19:55 +0700 Subject: [PATCH 1/6] fix chat doesn't scroll to bottom --- src/libs/actions/IOU.ts | 7 ++++++- src/libs/actions/Report.ts | 2 +- src/pages/home/report/ReportActionsList.tsx | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 128ee5b85b7b..2702dd4b7b0c 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1983,12 +1983,17 @@ function getMoneyRequestInformation( reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, false, comment, optimisticTransaction); } else { reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction); + chatReport.lastVisibleActionCreated = reportPreviewAction.created; // Generated ReportPreview action is a parent report action of the iou report. // We are setting the iou report's parentReportActionID to display subtitle correctly in IOU page when offline. iouReport.parentReportActionID = reportPreviewAction.reportActionID; } + if (iouAction) { + iouReport.lastVisibleActionCreated = iouAction.created; + } + const shouldCreateOptimisticPersonalDetails = isNewChatReport && !allPersonalDetails[payerAccountID]; // Add optimistic personal details for participant const optimisticPersonalDetailListAction = shouldCreateOptimisticPersonalDetails @@ -4625,7 +4630,7 @@ function startSplitBill({ API.write(WRITE_COMMANDS.START_SPLIT_BILL, parameters, {optimisticData, successData, failureData}); Navigation.dismissModalWithReport(splitChatReport); - Report.notifyNewAction(splitChatReport.chatReportID ?? '', currentUserAccountID); + Report.notifyNewAction(splitChatReport.reportID ?? '', currentUserAccountID); } /** Used for editing a split expense while it's still scanning or when SmartScan fails, it completes a split expense started by startSplitBill above. diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 7c73ef4a1eac..1dd67332cb99 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -478,7 +478,7 @@ function addActions(reportID: string, text = '', file?: FileObject) { const lastCommentText = ReportUtils.formatReportLastMessageText(lastComment?.text ?? ''); const optimisticReport: Partial = { - lastVisibleActionCreated: currentTime, + lastVisibleActionCreated: lastAction?.created, lastMessageTranslationKey: lastComment?.translationKey ?? '', lastMessageText: lastCommentText, lastMessageHtml: lastCommentText, diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index c700fea4fb85..6ad01455b543 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -211,15 +211,17 @@ function ReportActionsList({ ); // whisper action doesn't affect lastVisibleActionCreated, so we should not take it into account while checking if there is the newest report action - const newestVisibleReportAction = useMemo(() => sortedVisibleReportActions.find((item) => !ReportActionsUtils.isWhisperAction(item)) ?? null, [sortedVisibleReportActions]); + // const newestVisibleReportAction = useMemo(() => sortedVisibleReportActions.find((item) => !ReportActionsUtils.isWhisperAction(item)) ?? null, [sortedVisibleReportActions]); const lastActionIndex = sortedVisibleReportActions[0]?.reportActionID; const reportActionSize = useRef(sortedVisibleReportActions.length); - const hasNewestReportAction = newestVisibleReportAction?.created === report.lastVisibleActionCreated; + const hasNewestReportAction = sortedVisibleReportActions[0]?.created === report.lastVisibleActionCreated; const hasNewestReportActionRef = useRef(hasNewestReportAction); hasNewestReportActionRef.current = hasNewestReportAction; const previousLastIndex = useRef(lastActionIndex); + console.log(sortedVisibleReportActions[0].created, report.lastVisibleActionCreated) + const isLastPendingActionIsDelete = sortedReportActions?.[0]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; const linkedReportActionID = route.params?.reportActionID ?? ''; @@ -346,6 +348,7 @@ function ReportActionsList({ (isFromCurrentUser: boolean) => { // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where // they are now in the list. + console.log(hasNewestReportActionRef.current); if (!isFromCurrentUser || !hasNewestReportActionRef.current) { return; } From d4e7d5d6f98614885aefade9cb335791934512c5 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 4 Jun 2024 13:10:09 +0700 Subject: [PATCH 2/6] fix lint --- src/pages/home/report/ReportActionsList.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 6ad01455b543..940feb99bc27 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -210,9 +210,6 @@ function ReportActionsList({ [sortedReportActions, isOffline], ); - // whisper action doesn't affect lastVisibleActionCreated, so we should not take it into account while checking if there is the newest report action - // const newestVisibleReportAction = useMemo(() => sortedVisibleReportActions.find((item) => !ReportActionsUtils.isWhisperAction(item)) ?? null, [sortedVisibleReportActions]); - const lastActionIndex = sortedVisibleReportActions[0]?.reportActionID; const reportActionSize = useRef(sortedVisibleReportActions.length); const hasNewestReportAction = sortedVisibleReportActions[0]?.created === report.lastVisibleActionCreated; @@ -220,8 +217,6 @@ function ReportActionsList({ hasNewestReportActionRef.current = hasNewestReportAction; const previousLastIndex = useRef(lastActionIndex); - console.log(sortedVisibleReportActions[0].created, report.lastVisibleActionCreated) - const isLastPendingActionIsDelete = sortedReportActions?.[0]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; const linkedReportActionID = route.params?.reportActionID ?? ''; @@ -348,7 +343,6 @@ function ReportActionsList({ (isFromCurrentUser: boolean) => { // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where // they are now in the list. - console.log(hasNewestReportActionRef.current); if (!isFromCurrentUser || !hasNewestReportActionRef.current) { return; } From 9a3491b6a4b4ec74f5b728162f17b34f0ea6be42 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 5 Jun 2024 15:09:40 +0700 Subject: [PATCH 3/6] move update to buildOnyxDataForMoneyRequest --- src/libs/actions/IOU.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 1050fdb48779..fe3a5a8425dd 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -507,6 +507,7 @@ function buildOnyxDataForMoneyRequest( ...iouReport, lastMessageText: iouAction.message?.[0]?.text, lastMessageHtml: iouAction.message?.[0]?.html, + lastVisibleActionCreated: iouAction.created, pendingFields: { ...(shouldCreateNewMoneyRequestReport ? {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : {preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}), }, @@ -1991,10 +1992,6 @@ function getMoneyRequestInformation( iouReport.parentReportActionID = reportPreviewAction.reportActionID; } - if (iouAction) { - iouReport.lastVisibleActionCreated = iouAction.created; - } - const shouldCreateOptimisticPersonalDetails = isNewChatReport && !allPersonalDetails[payerAccountID]; // Add optimistic personal details for participant const optimisticPersonalDetailListAction = shouldCreateOptimisticPersonalDetails From 7fcaeca565775b670ff86fbee4ab902fe1ef7480 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 5 Jun 2024 21:59:29 +0700 Subject: [PATCH 4/6] merge main --- src/libs/DateUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/DateUtils.ts b/src/libs/DateUtils.ts index 50cb9a20dff6..032a8261bec9 100644 --- a/src/libs/DateUtils.ts +++ b/src/libs/DateUtils.ts @@ -380,7 +380,8 @@ function getDBTime(timestamp: string | number = ''): string { */ function getDBTimeWithSkew(timestamp: string | number = ''): string { if (networkTimeSkew > 0) { - return getDBTime(new Date(timestamp).valueOf() + networkTimeSkew); + const datetime = timestamp ? new Date(timestamp) : new Date(); + return getDBTime(datetime.valueOf() + networkTimeSkew); } return getDBTime(timestamp); } From 5a8f69ae5af682c807016cd51f3ac4bed82d7d4e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 6 Jun 2024 11:50:00 +0700 Subject: [PATCH 5/6] fix lastVisibleActionCreated of task and split case --- ios/Podfile.lock | 2 +- src/libs/actions/IOU.ts | 1 + src/libs/actions/Task.ts | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index de363c211cb3..eee5c82f82ae 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2606,7 +2606,7 @@ SPEC CHECKSUMS: SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Turf: 13d1a92d969ca0311bbc26e8356cca178ce95da2 VisionCamera: 1394a316c7add37e619c48d7aa40b38b954bf055 - Yoga: 64cd2a583ead952b0315d5135bf39e053ae9be70 + Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312 PODFILE CHECKSUM: 66a5c97ae1059e4da1993a4ad95abe5d819f555b diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 49c8cfe666a6..066ee1cd0c61 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3835,6 +3835,7 @@ function createSplitsAndOnyxData( splitChatReport.lastMessageText = splitIOUReportAction.message?.[0]?.text; splitChatReport.lastMessageHtml = splitIOUReportAction.message?.[0]?.html; splitChatReport.lastActorAccountID = currentUserAccountID; + splitChatReport.lastVisibleActionCreated = splitIOUReportAction.created; let splitChatReportNotificationPreference = splitChatReport.notificationPreference; if (splitChatReportNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 55d898d3d4f3..57b551510d58 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -131,10 +131,10 @@ function createTaskAndNavigate( const optimisticAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(taskReportID, title, assigneeAccountID, `task for ${title}`, parentReportID); optimisticTaskReport.parentReportActionID = optimisticAddCommentReport.reportAction.reportActionID; - const currentTime = DateUtils.getDBTime(); + const currentTime = DateUtils.getDBTimeWithSkew(); const lastCommentText = ReportUtils.formatReportLastMessageText(optimisticAddCommentReport?.reportAction?.message?.[0]?.text ?? ''); const optimisticParentReport = { - lastVisibleActionCreated: currentTime, + lastVisibleActionCreated: optimisticAddCommentReport.reportAction.created, lastMessageText: lastCommentText, lastActorAccountID: currentUserAccountID, lastReadTime: currentTime, From 9a8a96b2de2cd69c68abaade4f7cf0a16ca4f697 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 7 Jun 2024 13:07:28 +0700 Subject: [PATCH 6/6] revert unrelated change --- ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index eee5c82f82ae..de363c211cb3 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2606,7 +2606,7 @@ SPEC CHECKSUMS: SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Turf: 13d1a92d969ca0311bbc26e8356cca178ce95da2 VisionCamera: 1394a316c7add37e619c48d7aa40b38b954bf055 - Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312 + Yoga: 64cd2a583ead952b0315d5135bf39e053ae9be70 PODFILE CHECKSUM: 66a5c97ae1059e4da1993a4ad95abe5d819f555b