Skip to content

Commit

Permalink
Merge pull request #40271 from bernhardoj/fix/37519-group-chat-not-sh…
Browse files Browse the repository at this point in the history
…ow-in-search-after-split

Fix group chat isn't shows in search page after split
  • Loading branch information
marcochavezf committed Apr 25, 2024
2 parents 1b3301b + 2f8983d commit 34434a5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1467,8 +1467,8 @@ function createOptionList(personalDetails: OnyxEntry<PersonalDetailsList>, repor
}

const isSelfDM = ReportUtils.isSelfDM(report);
// Currently, currentUser is not included in visibleChatMemberAccountIDs, so for selfDM we need to add the currentUser as participants.
const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : report.visibleChatMemberAccountIDs ?? [];
// Currently, currentUser is not included in participants, so for selfDM we need to add the currentUser as participants.
const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : Object.keys(report.participants ?? {}).map(Number);

if (!accountIDs || accountIDs.length === 0) {
return;
Expand Down Expand Up @@ -1688,8 +1688,8 @@ function getOptions(
const isPolicyExpenseChat = option.isPolicyExpenseChat;
const isMoneyRequestReport = option.isMoneyRequestReport;
const isSelfDM = option.isSelfDM;
// Currently, currentUser is not included in visibleChatMemberAccountIDs, so for selfDM we need to add the currentUser as participants.
const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : report.visibleChatMemberAccountIDs ?? [];
// Currently, currentUser is not included in participants, so for selfDM we need to add the currentUser as participants.
const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : Object.keys(report.participants ?? {}).map(Number);

if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) {
return;
Expand Down
10 changes: 9 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3167,6 +3167,11 @@ function createSplitsAndOnyxData(
splitChatReport.lastMessageText = splitIOUReportAction.message?.[0]?.text;
splitChatReport.lastMessageHtml = splitIOUReportAction.message?.[0]?.html;

let splitChatReportNotificationPreference = splitChatReport.notificationPreference;
if (splitChatReportNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
splitChatReportNotificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS;
}

// If we have an existing splitChatReport (group chat or workspace) use it's pending fields, otherwise indicate that we are adding a chat
if (!existingSplitChatReport) {
splitChatReport.pendingFields = {
Expand All @@ -3180,7 +3185,10 @@ function createSplitsAndOnyxData(
// and we need the data to be available when we navigate to the chat page
onyxMethod: existingSplitChatReport ? Onyx.METHOD.MERGE : Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${splitChatReport.reportID}`,
value: splitChatReport,
value: {
...splitChatReport,
notificationPreference: splitChatReportNotificationPreference,
},
},
{
onyxMethod: Onyx.METHOD.SET,
Expand Down
50 changes: 50 additions & 0 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ describe('OptionsListUtils', () => {
reportID: '1',
participantAccountIDs: [2, 1],
visibleChatMemberAccountIDs: [2, 1],
participants: {
2: {},
1: {},
},
reportName: 'Iron Man, Mister Fantastic',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -31,6 +35,9 @@ describe('OptionsListUtils', () => {
reportID: '2',
participantAccountIDs: [3],
visibleChatMemberAccountIDs: [3],
participants: {
3: {},
},
reportName: 'Spider-Man',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -43,6 +50,9 @@ describe('OptionsListUtils', () => {
reportID: '3',
participantAccountIDs: [1],
visibleChatMemberAccountIDs: [1],
participants: {
1: {},
},
reportName: 'Mister Fantastic',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -53,6 +63,9 @@ describe('OptionsListUtils', () => {
reportID: '4',
participantAccountIDs: [4],
visibleChatMemberAccountIDs: [4],
participants: {
4: {},
},
reportName: 'Black Panther',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -63,6 +76,9 @@ describe('OptionsListUtils', () => {
reportID: '5',
participantAccountIDs: [5],
visibleChatMemberAccountIDs: [5],
participants: {
5: {},
},
reportName: 'Invisible Woman',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -73,6 +89,9 @@ describe('OptionsListUtils', () => {
reportID: '6',
participantAccountIDs: [6],
visibleChatMemberAccountIDs: [6],
participants: {
6: {},
},
reportName: 'Thor',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -85,6 +104,9 @@ describe('OptionsListUtils', () => {
reportID: '7',
participantAccountIDs: [7],
visibleChatMemberAccountIDs: [7],
participants: {
7: {},
},
reportName: 'Captain America',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -97,6 +119,9 @@ describe('OptionsListUtils', () => {
reportID: '8',
participantAccountIDs: [12],
visibleChatMemberAccountIDs: [12],
participants: {
12: {},
},
reportName: 'Silver Surfer',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -109,6 +134,9 @@ describe('OptionsListUtils', () => {
reportID: '9',
participantAccountIDs: [8],
visibleChatMemberAccountIDs: [8],
participants: {
8: {},
},
reportName: 'Mister Sinister',
iouReportID: '100',
type: CONST.REPORT.TYPE.CHAT,
Expand All @@ -122,6 +150,10 @@ describe('OptionsListUtils', () => {
isPinned: false,
participantAccountIDs: [2, 7],
visibleChatMemberAccountIDs: [2, 7],
participants: {
2: {},
7: {},
},
reportName: '',
oldPolicyName: "SHIELD's workspace",
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
Expand Down Expand Up @@ -212,6 +244,9 @@ describe('OptionsListUtils', () => {
reportID: '11',
participantAccountIDs: [999],
visibleChatMemberAccountIDs: [999],
participants: {
999: {},
},
reportName: 'Concierge',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -226,6 +261,9 @@ describe('OptionsListUtils', () => {
reportID: '12',
participantAccountIDs: [1000],
visibleChatMemberAccountIDs: [1000],
participants: {
1000: {},
},
reportName: 'Chronos',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -240,6 +278,9 @@ describe('OptionsListUtils', () => {
reportID: '13',
participantAccountIDs: [1001],
visibleChatMemberAccountIDs: [1001],
participants: {
1001: {},
},
reportName: 'Receipts',
type: CONST.REPORT.TYPE.CHAT,
},
Expand All @@ -254,6 +295,11 @@ describe('OptionsListUtils', () => {
reportID: '14',
participantAccountIDs: [1, 10, 3],
visibleChatMemberAccountIDs: [1, 10, 3],
participants: {
1: {},
10: {},
3: {},
},
reportName: '',
oldPolicyName: 'Avengers Room',
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS,
Expand All @@ -271,6 +317,10 @@ describe('OptionsListUtils', () => {
reportID: '15',
participantAccountIDs: [3, 4],
visibleChatMemberAccountIDs: [3, 4],
participants: {
3: {},
4: {},
},
reportName: 'Spider-Man, Black Panther',
type: CONST.REPORT.TYPE.CHAT,
chatType: CONST.REPORT.CHAT_TYPE.DOMAIN_ALL,
Expand Down

0 comments on commit 34434a5

Please sign in to comment.