Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3367321
D13151.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
D13151.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
@@ -18,7 +18,6 @@
import { useDispatchWithMessageSource } from '../../hooks/ops-hooks.js';
import { mergeUpdatesWithMessageInfos } from '../../reducers/message-reducer.js';
import { getAllPeerUserIDAndDeviceIDs } from '../../selectors/user-selectors.js';
-import { usePeerToPeerCommunication } from '../../tunnelbroker/peer-to-peer-context.js';
import {
processDMOpsActionType,
queueDMOpsActionType,
@@ -189,14 +188,12 @@
dmOperationSpecification: OutboundDMOperationSpecification,
) => Promise<void> {
const processDMOps = useProcessDMOperation();
- const { sendDMOperation } = usePeerToPeerCommunication();
return React.useCallback(
async (dmOperationSpecification: OutboundDMOperationSpecification) => {
await processDMOps(dmOperationSpecification);
- await sendDMOperation(dmOperationSpecification);
},
- [processDMOps, sendDMOperation],
+ [processDMOps],
);
}
diff --git a/lib/tunnelbroker/peer-to-peer-context.js b/lib/tunnelbroker/peer-to-peer-context.js
--- a/lib/tunnelbroker/peer-to-peer-context.js
+++ b/lib/tunnelbroker/peer-to-peer-context.js
@@ -9,17 +9,11 @@
useTunnelbroker,
} from './tunnelbroker-context.js';
import { usePeerOlmSessionsCreatorContext } from '../components/peer-olm-session-creator-provider.react.js';
-import { getAllPeerUserIDAndDeviceIDs } from '../selectors/user-selectors.js';
-import {
- createMessagesToPeersFromDMOp,
- type OutboundDMOperationSpecification,
-} from '../shared/dm-ops/dm-op-utils.js';
import {
type AuthMetadata,
IdentityClientContext,
type IdentityClientContextType,
} from '../shared/identity-client-context.js';
-import { scheduleP2PMessagesActionType } from '../types/dm-ops.js';
import {
type OutboundP2PMessage,
outboundP2PMessageStatuses,
@@ -31,16 +25,16 @@
import { getConfig } from '../utils/config.js';
import { getMessageForException } from '../utils/errors.js';
import { olmSessionErrors } from '../utils/olm-utils.js';
-import { useDispatch, useSelector } from '../utils/redux-utils.js';
type PeerToPeerContextType = {
+processOutboundMessages: (
outboundMessageIDs: ?$ReadOnlyArray<string>,
dmOpID: ?string,
) => void,
- +sendDMOperation: (
- op: OutboundDMOperationSpecification,
- ) => Promise<$ReadOnlyArray<string>>,
+ +getDMOpsSendingPromise: () => {
+ +promise: Promise<$ReadOnlyArray<string>>,
+ +dmOpID: string,
+ },
+broadcastEphemeralMessage: (
contentPayload: string,
recipients: $ReadOnlyArray<{ +userID: string, +deviceID: string }>,
@@ -190,46 +184,27 @@
const identityContext = React.useContext(IdentityClientContext);
invariant(identityContext, 'Identity context should be set');
- const dispatch = useDispatch();
const dmOpsSendingPromiseResolvers = React.useRef<
Map<
string,
{
- +resolve: ($ReadOnlyArray<string>) => mixed,
+ +resolve: (messageIDs: $ReadOnlyArray<string>) => mixed,
+reject: Error => mixed,
},
>,
>(new Map());
- const allPeerUserIDAndDeviceIDs = useSelector(getAllPeerUserIDAndDeviceIDs);
- const currentUserInfo = useSelector(state => state.currentUserInfo);
// This returns a promise that will be resolved with arrays of successfully
// sent messages, so in case of failing all messages (e.g. no internet
// connection) it will still resolve but with an empty array.
- const sendDMOperation = React.useCallback(
- async (op: OutboundDMOperationSpecification) => {
- const dmOpID = uuid.v4();
- const promise = new Promise<$ReadOnlyArray<string>>((resolve, reject) => {
- dmOpsSendingPromiseResolvers.current.set(dmOpID, { resolve, reject });
- });
-
- const messages = await createMessagesToPeersFromDMOp(
- op,
- allPeerUserIDAndDeviceIDs,
- currentUserInfo,
- );
- dispatch({
- type: scheduleP2PMessagesActionType,
- payload: {
- dmOpID,
- messages,
- },
- });
+ const getDMOpsSendingPromise = React.useCallback(() => {
+ const dmOpID = uuid.v4();
+ const promise = new Promise<$ReadOnlyArray<string>>((resolve, reject) => {
+ dmOpsSendingPromiseResolvers.current.set(dmOpID, { resolve, reject });
+ });
- return promise;
- },
- [allPeerUserIDAndDeviceIDs, currentUserInfo, dispatch],
- );
+ return { promise, dmOpID };
+ }, []);
const processingQueue = React.useRef<
Array<{
@@ -367,10 +342,14 @@
const value: PeerToPeerContextType = React.useMemo(
() => ({
processOutboundMessages,
- sendDMOperation,
+ getDMOpsSendingPromise,
broadcastEphemeralMessage,
}),
- [broadcastEphemeralMessage, processOutboundMessages, sendDMOperation],
+ [
+ broadcastEphemeralMessage,
+ processOutboundMessages,
+ getDMOpsSendingPromise,
+ ],
);
return (
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 2:29 PM (21 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2585116
Default Alt Text
D13151.diff (4 KB)
Attached To
Mode
D13151: [lib] deprecate `sendDMOperation` and implement method to create sending promise
Attached
Detach File
Event Timeline
Log In to Comment