Skip to content

Commit

Permalink
[lib] Extract user ids from DM ops
Browse files Browse the repository at this point in the history
Summary: issue: [[https://linear.app/comm/issue/ENG-8829/connect-dm-ops-to-userinfoshandler | ENG-8829]]

Test Plan: Tested by dispatching a create_thread op, and then an add_members to the just created thick thread. Checked that the user id was added to redux.

Reviewers: tomek, kamil

Reviewed By: tomek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D13205
  • Loading branch information
InkaAlicja committed Sep 2, 2024
1 parent 6186db4 commit 1d31bb5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/shared/dm-ops/process-dm-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createMessagesToPeersFromDMOp,
dmOperationSpecificationTypes,
} from './dm-op-utils.js';
import { processNewUserIDsActionType } from '../../actions/user-actions.js';
import { useLoggedInUserInfo } from '../../hooks/account-hooks.js';
import { useGetLatestMessageEdit } from '../../hooks/latest-message-edit.js';
import { useDispatchWithMetadata } from '../../hooks/ops-hooks.js';
Expand All @@ -25,15 +26,17 @@ import {
sendDMActionTypes,
type SendDMOpsSuccessPayload,
} from '../../types/dm-ops.js';
import { dmOperationValidator } from '../../types/dm-ops.js';
import type { LocalMessageInfo } from '../../types/message-types.js';
import type { RawThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js';
import type { DispatchMetadata } from '../../types/redux-types.js';
import type { OutboundP2PMessage } from '../../types/sqlite-types.js';
import { threadTypes } from '../../types/thread-types-enum.js';
import type { LegacyRawThreadInfo } from '../../types/thread-types.js';
import { updateTypes } from '../../types/update-types-enum.js';
import { extractUserIDsFromPayload } from '../../utils/conversion-utils.js';
import { useDispatchActionPromise } from '../../utils/redux-promise-utils.js';
import { useSelector } from '../../utils/redux-utils.js';
import { useSelector, useDispatch } from '../../utils/redux-utils.js';
import { messageSpecs } from '../messages/message-specs.js';
import { updateSpecs } from '../updates/update-specs.js';

Expand All @@ -58,6 +61,8 @@ function useProcessDMOperation(): (
const allPeerUserIDAndDeviceIDs = useSelector(getAllPeerUserIDAndDeviceIDs);
const currentUserInfo = useSelector(state => state.currentUserInfo);

const dispatch = useDispatch();

return React.useCallback(
async (
dmOperationSpecification: DMOperationSpecification,
Expand Down Expand Up @@ -154,6 +159,14 @@ function useProcessDMOperation(): (
return;
}

const newUserIDs = extractUserIDsFromPayload(dmOperationValidator, dmOp);
if (newUserIDs.length > 0) {
dispatch({
type: processNewUserIDsActionType,
payload: { userIDs: newUserIDs },
});
}

const dmOpSpec = dmOpSpecs[dmOp.type];
const notificationsCreationDataPromise = (async () => {
return await dmOpSpec.notificationsCreationData?.(dmOp, utilities);
Expand Down Expand Up @@ -252,6 +265,7 @@ function useProcessDMOperation(): (
allPeerUserIDAndDeviceIDs,
currentUserInfo,
threadInfos,
dispatch,
],
);
}
Expand Down

0 comments on commit 1d31bb5

Please sign in to comment.