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: Welcome message flickers on LHN after message deletion #23341

Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,7 @@ function getLastMessageTextForReport(report) {
// Yeah this is a bit ugly. If the latest report action that is not a whisper has been moderated as pending remove, then set the last message text to the text of the latest visible action that is not a whisper.
const lastNonWhisper = _.find(allSortedReportActions[report.reportID], (action) => !ReportActionUtils.isWhisperAction(action)) || {};
if (ReportActionUtils.isPendingRemove(lastNonWhisper)) {
const latestVisibleAction =
_.find(
allSortedReportActions[report.reportID],
(action) => ReportActionUtils.shouldReportActionBeVisible(action, action.reportActionID) && !ReportActionUtils.isWhisperAction(action),
) || {};
const latestVisibleAction = _.find(allSortedReportActions[report.reportID], (action) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(action)) || {};
lastMessageTextFromReport = lodashGet(latestVisibleAction, 'message[0].text', '');
}
}
Expand Down
106 changes: 59 additions & 47 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ function isReportPreviewAction(reportAction) {
return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW;
}

function isWhisperAction(action) {
return (action.whisperedToAccountIDs || []).length > 0;
}

/**
* @param {Object} reportAction
* @returns {Boolean}
Expand Down Expand Up @@ -270,49 +274,6 @@ function isConsecutiveActionMadeByPreviousActor(reportActions, actionIndex) {
return currentAction.actorAccountID === previousAction.actorAccountID;
}

/**
* @param {String} reportID
* @param {Object} [actionsToMerge]
* @return {Object}
*/
function getLastVisibleAction(reportID, actionsToMerge = {}) {
const actions = _.toArray(lodashMerge({}, allReportActions[reportID], actionsToMerge));
const visibleActions = _.filter(actions, (action) => !isDeletedAction(action));

if (_.isEmpty(visibleActions)) {
return {};
}

return _.max(visibleActions, (action) => moment.utc(action.created).valueOf());
}

/**
* @param {String} reportID
* @param {Object} [actionsToMerge]
* @return {Object}
*/
function getLastVisibleMessage(reportID, actionsToMerge = {}) {
const lastVisibleAction = getLastVisibleAction(reportID, actionsToMerge);
const message = lodashGet(lastVisibleAction, ['message', 0], {});

if (isReportMessageAttachment(message)) {
return {
lastMessageTranslationKey: CONST.TRANSLATION_KEYS.ATTACHMENT,
};
}

if (isCreatedAction(lastVisibleAction)) {
return {
lastMessageText: '',
};
}

const messageText = lodashGet(message, 'text', '');
return {
lastMessageText: String(messageText).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(),
};
}

/**
* Checks if a reportAction is deprecated.
*
Expand Down Expand Up @@ -377,6 +338,60 @@ function shouldReportActionBeVisible(reportAction, key) {
return !isDeleted || isPending || isDeletedParentAction;
}

/**
* Checks if a reportAction is fit for display as report last action, meaning that
* it satisfies shouldReportActionBeVisible, it's not whisper action and not deleted.
*
* @param {Object} reportAction
* @returns {Boolean}
*/
function shouldReportActionBeVisibleAsLastAction(reportAction) {
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && !isWhisperAction(reportAction) && !isDeletedAction(reportAction);
tienifr marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @param {String} reportID
* @param {Object} [actionsToMerge]
* @return {Object}
*/
function getLastVisibleAction(reportID, actionsToMerge = {}) {
const actions = _.toArray(lodashMerge({}, allReportActions[reportID], actionsToMerge));
const visibleActions = _.filter(actions, (action) => shouldReportActionBeVisibleAsLastAction(action));

if (_.isEmpty(visibleActions)) {
return {};
}

return _.max(visibleActions, (action) => moment.utc(action.created).valueOf());
}

/**
* @param {String} reportID
* @param {Object} [actionsToMerge]
* @return {Object}
*/
function getLastVisibleMessage(reportID, actionsToMerge = {}) {
const lastVisibleAction = getLastVisibleAction(reportID, actionsToMerge);
const message = lodashGet(lastVisibleAction, ['message', 0], {});

if (isReportMessageAttachment(message)) {
return {
lastMessageTranslationKey: CONST.TRANSLATION_KEYS.ATTACHMENT,
};
}

if (isCreatedAction(lastVisibleAction)) {
return {
lastMessageText: '',
};
}

const messageText = lodashGet(message, 'text', '');
return {
lastMessageText: String(messageText).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(),
};
}

/**
* A helper method to filter out report actions keyed by sequenceNumbers.
*
Expand Down Expand Up @@ -535,10 +550,6 @@ function isMessageDeleted(reportAction) {
return lodashGet(reportAction, ['message', 0, 'isDeletedParentAction'], false);
}

function isWhisperAction(action) {
return (action.whisperedToAccountIDs || []).length > 0;
}

export {
getSortedReportActions,
getLastVisibleAction,
Expand All @@ -547,6 +558,7 @@ export {
extractLinksFromMessageHtml,
isDeletedAction,
shouldReportActionBeVisible,
shouldReportActionBeVisibleAsLastAction,
isReportActionDeprecated,
isConsecutiveActionMadeByPreviousActor,
getSortedReportActionsForDisplay,
Expand Down
Loading