Skip to content

Commit

Permalink
Merge pull request Expensify#30863 from Expensify/rodrigo-visibleChat…
Browse files Browse the repository at this point in the history
…MemberList

Using visibleChatMemberList instead of participants ids
  • Loading branch information
marcaaron authored Jan 4, 2024
2 parents cafe831 + 8a7fb19 commit 9b74851
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ function getSearchText(report, reportName, personalDetailList, isChatRoomOrPolic

Array.prototype.push.apply(searchTerms, chatRoomSubtitle.split(/[,\s]/));
} else {
const participantAccountIDs = report.participantAccountIDs || [];
for (let i = 0; i < participantAccountIDs.length; i++) {
const accountID = participantAccountIDs[i];
const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs || [];
for (let i = 0; i < visibleChatMemberAccountIDs.length; i++) {
const accountID = visibleChatMemberAccountIDs[i];

if (allPersonalDetails[accountID] && allPersonalDetails[accountID].login) {
searchTerms = searchTerms.concat(allPersonalDetails[accountID].login);
Expand Down Expand Up @@ -506,7 +506,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, {
result.isPinned = report.isPinned;
result.iouReportID = report.iouReportID;
result.keyForList = String(report.reportID);
result.tooltipText = ReportUtils.getReportParticipantsTitle(report.participantAccountIDs || []);
result.tooltipText = ReportUtils.getReportParticipantsTitle(report.visibleChatMemberAccountIDs || []);
result.isWaitingOnBankAccount = report.isWaitingOnBankAccount;
result.policyID = report.policyID;

Expand Down Expand Up @@ -573,7 +573,7 @@ function getPolicyExpenseReportOption(report) {
const expenseReport = policyExpenseReports[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`];

const option = createOption(
expenseReport.participantAccountIDs,
expenseReport.visibleChatMemberAccountIDs,
allPersonalDetails,
expenseReport,
{},
Expand Down Expand Up @@ -1342,7 +1342,7 @@ function getOptions(
const isTaskReport = ReportUtils.isTaskReport(report);
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report);
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
const accountIDs = report.participantAccountIDs || [];
const accountIDs = report.visibleChatMemberAccountIDs || [];

if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) {
return;
Expand Down
40 changes: 38 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ type OptimisticChatReport = Pick<
| 'parentReportActionID'
| 'parentReportID'
| 'participantAccountIDs'
| 'visibleChatMemberAccountIDs'
| 'policyID'
| 'reportID'
| 'reportName'
Expand Down Expand Up @@ -265,6 +266,7 @@ type OptimisticTaskReport = Pick<
| 'description'
| 'ownerAccountID'
| 'participantAccountIDs'
| 'visibleChatMemberAccountIDs'
| 'managerID'
| 'type'
| 'parentReportID'
Expand Down Expand Up @@ -302,6 +304,7 @@ type OptimisticIOUReport = Pick<
| 'managerID'
| 'ownerAccountID'
| 'participantAccountIDs'
| 'visibleChatMemberAccountIDs'
| 'reportID'
| 'state'
| 'stateNum'
Expand Down Expand Up @@ -2508,14 +2511,19 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number
const formattedTotal = CurrencyUtils.convertToDisplayString(total, currency);
const personalDetails = getPersonalDetailsForAccountID(payerAccountID);
const payerEmail = 'login' in personalDetails ? personalDetails.login : '';

// When creating a report the participantsAccountIDs and visibleChatMemberAccountIDs are the same
const participantsAccountIDs = [payeeAccountID, payerAccountID];

return {
type: CONST.REPORT.TYPE.IOU,
cachedTotal: formattedTotal,
chatReportID,
currency,
managerID: payerAccountID,
ownerAccountID: payeeAccountID,
participantAccountIDs: [payeeAccountID, payerAccountID],
participantAccountIDs: participantsAccountIDs,
visibleChatMemberAccountIDs: participantsAccountIDs,
reportID: generateReportID(),
state: CONST.REPORT.STATE.SUBMITTED,
stateNum: isSendingMoney ? CONST.REPORT.STATE_NUM.SUBMITTED : CONST.REPORT.STATE_NUM.PROCESSING,
Expand Down Expand Up @@ -3051,7 +3059,9 @@ function buildOptimisticChatReport(
ownerAccountID: ownerAccountID || CONST.REPORT.OWNER_ACCOUNT_ID_FAKE,
parentReportActionID,
parentReportID,
// When creating a report the participantsAccountIDs and visibleChatMemberAccountIDs are the same
participantAccountIDs: participantList,
visibleChatMemberAccountIDs: participantList,
policyID,
reportID: generateReportID(),
reportName,
Expand Down Expand Up @@ -3253,12 +3263,16 @@ function buildOptimisticTaskReport(
description?: string,
policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE,
): OptimisticTaskReport {
// When creating a report the participantsAccountIDs and visibleChatMemberAccountIDs are the same
const participantsAccountIDs = assigneeAccountID && assigneeAccountID !== ownerAccountID ? [assigneeAccountID] : [];

return {
reportID: generateReportID(),
reportName: title,
description,
ownerAccountID,
participantAccountIDs: assigneeAccountID && assigneeAccountID !== ownerAccountID ? [assigneeAccountID] : [],
participantAccountIDs: participantsAccountIDs,
visibleChatMemberAccountIDs: participantsAccountIDs,
managerID: assigneeAccountID,
type: CONST.REPORT.TYPE.TASK,
parentReportID,
Expand Down Expand Up @@ -4085,6 +4099,8 @@ function getTaskAssigneeChatOnyxData(

/**
* Returns an array of the participants Ids of a report
*
* @deprecated Use getVisibleMemberIDs instead
*/
function getParticipantsIDs(report: OnyxEntry<Report>): number[] {
if (!report) {
Expand All @@ -4102,6 +4118,25 @@ function getParticipantsIDs(report: OnyxEntry<Report>): number[] {
return participants;
}

/**
* Returns an array of the visible member accountIDs for a report*
*/
function getVisibleMemberIDs(report: OnyxEntry<Report>): number[] {
if (!report) {
return [];
}

const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs ?? [];

// Build participants list for IOU/expense reports
if (isMoneyRequestReport(report)) {
const onlyTruthyValues = [report.managerID, report.ownerAccountID, ...visibleChatMemberAccountIDs].filter(Boolean) as number[];
const onlyUnique = [...new Set([...onlyTruthyValues])];
return onlyUnique;
}
return visibleChatMemberAccountIDs;
}

/**
* Return iou report action display message
*/
Expand Down Expand Up @@ -4420,6 +4455,7 @@ export {
getTransactionDetails,
getTaskAssigneeChatOnyxData,
getParticipantsIDs,
getVisibleMemberIDs,
canEditMoneyRequest,
canEditFieldOfMoneyRequest,
buildTransactionThread,
Expand Down
6 changes: 3 additions & 3 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ function getOrderedReportIDs(
[currentReportId, allReports, betas, policies, priorityMode, allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentReportId}`]?.length || 1],
(key, value: unknown) => {
/**
* Exclude 'participantAccountIDs', 'participants' and 'lastMessageText' not to overwhelm a cached key value with huge data,
* Exclude some properties not to overwhelm a cached key value with huge data,
* which we don't need to store in a cacheKey
*/
if (key === 'participantAccountIDs' || key === 'participants' || key === 'lastMessageText') {
if (key === 'participantAccountIDs' || key === 'participants' || key === 'lastMessageText' || key === 'visibleChatMemberAccountIDs') {
return undefined;
}

Expand Down Expand Up @@ -305,7 +305,7 @@ function getOptionData(
result.isPinned = report.isPinned;
result.iouReportID = report.iouReportID;
result.keyForList = String(report.reportID);
result.tooltipText = ReportUtils.getReportParticipantsTitle(report.participantAccountIDs ?? []);
result.tooltipText = ReportUtils.getReportParticipantsTitle(report.visibleChatMemberAccountIDs ?? []);
result.hasOutstandingChildRequest = report.hasOutstandingChildRequest;
result.parentReportID = report.parentReportID ?? '';
result.isWaitingOnBankAccount = report.isWaitingOnBankAccount;
Expand Down
9 changes: 8 additions & 1 deletion src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,15 @@ function buildAnnounceRoomMembersOnyxData(policyID, accountIDs) {
return announceRoomMembers;
}

// Everyone in special policy rooms is visible
const participantAccountIDs = [...announceReport.participantAccountIDs, ...accountIDs];

announceRoomMembers.onyxOptimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
participantAccountIDs: [...announceReport.participantAccountIDs, ...accountIDs],
participantAccountIDs,
visibleChatMemberAccountIDs: participantAccountIDs,
},
});

Expand All @@ -287,6 +291,7 @@ function buildAnnounceRoomMembersOnyxData(policyID, accountIDs) {
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
participantAccountIDs: announceReport.participantAccountIDs,
visibleChatMemberAccountIDs: announceReport.visibleChatMemberAccountIDs,
},
});
return announceRoomMembers;
Expand Down Expand Up @@ -315,6 +320,7 @@ function removeOptimisticAnnounceRoomMembers(policyID, accountIDs) {
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
participantAccountIDs: [...remainUsers],
visibleChatMemberAccountIDs: [...remainUsers],
},
});

Expand All @@ -323,6 +329,7 @@ function removeOptimisticAnnounceRoomMembers(policyID, accountIDs) {
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
participantAccountIDs: announceReport.participantAccountIDs,
visibleChatMemberAccountIDs: announceReport.visibleChatMemberAccountIDs,
},
});
return announceRoomMembers;
Expand Down
9 changes: 9 additions & 0 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,9 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record<string
const participantAccountIDsAfterInvitation = [...new Set([...(report?.participantAccountIDs ?? []), ...inviteeAccountIDs])].filter(
(accountID): accountID is number => typeof accountID === 'number',
);
const visibleMemberAccountIDsAfterInvitation = [...new Set([...(report?.visibleChatMemberAccountIDs ?? []), ...inviteeAccountIDs])].filter(
(accountID): accountID is number => typeof accountID === 'number',
);

