Skip to content

Commit

Permalink
Merge pull request #34237 from FitseTLT/fix-include-current-user-on-m…
Browse files Browse the repository at this point in the history
…embers-list

Fix - include current user in group chat members list
  • Loading branch information
MonilBhavsar authored Jan 24, 2024
2 parents c0fbb97 + eb3e0a2 commit 5d41d84
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 66 deletions.
146 changes: 82 additions & 64 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,84 @@ function getWorkspaceIcon(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> =
return workspaceIcon;
}

/**
* Checks if a report is a group chat.
*
* A report is a group chat if it meets the following conditions:
* - Not a chat thread.
* - Not a task report.
* - Not a money request / IOU report.
* - Not an archived room.
* - Not a public / admin / announce chat room (chat type doesn't match any of the specified types).
* - More than 1 participant (note that participantAccountIDs excludes the current user).
*
*/
function isGroupChat(report: OnyxEntry<Report>): boolean {
return Boolean(
report &&
!isChatThread(report) &&
!isTaskReport(report) &&
!isMoneyRequestReport(report) &&
!isArchivedRoom(report) &&
!Object.values(CONST.REPORT.CHAT_TYPE).some((chatType) => chatType === getChatType(report)) &&
(report.participantAccountIDs?.length ?? 0) > 1,
);
}

function getGroupChatParticipantIDs(participants: number[]): number[] {
return [...new Set([...participants, ...(currentUserAccountID ? [currentUserAccountID] : [])])];
}

/**
* Returns an array of the participants Ids of a report
*
* @deprecated Use getVisibleMemberIDs instead
*/
function getParticipantsIDs(report: OnyxEntry<Report>): number[] {
if (!report) {
return [];
}

const participants = report.participantAccountIDs ?? [];

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

if (isGroupChat(report)) {
return getGroupChatParticipantIDs(participants);
}

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;
}

if (isGroupChat(report)) {
return getGroupChatParticipantIDs(visibleChatMemberAccountIDs);
}

return visibleChatMemberAccountIDs;
}

/**
* Returns the appropriate icons for the given chat report using the stored personalDetails.
* The Avatar sources can be URLs or Icon components according to the chat type.
Expand Down Expand Up @@ -1575,6 +1653,10 @@ function getIcons(
return isPayer ? [managerIcon, ownerIcon] : [ownerIcon, managerIcon];
}

if (isGroupChat(report)) {
return getIconsForParticipants(getVisibleMemberIDs(report), personalDetails);
}

return getIconsForParticipants(report?.participantAccountIDs ?? [], personalDetails);
}

Expand Down Expand Up @@ -4366,46 +4448,6 @@ function getTaskAssigneeChatOnyxData(
};
}

/**
* Returns an array of the participants Ids of a report
*
* @deprecated Use getVisibleMemberIDs instead
*/
function getParticipantsIDs(report: OnyxEntry<Report>): number[] {
if (!report) {
return [];
}

const participants = report.participantAccountIDs ?? [];

// Build participants list for IOU/expense reports
if (isMoneyRequestReport(report)) {
const onlyTruthyValues = [report.managerID, report.ownerAccountID, ...participants].filter(Boolean) as number[];
const onlyUnique = [...new Set([...onlyTruthyValues])];
return onlyUnique;
}
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 @@ -4462,30 +4504,6 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry<ReportAction>)
});
}

/**
* Checks if a report is a group chat.
*
* A report is a group chat if it meets the following conditions:
* - Not a chat thread.
* - Not a task report.
* - Not a money request / IOU report.
* - Not an archived room.
* - Not a public / admin / announce chat room (chat type doesn't match any of the specified types).
* - More than 2 participants.
*
*/
function isGroupChat(report: OnyxEntry<Report>): boolean {
return Boolean(
report &&
!isChatThread(report) &&
!isTaskReport(report) &&
!isMoneyRequestReport(report) &&
!isArchivedRoom(report) &&
!Object.values(CONST.REPORT.CHAT_TYPE).some((chatType) => chatType === getChatType(report)) &&
(report.participantAccountIDs?.length ?? 0) > 2,
);
}

function shouldUseFullTitleToDisplay(report: OnyxEntry<Report>): boolean {
return isMoneyRequestReport(report) || isPolicyExpenseChat(report) || isChatRoom(report) || isChatThread(report) || isTaskReport(report);
}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/ReportParticipantsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ function ReportParticipantsPage(props) {
<FullPageNotFoundView shouldShow={_.isEmpty(props.report) || ReportUtils.isArchivedRoom(props.report)}>
<HeaderWithBackButton
title={props.translate(
ReportUtils.isChatRoom(props.report) ||
ReportUtils.isGroupChat(props.report) ||
ReportUtils.isChatRoom(props.report) ||
ReportUtils.isPolicyExpenseChat(props.report) ||
ReportUtils.isChatThread(props.report) ||
ReportUtils.isTaskReport(props.report) ||
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function HeaderView(props) {
const {translate} = useLocalize();
const theme = useTheme();
const styles = useThemeStyles();
const participants = lodashGet(props.report, 'participantAccountIDs', []);
const participants = ReportUtils.getParticipantsIDs(props.report);
const participantPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, props.personalDetails);
const isMultipleParticipant = participants.length > 1;
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(participantPersonalDetails, isMultipleParticipant);
Expand Down

0 comments on commit 5d41d84

Please sign in to comment.