Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get last actor details from last report action if not present in personal details #15895

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Onyx from 'react-native-onyx';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import lodashOrderBy from 'lodash/orderBy';
import Str from 'expensify-common/lib/str';
import ONYXKEYS from '../ONYXKEYS';
Expand Down Expand Up @@ -249,7 +250,16 @@ function getOptionData(reportID) {
lastMessageTextFromReport = Str.htmlDecode(report ? report.lastMessageText : '');
}

const lastActorDetails = personalDetails[report.lastActorEmail] || null;
// If the last actor's details are not currently saved in Onyx Collection,
// then try to get that from the last report action.
let lastActorDetails = personalDetails[report.lastActorEmail] || null;
if (!lastActorDetails && lastReportActions[report.reportID] && lastReportActions[report.reportID].actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED) {
const lastActorDisplayName = lodashGet(lastReportActions[report.reportID], 'person[0].text');
Copy link
Member

@parasharrajat parasharrajat Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question to me: Are we sure that lastReport action and lastActorEmail from reportData are in sync at all times? Is there any possibility that report action is not yet synced but report data is updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Started digging this info.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be fine, the last report message is whats in the LHN, the data should be there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also seems like they are synced, but we could check if the report.lastActorEmail and lastReportActions actorEmail are the same and only use the display name of it if true. Perhaps it's worth the effort, please let me know the resolution to this doubt

lastActorDetails = lastActorDisplayName ? {
displayName: lastActorDisplayName,
login: report.lastActorEmail,
} : null;
}
let lastMessageText = hasMultipleParticipants && lastActorDetails && (lastActorDetails.login !== currentUserLogin.email)
? `${lastActorDetails.displayName}: `
: '';
Expand Down