Skip to content

Commit

Permalink
Include 'INVITE_TO_ROOM' action for startIndex calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
perunt committed Feb 2, 2024
1 parent 150e9a4 commit 6f9746a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
25 changes: 16 additions & 9 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMe
const policyChangeActionsSet = new Set<string>(Object.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG));

const allReports: OnyxCollection<Report> = {};

type ActionableMentionWhisperResolution = {
resolution: ValueOf<typeof CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION>;
};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
callback: (report, key) => {
Expand Down Expand Up @@ -241,8 +245,8 @@ function getContinuousReportActionChain(sortedReportActions: ReportAction[], id?
// This ensures that we are moving in a sequence of related actions from newer to older.
while (
(endIndex < sortedReportActions.length - 1 && sortedReportActions[endIndex].previousReportActionID === sortedReportActions[endIndex + 1].reportActionID) ||
sortedReportActions[endIndex + 1]?.whisperedToAccountIDs?.length ||
sortedReportActions[endIndex]?.whisperedToAccountIDs?.length ||
!!sortedReportActions[endIndex + 1]?.whisperedToAccountIDs?.length ||
!!sortedReportActions[endIndex]?.whisperedToAccountIDs?.length ||
sortedReportActions[endIndex]?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ||
sortedReportActions[endIndex + 1]?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED ||
sortedReportActions[endIndex + 1]?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED
Expand All @@ -257,7 +261,8 @@ function getContinuousReportActionChain(sortedReportActions: ReportAction[], id?
// This additional check is to include recently sent messages that might not yet be part of the established sequence.
while (
(startIndex > 0 && sortedReportActions[startIndex].reportActionID === sortedReportActions[startIndex - 1].previousReportActionID) ||
sortedReportActions[startIndex - 1]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD
sortedReportActions[startIndex - 1]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD ||
sortedReportActions[startIndex - 1]?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM
) {
startIndex--;
}
Expand Down Expand Up @@ -526,16 +531,18 @@ function filterOutDeprecatedReportActions(reportActions: ReportActions | null):
* to ensure they will always be displayed in the same order (in case multiple actions have the same timestamp).
* This is all handled with getSortedReportActions() which is used by several other methods to keep the code DRY.
*/
function getSortedReportActionsForDisplay(reportActions: ReportActions | null, shouldIncludeInvisibleActions = false): ReportAction[] {
let filteredReportActions;
function getSortedReportActionsForDisplay(reportActions: ReportActions | null | ActionableMentionWhisperResolution, shouldIncludeInvisibleActions = false): ReportAction[] {
let filteredReportActions: ReportAction[] = [];
if (!reportActions) {
return [];
}

if (shouldIncludeInvisibleActions) {
// filteredReportActions = Object.values(reportActions ?? {}).filter((action) => action?.resolution !== CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE)
filteredReportActions = Object.values(reportActions ?? {});
filteredReportActions = Object.values(reportActions).filter((action): action is ReportAction => !action?.resolution);
} else {
filteredReportActions = Object.entries(reportActions ?? {})
filteredReportActions = Object.entries(reportActions)
.filter(([key, reportAction]) => shouldReportActionBeVisible(reportAction, key))
.map((entry) => entry[1]);
.map(([, reportAction]) => reportAction as ReportAction);
}

const baseURLAdjustedReportActions = filteredReportActions.map((reportAction) => replaceBaseURLInPolicyChangeLogAction(reportAction));
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const usePaginatedReportActionList = (linkedID, allReportActions, fetchNewerRepo
if (isFirstLinkedActionRender.current) {
return allReportActions.slice(index, allReportActions.length);
}
const paginationSize = getInitialPaginationSize(allReportActions.length - index);
const paginationSize = getInitialPaginationSize();
const newStartIndex = index >= paginationSize ? index - paginationSize : 0;
return newStartIndex ? allReportActions.slice(newStartIndex, allReportActions.length) : allReportActions;
// currentReportActionID is needed to trigger batching once the report action has been positioned
Expand Down
9 changes: 1 addition & 8 deletions src/pages/home/report/getInitialPaginationSize/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import * as Browser from '@libs/Browser';
import CONST from '@src/CONST';

const isMobileSafari = Browser.isMobileSafari();

function getInitialPaginationSize(numToRender: number): number {
if (isMobileSafari) {
return Math.round(Math.min(numToRender / 3, CONST.MOBILE_PAGINATION_SIZE));
}
// WEB: Calculate and position it correctly for each frame, enabling the rendering of up to 50 items.
function getInitialPaginationSize(): number {
return CONST.WEB_PAGINATION_SIZE;
}
export default getInitialPaginationSize;

0 comments on commit 6f9746a

Please sign in to comment.