Skip to content

Commit

Permalink
[lib] Show staff alerts when an operation isn't processed
Browse files Browse the repository at this point in the history
Summary:
Show an alert for all the cases where an operation can't be immediately processed.

https://linear.app/comm/issue/ENG-9686/some-messages-from-newly-created-chat-missing-on-secondary-device#comment-61c90aa7

Depends on D13724

Test Plan: Checked that an alert is shown after queueing operations on web in dev mode. Deleted the dev check and made sure the alert isn't shown.

Reviewers: kamil, angelika

Reviewed By: kamil

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D13725
  • Loading branch information
palys-swm committed Oct 21, 2024
1 parent a6e16ec commit 9a1e431
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions lib/shared/dm-ops/process-dm-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ import {
queueDMOpsActionType,
dmOperationValidator,
} from '../../types/dm-ops.js';
import type { DMOperation } from '../../types/dm-ops.js';
import type { NotificationsCreationData } from '../../types/notif-types.js';
import type { DispatchMetadata } from '../../types/redux-types.js';
import type { OutboundP2PMessage } from '../../types/sqlite-types.js';
import { getConfig } from '../../utils/config.js';
import { extractUserIDsFromPayload } from '../../utils/conversion-utils.js';
import { isDev } from '../../utils/dev-utils.js';
import { useSelector, useDispatch } from '../../utils/redux-utils.js';
import { useIsCurrentUserStaff } from '../staff-utils.js';

function useProcessDMOperation(): (
dmOperationSpecification: DMOperationSpecification,
Expand All @@ -44,14 +48,28 @@ function useProcessDMOperation(): (

const dispatch = useDispatch();

const isCurrentUserStaff = useIsCurrentUserStaff();
const showOperationAlertToStaff = React.useCallback(
(description: string, operation: DMOperation) => {
if (!isCurrentUserStaff && !isDev) {
return;
}
getConfig().showAlert(description, JSON.stringify(operation));
},
[isCurrentUserStaff],
);

return React.useCallback(
async (
dmOperationSpecification: DMOperationSpecification,
dmOpID: ?string,
) => {
const { viewerID, ...restUtilities } = baseUtilities;
if (!viewerID) {
console.log('ignored DMOperation because logged out');
showOperationAlertToStaff(
'Ignored DMOperation because logged out',
dmOperationSpecification.op,
);
return;
}
const utilities: ProcessDMOperationUtilities = {
Expand Down Expand Up @@ -122,7 +140,10 @@ function useProcessDMOperation(): (
}

if (!dmOpSpecs[dmOp.type].operationValidator.is(dmOp)) {
console.log(`Ignoring ${dmOp.type} operation because it is invalid`);
showOperationAlertToStaff(
"Ignoring operation because it doesn't pass validation",
dmOp,
);
await confirmPeerToPeerMessage(dispatchMetadata);
return;
}
Expand All @@ -134,6 +155,10 @@ function useProcessDMOperation(): (

if (!processingCheckResult.isProcessingPossible) {
if (processingCheckResult.reason.type === 'invalid') {
showOperationAlertToStaff(
'Ignoring operation because it is invalid',
dmOp,
);
await confirmPeerToPeerMessage(dispatchMetadata);
return;
}
Expand All @@ -160,6 +185,18 @@ function useProcessDMOperation(): (
userID: processingCheckResult.reason.userID,
};
}

if (condition?.type) {
showOperationAlertToStaff(
`Adding operation to the ${condition.type} queue`,
dmOp,
);
} else {
showOperationAlertToStaff(
'Operation should be added to a queue but its type is missing',
dmOp,
);
}
dispatchWithMetadata(
{
type: queueDMOpsActionType,
Expand Down Expand Up @@ -239,9 +276,10 @@ function useProcessDMOperation(): (
baseUtilities,
processBlobHolders,
dispatchWithMetadata,
showOperationAlertToStaff,
createMessagesToPeersFromDMOp,
dispatch,
confirmPeerToPeerMessage,
dispatch,
],
);
}
Expand Down

0 comments on commit 9a1e431

Please sign in to comment.