Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3102096
D13793.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13793.diff
View Options
diff --git a/lib/shared/dm-ops/process-dm-ops.js b/lib/shared/dm-ops/process-dm-ops.js
--- a/lib/shared/dm-ops/process-dm-ops.js
+++ b/lib/shared/dm-ops/process-dm-ops.js
@@ -26,15 +26,12 @@
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';
+import { useStaffAlert } from '../staff-utils.js';
function useProcessDMOperation(): (
dmOperationSpecification: DMOperationSpecification,
@@ -48,16 +45,7 @@
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],
- );
+ const { showAlertToStaff } = useStaffAlert();
return React.useCallback(
async (
@@ -66,9 +54,9 @@
) => {
const { viewerID, ...restUtilities } = baseUtilities;
if (!viewerID) {
- showOperationAlertToStaff(
+ showAlertToStaff(
'Ignored DMOperation because logged out',
- dmOperationSpecification.op,
+ JSON.stringify(dmOperationSpecification.op),
);
return;
}
@@ -140,9 +128,9 @@
}
if (!dmOpSpecs[dmOp.type].operationValidator.is(dmOp)) {
- showOperationAlertToStaff(
+ showAlertToStaff(
"Ignoring operation because it doesn't pass validation",
- dmOp,
+ JSON.stringify(dmOp),
);
await confirmPeerToPeerMessage(dispatchMetadata);
return;
@@ -155,9 +143,9 @@
if (!processingCheckResult.isProcessingPossible) {
if (processingCheckResult.reason.type === 'invalid') {
- showOperationAlertToStaff(
+ showAlertToStaff(
'Ignoring operation because it is invalid',
- dmOp,
+ JSON.stringify(dmOp),
);
await confirmPeerToPeerMessage(dispatchMetadata);
return;
@@ -187,14 +175,14 @@
}
if (condition?.type) {
- showOperationAlertToStaff(
+ showAlertToStaff(
`Adding operation to the ${condition.type} queue`,
- dmOp,
+ JSON.stringify(dmOp),
);
} else {
- showOperationAlertToStaff(
+ showAlertToStaff(
'Operation should be added to a queue but its type is missing',
- dmOp,
+ JSON.stringify(dmOp),
);
}
dispatchWithMetadata(
@@ -276,7 +264,7 @@
baseUtilities,
processBlobHolders,
dispatchWithMetadata,
- showOperationAlertToStaff,
+ showAlertToStaff,
createMessagesToPeersFromDMOp,
confirmPeerToPeerMessage,
dispatch,
diff --git a/lib/shared/staff-utils.js b/lib/shared/staff-utils.js
--- a/lib/shared/staff-utils.js
+++ b/lib/shared/staff-utils.js
@@ -1,7 +1,11 @@
// @flow
+import * as React from 'react';
+
import bots from '../facts/bots.js';
import staff from '../facts/staff.js';
+import { getConfig } from '../utils/config.js';
+import { isDev } from '../utils/dev-utils.js';
import { useSelector } from '../utils/redux-utils.js';
function isStaff(userID: string): boolean {
@@ -24,4 +28,24 @@
return isCurrentUserStaff;
}
-export { isStaff, useIsCurrentUserStaff };
+type StaffAlertHook = {
+ +showAlertToStaff: (title: string, message: string) => void,
+};
+
+function useStaffAlert(): StaffAlertHook {
+ const isCurrentUserStaff = useIsCurrentUserStaff();
+
+ const showAlertToStaff = React.useCallback(
+ (title: string, message: string) => {
+ if (!isCurrentUserStaff && !isDev) {
+ return;
+ }
+ getConfig().showAlert(title, message);
+ },
+ [isCurrentUserStaff],
+ );
+
+ return { showAlertToStaff };
+}
+
+export { isStaff, useIsCurrentUserStaff, useStaffAlert };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 31, 10:27 AM (21 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2391610
Default Alt Text
D13793.diff (4 KB)
Attached To
Mode
D13793: [lib] Factor out useStaffAlert()
Attached
Detach File
Event Timeline
Log In to Comment