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 @@ -8,6 +8,7 @@ import { type ProcessDMOperationUtilities } from './dm-op-spec.js'; import { dmOpSpecs } from './dm-op-specs.js'; import { useProcessAndSendDMOperation } from './process-dm-ops.js'; +import { setMissingDeviceListsActionType } from '../../actions/aux-user-actions.js'; import { useFindUserIdentities } from '../../actions/find-user-identities-actions.js'; import { useLoggedInUserInfo } from '../../hooks/account-hooks.js'; import { useGetLatestMessageEdit } from '../../hooks/latest-message-edit.js'; @@ -44,9 +45,9 @@ import { updateTypes } from '../../types/update-types-enum.js'; import type { ClientUpdateInfo } from '../../types/update-types.js'; import { getContentSigningKey } from '../../utils/crypto-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 { userHasDeviceList } from '../thread-utils.js'; +import { userHasDeviceList, deviceListIsNonEmpty } from '../thread-utils.js'; function generateMessagesToPeers( message: DMOperation, @@ -127,6 +128,7 @@ const utilities = useSendDMOperationUtils(); const auxUserInfos = useSelector(state => state.auxUserStore.auxUserInfos); const getAndUpdateDeviceListsForUsers = useGetAndUpdateDeviceListsForUsers(); + const dispatch = useDispatch(); const getUsersWithoutDeviceList = React.useCallback( (userIDs: $ReadOnlyArray) => { @@ -156,6 +158,22 @@ true, ); + const missingUsers: $ReadOnlyArray = + missingDeviceListsUserIDs.filter( + id => !deviceListIsNonEmpty(deviceLists[id]), + ); + if (missingUsers.length > 0) { + dispatch({ + type: setMissingDeviceListsActionType, + payload: { + usersMissingFromIdentity: { + userIDs: missingUsers, + time: Date.now(), + }, + }, + }); + } + const updatedPeers: Array = []; for (const userID of missingDeviceListsUserIDs) { if (deviceLists[userID] && deviceLists[userID].devices.length > 0) { @@ -169,7 +187,7 @@ } return updatedPeers; }, - [getAndUpdateDeviceListsForUsers, getUsersWithoutDeviceList], + [dispatch, getAndUpdateDeviceListsForUsers, getUsersWithoutDeviceList], ); return React.useCallback( diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -42,6 +42,7 @@ usersWithPersonalThreadSelector, } from '../selectors/user-selectors.js'; import type { AuxUserInfos } from '../types/aux-user-types.js'; +import type { RawDeviceList } from '../types/identity-service-types.js'; import type { RelativeMemberInfo, RawThreadInfo, @@ -1824,10 +1825,11 @@ userID: string, auxUserInfos: AuxUserInfos, ): boolean { - return ( - !!auxUserInfos[userID]?.deviceList && - auxUserInfos[userID].deviceList.devices.length > 0 - ); + return deviceListIsNonEmpty(auxUserInfos[userID]?.deviceList); +} + +function deviceListIsNonEmpty(deviceList?: RawDeviceList): boolean { + return !!deviceList && deviceList.devices.length > 0; } export { @@ -1898,4 +1900,5 @@ isMemberActive, createThreadTimestamps, userHasDeviceList, + deviceListIsNonEmpty, };