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

Disable thread in archived room #38251

Merged
merged 4 commits into from
Mar 22, 2024
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
3 changes: 3 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5341,6 +5341,7 @@ function hasUpdatedTotal(report: OnyxEntry<Report>): boolean {
* - The action is listed in the thread-disabled list
* - The action is a split bill action
* - The action is deleted and is not threaded
* - The report is archived and the action is not threaded
* - The action is a whisper action and it's neither a report preview nor IOU action
* - The action is the thread's first chat
*/
Expand All @@ -5350,11 +5351,13 @@ function shouldDisableThread(reportAction: OnyxEntry<ReportAction>, reportID: st
const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction);
const isIOUAction = ReportActionsUtils.isMoneyRequestAction(reportAction);
const isWhisperAction = ReportActionsUtils.isWhisperAction(reportAction);
const isArchivedReport = isArchivedRoom(getReport(reportID));

return (
CONST.REPORT.ACTIONS.THREAD_DISABLED.some((action: string) => action === reportAction?.actionName) ||
isSplitBillAction ||
(isDeletedAction && !reportAction?.childVisibleActionCount) ||
(isArchivedReport && !reportAction?.childVisibleActionCount) ||
(isWhisperAction && !isReportPreviewAction && !isIOUAction) ||
isThreadFirstChat(reportAction, reportID)
);
Expand Down
73 changes: 73 additions & 0 deletions tests/unit/ReportUtilsTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Onyx from 'react-native-onyx';
import _ from 'underscore';
import CONST from '../../src/CONST';
import * as NumberUtils from '../../src/libs/NumberUtils';
import * as ReportUtils from '../../src/libs/ReportUtils';
import ONYXKEYS from '../../src/ONYXKEYS';
import * as LHNTestUtils from '../utils/LHNTestUtils';
Expand Down Expand Up @@ -639,6 +640,78 @@ describe('ReportUtils', () => {
});
});

describe('shouldDisableThread', () => {
const reportID = '1';

it('should disable on thread-disabled actions', () => {
const reportAction = ReportUtils.buildOptimisticCreatedReportAction('email1@test.com');
expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy();
});

it('should disable thread on split bill actions', () => {
const reportAction = ReportUtils.buildOptimisticIOUReportAction(
CONST.IOU.REPORT_ACTION_TYPE.SPLIT,
50000,
CONST.CURRENCY.USD,
'',
[{login: 'email1@test.com'}, {login: 'email2@test.com'}],
NumberUtils.rand64(),
);
expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy();
});

it('should disable on deleted and not-thread actions', () => {
const reportAction = {
message: [
{
translationKey: '',
type: 'COMMENT',
html: '',
text: '',
isEdited: true,
},
],
childVisibleActionCount: 1,
};
expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeFalsy();

reportAction.childVisibleActionCount = 0;
expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy();
});

it('should disable on archived reports and not-thread actions', () => {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
})
.then(() => waitForBatchedUpdates())
.then(() => {
const reportAction = {
childVisibleActionCount: 1,
};
expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeFalsy();

reportAction.childVisibleActionCount = 0;
expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy();
});
});

it("should disable on a whisper action and it's neither a report preview nor IOU action", () => {
const reportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
whisperedToAccountIDs: [123456],
};
expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy();
});

it('should disable on thread first chat', () => {
const reportAction = {
childReportID: reportID,
};
expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy();
});
});

describe('getAllAncestorReportActions', () => {
const reports = [
{reportID: '1', lastReadTime: '2024-02-01 04:56:47.233', reportName: 'Report'},
Expand Down
Loading