Skip to content

Commit 74fcba9

Browse files
committed
Hoist report-level subscriptions out of each message row
1 parent fd63838 commit 74fcba9

5 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/hooks/usePendingConciergeResponse.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {useEffect, useRef} from 'react';
22
import type {OnyxEntry} from 'react-native-onyx';
33
import {clearAgentZeroProcessingIndicator} from '@libs/actions/Report';
4-
import {applyPendingConciergeAction, clearPendingFollowupList, discardPendingConciergeAction} from '@libs/actions/Report/SuggestedFollowup';
4+
import {applyPendingConciergeAction, clearPendingFollowupList, discardPendingConciergeAction, hidePendingFollowupList} from '@libs/actions/Report/SuggestedFollowup';
55
import {MAX_AGE_MS} from '@libs/AgentZeroOptimisticStore';
66
import Log from '@libs/Log';
77
import {rand64} from '@libs/NumberUtils';
@@ -86,10 +86,18 @@ function usePendingConciergeResponse(reportID: string | undefined) {
8686
wasOfflineRef.current = isOffline;
8787
}, [isOffline]);
8888

89+
// Hide the followup-list skeleton when the user is offline.
90+
useEffect(() => {
91+
if (!reportID || !pendingFollowupList || !!pendingFollowupList.hidden === isOffline) {
92+
return;
93+
}
94+
hidePendingFollowupList(reportID, isOffline || null);
95+
}, [reportID, isOffline, pendingFollowupList]);
96+
8997
// Clear the pending followup-list skeleton flag as soon as the server reply
90-
// (with <followup-list>) overwrites the optimistic action. A TTL fallback
91-
// guards against the case where no followup-list ever arrives so the skeleton
92-
// won't get stuck.
98+
// (with <followup-list>) overwrites the optimistic action.
99+
// A TTL fallback guards against the case where no followup-list ever arrives
100+
// so the skeleton won't get stuck.
93101
useEffect(() => {
94102
if (!reportID || !pendingFollowupList) {
95103
return;

src/libs/actions/Report/SuggestedFollowup.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ function clearPendingFollowupList(reportID: string | undefined) {
144144
Onyx.set(`${ONYXKEYS.COLLECTION.CONCIERGE_PENDING_FOLLOWUP_LIST}${reportID}`, null);
145145
}
146146

147+
/**
148+
* Temporarily hides the pending followup-list skeleton.
149+
*/
150+
function hidePendingFollowupList(reportID: string | undefined, hidden: boolean | null) {
151+
if (!reportID) {
152+
return;
153+
}
154+
Onyx.merge(`${ONYXKEYS.COLLECTION.CONCIERGE_PENDING_FOLLOWUP_LIST}${reportID}`, {hidden});
155+
}
156+
147157
/**
148158
* Applies a pending concierge response by moving it to REPORT_ACTIONS
149159
* and clearing the pending state.
@@ -168,4 +178,4 @@ function applyPendingConciergeAction(reportID: string | undefined, reportAction:
168178
]);
169179
}
170180

171-
export {resolveSuggestedFollowup, discardPendingConciergeAction, applyPendingConciergeAction, clearPendingFollowupList, CONCIERGE_RESPONSE_DELAY_MS};
181+
export {resolveSuggestedFollowup, discardPendingConciergeAction, applyPendingConciergeAction, clearPendingFollowupList, hidePendingFollowupList, CONCIERGE_RESPONSE_DELAY_MS};

src/pages/inbox/report/actionContents/ChatMessageContent.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import {hasPendingFollowupListSkeletonSelector} from '@selectors/AgentZeroChat';
12
import React from 'react';
23
import {View} from 'react-native';
34
import {AttachmentContext} from '@components/AttachmentContext';
45
import Button from '@components/Button';
56
import MentionReportContext from '@components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/MentionReportContext';
67
import Text from '@components/Text';
78
import useLocalize from '@hooks/useLocalize';
8-
import useNetwork from '@hooks/useNetwork';
99
import useOnyx from '@hooks/useOnyx';
1010
import useResponsiveLayout from '@hooks/useResponsiveLayout';
1111
import useThemeStyles from '@hooks/useThemeStyles';
@@ -50,9 +50,9 @@ function ChatMessageContent({action, policyID, reportID, originalReportID, displ
5050

5151
const {hasBeenFlagged} = getModerationFlagState(action);
5252

53-
const {isOffline} = useNetwork();
54-
const [pendingFollowupList] = useOnyx(`${ONYXKEYS.COLLECTION.CONCIERGE_PENDING_FOLLOWUP_LIST}${reportID}`);
55-
const hasPendingFollowupListSkeleton = !isOffline && pendingFollowupList?.reportActionID === action.reportActionID;
53+
const [hasPendingFollowupListSkeleton = false] = useOnyx(`${ONYXKEYS.COLLECTION.CONCIERGE_PENDING_FOLLOWUP_LIST}${reportID}`, {
54+
selector: hasPendingFollowupListSkeletonSelector(action.reportActionID),
55+
});
5656

5757
const messageHtml = getReportActionMessage(action)?.html;
5858
const mayHaveActionableButtons =

src/selectors/AgentZeroChat.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
22
import ONYXKEYS from '@src/ONYXKEYS';
3-
import type {AgentPrompt} from '@src/types/onyx';
3+
import type {AgentPrompt, ConciergePendingFollowupList} from '@src/types/onyx';
44
import type Report from '@src/types/onyx/Report';
55

66
const getReportParticipantAccountIDs = (report: OnyxEntry<Report>): number[] => (report?.participants ? Object.keys(report.participants).map(Number) : []);
@@ -23,4 +23,9 @@ const getAgentAccountIDFlags = (agentPrompts: OnyxCollection<AgentPrompt>): Reco
2323
return flags;
2424
};
2525

26-
export {getReportParticipantAccountIDs, getAgentAccountIDFlags};
26+
const hasPendingFollowupListSkeletonSelector =
27+
(reportActionID: string) =>
28+
(pending: OnyxEntry<ConciergePendingFollowupList>): boolean =>
29+
!pending?.hidden && pending?.reportActionID === reportActionID;
30+
31+
export {getReportParticipantAccountIDs, getAgentAccountIDFlags, hasPendingFollowupListSkeletonSelector};

src/types/onyx/ConciergePendingFollowupList.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ type ConciergePendingFollowupList = {
55

66
/** Timestamp (ms) when the pending flag was created, used for TTL cleanup */
77
createdAt: number;
8+
9+
/** Whether the skeleton should be visually hidden (e.g., user is offline) */
10+
hidden?: boolean;
811
};
912

1013
export default ConciergePendingFollowupList;

0 commit comments

Comments
 (0)