Skip to content

Commit

Permalink
Merge pull request #40254 from s77rt/participants-migration
Browse files Browse the repository at this point in the history
Participants migration
  • Loading branch information
marcaaron authored May 13, 2024
2 parents ab3cd7d + 7234ceb commit c701d16
Show file tree
Hide file tree
Showing 26 changed files with 654 additions and 427 deletions.
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 useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -34,12 +34,16 @@ type ReportWelcomeTextProps = ReportWelcomeTextOnyxProps & {
function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [session] = useOnyx(ONYXKEYS.SESSION);
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) => accountID !== session?.accountID || !isOneOnOneChat);
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) => accountID !== currentUserAccountID || !isOneOnOneChat);

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) => accountID !== currentUserAccountID || !isOneOnOneChat);

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) => accountID !== currentUserAccountID || !isOneOnOneChat);

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) => accountID !== currentUserAccountID || !isOneOnOneChat);

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) => accountID !== currentUserAccountID || !isOneOnOneChat);

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

0 comments on commit c701d16

Please sign in to comment.