diff --git a/lib/shared/dm-ops/dm-op-utils.js b/lib/shared/dm-ops/dm-op-utils.js --- a/lib/shared/dm-ops/dm-op-utils.js +++ b/lib/shared/dm-ops/dm-op-utils.js @@ -2,7 +2,10 @@ import uuid from 'uuid'; +import type { ProcessDMOperationUtilities } from './dm-op-spec.js'; +import { dmOpSpecs } from './dm-op-specs.js'; import type { DMOperation } from '../../types/dm-ops.js'; +import type { NotificationsCreationData } from '../../types/notif-types.js'; import { outboundP2PMessageStatuses, type OutboundP2PMessage, @@ -87,4 +90,12 @@ ); } -export { createMessagesToPeersFromDMOp }; +async function getNotificationsCreationDataFromDMOp( + operation: DMOperationSpecification, + utilities: ProcessDMOperationUtilities, +): Promise { + const { op } = operation; + return await dmOpSpecs[op.type].notificationsCreationData?.(op, utilities); +} + +export { createMessagesToPeersFromDMOp, getNotificationsCreationDataFromDMOp }; 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,9 +9,11 @@ useTunnelbroker, } from './tunnelbroker-context.js'; import { usePeerOlmSessionsCreatorContext } from '../components/peer-olm-session-creator-provider.react.js'; +import { useGetLatestMessageEdit } from '../hooks/latest-message-edit.js'; import { getAllPeerUserIDAndDeviceIDs } from '../selectors/user-selectors.js'; import { createMessagesToPeersFromDMOp, + getNotificationsCreationDataFromDMOp, type DMOperationSpecification, } from '../shared/dm-ops/dm-op-utils.js'; import { @@ -178,6 +180,17 @@ const allPeerUserIDAndDeviceIDs = useSelector(getAllPeerUserIDAndDeviceIDs); const currentUserInfo = useSelector(state => state.currentUserInfo); + const fetchMessage = useGetLatestMessageEdit(); + const threadInfos = useSelector(state => state.threadStore.threadInfos); + + const utilities = React.useMemo( + () => ({ + fetchMessage, + threadInfos, + }), + [fetchMessage, threadInfos], + ); + const sendDMOperation = React.useCallback( async (op: DMOperationSpecification) => { const dmOpID = uuid.v4(); @@ -190,18 +203,21 @@ allPeerUserIDAndDeviceIDs, currentUserInfo, ); + const notificationsCreationData = + await getNotificationsCreationDataFromDMOp(op, utilities); dispatch({ type: scheduleP2PMessagesActionType, payload: { dmOpID, messages, + notificationsCreationData, }, }); return promise; }, - [allPeerUserIDAndDeviceIDs, currentUserInfo, dispatch], + [utilities, allPeerUserIDAndDeviceIDs, currentUserInfo, dispatch], ); const processingQueue = React.useRef<