Skip to content
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
68 changes: 36 additions & 32 deletions src/libs/API/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type {OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {SetRequired} from 'type-fest';
import {resolveDuplicationConflictAction, resolveEnableFeatureConflicts} from '@libs/actions/RequestConflictUtils';
import type {EnablePolicyFeatureCommand, RequestMatcher} from '@libs/actions/RequestConflictUtils';
import Log from '@libs/Log';
import {handleDeletedAccount, HandleUnusedOptimisticID, Logging, Pagination, Reauthentication, RecheckConnection, SaveResponseInOnyx} from '@libs/Middleware';
import {isOffline} from '@libs/Network/NetworkStore';
Expand Down Expand Up @@ -134,16 +136,6 @@ function processRequest(request: OnyxRequest, type: ApiRequestType): Promise<voi
/**
* All calls to API.write() will be persisted to disk as JSON with the params, successData, and failureData (or finallyData, if included in place of the former two values).
* This is so that if the network is unavailable or the app is closed, we can send the WRITE request later.
*
* @param command - Name of API command to call.
* @param apiCommandParameters - Parameters to send to the API.
* @param onyxData - Object containing errors, loading states, and optimistic UI data that will be merged
* into Onyx before and after a request is made. Each nested object will be formatted in
* the same way as an API response.
* @param [onyxData.optimisticData] - Onyx instructions that will be passed to Onyx.update() before the request is made.
* @param [onyxData.successData] - Onyx instructions that will be passed to Onyx.update() when the response has jsonCode === 200.
* @param [onyxData.failureData] - Onyx instructions that will be passed to Onyx.update() when the response has jsonCode !== 200.
* @param [onyxData.finallyData] - Onyx instructions that will be passed to Onyx.update() when the response has jsonCode === 200 or jsonCode !== 200.
*/

function write<TCommand extends WriteCommand>(
Expand All @@ -157,24 +149,46 @@ function write<TCommand extends WriteCommand>(
return processRequest(request, CONST.API_REQUEST_TYPE.WRITE);
}

/**
* This function is used to write data to the API while ensuring that there are no duplicate requests in the queue.
* If a duplicate request is found, it resolves the conflict by replacing the duplicated request with the new one.
*/
function writeWithNoDuplicatesConflictAction<TCommand extends WriteCommand>(
command: TCommand,
apiCommandParameters: ApiRequestCommandParameters[TCommand],
onyxData: OnyxData = {},
requestMatcher: RequestMatcher = (request) => request.command === command,
): Promise<void | Response> {
const conflictResolver = {
checkAndFixConflictingRequest: (persistedRequests: OnyxRequest[]) => resolveDuplicationConflictAction(persistedRequests, requestMatcher),
};

return write(command, apiCommandParameters, onyxData, conflictResolver);
}

/**
* This function is used to write data to the API while ensuring that there are no conflicts with enabling policy features.
* If a conflict is found, it resolves the conflict by deleting the duplicated request.
*/
function writeWithNoDuplicatesEnableFeatureConflicts<TCommand extends EnablePolicyFeatureCommand>(
command: TCommand,
apiCommandParameters: ApiRequestCommandParameters[TCommand],
onyxData: OnyxData = {},
): Promise<void | Response> {
const conflictResolver = {
checkAndFixConflictingRequest: (persistedRequests: OnyxRequest[]) => resolveEnableFeatureConflicts(command, persistedRequests, apiCommandParameters),
};

return write(command, apiCommandParameters, onyxData, conflictResolver);
}

/**
* For commands where the network response must be accessed directly or when there is functionality that can only
* happen once the request is finished (eg. calling third-party services like Onfido and Plaid, redirecting a user
* depending on the response data, etc.).
* It works just like API.read(), except that it will return a promise.
* Using this method is discouraged and will throw an ESLint error. Use it sparingly and only when all other alternatives have been exhausted.
* It is best to discuss it in Slack anytime you are tempted to use this method.
*
* @param command - Name of API command to call.
* @param apiCommandParameters - Parameters to send to the API.
* @param onyxData - Object containing errors, loading states, and optimistic UI data that will be merged
* into Onyx before and after a request is made. Each nested object will be formatted in
* the same way as an API response.
* @param [onyxData.optimisticData] - Onyx instructions that will be passed to Onyx.update() before the request is made.
* @param [onyxData.successData] - Onyx instructions that will be passed to Onyx.update() when the response has jsonCode === 200.
* @param [onyxData.failureData] - Onyx instructions that will be passed to Onyx.update() when the response has jsonCode !== 200.
* @param [onyxData.finallyData] - Onyx instructions that will be passed to Onyx.update() when the response has jsonCode === 200 or jsonCode !== 200.
* @returns
*/
function makeRequestWithSideEffects<TCommand extends SideEffectRequestCommand>(
command: TCommand,
Expand Down Expand Up @@ -202,16 +216,6 @@ function waitForWrites<TCommand extends ReadCommand>(command: TCommand) {

/**
* Requests made with this method are not be persisted to disk. If there is no network connectivity, the request is ignored and discarded.
*
* @param command - Name of API command to call.
* @param apiCommandParameters - Parameters to send to the API.
* @param onyxData - Object containing errors, loading states, and optimistic UI data that will be merged
* into Onyx before and after a request is made. Each nested object will be formatted in
* the same way as an API response.
* @param [onyxData.optimisticData] - Onyx instructions that will be passed to Onyx.update() before the request is made.
* @param [onyxData.successData] - Onyx instructions that will be passed to Onyx.update() when the response has jsonCode === 200.
* @param [onyxData.failureData] - Onyx instructions that will be passed to Onyx.update() when the response has jsonCode !== 200.
* @param [onyxData.finallyData] - Onyx instructions that will be passed to Onyx.update() when the response has jsonCode === 200 or jsonCode !== 200.
*/
function read<TCommand extends ReadCommand>(command: TCommand, apiCommandParameters: ApiRequestCommandParameters[TCommand], onyxData: OnyxData = {}): void {
Log.info('[API] Called API.read', false, {command, ...apiCommandParameters});
Expand Down Expand Up @@ -281,4 +285,4 @@ function paginate<TRequestType extends ApiRequestType, TCommand extends CommandO
}
}

export {write, makeRequestWithSideEffects, read, paginate};
export {write, makeRequestWithSideEffects, read, paginate, writeWithNoDuplicatesConflictAction, writeWithNoDuplicatesEnableFeatureConflicts};
9 changes: 2 additions & 7 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import {setShouldForceOffline} from './Network';
import {getAll, rollbackOngoingRequest, save} from './PersistedRequests';
import {createDraftInitialWorkspace, createWorkspace, generatePolicyID} from './Policy/Policy';
import {resolveDuplicationConflictAction} from './RequestConflictUtils';
import {isAnonymousUser} from './Session';
import Timing from './Timing';

Expand All @@ -43,7 +42,7 @@

let currentUserAccountID: number | undefined;
let currentUserEmail: string;
Onyx.connect({

Check warning on line 45 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
currentUserAccountID = val?.accountID;
Expand All @@ -52,14 +51,14 @@
});

let isSidebarLoaded: boolean | undefined;
Onyx.connect({

Check warning on line 54 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.IS_SIDEBAR_LOADED,
callback: (val) => (isSidebarLoaded = val),
initWithStoredValues: false,
});

let preferredLocale: Locale | undefined;
Onyx.connect({

Check warning on line 61 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: (val) => {
if (!val || !isSupportedLocale(val)) {
Expand All @@ -79,7 +78,7 @@
});

let priorityMode: ValueOf<typeof CONST.PRIORITY_MODE> | undefined;
Onyx.connect({

Check warning on line 81 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_PRIORITY_MODE,
callback: (nextPriorityMode) => {
// When someone switches their priority mode we need to fetch all their chats because only #focus mode works with a subset of a user's chats. This is only possible via the OpenApp command.
Expand All @@ -92,7 +91,7 @@
});

let isUsingImportedState: boolean | undefined;
Onyx.connect({

Check warning on line 94 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.IS_USING_IMPORTED_STATE,
callback: (value) => {
isUsingImportedState = value ?? false;
Expand All @@ -100,7 +99,7 @@
});

let preservedUserSession: OnyxTypes.Session | undefined;
Onyx.connect({

Check warning on line 102 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PRESERVED_USER_SESSION,
callback: (value) => {
preservedUserSession = value;
Expand All @@ -108,7 +107,7 @@
});

let preservedShouldUseStagingServer: boolean | undefined;
Onyx.connect({

Check warning on line 110 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.ACCOUNT,
callback: (value) => {
preservedShouldUseStagingServer = value?.shouldUseStagingServer;
Expand All @@ -121,7 +120,7 @@
});

let hasLoadedApp: boolean | undefined;
Onyx.connect({

Check warning on line 123 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.HAS_LOADED_APP,
callback: (value) => {
hasLoadedApp = value;
Expand All @@ -130,7 +129,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 132 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -154,7 +153,7 @@
ONYXKEYS.PRESERVED_USER_SESSION,
];

Onyx.connect({

Check warning on line 156 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.RESET_REQUIRED,
callback: (isResetRequired) => {
if (!isResetRequired) {
Expand Down Expand Up @@ -332,9 +331,7 @@
function openApp(shouldKeepPublicRooms = false) {
return getPolicyParamsForOpenOrReconnect().then((policyParams: PolicyParamsForOpenOrReconnect) => {
const params: OpenAppParams = {enablePriorityModeFilter: true, ...policyParams};
return API.write(WRITE_COMMANDS.OPEN_APP, params, getOnyxDataForOpenOrReconnect(true, undefined, shouldKeepPublicRooms), {
checkAndFixConflictingRequest: (persistedRequests) => resolveDuplicationConflictAction(persistedRequests, (request) => request.command === WRITE_COMMANDS.OPEN_APP),
});
return API.writeWithNoDuplicatesConflictAction(WRITE_COMMANDS.OPEN_APP, params, getOnyxDataForOpenOrReconnect(true, undefined, shouldKeepPublicRooms));
});
}

Expand All @@ -359,9 +356,7 @@
}

const isFullReconnect = !updateIDFrom;
API.write(WRITE_COMMANDS.RECONNECT_APP, params, getOnyxDataForOpenOrReconnect(false, isFullReconnect), {
checkAndFixConflictingRequest: (persistedRequests) => resolveDuplicationConflictAction(persistedRequests, (request) => request.command === WRITE_COMMANDS.RECONNECT_APP),
});
API.writeWithNoDuplicatesConflictAction(WRITE_COMMANDS.RECONNECT_APP, params, getOnyxDataForOpenOrReconnect(false, isFullReconnect, isSidebarLoaded));
});
});
}
Expand Down
5 changes: 1 addition & 4 deletions src/libs/actions/Policy/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import enhanceParameters from '@libs/Network/enhanceParameters';
import {hasEnabledOptions} from '@libs/OptionsListUtils';
import {getPolicy, goBackWhenEnableFeature} from '@libs/PolicyUtils';
import {getAllPolicyReports, pushTransactionViolationsOnyxData} from '@libs/ReportUtils';
import {resolveEnableFeatureConflicts} from '@userActions/RequestConflictUtils';
import {getFinishOnboardingTaskOnyxData} from '@userActions/Task';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -1104,9 +1103,7 @@ function enablePolicyCategories(

const parameters: EnablePolicyCategoriesParams = {policyID, enabled};

API.write(WRITE_COMMANDS.ENABLE_POLICY_CATEGORIES, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_CATEGORIES, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_CATEGORIES, parameters, onyxData);

if (enabled && getIsNarrowLayout() && shouldGoBack) {
goBackWhenEnableFeature(policyID);
Expand Down
5 changes: 1 addition & 4 deletions src/libs/actions/Policy/DistanceRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import * as ErrorUtils from '@libs/ErrorUtils';
import getIsNarrowLayout from '@libs/getIsNarrowLayout';
import {getDistanceRateCustomUnit, goBackWhenEnableFeature, removePendingFieldsFromCustomUnit} from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {resolveEnableFeatureConflicts} from '@userActions/RequestConflictUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Report, Transaction, TransactionViolation} from '@src/types/onyx';
Expand Down Expand Up @@ -180,9 +179,7 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) {

const parameters: EnablePolicyDistanceRatesParams = {policyID, enabled};

API.write(WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES, parameters, onyxData);

if (enabled && getIsNarrowLayout()) {
goBackWhenEnableFeature(policyID);
Expand Down
33 changes: 8 additions & 25 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ import * as ReportUtils from '@libs/ReportUtils';
import type {PolicySelector} from '@pages/home/sidebar/FloatingActionButtonAndPopover';
import * as PaymentMethods from '@userActions/PaymentMethods';
import * as PersistedRequests from '@userActions/PersistedRequests';
import {resolveEnableFeatureConflicts} from '@userActions/RequestConflictUtils';
import {buildTaskData} from '@userActions/Task';
import {getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow';
import type {OnboardingCompanySize, OnboardingPurpose} from '@userActions/Welcome/OnboardingFlow';
Expand Down Expand Up @@ -3101,9 +3100,7 @@ function enablePolicyConnections(policyID: string, enabled: boolean) {

const parameters: EnablePolicyConnectionsParams = {policyID, enabled};

API.write(WRITE_COMMANDS.ENABLE_POLICY_CONNECTIONS, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_CONNECTIONS, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_CONNECTIONS, parameters, onyxData);

if (enabled && getIsNarrowLayout()) {
goBackWhenEnableFeature(policyID);
Expand Down Expand Up @@ -3160,9 +3157,7 @@ function enableExpensifyCard(policyID: string, enabled: boolean, shouldNavigateT

const parameters: EnablePolicyExpensifyCardsParams = {authToken, policyID, enabled};

API.write(WRITE_COMMANDS.ENABLE_POLICY_EXPENSIFY_CARDS, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_EXPENSIFY_CARDS, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_EXPENSIFY_CARDS, parameters, onyxData);

if (enabled && shouldNavigateToExpensifyCardPage) {
navigateToExpensifyCardPage(policyID);
Expand Down Expand Up @@ -3217,9 +3212,7 @@ function enableCompanyCards(policyID: string, enabled: boolean, shouldGoBack = t

const parameters: EnablePolicyCompanyCardsParams = {authToken, policyID, enabled};

API.write(WRITE_COMMANDS.ENABLE_POLICY_COMPANY_CARDS, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_COMPANY_CARDS, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_COMPANY_CARDS, parameters, onyxData);

if (enabled && getIsNarrowLayout() && shouldGoBack) {
goBackWhenEnableFeature(policyID);
Expand Down Expand Up @@ -3267,9 +3260,7 @@ function enablePolicyReportFields(policyID: string, enabled: boolean) {

const parameters: EnablePolicyReportFieldsParams = {policyID, enabled};

API.write(WRITE_COMMANDS.ENABLE_POLICY_REPORT_FIELDS, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_REPORT_FIELDS, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_REPORT_FIELDS, parameters, onyxData);
}

function enablePolicyTaxes(policyID: string, enabled: boolean) {
Expand Down Expand Up @@ -3387,9 +3378,7 @@ function enablePolicyTaxes(policyID: string, enabled: boolean) {
if (shouldAddDefaultTaxRatesData) {
parameters.taxFields = JSON.stringify(defaultTaxRates);
}
API.write(WRITE_COMMANDS.ENABLE_POLICY_TAXES, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_TAXES, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_TAXES, parameters, onyxData);

if (enabled && getIsNarrowLayout()) {
goBackWhenEnableFeature(policyID);
Expand Down Expand Up @@ -3492,9 +3481,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
setWorkspaceAutoReportingFrequency(policyID, CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT);
}

API.write(WRITE_COMMANDS.ENABLE_POLICY_WORKFLOWS, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_WORKFLOWS, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_WORKFLOWS, parameters, onyxData);

if (enabled && getIsNarrowLayout()) {
goBackWhenEnableFeature(policyID);
Expand Down Expand Up @@ -3560,9 +3547,7 @@ function enablePolicyRules(policyID: string, enabled: boolean, shouldGoBack = tr
};

const parameters: SetPolicyRulesEnabledParams = {policyID, enabled};
API.write(WRITE_COMMANDS.SET_POLICY_RULES_ENABLED, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.SET_POLICY_RULES_ENABLED, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.SET_POLICY_RULES_ENABLED, parameters, onyxData);

if (enabled && getIsNarrowLayout() && shouldGoBack) {
goBackWhenEnableFeature(policyID);
Expand Down Expand Up @@ -3675,9 +3660,7 @@ function enablePolicyInvoicing(policyID: string, enabled: boolean) {

const parameters: EnablePolicyInvoicingParams = {policyID, enabled};

API.write(WRITE_COMMANDS.ENABLE_POLICY_INVOICING, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_INVOICING, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_INVOICING, parameters, onyxData);

if (enabled && getIsNarrowLayout()) {
goBackWhenEnableFeature(policyID);
Expand Down
5 changes: 1 addition & 4 deletions src/libs/actions/Policy/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {goBackWhenEnableFeature} from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {getTagArrayFromName} from '@libs/TransactionUtils';
import type {PolicyTagList} from '@pages/workspace/tags/types';
import {resolveEnableFeatureConflicts} from '@userActions/RequestConflictUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ImportedSpreadsheet, Policy, PolicyTag, PolicyTagLists, PolicyTags, RecentlyUsedTags, Report} from '@src/types/onyx';
Expand Down Expand Up @@ -765,9 +764,7 @@ function enablePolicyTags(policyID: string, enabled: boolean) {

const parameters: EnablePolicyTagsParams = {policyID, enabled};

API.write(WRITE_COMMANDS.ENABLE_POLICY_TAGS, parameters, onyxData, {
checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_TAGS, persistedRequests, parameters),
});
API.writeWithNoDuplicatesEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_TAGS, parameters, onyxData);

if (enabled && getIsNarrowLayout()) {
goBackWhenEnableFeature(policyID);
Expand Down
7 changes: 2 additions & 5 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1595,14 +1595,11 @@ function readNewestAction(reportID: string | undefined, shouldResetUnreadMarker
lastReadTime,
};

API.write(
API.writeWithNoDuplicatesConflictAction(
WRITE_COMMANDS.READ_NEWEST_ACTION,
parameters,
{optimisticData},
{
checkAndFixConflictingRequest: (persistedRequests) =>
resolveDuplicationConflictAction(persistedRequests, (request) => request.command === WRITE_COMMANDS.READ_NEWEST_ACTION && request.data?.reportID === parameters.reportID),
},
(request) => request.command === WRITE_COMMANDS.READ_NEWEST_ACTION && request.data?.reportID === parameters.reportID,
);

if (shouldResetUnreadMarker) {
Expand Down
2 changes: 2 additions & 0 deletions src/libs/actions/RequestConflictUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,5 @@ export {
resolveEnableFeatureConflicts,
enablePolicyFeatureCommand,
};

export type {EnablePolicyFeatureCommand, RequestMatcher};
10 changes: 1 addition & 9 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import {reconnectApp} from './App';
import applyOnyxUpdatesReliably from './applyOnyxUpdatesReliably';
import {openOldDotLink} from './Link';
import {showReportActionNotification} from './Report';
import {resolveDuplicationConflictAction} from './RequestConflictUtils';
import {resendValidateCode as sessionResendValidateCode} from './Session';
import Timing from './Timing';

Expand Down Expand Up @@ -814,14 +813,7 @@ function pingPusher() {
lastPingSentTimestamp = pingTimestamp;

const parameters: PusherPingParams = {pingID, pingTimestamp};
API.write(
WRITE_COMMANDS.PUSHER_PING,
parameters,
{},
{
checkAndFixConflictingRequest: (persistedRequests) => resolveDuplicationConflictAction(persistedRequests, (request) => request.command === WRITE_COMMANDS.PUSHER_PING),
},
);
API.writeWithNoDuplicatesConflictAction(WRITE_COMMANDS.PUSHER_PING, parameters);
Log.info(`[Pusher PINGPONG] Sending a PING to the server: ${pingID} timestamp: ${pingTimestamp}`);
Timing.start(CONST.TIMING.PUSHER_PING_PONG);
}
Expand Down
Loading
Loading