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

Participants migration #40254

Merged
merged 29 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
92a6265
Participants onyx migration
s77rt Apr 15, 2024
57c8c70
Merge branch 'Expensify:main' into participants-migration
s77rt Apr 21, 2024
07356fb
Participants migration: ReportUtils, OptionsListUtils, ReportWelcomeText
s77rt Apr 21, 2024
bc24bfa
remove diff.tmp
s77rt Apr 21, 2024
54745c9
Merge branch 'Expensify:main' into participants-migration
s77rt Apr 24, 2024
ea56625
Participants migration: SidebarUtils, IOU, Task
s77rt Apr 24, 2024
f2ba3a3
Merge branch 'main' into participants-migration
s77rt Apr 28, 2024
bfba18d
Participants migration: Task, Report, Policy, HeaderView, ProfilePage…
s77rt Apr 28, 2024
716c944
Participants migration: IOUTest, PolicyTest, UnreadIndicatorsTest, Op…
s77rt Apr 28, 2024
4ec3fb5
Participants migration: useReportIDs, RoomInvitePage, RoomMembersPage…
s77rt Apr 28, 2024
a3dcdda
Participants migration: lint
s77rt Apr 28, 2024
a85a08b
Merge branch 'main' into participants-migration
s77rt May 2, 2024
ccb420b
Fix isMultipleParticipant condition
s77rt May 2, 2024
9f6afd8
fix participants length
s77rt May 2, 2024
5338841
Fix getChatByParticipants
s77rt May 3, 2024
35ed090
fix more tests
s77rt May 3, 2024
a4853b6
Fix IOUTest and lint
s77rt May 3, 2024
e56163f
Onyx migration: add current user as a participant
s77rt May 3, 2024
c0d0f7c
Merge branch 'Expensify:main' into participants-migration
s77rt May 3, 2024
2733e47
Clear optimistic participants on OpenReport
s77rt May 4, 2024
4231757
Clear optimistic participants on IOU
s77rt May 5, 2024
a91f310
Clear optimistic participants on Task
s77rt May 5, 2024
e247a3b
Fix IOUTest
s77rt May 5, 2024
540e535
Merge branch 'main' into participants-migration
s77rt May 6, 2024
8d43462
Onyx migration: correct reports by removing invalid participants
s77rt May 7, 2024
30e119e
Add assigneeAccountID to participants only if it's set
s77rt May 7, 2024
2d7587a
Merge branch 'Expensify:main' into participants-migration
s77rt May 13, 2024
1d27719
Make filter condition more readable
s77rt May 13, 2024
7234ceb
Merge branch 'main' into participants-migration
s77rt May 13, 2024
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
8 changes: 4 additions & 4 deletions src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp
newReportOption: OptionsListUtils.SearchOption<Report>;
}> = [];