type PersonalDetailsOnyxData = {
optimisticData: OnyxUpdate[];
Expand All @@ -2170,6 +2173,7 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record<string
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
participantAccountIDs: participantAccountIDsAfterInvitation,
visibleChatMemberAccountIDs: visibleMemberAccountIDsAfterInvitation,
},
},
...newPersonalDetailsOnyxData.optimisticData,
Expand All @@ -2183,6 +2187,7 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record<string
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
participantAccountIDs: report.participantAccountIDs,
visibleChatMemberAccountIDs: report.visibleChatMemberAccountIDs,
},
},
...newPersonalDetailsOnyxData.failureData,
Expand All @@ -2206,13 +2211,15 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) {
const report = allReports?.[reportID];

const participantAccountIDsAfterRemoval = report?.participantAccountIDs?.filter((id: number) => !targetAccountIDs.includes(id));
const visibleChatMemberAccountIDsAfterRemoval = report?.visibleChatMemberAccountIDs?.filter((id: number) => !targetAccountIDs.includes(id));

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
participantAccountIDs: participantAccountIDsAfterRemoval,
visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval,
},
},
];
Expand All @@ -2223,6 +2230,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) {
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
participantAccountIDs: report?.participantAccountIDs,
visibleChatMemberAccountIDs: report?.visibleChatMemberAccountIDs,
},
},
];
Expand All @@ -2235,6 +2243,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) {
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
participantAccountIDs: participantAccountIDsAfterRemoval,
visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval,
},
},
];
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,10 @@ function editTaskAssignee(report, ownerAccountID, assigneeEmail, assigneeAccount
// Check if the assignee actually changed
if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== ownerAccountID && assigneeChatReport) {
const participants = lodashGet(report, 'participantAccountIDs', []);
if (!participants.includes(assigneeAccountID)) {
const visibleMembers = lodashGet(report, 'visibleChatMemberAccountIDs', []);
if (!visibleMembers.includes(assigneeAccountID)) {
optimisticReport.participantAccountIDs = [...participants, assigneeAccountID];
optimisticReport.visibleChatMemberAccountIDs = [...visibleMembers, assigneeAccountID];
}

assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function ReportDetailsPage(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps -- policy is a dependency because `getChatRoomSubtitle` calls `getPolicyName` which in turn retrieves the value from the `policy` value stored in Onyx
const chatRoomSubtitle = useMemo(() => ReportUtils.getChatRoomSubtitle(props.report), [props.report, policy]);
const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(props.report);
const participants = useMemo(() => ReportUtils.getParticipantsIDs(props.report), [props.report]);
const participants = useMemo(() => ReportUtils.getVisibleMemberIDs(props.report), [props.report]);

const isGroupDMChat = useMemo(() => ReportUtils.isDM(props.report) && participants.length > 1, [props.report, participants.length]);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReportParticipantsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const defaultProps = {
* @return {Array}
*/
const getAllParticipants = (report, personalDetails, translate) =>
_.chain(ReportUtils.getParticipantsIDs(report))
_.chain(ReportUtils.getVisibleMemberIDs(report))
.map((accountID, index) => {
const userPersonalDetail = lodashGet(personalDetails, accountID, {displayName: personalDetails.displayName || translate('common.hidden'), avatar: ''});
const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login || '') || translate('common.hidden');
Expand Down
5 changes: 4 additions & 1 deletion src/pages/RoomInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ function RoomInvitePage(props) {
const [userToInvite, setUserToInvite] = useState(null);

// Any existing participants and Expensify emails should not be eligible for invitation
const excludedUsers = useMemo(() => [...PersonalDetailsUtils.getLoginsByAccountIDs(lodashGet(props.report, 'participantAccountIDs', [])), ...CONST.EXPENSIFY_EMAILS], [props.report]);
const excludedUsers = useMemo(
() => [...PersonalDetailsUtils.getLoginsByAccountIDs(lodashGet(props.report, 'visibleChatMemberAccountIDs', [])), ...CONST.EXPENSIFY_EMAILS],
[props.report],
);

useEffect(() => {
const inviteOptions = OptionsListUtils.getMemberInviteOptions(props.personalDetails, props.betas, searchTerm, excludedUsers);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/RoomMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function RoomMembersPage(props) {
const getMemberOptions = () => {
let result = [];

_.each(props.report.participantAccountIDs, (accountID) => {
_.each(props.report.visibleChatMemberAccountIDs, (accountID) => {
const details = personalDetails[accountID];

if (!details) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ShareCodePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ShareCodePage extends React.Component {
}
if (ReportUtils.isMoneyRequestReport(this.props.report)) {
// generate subtitle from participants
return _.map(ReportUtils.getParticipantsIDs(this.props.report), (accountID) => ReportUtils.getDisplayNameForParticipant(accountID)).join(' & ');
return _.map(ReportUtils.getVisibleMemberIDs(this.props.report), (accountID) => ReportUtils.getDisplayNameForParticipant(accountID)).join(' & ');
}

if (isReport) {
Expand Down
3 changes: 3 additions & 0 deletions src/pages/reportPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export default PropTypes.shape({
/** List of accountIDs of participants of the report */
participantAccountIDs: PropTypes.arrayOf(PropTypes.number),

/** List of accountIDs of visible members of the report */
visibleChatMemberAccountIDs: PropTypes.arrayOf(PropTypes.number),

/** Linked policy's ID */
policyID: PropTypes.string,

Expand Down
1 change: 1 addition & 0 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ type Report = {
lastActorAccountID?: number;
ownerAccountID?: number;
participantAccountIDs?: number[];
visibleChatMemberAccountIDs?: number[];
total?: number;
currency?: string;
parentReportActionIDs?: number[];
Expand Down
Loading

0 comments on commit 9b74851

Please sign in to comment.