Skip to content

Commit

Permalink
[native] Replace some alerts with logs
Browse files Browse the repository at this point in the history
Summary:
It is important that we don't replace alerts that are critical. Also, on the web we aren't handling the logs yet, so we should use the old mechanism.

https://linear.app/comm/issue/ENG-10140/replace-staff-alerts-with-a-log

Depends on D14296

Test Plan: Called `addLog` on the web and mobile and checked if the behavior is correct.

Reviewers: kamil, angelika

Reviewed By: kamil

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D14297
  • Loading branch information
palys-swm committed Feb 12, 2025
1 parent fdfcabd commit ac174fe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
13 changes: 10 additions & 3 deletions lib/components/debug-logs-context-provider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,32 @@
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,
};

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,
{
title,
message,
timestamp: Date.now(),
},
]),
[],
]);
},
[isCurrentUserStaff],
);

const clearLogs = React.useCallback(() => setLogs([]), []);
Expand Down
16 changes: 8 additions & 8 deletions lib/shared/dm-ops/process-dm-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} 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,
Expand All @@ -30,7 +31,6 @@ import type { DispatchMetadata } from '../../types/redux-types.js';
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,
Expand All @@ -44,7 +44,7 @@ function useProcessDMOperation(): (

const dispatch = useDispatch();

const { showAlertToStaff } = useStaffAlert();
const { addLog } = useDebugLogs();

return React.useCallback(
async (
Expand All @@ -53,7 +53,7 @@ function useProcessDMOperation(): (
) => {
const { viewerID, ...restUtilities } = baseUtilities;
if (!viewerID) {
showAlertToStaff(
addLog(
'Ignored DMOperation because logged out',
JSON.stringify(dmOperationSpecification.op),
);
Expand Down Expand Up @@ -127,7 +127,7 @@ function useProcessDMOperation(): (
}

if (!dmOpSpecs[dmOp.type].operationValidator.is(dmOp)) {
showAlertToStaff(
addLog(
"Ignoring operation because it doesn't pass validation",
JSON.stringify(dmOp),
);
Expand All @@ -142,7 +142,7 @@ function useProcessDMOperation(): (

if (!processingCheckResult.isProcessingPossible) {
if (processingCheckResult.reason.type === 'invalid') {
showAlertToStaff(
addLog(
'Ignoring operation because it is invalid',
JSON.stringify(dmOp),
);
Expand Down Expand Up @@ -174,12 +174,12 @@ function useProcessDMOperation(): (
}

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),
);
Expand Down Expand Up @@ -251,10 +251,10 @@ function useProcessDMOperation(): (
);
},
[
addLog,
baseUtilities,
processBlobHolders,
dispatchWithMetadata,
showAlertToStaff,
createMessagesToPeersFromDMOp,
confirmPeerToPeerMessage,
dispatch,
Expand Down
16 changes: 8 additions & 8 deletions lib/tunnelbroker/use-peer-to-peer-message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useResendPeerToPeerMessages } from './use-resend-peer-to-peer-messages.
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,
Expand All @@ -23,7 +24,6 @@ import {
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,
Expand Down Expand Up @@ -199,7 +199,7 @@ function usePeerToPeerMessageHandler(): (
const resendPeerToPeerMessages = useResendPeerToPeerMessages();
const { createOlmSessionsWithUser } = usePeerOlmSessionsCreatorContext();

const { showAlertToStaff } = useStaffAlert();
const { addLog } = useDebugLogs();

return React.useCallback(
async (message: PeerToPeerMessage, messageID: string) => {
Expand All @@ -222,8 +222,8 @@ function usePeerToPeerMessageHandler(): (
`${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}`,
);
Expand Down Expand Up @@ -279,7 +279,7 @@ function usePeerToPeerMessageHandler(): (
`${senderDeviceID}: ${errorMessage}, ` +
`session version: ${sessionVersion}`,
);
showAlertToStaff(
addLog(
'Error creating inbound session with device ',
`${senderDeviceID}: ${errorMessage}, ` +
`session version: ${sessionVersion}`,
Expand Down Expand Up @@ -337,8 +337,8 @@ function usePeerToPeerMessageHandler(): (
'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}`,
);

Expand Down Expand Up @@ -448,6 +448,7 @@ function usePeerToPeerMessageHandler(): (
}
},
[
addLog,
broadcastDeviceListUpdates,
createOlmSessionsWithUser,
dispatch,
Expand All @@ -458,7 +459,6 @@ function usePeerToPeerMessageHandler(): (
identityClient,
olmAPI,
resendPeerToPeerMessages,
showAlertToStaff,
sqliteAPI,
],
);
Expand Down

0 comments on commit ac174fe

Please sign in to comment.