Skip to content

Commit

Permalink
Merge pull request #27956 from janicduplessis/@janic/is-consecutive
Browse files Browse the repository at this point in the history
  • Loading branch information
mountiny authored Sep 25, 2023
2 parents 89645c7 + f0d613c commit c3e3ffa
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,23 @@ function extractLinksFromMessageHtml(reportAction) {
return _.map([...htmlContent.matchAll(regex)], (match) => match[1]);
}

/**
* Returns the report action immediately before the specified index.
* @param {Array} reportActions - all actions
* @param {Number} actionIndex - index of the action
* @returns {Object|null}
*/
function findPreviousAction(reportActions, actionIndex) {
for (let i = actionIndex + 1; i < reportActions.length; i++) {
// Find the next non-pending deletion report action, as the pending delete action means that it is not displayed in the UI, but still is in the report actions list.
// If we are offline, all actions are pending but shown in the UI, so we take the previous action, even if it is a delete.
if (isNetworkOffline || reportActions[i].pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return reportActions[i];
}
}
return null;
}

/**
* Returns true when the report action immediately before the specified index is a comment made by the same actor who who is leaving a comment in the action at the specified index.
* Also checks to ensure that the comment is not too old to be shown as a grouped comment.
Expand All @@ -258,9 +275,7 @@ function extractLinksFromMessageHtml(reportAction) {
* @returns {Boolean}
*/
function isConsecutiveActionMadeByPreviousActor(reportActions, actionIndex) {
// Find the next non-pending deletion report action, as the pending delete action means that it is not displayed in the UI, but still is in the report actions list.
// If we are offline, all actions are pending but shown in the UI, so we take the previous action, even if it is a delete.
const previousAction = _.find(_.drop(reportActions, actionIndex + 1), (action) => isNetworkOffline || action.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
const previousAction = findPreviousAction(reportActions, actionIndex);
const currentAction = reportActions[actionIndex];

// It's OK for there to be no previous action, and in that case, false will be returned
Expand Down

0 comments on commit c3e3ffa

Please sign in to comment.