diff --git a/Mobile-Expensify b/Mobile-Expensify index cf896cf6e953..418087e041bf 160000 --- a/Mobile-Expensify +++ b/Mobile-Expensify @@ -1 +1 @@ -Subproject commit cf896cf6e953bcd76db68b652680e5c0409cada6 +Subproject commit 418087e041bf32662a3407f8e4b7cc1952ba68ba diff --git a/android/app/build.gradle b/android/app/build.gradle index 632a6705074e..ca7a79e3d3ea 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -111,8 +111,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled rootProject.ext.multiDexEnabled - versionCode 1009035109 - versionName "9.3.51-9" + versionCode 1009035110 + versionName "9.3.51-10" // Supported language variants must be declared here to avoid from being removed during the compilation. // This also helps us to not include unnecessary language variants in the APK. resConfigs "en", "es" diff --git a/ios/NewExpensify/Info.plist b/ios/NewExpensify/Info.plist index 5ba22b20c270..ba114d7b843e 100644 --- a/ios/NewExpensify/Info.plist +++ b/ios/NewExpensify/Info.plist @@ -44,7 +44,7 @@ CFBundleVersion - 9.3.51.9 + 9.3.51.10 FullStory OrgId diff --git a/ios/NotificationServiceExtension/Info.plist b/ios/NotificationServiceExtension/Info.plist index e999c3c7ad89..de09818309f3 100644 --- a/ios/NotificationServiceExtension/Info.plist +++ b/ios/NotificationServiceExtension/Info.plist @@ -13,7 +13,7 @@ CFBundleShortVersionString 9.3.51 CFBundleVersion - 9.3.51.9 + 9.3.51.10 NSExtension NSExtensionPointIdentifier diff --git a/ios/ShareViewController/Info.plist b/ios/ShareViewController/Info.plist index 8d4f71113043..b0f55a182ee1 100644 --- a/ios/ShareViewController/Info.plist +++ b/ios/ShareViewController/Info.plist @@ -13,7 +13,7 @@ CFBundleShortVersionString 9.3.51 CFBundleVersion - 9.3.51.9 + 9.3.51.10 NSExtension NSExtensionAttributes diff --git a/package-lock.json b/package-lock.json index c00f7d023e06..d4e993b48d17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "new.expensify", - "version": "9.3.51-9", + "version": "9.3.51-10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "new.expensify", - "version": "9.3.51-9", + "version": "9.3.51-10", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index f4d810621725..14ee58604d82 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "new.expensify", - "version": "9.3.51-9", + "version": "9.3.51-10", "author": "Expensify, Inc.", "homepage": "https://new.expensify.com", "description": "New Expensify is the next generation of Expensify: a reimagination of payments based atop a foundation of chat.", diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index 18d0657f32ee..2285de6b66fd 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHNData.tsx @@ -117,7 +117,6 @@ function OptionRowLHNData({ const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); const {login} = useCurrentUserPersonalDetails(); const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${fullReport?.policyID}`); - const [fullReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${fullReport?.reportID}`); const card = useGetExpensifyCardFromReportAction({reportAction: lastAction, policyID: fullReport?.policyID}); @@ -156,7 +155,6 @@ function OptionRowLHNData({ reportAttributesDerived, policyTags, currentUserLogin: login ?? '', - reportActions: fullReportActions, }); // For single-sender IOUs, trim to the sender's avatar to match the header. diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx index e31fb88e4267..2c8eb1344fd8 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx @@ -477,7 +477,7 @@ function MoneyRequestReportActionsList({ return; } - if (isUnread(report, transactionThreadReport, isReportArchived, reportActionsObject) || (lastAction && isCurrentActionUnread(report, lastAction, visibleReportActions))) { + if (isUnread(report, transactionThreadReport, isReportArchived) || (lastAction && isCurrentActionUnread(report, lastAction, visibleReportActions))) { // On desktop, when the notification center is displayed, isVisible will return false. // Currently, there's no programmatic way to dismiss the notification center panel. // To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification. diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 47ecd6259245..960d877b1a77 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -2303,8 +2303,6 @@ function prepareReportOptionsForDisplay( const report = option.item; const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`]; - // eslint-disable-next-line @typescript-eslint/no-deprecated - const reportActions = deprecatedAllReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]; /** * By default, generated options does not have the chat preview line enabled. * If showChatPreviewLine or forcePolicyNamePreview are true, let's generate and overwrite the alternate text. @@ -2332,7 +2330,7 @@ function prepareReportOptionsForDisplay( : undefined; const oneTransactionThreadReport = oneTransactionThreadReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionThreadReportID}`] : undefined; - isOptionUnread = isUnread(report, oneTransactionThreadReport, !!option.private_isArchived, reportActions) && !!report.lastActorAccountID; + isOptionUnread = isUnread(report, oneTransactionThreadReport, !!option.private_isArchived) && !!report.lastActorAccountID; } let lastIOUCreationDate; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ebd12ac5c7a5..eb17b0ec2cd8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9093,32 +9093,8 @@ function generateIsEmptyReport(report: OnyxEntry, isReportArchived: bool return !lastVisibleMessage.lastMessageText; } -/** - * Get the latest report action from other users - * @param reportActions - The report actions - * @param accountID - The current user account ID (to exclude own actions) - * @returns The latest report action from other users - */ -function getLatestReportActionFromOtherUsers(reportActions: ReportActions | undefined, accountID: number | undefined): ReportAction | null { - if (!accountID) { - return null; - } - - return Object.values(reportActions ?? {}).reduce((latest: ReportAction | null, current: ReportAction) => { - if ( - !isDeletedAction(current) && - current.actorAccountID !== accountID && - (!latest || current.created > latest.created) && - (!isWhisperAction(current) || current.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER) - ) { - return current; - } - return latest; - }, null); -} - // We need oneTransactionThreadReport to get the correct last visible action created -function isUnread(report: OnyxEntry, oneTransactionThreadReport: OnyxEntry, isReportArchived: boolean | undefined, reportActions: ReportActions | undefined): boolean { +function isUnread(report: OnyxEntry, oneTransactionThreadReport: OnyxEntry, isReportArchived: boolean | undefined): boolean { if (!report) { return false; } @@ -9130,16 +9106,13 @@ function isUnread(report: OnyxEntry, oneTransactionThreadReport: OnyxEnt if (!report.lastReadTime) { return true; } - - const latestReportActionFromOtherUsers = getLatestReportActionFromOtherUsers(reportActions, deprecatedCurrentUserAccountID); - // lastVisibleActionCreated and lastReadTime are both datetime strings and can be compared directly const lastVisibleActionCreated = getReportLastVisibleActionCreated(report, oneTransactionThreadReport); const lastReadTime = report.lastReadTime ?? ''; const lastMentionedTime = report.lastMentionedTime ?? ''; // If the user was mentioned and the comment got deleted the lastMentionedTime will be more recent than the lastVisibleActionCreated - return lastReadTime < (lastVisibleActionCreated ?? '') || lastReadTime < lastMentionedTime || lastReadTime < (latestReportActionFromOtherUsers?.created ?? ''); + return lastReadTime < (lastVisibleActionCreated ?? '') || lastReadTime < lastMentionedTime; } function isIOUOwnedByCurrentUser(report: OnyxEntry, allReportsDict?: OnyxCollection): boolean { @@ -9727,8 +9700,7 @@ function reasonForReportToBeInOptionList({ if (isInFocusMode) { const oneTransactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, currentReportActions); const oneTransactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionThreadReportID}`]; - const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.reportID}`]; - return isUnread(report, oneTransactionThreadReport, isReportArchived, reportActions) && getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE + return isUnread(report, oneTransactionThreadReport, isReportArchived) && getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE ? CONST.REPORT_IN_LHN_REASONS.IS_UNREAD : null; } @@ -13876,7 +13848,6 @@ export { getBillableAndTaxTotal, getReportForHeader, isReportOpenOrUnsubmitted, - getLatestReportActionFromOtherUsers, getIconsForExpenseReport, getTransactionSortValue, isSortableColumnName, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 8efe533ea374..8b99c565a8df 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -696,7 +696,6 @@ function getOptionData({ reportAttributesDerived, policyTags, currentUserLogin, - reportActions, }: { report: OnyxEntry; oneTransactionThreadReport: OnyxEntry; @@ -721,7 +720,6 @@ function getOptionData({ reportAttributesDerived?: ReportAttributesDerivedValue['reports']; policyTags?: OnyxEntry; currentUserLogin: string; - reportActions?: ReportActions; }): OptionData | undefined { // When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for // this method to be called after the Onyx data has been cleared out. In that case, it's fine to do @@ -802,7 +800,7 @@ function getOptionData({ result.statusNum = report.statusNum; // When the only message of a report is deleted lastVisibleActionCreated is not reset leading to wrongly // setting it Unread so we add additional condition here to avoid empty chat LHN from being bold. - result.isUnread = isUnread(report, oneTransactionThreadReport, isReportArchived, reportActions) && !!report.lastActorAccountID; + result.isUnread = isUnread(report, oneTransactionThreadReport, isReportArchived) && !!report.lastActorAccountID; result.isUnreadWithMention = isUnreadWithMention(report); result.isPinned = report.isPinned; result.iouReportID = report.iouReportID; diff --git a/src/libs/UnreadIndicatorUpdater/index.ts b/src/libs/UnreadIndicatorUpdater/index.ts index 83b7f60892b9..272620e70b58 100644 --- a/src/libs/UnreadIndicatorUpdater/index.ts +++ b/src/libs/UnreadIndicatorUpdater/index.ts @@ -49,10 +49,9 @@ function getUnreadReportsForUnreadIndicator(reports: OnyxCollection, cur const oneTransactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.reportID}`]); const oneTransactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionThreadReportID}`]; const nameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; - const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.reportID}`]; const isReportArchived = ReportUtils.isArchivedReport(nameValuePairs); return ( - ReportUtils.isUnread(report, oneTransactionThreadReport, isReportArchived, reportActions) && + ReportUtils.isUnread(report, oneTransactionThreadReport, isReportArchived) && ReportUtils.shouldReportBeInOptionList({ report, chatReport, diff --git a/src/libs/actions/Report/MarkAllMessageAsRead.tsx b/src/libs/actions/Report/MarkAllMessageAsRead.tsx index 558aa8b7a18f..422a5739ad53 100644 --- a/src/libs/actions/Report/MarkAllMessageAsRead.tsx +++ b/src/libs/actions/Report/MarkAllMessageAsRead.tsx @@ -49,8 +49,7 @@ function markAllMessagesAsRead(archivedReportsIdSet: ArchivedReportsIDSet) { const oneTransactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]); const oneTransactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionThreadReportID}`]; const isArchivedReport = archivedReportsIdSet.has(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`); - const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]; - if (!isUnread(report, oneTransactionThreadReport, isArchivedReport, reportActions)) { + if (!isUnread(report, oneTransactionThreadReport, isArchivedReport)) { continue; } diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index a805de5dd545..a03ba92184a4 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -127,7 +127,6 @@ import { getChildReportNotificationPreference, getDefaultNotificationPreferenceForReport, getLastVisibleMessage, - getLatestReportActionFromOtherUsers, getNextApproverAccountID, getOptimisticDataForAncestors, getOriginalReportID, @@ -2338,7 +2337,18 @@ function markCommentAsUnread(reportID: string | undefined, reportActions: OnyxEn } // Find the latest report actions from other users - const latestReportActionFromOtherUsers = getLatestReportActionFromOtherUsers(reportActions, currentUserAccountID); + const latestReportActionFromOtherUsers = Object.values(reportActions ?? {}).reduce((latest: ReportAction | null, current: ReportAction) => { + if ( + !ReportActionsUtils.isDeletedAction(current) && + current.actorAccountID !== currentUserAccountID && + (!latest || current.created > latest.created) && + // Whisper action doesn't affect lastVisibleActionCreated, so skip whisper action except actionable mention whisper + (!ReportActionsUtils.isWhisperAction(current) || current.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER) + ) { + return current; + } + return latest; + }, null); const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; @@ -2354,29 +2364,12 @@ function markCommentAsUnread(reportID: string | undefined, reportActions: OnyxEn // Since the report action with ID 100 will be the first with a timestamp above '2014-04-01 16:07:02.998', it's the first one that will be shown as unread const lastReadTime = DateUtils.subtractMillisecondsFromDateTime(actionCreationTime, 1); - const lastActorAccountID = - reportAction?.actorAccountID && reportAction.actorAccountID !== currentUserAccountID - ? reportAction.actorAccountID - : (latestReportActionFromOtherUsers?.actorAccountID ?? report?.lastActorAccountID); - const optimisticData: Array> = [ { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { lastReadTime, - ...(lastActorAccountID !== undefined && {lastActorAccountID}), - }, - }, - ]; - - const failureData: Array> = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - lastReadTime: report?.lastReadTime, - lastActorAccountID: report?.lastActorAccountID, }, }, ]; @@ -2387,7 +2380,7 @@ function markCommentAsUnread(reportID: string | undefined, reportActions: OnyxEn reportActionID: reportAction?.reportActionID, }; - API.write(WRITE_COMMANDS.MARK_AS_UNREAD, parameters, {optimisticData, failureData}); + API.write(WRITE_COMMANDS.MARK_AS_UNREAD, parameters, {optimisticData}); DeviceEventEmitter.emit(`unreadAction_${reportID}`, lastReadTime); } diff --git a/src/pages/inbox/report/ReportActionsList.tsx b/src/pages/inbox/report/ReportActionsList.tsx index 24170c577d8a..6c009ff51b46 100644 --- a/src/pages/inbox/report/ReportActionsList.tsx +++ b/src/pages/inbox/report/ReportActionsList.tsx @@ -398,7 +398,7 @@ function ReportActionsList({ return; } - if (isUnread(report, transactionThreadReport, isReportArchived, reportActionsFromOnyx) || (lastAction && isCurrentActionUnread(report, lastAction, sortedVisibleReportActions))) { + if (isUnread(report, transactionThreadReport, isReportArchived) || (lastAction && isCurrentActionUnread(report, lastAction, sortedVisibleReportActions))) { // On desktop, when the notification center is displayed, isVisible will return false. // Currently, there's no programmatic way to dismiss the notification center panel. // To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification. diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 8a1d2e04490b..1f2da0ed4ce7 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -574,7 +574,7 @@ describe('actions/Report', () => { }) .then(() => { // Then the report will be unread - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(true); + expect(ReportUtils.isUnread(report, undefined, undefined)).toBe(true); // And show a green dot for unread mentions in the LHN expect(ReportUtils.isUnreadWithMention(report)).toBe(true); @@ -588,7 +588,7 @@ describe('actions/Report', () => { }) .then(() => { // The report will be read - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(false); + expect(ReportUtils.isUnread(report, undefined, undefined)).toBe(false); expect(toZonedTime(report?.lastReadTime ?? '', UTC).getTime()).toBeGreaterThanOrEqual(toZonedTime(currentTime, UTC).getTime()); // And no longer show the green dot for unread mentions in the LHN @@ -600,7 +600,7 @@ describe('actions/Report', () => { }) .then(() => { // Then the report will be unread and show the green dot for unread mentions in LHN - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(true); + expect(ReportUtils.isUnread(report, undefined, undefined)).toBe(true); expect(ReportUtils.isUnreadWithMention(report)).toBe(true); expect(report?.lastReadTime).toBe(DateUtils.subtractMillisecondsFromDateTime(reportActionCreatedDate, 1)); @@ -619,7 +619,7 @@ describe('actions/Report', () => { }) .then(() => { // The report will be read, the green dot for unread mentions will go away, and the lastReadTime updated - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(false); + expect(ReportUtils.isUnread(report, undefined, undefined)).toBe(false); expect(ReportUtils.isUnreadWithMention(report)).toBe(false); expect(toZonedTime(report?.lastReadTime ?? '', UTC).getTime()).toBeGreaterThanOrEqual(toZonedTime(currentTime, UTC).getTime()); expect(report?.lastMessageText).toBe('Current User Comment 1'); @@ -638,7 +638,7 @@ describe('actions/Report', () => { }) .then(() => { // The report will be read and the lastReadTime updated - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(false); + expect(ReportUtils.isUnread(report, undefined, undefined)).toBe(false); expect(toZonedTime(report?.lastReadTime ?? '', UTC).getTime()).toBeGreaterThanOrEqual(toZonedTime(currentTime, UTC).getTime()); expect(report?.lastMessageText).toBe('Current User Comment 2'); @@ -656,7 +656,7 @@ describe('actions/Report', () => { }) .then(() => { // The report will be read and the lastReadTime updated - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(false); + expect(ReportUtils.isUnread(report, undefined, undefined)).toBe(false); expect(toZonedTime(report?.lastReadTime ?? '', UTC).getTime()).toBeGreaterThanOrEqual(toZonedTime(currentTime, UTC).getTime()); expect(report?.lastMessageText).toBe('Current User Comment 3'); @@ -671,23 +671,10 @@ describe('actions/Report', () => { reportID: REPORT_ID, }; - const USER_2_BASE_ACTION = { - ...USER_1_BASE_ACTION, - actorAccountID: USER_2_ACCOUNT_ID, - }; - - reportActionCreatedDate = DateUtils.getDBTime(); - const optimisticReportActions: OnyxUpdate = { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, value: { - 100: { - ...USER_2_BASE_ACTION, - message: [{type: 'COMMENT', html: 'Other user comment', text: 'Other user comment'}], - created: reportActionCreatedDate, - reportActionID: '100', - }, 200: { ...USER_1_BASE_ACTION, message: [{type: 'COMMENT', html: 'Current User Comment 1', text: 'Current User Comment 1'}], @@ -711,6 +698,8 @@ describe('actions/Report', () => { }, }; + reportActionCreatedDate = DateUtils.getDBTime(); + const optimisticReportActionsValue = optimisticReportActions.value as Record; if (optimisticReportActionsValue?.[400]) { @@ -749,7 +738,7 @@ describe('actions/Report', () => { .then(() => { // Then no change will occur expect(report?.lastReadTime).toBe(reportActionCreatedDate); - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(false); + expect(ReportUtils.isUnread(report, undefined, undefined)).toBe(false); // When the user manually marks a message as "unread" Report.markCommentAsUnread(REPORT_ID, reportActions, reportActions[400], USER_1_ACCOUNT_ID); @@ -757,7 +746,7 @@ describe('actions/Report', () => { }) .then(() => { // Then we should expect the report to be to be unread - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(true); + expect(ReportUtils.isUnread(report, undefined, undefined)).toBe(true); expect(report?.lastReadTime).toBe(DateUtils.subtractMillisecondsFromDateTime(reportActions[400].created, 1)); rerender(report); @@ -765,59 +754,10 @@ describe('actions/Report', () => { Report.deleteReportComment(report, {...reportActions[400]}, ancestors.current, undefined, undefined, USER_1_LOGIN); return waitForBatchedUpdates(); }) - .then(() => { - const lastVisibleActionCreated = reportActions[300].created; - const newerOtherUserActionCreated = DateUtils.getDBTime(); - - // Make report read by lastVisibleActionCreated, but keep a newer action from another user. - return Promise.all([ - Onyx.merge( - `${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}` as const, - { - lastMessageText: 'Current User Comment 2', - lastVisibleActionCreated, - lastReadTime: lastVisibleActionCreated, - } as Partial, - ), - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}` as const, { - 100: { - ...reportActions['100'], - created: newerOtherUserActionCreated, - message: [{type: 'COMMENT', html: 'Other user comment', text: 'Other user comment'}], - } as OnyxTypes.ReportAction, - }), - ]); - }) - .then(() => waitForBatchedUpdates()) - .then(() => { - // IOU report should be unread when latest visible action is from current user, but a newer other-user action exists. - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(true); - - // Mark action 100 (other user) as deleted so latestReportActionFromOtherUsers is null. - const deletedMessage = [{type: 'COMMENT' as const, html: '', text: '', deleted: 'true' as const}]; - return Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}` as const, { - 100: { - ...reportActions['100'], - message: deletedMessage, - } as OnyxTypes.ReportAction, - }); - }) - .then(() => waitForBatchedUpdates()) - .then(() => { - // With all other-user actions deleted, report should be read when lastReadTime >= lastVisibleActionCreated. - return Onyx.merge( - `${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}` as const, - { - lastReadTime: report?.lastVisibleActionCreated, - } as Partial, - ); - }) - .then(() => waitForBatchedUpdates()) .then(() => getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}` as const)) - .then((currentReport) => { - report = currentReport ?? report; - expect(ReportUtils.isUnread(report, undefined, undefined, reportActions)).toBe(false); - expect(report?.lastMessageText).toBe('Current User Comment 2'); + .then((updatedReport) => { + expect(ReportUtils.isUnread(updatedReport, undefined, undefined)).toBe(false); + expect(updatedReport?.lastMessageText).toBe('Current User Comment 2'); }); waitForBatchedUpdates(); // flushing onyx.set as it will be batched return setPromise; @@ -2767,7 +2707,7 @@ describe('actions/Report', () => { key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, callback: (reportVal) => { Onyx.disconnect(connection); - resolve(ReportUtils.isUnread(reportVal, undefined, undefined, undefined)); + resolve(ReportUtils.isUnread(reportVal, undefined, undefined)); }, }); });