Page MenuHomePhabricator

D14297.diff
No OneTemporary

D14297.diff

diff --git a/lib/components/debug-logs-context-provider.react.js b/lib/components/debug-logs-context-provider.react.js
--- a/lib/components/debug-logs-context-provider.react.js
+++ b/lib/components/debug-logs-context-provider.react.js
@@ -3,6 +3,8 @@
import * as React from 'react';
import { type DebugLog, DebugLogsContext } from './debug-logs-context.js';
+import { useIsCurrentUserStaff } from '../shared/staff-utils.js';
+import { isDev } from '../utils/dev-utils.js';
type Props = {
+children: React.Node,
@@ -10,9 +12,13 @@
function DebugLogsContextProvider(props: Props): React.Node {
const [logs, setLogs] = React.useState<$ReadOnlyArray<DebugLog>>([]);
+ const isCurrentUserStaff = useIsCurrentUserStaff();
const addLog = React.useCallback(
- (title: string, message: string) =>
+ (title: string, message: string) => {
+ if (!isCurrentUserStaff && !isDev) {
+ return;
+ }
setLogs(prevLogs => [
...prevLogs,
{
@@ -20,8 +26,9 @@
message,
timestamp: Date.now(),
},
- ]),
- [],
+ ]);
+ },
+ [isCurrentUserStaff],
);
const clearLogs = React.useCallback(() => setLogs([]), []);
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
@@ -15,6 +15,7 @@
} from './dm-op-utils.js';
import { useProcessBlobHolders } from '../../actions/holder-actions.js';
import { processNewUserIDsActionType } from '../../actions/user-actions.js';
+import { useDebugLogs } from '../../components/debug-logs-context.js';
import { useDispatchWithMetadata } from '../../hooks/ops-hooks.js';
import {
usePeerToPeerCommunication,
@@ -30,7 +31,6 @@
import type { OutboundP2PMessage } from '../../types/sqlite-types.js';
import { extractUserIDsFromPayload } from '../../utils/conversion-utils.js';
import { useSelector, useDispatch } from '../../utils/redux-utils.js';
-import { useStaffAlert } from '../staff-utils.js';
function useProcessDMOperation(): (
dmOperationSpecification: DMOperationSpecification,
@@ -44,7 +44,7 @@
const dispatch = useDispatch();
- const { showAlertToStaff } = useStaffAlert();
+ const { addLog } = useDebugLogs();
return React.useCallback(
async (
@@ -53,7 +53,7 @@
) => {
const { viewerID, ...restUtilities } = baseUtilities;
if (!viewerID) {
- showAlertToStaff(
+ addLog(
'Ignored DMOperation because logged out',
JSON.stringify(dmOperationSpecification.op),
);
@@ -127,7 +127,7 @@
}
if (!dmOpSpecs[dmOp.type].operationValidator.is(dmOp)) {
- showAlertToStaff(
+ addLog(
"Ignoring operation because it doesn't pass validation",
JSON.stringify(dmOp),
);
@@ -142,7 +142,7 @@
if (!processingCheckResult.isProcessingPossible) {
if (processingCheckResult.reason.type === 'invalid') {
- showAlertToStaff(
+ addLog(
'Ignoring operation because it is invalid',
JSON.stringify(dmOp),
);
@@ -174,12 +174,12 @@
}
if (condition?.type) {
- showAlertToStaff(
+ addLog(
`Adding operation to the ${condition.type} queue`,
JSON.stringify(dmOp),
);
} else {
- showAlertToStaff(
+ addLog(
'Operation should be added to a queue but its type is missing',
JSON.stringify(dmOp),
);
@@ -251,10 +251,10 @@
);
},
[
+ addLog,
baseUtilities,
processBlobHolders,
dispatchWithMetadata,
- showAlertToStaff,
createMessagesToPeersFromDMOp,
confirmPeerToPeerMessage,
dispatch,
diff --git a/lib/tunnelbroker/use-peer-to-peer-message-handler.js b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
--- a/lib/tunnelbroker/use-peer-to-peer-message-handler.js
+++ b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
@@ -9,6 +9,7 @@
import { removePeerUsersActionType } from '../actions/aux-user-actions.js';
import { invalidateTunnelbrokerDeviceTokenActionType } from '../actions/tunnelbroker-actions.js';
import { logOutActionTypes, useBaseLogOut } from '../actions/user-actions.js';
+import { useDebugLogs } from '../components/debug-logs-context.js';
import { usePeerOlmSessionsCreatorContext } from '../components/peer-olm-session-creator-provider.react.js';
import {
useBroadcastDeviceListUpdates,
@@ -23,7 +24,6 @@
import { dmOperationSpecificationTypes } from '../shared/dm-ops/dm-op-utils.js';
import { useProcessDMOperation } from '../shared/dm-ops/process-dm-ops.js';
import { IdentityClientContext } from '../shared/identity-client-context.js';
-import { useStaffAlert } from '../shared/staff-utils.js';
import type { DeviceOlmInboundKeys } from '../types/identity-service-types.js';
import {
peerToPeerMessageTypes,
@@ -199,7 +199,7 @@
const resendPeerToPeerMessages = useResendPeerToPeerMessages();
const { createOlmSessionsWithUser } = usePeerOlmSessionsCreatorContext();
- const { showAlertToStaff } = useStaffAlert();
+ const { addLog } = useDebugLogs();
return React.useCallback(
async (message: PeerToPeerMessage, messageID: string) => {
@@ -222,8 +222,8 @@
`${senderDeviceID}: No keys for the device, ` +
`session version: ${sessionVersion}`,
);
- showAlertToStaff(
- 'Error creating inbound session with device ',
+ addLog(
+ 'Error creating inbound session with device',
`${senderDeviceID}: No keys for the device, ` +
`session version: ${sessionVersion}`,
);
@@ -279,7 +279,7 @@
`${senderDeviceID}: ${errorMessage}, ` +
`session version: ${sessionVersion}`,
);
- showAlertToStaff(
+ addLog(
'Error creating inbound session with device ',
`${senderDeviceID}: ${errorMessage}, ` +
`session version: ${sessionVersion}`,
@@ -337,8 +337,8 @@
'Error decrypting message from device ' +
`${message.senderInfo.deviceID}: ${errorMessage}`,
);
- showAlertToStaff(
- 'Error decrypting message from device ',
+ addLog(
+ 'Error decrypting message from device',
`${message.senderInfo.deviceID}: ${errorMessage}`,
);
@@ -448,6 +448,7 @@
}
},
[
+ addLog,
broadcastDeviceListUpdates,
createOlmSessionsWithUser,
dispatch,
@@ -458,7 +459,6 @@
identityClient,
olmAPI,
resendPeerToPeerMessages,
- showAlertToStaff,
sqliteAPI,
],
);

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 15, 6:22 PM (9 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3341749
Default Alt Text
D14297.diff (6 KB)

Event Timeline