Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
paultsimura committed Feb 20, 2024
1 parent ab40861 commit c4dcda1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,10 @@ function getCurrentUserAvatarOrDefault(): UserUtils.AvatarSource {
return allPersonalDetails?.[currentUserAccountID ?? '']?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID);
}

function getCurrentUserDisplayNameOrEmail(): string | undefined {
return allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail;
}

/**
* Returns the necessary reportAction onyx data to indicate that the chat has been created optimistically
* @param [created] - Action created time
Expand All @@ -3464,7 +3468,7 @@ function buildOptimisticCreatedReportAction(emailCreatingAction: string, created
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail,
text: getCurrentUserDisplayNameOrEmail(),
},
],
automatic: false,
Expand Down Expand Up @@ -3500,7 +3504,7 @@ function buildOptimisticRenamedRoomReportAction(newName: string, oldName: string
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail,
text: getCurrentUserDisplayNameOrEmail(),
},
],
originalMessage: {
Expand Down Expand Up @@ -3541,7 +3545,7 @@ function buildOptimisticHoldReportAction(comment: string, created = DateUtils.ge
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail,
text: getCurrentUserDisplayNameOrEmail(),
},
],
automatic: false,
Expand Down Expand Up @@ -3572,7 +3576,7 @@ function buildOptimisticUnHoldReportAction(created = DateUtils.getDBTime()): Opt
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'normal',
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail,
text: getCurrentUserDisplayNameOrEmail(),
},
],
automatic: false,
Expand Down Expand Up @@ -3617,7 +3621,7 @@ function buildOptimisticEditedTaskFieldReportAction({title, description}: Task):
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail,
text: getCurrentUserDisplayNameOrEmail(),
},
],
automatic: false,
Expand All @@ -3644,7 +3648,7 @@ function buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID: numbe
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail,
text: getCurrentUserDisplayNameOrEmail(),
},
],
automatic: false,
Expand Down Expand Up @@ -3687,7 +3691,7 @@ function buildOptimisticClosedReportAction(emailClosingReport: string, policyNam
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail,
text: getCurrentUserDisplayNameOrEmail(),
},
],
reportActionID: NumberUtils.rand64(),
Expand Down

0 comments on commit c4dcda1

Please sign in to comment.