From 12ca6d49cc6f7ac282058b780cb9903391a8f0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 25 Apr 2022 17:18:10 -0500 Subject: [PATCH 01/11] pass lastActionType property --- src/libs/actions/Report.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 62b41231b58e..9c7b772182ad 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -189,6 +189,7 @@ function getChatReportName(fullReport, chatType, oldPolicyName) { function getSimplifiedReportObject(report) { const createTimestamp = lodashGet(report, 'lastActionCreated', 0); const lastMessageTimestamp = moment.utc(createTimestamp).unix(); + const lastActionType = lodashGet(report, ['lastActionType'], ''); const lastActionMessage = lodashGet(report, ['lastActionMessage', 'html'], ''); const isLastMessageAttachment = new RegExp(`]*${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}\\s*=\\s*"[^"]*"[^>]*>`, 'gi').test(lastActionMessage); const chatType = lodashGet(report, ['reportNameValuePairs', 'chatType'], ''); @@ -228,6 +229,7 @@ function getSimplifiedReportObject(report) { maxSequenceNumber: lodashGet(report, 'reportActionCount', 0), participants: getParticipantEmailsFromReport(report), isPinned: report.isPinned, + lastActionType, lastVisitedTimestamp: lodashGet(report, [ 'reportNameValuePairs', `lastRead_${currentUserAccountID}`, From bc4148c2b1a3265822297f0600733cf6413078c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 25 Apr 2022 17:41:37 -0500 Subject: [PATCH 02/11] add getLastAction to ReportActions --- src/libs/actions/ReportActions.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/ReportActions.js b/src/libs/actions/ReportActions.js index 780fe2f79e4e..d5ff01405c80 100644 --- a/src/libs/actions/ReportActions.js +++ b/src/libs/actions/ReportActions.js @@ -111,9 +111,14 @@ function getLastVisibleMessageText(reportID) { ); } +function getLastAction(reportID) { + return _.last(reportActions[reportID]); +} + export { isReportMissingActions, dangerouslyGetReportActionsMaxSequenceNumber, getDeletedCommentsCount, + getLastAction, getLastVisibleMessageText, }; From 9aef425518e817fa7112c6d2847d4de228bbb3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 25 Apr 2022 17:42:49 -0500 Subject: [PATCH 03/11] get last message according to last action --- src/libs/OptionsListUtils.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 6c9b105e1d38..bf2e9da72754 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -9,6 +9,7 @@ import CONST from '../CONST'; import * as ReportUtils from './reportUtils'; import * as Localize from './Localize'; import Permissions from './Permissions'; +import * as ReportActions from './actions/ReportActions'; /** * OptionsListUtils is used to build a list options passed to the OptionsList component. Several different UI views can @@ -221,11 +222,20 @@ function createOption(logins, personalDetails, report, { const lastMessageTextFromReport = ReportUtils.isReportMessageAttachment({text: lodashGet(report, 'lastMessageText', ''), html: lodashGet(report, 'lastMessageHtml', '')}) ? `[${Localize.translateLocal('common.attachment')}]` : Str.htmlDecode(lodashGet(report, 'lastMessageText', '')); - let lastMessageText = report && !isArchivedRoom && hasMultipleParticipants && lastActorDetails + let lastMessageText = report && hasMultipleParticipants && lastActorDetails ? `${lastActorDetails.displayName}: ` : ''; lastMessageText += report ? lastMessageTextFromReport : ''; + if (isPolicyExpenseChat && isArchivedRoom) { + const reportClosedAction = ReportActions.getLastAction(report.reportID); + const archiveReason = lodashGet(reportClosedAction, 'originalMessage.reason', CONST.REPORT.ARCHIVE_REASON.DEFAULT); + lastMessageText = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { + displayName: `${lastActorDetails.displayName}`, + policyName: `${ReportUtils.getPolicyName(report, policies)}`, + }); + } + const tooltipText = ReportUtils.getReportParticipantsTitle(lodashGet(report, ['participants'], [])); const subtitle = ReportUtils.getChatRoomSubtitle(report, policies); let text; From 1dd174387a08ccff7af5b07ef6c3199f2fadbbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 25 Apr 2022 17:43:36 -0500 Subject: [PATCH 04/11] remove unnessary lastActionType --- src/libs/actions/Report.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 9c7b772182ad..62b41231b58e 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -189,7 +189,6 @@ function getChatReportName(fullReport, chatType, oldPolicyName) { function getSimplifiedReportObject(report) { const createTimestamp = lodashGet(report, 'lastActionCreated', 0); const lastMessageTimestamp = moment.utc(createTimestamp).unix(); - const lastActionType = lodashGet(report, ['lastActionType'], ''); const lastActionMessage = lodashGet(report, ['lastActionMessage', 'html'], ''); const isLastMessageAttachment = new RegExp(`]*${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}\\s*=\\s*"[^"]*"[^>]*>`, 'gi').test(lastActionMessage); const chatType = lodashGet(report, ['reportNameValuePairs', 'chatType'], ''); @@ -229,7 +228,6 @@ function getSimplifiedReportObject(report) { maxSequenceNumber: lodashGet(report, 'reportActionCount', 0), participants: getParticipantEmailsFromReport(report), isPinned: report.isPinned, - lastActionType, lastVisitedTimestamp: lodashGet(report, [ 'reportNameValuePairs', `lastRead_${currentUserAccountID}`, From 0efe8928add524f7c0b52b0223fe59f3596feb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 25 Apr 2022 17:58:59 -0500 Subject: [PATCH 05/11] clean up a little bit the logic to get last message --- src/libs/OptionsListUtils.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index bf2e9da72754..e1742be0d2da 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -228,11 +228,10 @@ function createOption(logins, personalDetails, report, { lastMessageText += report ? lastMessageTextFromReport : ''; if (isPolicyExpenseChat && isArchivedRoom) { - const reportClosedAction = ReportActions.getLastAction(report.reportID); - const archiveReason = lodashGet(reportClosedAction, 'originalMessage.reason', CONST.REPORT.ARCHIVE_REASON.DEFAULT); + const archiveReason = lodashGet(ReportActions.getLastAction(report.reportID), 'originalMessage.reason', CONST.REPORT.ARCHIVE_REASON.DEFAULT); lastMessageText = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { - displayName: `${lastActorDetails.displayName}`, - policyName: `${ReportUtils.getPolicyName(report, policies)}`, + displayName: lastActorDetails.displayName, + policyName: ReportUtils.getPolicyName(report, policies), }); } From d96df49d581bd91fe98a8d2f32793a5dbd590a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 25 Apr 2022 18:08:10 -0500 Subject: [PATCH 06/11] fix warning message with SubcriptAvatar secondary icon --- src/components/OptionRow.js | 2 +- src/pages/home/HeaderView.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/OptionRow.js b/src/components/OptionRow.js index 9d8a4119eb4c..c6d318d8009b 100644 --- a/src/components/OptionRow.js +++ b/src/components/OptionRow.js @@ -163,7 +163,7 @@ const OptionRow = (props) => { { !_.isEmpty(props.option.icons) && ( - props.option.shouldShowSubscript ? ( + props.option.shouldShowSubscript && props.option.icons.length > 1 ? ( { }} style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]} > - {shouldShowSubscript ? ( + {shouldShowSubscript && icons.length > 1 ? ( Date: Tue, 26 Apr 2022 13:14:54 -0500 Subject: [PATCH 07/11] don't show SubscriptAvatar when workspace is archived --- src/components/OptionRow.js | 2 +- src/libs/OptionsListUtils.js | 2 +- src/pages/home/HeaderView.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/OptionRow.js b/src/components/OptionRow.js index c6d318d8009b..9d8a4119eb4c 100644 --- a/src/components/OptionRow.js +++ b/src/components/OptionRow.js @@ -163,7 +163,7 @@ const OptionRow = (props) => { { !_.isEmpty(props.option.icons) && ( - props.option.shouldShowSubscript && props.option.icons.length > 1 ? ( + props.option.shouldShowSubscript ? ( { // these users via alternative means. It is possible to request a call with Concierge so we leave the option for them. const shouldShowCallButton = isConcierge || !isAutomatedExpensifyAccount; const avatarTooltip = isChatRoom ? undefined : _.pluck(displayNamesWithTooltips, 'tooltip'); - const shouldShowSubscript = isPolicyExpenseChat && !props.report.isOwnPolicyExpenseChat; + const shouldShowSubscript = isPolicyExpenseChat && !props.report.isOwnPolicyExpenseChat && !ReportUtils.isArchivedRoom(props.report); const icons = ReportUtils.getIcons(props.report, props.personalDetails, props.policies); return ( @@ -136,7 +136,7 @@ const HeaderView = (props) => { }} style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]} > - {shouldShowSubscript && icons.length > 1 ? ( + {shouldShowSubscript ? ( Date: Tue, 26 Apr 2022 13:22:06 -0500 Subject: [PATCH 08/11] add reportActions subscription in OptionListUtils --- src/libs/OptionsListUtils.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 733158ffb53d..aa356f2b875a 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -10,6 +10,7 @@ import * as ReportUtils from './reportUtils'; import * as Localize from './Localize'; import Permissions from './Permissions'; import * as ReportActions from './actions/ReportActions'; +import * as CollectionUtils from './CollectionUtils'; /** * OptionsListUtils is used to build a list options passed to the OptionsList component. Several different UI views can @@ -77,6 +78,18 @@ Onyx.connect({ }, }); +const reportActions = {}; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, + callback: (actions, key) => { + if (!key || !actions) { + return; + } + const reportID = CollectionUtils.extractCollectionItemID(key); + reportActions[reportID] = _.toArray(actions); + }, +}); + // We are initializing a default avatar here so that we use the same default color for each user we are inviting. This // will update when the OptionsListUtils re-loads. But will stay the same color for the life of the JS session. const defaultAvatarForUserToInvite = ReportUtils.getDefaultAvatar(); From e15b84cb4da2dd601e824760620dcc00fc90ea9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Tue, 26 Apr 2022 13:22:40 -0500 Subject: [PATCH 09/11] remove getLastAction from ReportActions --- src/libs/actions/ReportActions.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libs/actions/ReportActions.js b/src/libs/actions/ReportActions.js index d5ff01405c80..780fe2f79e4e 100644 --- a/src/libs/actions/ReportActions.js +++ b/src/libs/actions/ReportActions.js @@ -111,14 +111,9 @@ function getLastVisibleMessageText(reportID) { ); } -function getLastAction(reportID) { - return _.last(reportActions[reportID]); -} - export { isReportMissingActions, dangerouslyGetReportActionsMaxSequenceNumber, getDeletedCommentsCount, - getLastAction, getLastVisibleMessageText, }; From 5b2d7c6615a27b1403298017d9e5048aac2f7222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Tue, 26 Apr 2022 13:24:45 -0500 Subject: [PATCH 10/11] use reportActions object to get archiveReason --- src/libs/OptionsListUtils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index aa356f2b875a..d06939b2321c 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -9,7 +9,6 @@ import CONST from '../CONST'; import * as ReportUtils from './reportUtils'; import * as Localize from './Localize'; import Permissions from './Permissions'; -import * as ReportActions from './actions/ReportActions'; import * as CollectionUtils from './CollectionUtils'; /** @@ -241,7 +240,7 @@ function createOption(logins, personalDetails, report, { lastMessageText += report ? lastMessageTextFromReport : ''; if (isPolicyExpenseChat && isArchivedRoom) { - const archiveReason = lodashGet(ReportActions.getLastAction(report.reportID), 'originalMessage.reason', CONST.REPORT.ARCHIVE_REASON.DEFAULT); + const archiveReason = lodashGet(_.last(reportActions[report.reportID]), 'originalMessage.reason', CONST.REPORT.ARCHIVE_REASON.DEFAULT); lastMessageText = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { displayName: lastActorDetails.displayName, policyName: ReportUtils.getPolicyName(report, policies), From b6fefbcaf4747d5fc8fc99f35099c83f422a3a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Tue, 26 Apr 2022 15:48:56 -0500 Subject: [PATCH 11/11] change reportActions to lastReportActions --- src/libs/OptionsListUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index d06939b2321c..04413d6e40b0 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -77,7 +77,7 @@ Onyx.connect({ }, }); -const reportActions = {}; +const lastReportActions = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, callback: (actions, key) => { @@ -85,7 +85,7 @@ Onyx.connect({ return; } const reportID = CollectionUtils.extractCollectionItemID(key); - reportActions[reportID] = _.toArray(actions); + lastReportActions[reportID] = _.last(_.toArray(actions)); }, }); @@ -240,7 +240,7 @@ function createOption(logins, personalDetails, report, { lastMessageText += report ? lastMessageTextFromReport : ''; if (isPolicyExpenseChat && isArchivedRoom) { - const archiveReason = lodashGet(_.last(reportActions[report.reportID]), 'originalMessage.reason', CONST.REPORT.ARCHIVE_REASON.DEFAULT); + const archiveReason = lodashGet(lastReportActions[report.reportID], 'originalMessage.reason', CONST.REPORT.ARCHIVE_REASON.DEFAULT); lastMessageText = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { displayName: lastActorDetails.displayName, policyName: ReportUtils.getPolicyName(report, policies),