Object.keys(personalDetails).forEach((accoutID) => {
const prevPersonalDetail = prevPersonalDetails?.[accoutID];
const personalDetail = personalDetails?.[accoutID];
Object.keys(personalDetails).forEach((accountID) => {
const prevPersonalDetail = prevPersonalDetails?.[accountID];
const personalDetail = personalDetails?.[accountID];

if (isEqualPersonalDetail(prevPersonalDetail, personalDetail)) {
return;
}

Object.values(reports ?? {})
.filter((report) => Boolean(report?.participantAccountIDs?.includes(Number(accoutID))) || (ReportUtils.isSelfDM(report) && report?.ownerAccountID === Number(accoutID)))
.filter((report) => Boolean(Object.keys(report?.participants ?? {}).includes(accountID)) || (ReportUtils.isSelfDM(report) && report?.ownerAccountID === Number(accountID)))
.forEach((report) => {
if (!report) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/components/OptionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ function OptionRow({
const hoveredStyle = hoverStyle ? flattenHoverStyle : styles.sidebarLinkHover;
const hoveredBackgroundColor = hoveredStyle?.backgroundColor ? (hoveredStyle.backgroundColor as string) : backgroundColor;
const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor;
const isMultipleParticipant = (option.participantsList?.length ?? 0) > 1;
const shouldUseShortFormInTooltip = (option.participantsList?.length ?? 0) > 1;

// We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade.
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips((option.participantsList ?? (option.accountID ? [option] : [])).slice(0, 10), isMultipleParticipant);
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips((option.participantsList ?? (option.accountID ? [option] : [])).slice(0, 10), shouldUseShortFormInTooltip);
let subscriptColor = theme.appBG;
if (optionIsFocused) {
subscriptColor = focusedBackgroundColor;
Expand Down
8 changes: 6 additions & 2 deletions src/components/ReportWelcomeText.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useMemo} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -35,13 +35,17 @@ type ReportWelcomeTextProps = ReportWelcomeTextOnyxProps & {
function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [session] = useOnyx(ONYXKEYS.SESSION);
const {canUseTrackExpense} = usePermissions();
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report);
const isChatRoom = ReportUtils.isChatRoom(report);
const isSelfDM = ReportUtils.isSelfDM(report);
const isInvoiceRoom = ReportUtils.isInvoiceRoom(report);
const isOneOnOneChat = ReportUtils.isOneOnOneChat(report);
const isDefault = !(isChatRoom || isPolicyExpenseChat || isSelfDM || isInvoiceRoom);
const participantAccountIDs = report?.participantAccountIDs ?? [];
const participantAccountIDs = Object.keys(report?.participants ?? {})
.map(Number)
.filter((accountID) => !isOneOnOneChat || accountID !== session?.accountID);
const isMultipleParticipant = participantAccountIDs.length > 1;
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails), isMultipleParticipant);
const isUserPolicyAdmin = PolicyUtils.isPolicyAdmin(policy);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useReportIDs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ReportIDsContext = createContext<ReportIDsContextValue>({
const chatReportSelector = (report: OnyxEntry<OnyxTypes.Report>): ChatReportSelector =>
(report && {
reportID: report.reportID,
participantAccountIDs: report.participantAccountIDs,
participants: report.participants,
isPinned: report.isPinned,
isHidden: report.isHidden,
notificationPreference: report.notificationPreference,
Expand Down
69 changes: 39 additions & 30 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,20 @@ function createOption(
result.isPinned = report.isPinned;
result.iouReportID = report.iouReportID;
result.keyForList = String(report.reportID);
result.tooltipText = ReportUtils.getReportParticipantsTitle(report.visibleChatMemberAccountIDs ?? []);
result.isWaitingOnBankAccount = report.isWaitingOnBankAccount;
result.policyID = report.policyID;
result.isSelfDM = ReportUtils.isSelfDM(report);

// For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants
const isOneOnOneChat = ReportUtils.isOneOnOneChat(report);
const visibleParticipantAccountIDs = Object.entries(report.participants ?? {})
.filter(([, participant]) => participant && !participant.hidden)
.map(([accountID]) => Number(accountID))
.filter((accountID) => !isOneOnOneChat || accountID !== currentUserAccountID);

result.tooltipText = ReportUtils.getReportParticipantsTitle(visibleParticipantAccountIDs);
result.isOneOnOneChat = isOneOnOneChat;

hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat;
subtitle = ReportUtils.getChatRoomSubtitle(report);

Expand Down Expand Up @@ -776,8 +785,15 @@ function createOption(
function getReportOption(participant: Participant): ReportUtils.OptionData {
const report = ReportUtils.getReport(participant.reportID);

// For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants
const isOneOnOneChat = ReportUtils.isOneOnOneChat(report);
const visibleParticipantAccountIDs = Object.entries(report?.participants ?? {})
.filter(([, reportParticipant]) => reportParticipant && !reportParticipant.hidden)
.map(([accountID]) => Number(accountID))
.filter((accountID) => !isOneOnOneChat || accountID !== currentUserAccountID);

const option = createOption(
report?.visibleChatMemberAccountIDs ?? [],
visibleParticipantAccountIDs,
allPersonalDetails ?? {},
!isEmptyObject(report) ? report : null,
{},
Expand Down Expand Up @@ -806,8 +822,12 @@ function getReportOption(participant: Participant): ReportUtils.OptionData {
function getPolicyExpenseReportOption(participant: Participant | ReportUtils.OptionData): ReportUtils.OptionData {
const expenseReport = ReportUtils.isPolicyExpenseChat(participant) ? ReportUtils.getReport(participant.reportID) : null;

const visibleParticipantAccountIDs = Object.entries(expenseReport?.participants ?? {})
.filter(([, reportParticipant]) => reportParticipant && !reportParticipant.hidden)
.map(([accountID]) => Number(accountID));

const option = createOption(
expenseReport?.visibleChatMemberAccountIDs ?? [],
visibleParticipantAccountIDs,
allPersonalDetails ?? {},
!isEmptyObject(expenseReport) ? expenseReport : null,
{},
Expand Down Expand Up @@ -1467,19 +1487,11 @@ function createOptionList(personalDetails: OnyxEntry<PersonalDetailsList>, repor
return;
}

const isSelfDM = ReportUtils.isSelfDM(report);
let accountIDs = [];

if (isSelfDM) {
// For selfDM we need to add the currentUser as participants.
accountIDs = [currentUserAccountID ?? 0];
} else {
accountIDs = Object.keys(report.participants ?? {}).map(Number);
if (ReportUtils.isOneOnOneChat(report)) {
// For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants
accountIDs = accountIDs.filter((accountID) => accountID !== currentUserAccountID);
}
}
// For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants
const isOneOnOneChat = ReportUtils.isOneOnOneChat(report);
const accountIDs = Object.keys(report.participants ?? {})
.map(Number)
.filter((accountID) => !isOneOnOneChat || accountID !== currentUserAccountID);

if (!accountIDs || accountIDs.length === 0) {
return;
Expand Down Expand Up @@ -1511,8 +1523,11 @@ function createOptionList(personalDetails: OnyxEntry<PersonalDetailsList>, repor
}

function createOptionFromReport(report: Report, personalDetails: OnyxEntry<PersonalDetailsList>) {
const isSelfDM = ReportUtils.isSelfDM(report);
const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : report.participantAccountIDs ?? [];
// For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants
const isOneOnOneChat = ReportUtils.isOneOnOneChat(report);
const accountIDs = Object.keys(report.participants ?? {})
.map(Number)
.filter((accountID) => !isOneOnOneChat || accountID !== currentUserAccountID);

return {
item: report,
Expand Down Expand Up @@ -1768,18 +1783,12 @@ function getOptions(
const isPolicyExpenseChat = option.isPolicyExpenseChat;
const isMoneyRequestReport = option.isMoneyRequestReport;
const isSelfDM = option.isSelfDM;
let accountIDs = [];

if (isSelfDM) {
// For selfDM we need to add the currentUser as participants.
accountIDs = [currentUserAccountID ?? 0];
} else {
accountIDs = Object.keys(report.participants ?? {}).map(Number);
if (ReportUtils.isOneOnOneChat(report)) {
// For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants
accountIDs = accountIDs.filter((accountID) => accountID !== currentUserAccountID);
}
}
const isOneOnOneChat = option.isOneOnOneChat;

// For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants
const accountIDs = Object.keys(report.participants ?? {})
.map(Number)
.filter((accountID) => !isOneOnOneChat || accountID !== currentUserAccountID);

if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) {
return;
Expand Down
Loading
Loading