Skip to content

Commit

Permalink
Merge pull request #34376 from paultsimura/fix/34054-join-empty-thread
Browse files Browse the repository at this point in the history
fix: Show Join & Leave buttons on empty threads
  • Loading branch information
srikarparsi authored Jan 15, 2024
2 parents 29e73ef + 200140e commit d5f0f6f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
19 changes: 16 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,13 +1100,25 @@ function getReportNotificationPreference(report: OnyxEntry<Report>): string | nu
}

/**
* Returns whether or not the author of the action is this user
*
* Checks if the current user is the action's author
*/
function isActionCreator(reportAction: OnyxEntry<ReportAction>): boolean {
function isActionCreator(reportAction: OnyxEntry<ReportAction> | Partial<ReportAction>): boolean {
return reportAction?.actorAccountID === currentUserAccountID;
}

/**
* Returns the notification preference of the action's child report if it exists.
* Otherwise, calculates it based on the action's authorship.
*/
function getChildReportNotificationPreference(reportAction: OnyxEntry<ReportAction> | Partial<ReportAction>): NotificationPreference {
const childReportNotificationPreference = reportAction?.childReportNotificationPreference ?? '';
if (childReportNotificationPreference) {
return childReportNotificationPreference;
}

return isActionCreator(reportAction) ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
}

/**
* Can only delete if the author is this user and the action is an ADDCOMMENT action or an IOU action in an unsettled report, or if the user is a
* policy admin
Expand Down Expand Up @@ -4600,6 +4612,7 @@ export {
getReportFieldTitle,
shouldDisplayThreadReplies,
shouldDisableThread,
getChildReportNotificationPreference,
};

export type {ExpenseOriginalMessage, OptionData, OptimisticChatReport, OptimisticCreatedReportAction};
2 changes: 1 addition & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ function navigateToAndOpenChildReport(childReportID = '0', parentReportAction: P
'',
undefined,
undefined,
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
ReportUtils.getChildReportNotificationPreference(parentReportAction),
parentReportAction.reportActionID,
parentReportID,
);
Expand Down
4 changes: 1 addition & 3 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ function HeaderView(props) {
const isAutomatedExpensifyAccount = ReportUtils.hasSingleParticipant(props.report) && ReportUtils.hasAutomatedExpensifyAccountIDs(participants);
const parentReportAction = ReportActionsUtils.getParentReportAction(props.report);
const isCanceledTaskReport = ReportUtils.isCanceledTaskReport(props.report, parentReportAction);
const lastVisibleMessage = ReportActionsUtils.getLastVisibleMessage(props.report.reportID);
const isWhisperAction = ReportActionsUtils.isWhisperAction(parentReportAction);
const isEmptyChat = !props.report.lastMessageText && !props.report.lastMessageTranslationKey && !lastVisibleMessage.lastMessageText && !lastVisibleMessage.lastMessageTranslationKey;
const isUserCreatedPolicyRoom = ReportUtils.isUserCreatedPolicyRoom(props.report);
const isPolicyMember = useMemo(() => !_.isEmpty(props.policy), [props.policy]);
const canLeaveRoom = ReportUtils.canLeaveRoom(props.report, isPolicyMember);
Expand Down Expand Up @@ -153,7 +151,7 @@ function HeaderView(props) {
),
);

const canJoinOrLeave = (isChatThread && !isEmptyChat) || isUserCreatedPolicyRoom || canLeaveRoom;
const canJoinOrLeave = isChatThread || isUserCreatedPolicyRoom || canLeaveRoom;
const canJoin = canJoinOrLeave && !isWhisperAction && props.report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
const canLeave = canJoinOrLeave && ((isChatThread && props.report.notificationPreference.length) || isUserCreatedPolicyRoom || canLeaveRoom);
if (canJoin) {
Expand Down
28 changes: 6 additions & 22 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,18 @@ export default [
successTextTranslateKey: '',
successIcon: null,
shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID) => {
let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', '');
if (!childReportNotificationPreference) {
const isActionCreator = ReportUtils.isActionCreator(reportAction);
childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
}
const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction);
const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction);
const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, reportID);
const subscribed = childReportNotificationPreference !== 'hidden';
const subscribed = childReportNotificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
const isCommentAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportUtils.isThreadFirstChat(reportAction, reportID);
const isReportPreviewAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW;
const isIOUAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && !ReportActionsUtils.isSplitBillAction(reportAction);
const isWhisperAction = ReportActionsUtils.isWhisperAction(reportAction);
return !subscribed && !isWhisperAction && (isCommentAction || isReportPreviewAction || isIOUAction) && (!isDeletedAction || shouldDisplayThreadReplies);
},
onPress: (closePopover, {reportAction, reportID}) => {
let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', '');
if (!childReportNotificationPreference) {
const isActionCreator = ReportUtils.isActionCreator(reportAction);
childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
}
const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction);
if (closePopover) {
hideContextMenu(false, () => {
ReportActionComposeFocusManager.focus();
Expand All @@ -196,14 +188,10 @@ export default [
successTextTranslateKey: '',
successIcon: null,
shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID) => {
let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', '');
if (!childReportNotificationPreference) {
const isActionCreator = ReportUtils.isActionCreator(reportAction);
childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
}
const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction);
const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction);
const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, reportID);
const subscribed = childReportNotificationPreference !== 'hidden';
const subscribed = childReportNotificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
if (type !== CONST.CONTEXT_MENU_TYPES.REPORT_ACTION) {
return false;
}
Expand All @@ -213,11 +201,7 @@ export default [
return subscribed && (isCommentAction || isReportPreviewAction || isIOUAction) && (!isDeletedAction || shouldDisplayThreadReplies);
},
onPress: (closePopover, {reportAction, reportID}) => {
let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', '');
if (!childReportNotificationPreference) {
const isActionCreator = ReportUtils.isActionCreator(reportAction);
childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
}
const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction);
if (closePopover) {
hideContextMenu(false, () => {
ReportActionComposeFocusManager.focus();
Expand Down

0 comments on commit d5f0f6f

Please sign in to comment.