Skip to content

Commit

Permalink
handling new system report type
Browse files Browse the repository at this point in the history
  • Loading branch information
burczu committed Apr 26, 2024
1 parent 9a58f4f commit 6da74e4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const chatTypes = {
POLICY_ROOM: 'policyRoom',
POLICY_EXPENSE_CHAT: 'policyExpenseChat',
SELF_DM: 'selfDM',
SYSTEM: 'system',
} as const;

// Explicit type annotation is required
Expand Down Expand Up @@ -1202,7 +1203,6 @@ const CONST = {
CHRONOS: '[email protected]',
CONCIERGE: '[email protected]',
CONTRIBUTORS: '[email protected]',
EXPENSIFY_PERSONA: '[email protected]',
FIRST_RESPONDER: '[email protected]',
GUIDES_DOMAIN: 'team.expensify.com',
HELP: '[email protected]',
Expand Down
21 changes: 19 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,10 @@ function isGroupChat(report: OnyxEntry<Report> | Partial<Report>): boolean {
return getChatType(report) === CONST.REPORT.CHAT_TYPE.GROUP;
}

function isSystemChat(report: OnyxEntry<Report> | Partial<Report>): boolean {
return getChatType(report) === CONST.REPORT.CHAT_TYPE.SYSTEM;
}

/**
* Only returns true if this is our main 1:1 DM report with Concierge
*/
Expand Down Expand Up @@ -4791,7 +4795,6 @@ function shouldReportBeInOptionList({
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
report?.isHidden ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
report?.participantAccountIDs?.includes(CONST.ACCOUNT_ID.NOTIFICATIONS) ||
(report?.participantAccountIDs?.length === 0 &&
!isChatThread(report) &&
!isPublicRoom(report) &&
Expand All @@ -4800,7 +4803,8 @@ function shouldReportBeInOptionList({
!isMoneyRequestReport(report) &&
!isTaskReport(report) &&
!isSelfDM(report) &&
!isGroupChat(report))
!isGroupChat(report) &&
!isSystemChat(report))
) {
return false;
}
Expand Down Expand Up @@ -4877,6 +4881,18 @@ function shouldReportBeInOptionList({
return true;
}

/**
* Returns the system report from the list of reports.
* TODO: this method may not be necessary if the participants list of the system report is filled correctly
*/
function getSystemChat(): OnyxEntry<Report> {
if (!allReports) {
return null;
}

return Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.SYSTEM) ?? null;
}

/**
* Attempts to find a report in onyx with the provided list of participants. Does not include threads, task, expense, room, and policy expense chat.
*/
Expand Down Expand Up @@ -6306,6 +6322,7 @@ export {
getRoomWelcomeMessage,
getRootParentReport,
getRouteFromLink,
getSystemChat,
getTaskAssigneeChatOnyxData,
getTransactionDetails,
getTransactionReportName,
Expand Down
6 changes: 6 additions & 0 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as OptionsListUtils from './OptionsListUtils';
import * as ReportActionsUtils from './ReportActionsUtils';
import * as ReportUtils from './ReportUtils';
import * as TaskUtils from './TaskUtils';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';

Check warning on line 23 in src/libs/SidebarUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected subpath import via alias '@libs/PersonalDetailsUtils'. Use './PersonalDetailsUtils' instead

Check failure on line 23 in src/libs/SidebarUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

`@libs/PersonalDetailsUtils` import should occur before import of `./CollectionUtils`

const visibleReportActionItems: ReportActions = {};
Onyx.connect({
Expand Down Expand Up @@ -245,6 +246,11 @@ function getOptionData({
participantAccountIDs = [report.ownerAccountID ?? 0];
}

// TODO: this is added for the testing purposes only - should be removed once participants list of the system report is filled
if (report.chatType === CONST.REPORT.CHAT_TYPE.SYSTEM) {
participantAccountIDs = [report.ownerAccountID ?? 0, ...PersonalDetailsUtils.getAccountIDsByLogins([CONST.EMAIL.NOTIFICATIONS])];
}

const participantPersonalDetailList = Object.values(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails)) as PersonalDetails[];
const personalDetail = participantPersonalDetailList[0] ?? {};
const hasErrors = Object.keys(result.allReportErrors ?? {}).length !== 0;
Expand Down
10 changes: 4 additions & 6 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3029,14 +3029,12 @@ function completeOnboarding(
},
adminsChatReportID?: string,
) {
let targetEmail: string = CONST.EMAIL.CONCIERGE;
if (currentUserAccountID % 2 === 1) {
// for odd accountID, we will use the expensify persona instead of concierge
targetEmail = CONST.EMAIL.EXPENSIFY_PERSONA;
}
const isAccountIDOdd = currentUserAccountID % 2 === 1;
const targetEmail = isAccountIDOdd ? CONST.EMAIL.NOTIFICATIONS : CONST.EMAIL.CONCIERGE;

const actorAccountID = PersonalDetailsUtils.getAccountIDsByLogins([targetEmail])[0];
const targetChatReport = ReportUtils.getChatByParticipants([actorAccountID]);
// TODO: using getSystemChat is rather not necessary if we could have participants list filled correctly
const targetChatReport= isAccountIDOdd ? ReportUtils.getSystemChat() : ReportUtils.getChatByParticipants([actorAccountID]);
const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {};

// Mention message
Expand Down

0 comments on commit 6da74e4

Please sign in to comment.