Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1061 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1066,7 +1066,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1069 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1084,7 +1084,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1087 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (deprecatedCurrentUserAccountID) {
Expand All @@ -1096,7 +1096,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1099 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1104,7 +1104,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1107 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1114,7 +1114,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1117 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1122,7 +1122,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1125 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1158,14 +1158,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1161 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1168 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1191,7 +1191,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1194 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -7855,6 +7855,8 @@
optimisticReportID?: string;
isPinned?: boolean;
chatReportID?: string;
// TODO: This'll be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66412
currentUserAccountID?: number;
};

function buildOptimisticChatReport({
Expand All @@ -7875,12 +7877,13 @@
optimisticReportID = '',
isPinned = false,
chatReportID = undefined,
currentUserAccountID = deprecatedCurrentUserAccountID,
}: BuildOptimisticChatReportParams): OptimisticChatReport {
const isWorkspaceChatType = chatType && isWorkspaceChat(chatType);
const participants = participantList.reduce((reportParticipants: Participants, accountID: number) => {
const participant: ReportParticipant = {
notificationPreference,
...(!isWorkspaceChatType && {role: accountID === deprecatedCurrentUserAccountID ? CONST.REPORT.ROLE.ADMIN : CONST.REPORT.ROLE.MEMBER}),
...(!isWorkspaceChatType && {role: accountID === currentUserAccountID ? CONST.REPORT.ROLE.ADMIN : CONST.REPORT.ROLE.MEMBER}),
};
// eslint-disable-next-line no-param-reassign
reportParticipants[accountID] = participant;
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/IOU/PerDiem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI
isNewChatReport = true;
chatReport = buildOptimisticChatReport({
participantList: [payerAccountID, payeeAccountID],
currentUserAccountID: currentUserAccountIDParam,
});
}

Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/IOU/SendInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ function getSendInvoiceInformation({
participantList: [receiverAccountID, currentUserAccountID],
chatType: CONST.REPORT.CHAT_TYPE.INVOICE,
policyID: senderWorkspaceID,
currentUserAccountID,
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/libs/actions/IOU/SendMoney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function getSendMoneyParams({
created,
merchant,
receipt,
currentUserAccountID,
}: {
report: OnyxEntry<OnyxTypes.Report>;
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
Expand All @@ -84,6 +85,7 @@ function getSendMoneyParams({
created?: string;
merchant?: string;
receipt?: Receipt;
currentUserAccountID: number;
}): SendMoneyParamsData {
const recipientEmail = addSMSDomainIfPhoneNumber(recipient.login ?? '');
const recipientAccountID = Number(recipient.accountID);
Expand All @@ -104,6 +106,7 @@ function getSendMoneyParams({
if (!chatReport) {
chatReport = buildOptimisticChatReport({
participantList: [recipientAccountID, managerID],
currentUserAccountID,
});
isNewChat = true;
}
Expand Down Expand Up @@ -503,6 +506,7 @@ function sendMoneyElsewhere(
created,
merchant,
receipt,
currentUserAccountID,
});
startSpan(CONST.TELEMETRY.SPAN_SUBMIT_TO_DESTINATION_VISIBLE, {
name: 'submit-to-destination-visible',
Expand Down Expand Up @@ -550,6 +554,7 @@ function sendMoneyWithWallet(
created,
merchant,
receipt,
currentUserAccountID,
});
startSpan(CONST.TELEMETRY.SPAN_SUBMIT_TO_DESTINATION_VISIBLE, {
name: 'submit-to-destination-visible',
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/IOU/Split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ function completeSplitBill(
existingChatReport ??
buildOptimisticChatReport({
participantList: participant.accountID ? [participant.accountID, sessionAccountID] : [],
currentUserAccountID: sessionAccountID,
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3326,6 +3326,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
chatReport = buildOptimisticChatReport({
participantList: [payerAccountID, payeeAccountID],
optimisticReportID: optimisticChatReportID,
currentUserAccountID: currentUserAccountIDParam,
});
}

Expand Down Expand Up @@ -7034,6 +7035,7 @@ function getOrCreateOptimisticSplitChatReport(existingSplitChatReportID: string
reportName: '',
chatType: CONST.REPORT.CHAT_TYPE.GROUP,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
currentUserAccountID,
});

return {existingSplitChatReport: null, splitChatReport};
Expand All @@ -7042,6 +7044,7 @@ function getOrCreateOptimisticSplitChatReport(existingSplitChatReportID: string
// Otherwise, create a new 1:1 chat report
const splitChatReport = buildOptimisticChatReport({
participantList: participantAccountIDs,
currentUserAccountID,
});
return {existingSplitChatReport: null, splitChatReport};
}
Expand Down Expand Up @@ -7361,6 +7364,7 @@ function createSplitsAndOnyxData({
existingChatReport ??
buildOptimisticChatReport({
participantList: [accountID, currentUserAccountID],
currentUserAccountID,
});
}

Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ function createPolicyExpenseChats(
policyID,
ownerAccountID: cleanAccountID,
notificationPreference,
currentUserAccountID: deprecatedSessionAccountID,
});

// Set correct notification preferences: visible for the submitter, hidden for others until there's activity
Expand Down
5 changes: 5 additions & 0 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,7 @@ function getOptimisticChatReport(accountID: number, currentUserAccountID: number
return buildOptimisticChatReport({
participantList: [accountID, currentUserAccountID],
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
currentUserAccountID,
});
}

Expand Down Expand Up @@ -1986,6 +1987,7 @@ function navigateToAndOpenReport(
newChat = buildOptimisticChatReport({
participantList: [...participantAccountIDs, currentUserAccountID],
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
currentUserAccountID,
});
// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
openReport({reportID: newChat?.reportID, introSelected, reportActionID: '', participantLoginList: userLogins, newReportObject: newChat, isSelfTourViewed, betas});
Expand Down Expand Up @@ -2027,6 +2029,7 @@ function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[],
if (!chat) {
newChat = buildOptimisticChatReport({
participantList: [...participantAccountIDs, currentUserAccountID],
currentUserAccountID,
});
// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
openReport({
Expand Down Expand Up @@ -2092,6 +2095,7 @@ function createChildReport(
parentReportActionID: parentReportAction.reportActionID,
parentReportID: parentReport?.reportID,
optimisticReportID: parentReportAction.childReportID,
currentUserAccountID,
});

const childReportID = childReport?.reportID ?? parentReportAction.childReportID;
Expand Down Expand Up @@ -2993,6 +2997,7 @@ function toggleSubscribeToChildReport(
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
parentReportActionID: parentReportAction.reportActionID,
parentReportID: parentReport?.reportID,
currentUserAccountID,
});

const participantLogins = PersonalDetailsUtils.getLoginsByAccountIDs(participantAccountIDs);
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ function setNewOptimisticAssignee(currentUserAccountID: number, assigneePersonal
policyID: CONST.POLICY.OWNER_EMAIL_FAKE,
ownerAccountID: CONST.POLICY.OWNER_ACCOUNT_ID_FAKE,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
currentUserAccountID,
});

Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/TeachersUnite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ type ExpenseReportActionData = Record<string, OptimisticCreatedReportAction>;
/**
* @param publicRoomReportID - This is the global reportID for the public room, we'll ignore the optimistic one
*/
function referTeachersUniteVolunteer(partnerUserID: string, firstName: string, lastName: string, policyID: string, publicRoomReportID: string) {
function referTeachersUniteVolunteer(partnerUserID: string, firstName: string, lastName: string, policyID: string, publicRoomReportID: string, currentUserAccountID: number) {
const optimisticPublicRoom = buildOptimisticChatReport({
participantList: [],
reportName: CONST.TEACHERS_UNITE.PUBLIC_ROOM_NAME,
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
policyID,
currentUserAccountID,
});
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_METADATA>> = [
{
Expand Down Expand Up @@ -86,6 +87,7 @@ function addSchoolPrincipal(
isOwnPolicyExpenseChat: true,
oldPolicyName: policyName,
optimisticReportID,
currentUserAccountID: sessionAccountID,
});
const expenseChatReportID = expenseChatData.reportID;
const expenseReportCreatedAction = buildOptimisticCreatedReportAction(sessionEmail);
Expand Down
4 changes: 3 additions & 1 deletion src/pages/TeachersUnite/KnowATeacherPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -27,6 +28,7 @@ function KnowATeacherPage() {
const {isProduction} = useEnvironment();
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE);
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
/**
* Submit form to pass firstName, partnerUserID and lastName
*/
Expand All @@ -39,7 +41,7 @@ function KnowATeacherPage() {

const policyID = isProduction ? CONST.TEACHERS_UNITE.PROD_POLICY_ID : CONST.TEACHERS_UNITE.TEST_POLICY_ID;
const publicRoomReportID = isProduction ? CONST.TEACHERS_UNITE.PROD_PUBLIC_ROOM_ID : CONST.TEACHERS_UNITE.TEST_PUBLIC_ROOM_ID;
TeachersUnite.referTeachersUniteVolunteer(contactMethod, firstName, lastName, policyID, publicRoomReportID);
TeachersUnite.referTeachersUniteVolunteer(contactMethod, firstName, lastName, policyID, publicRoomReportID, currentUserAccountID);
};

/**
Expand Down
4 changes: 3 additions & 1 deletion src/pages/workspace/WorkspaceNewRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ function WorkspaceNewRoomPage({ref}: WorkspaceNewRoomPageProps) {
*/
const submit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.NEW_ROOM_FORM>) => {
setNewRoomFormLoading();
const participants = [session?.accountID ?? CONST.DEFAULT_NUMBER_ID];
const currentUserAccountID = session?.accountID ?? CONST.DEFAULT_NUMBER_ID;
const participants = [currentUserAccountID];
const parsedDescription = getParsedComment(values.reportDescription ?? '', {policyID});
const policyReport = buildOptimisticChatReport({
participantList: participants,
Expand All @@ -130,6 +131,7 @@ function WorkspaceNewRoomPage({ref}: WorkspaceNewRoomPageProps) {
writeCapability: writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY,
description: parsedDescription,
currentUserAccountID,
});

// eslint-disable-next-line @typescript-eslint/no-deprecated
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6263,9 +6263,53 @@ describe('ReportUtils', () => {
it('should always set isPinned to false', () => {
const result = buildOptimisticChatReport({
participantList: [1, 2, 3],
currentUserAccountID: 1,
});
expect(result.isPinned).toBe(false);
});

it('should assign ADMIN role to currentUserAccountID and MEMBER role to others for non-workspace chats', () => {
const currentUser = 100;
const result = buildOptimisticChatReport({
participantList: [currentUser, 200, 300],
currentUserAccountID: currentUser,
});
expect(result.participants?.[currentUser]?.role).toBe(CONST.REPORT.ROLE.ADMIN);
expect(result.participants?.[200]?.role).toBe(CONST.REPORT.ROLE.MEMBER);
expect(result.participants?.[300]?.role).toBe(CONST.REPORT.ROLE.MEMBER);
});

it('should assign ADMIN role based on the provided currentUserAccountID, not the deprecated global value', () => {
const explicitCurrentUser = 999;
const result = buildOptimisticChatReport({
participantList: [explicitCurrentUser, 1, 2],
currentUserAccountID: explicitCurrentUser,
});
expect(result.participants?.[explicitCurrentUser]?.role).toBe(CONST.REPORT.ROLE.ADMIN);
expect(result.participants?.[1]?.role).toBe(CONST.REPORT.ROLE.MEMBER);
expect(result.participants?.[2]?.role).toBe(CONST.REPORT.ROLE.MEMBER);
});

it('should not assign role for workspace chat types', () => {
const currentUser = 100;
const result = buildOptimisticChatReport({
participantList: [currentUser, 200],
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
currentUserAccountID: currentUser,
});
expect(result.participants?.[currentUser]?.role).toBeUndefined();
expect(result.participants?.[200]?.role).toBeUndefined();
});

it('should assign all participants as MEMBER when currentUserAccountID is not in the participant list', () => {
const result = buildOptimisticChatReport({
participantList: [1, 2, 3],
currentUserAccountID: 999,
});
expect(result.participants?.[1]?.role).toBe(CONST.REPORT.ROLE.MEMBER);
expect(result.participants?.[2]?.role).toBe(CONST.REPORT.ROLE.MEMBER);
expect(result.participants?.[3]?.role).toBe(CONST.REPORT.ROLE.MEMBER);
});
});

describe('getWorkspaceNameUpdatedMessage', () => {
Expand Down
Loading