Page MenuHomePhorge

D15139.1765062792.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D15139.1765062792.diff

diff --git a/lib/hooks/peer-list-hooks.js b/lib/hooks/peer-list-hooks.js
--- a/lib/hooks/peer-list-hooks.js
+++ b/lib/hooks/peer-list-hooks.js
@@ -7,6 +7,7 @@
import {
getAllPeerDevices,
getAllPeerUserIDAndDeviceIDs,
+ getPeersPrimaryDeviceIDs,
} from '../selectors/user-selectors.js';
import { IdentityClientContext } from '../shared/identity-client-context.js';
import { usePeerToPeerCommunication } from '../tunnelbroker/peer-to-peer-context.js';
@@ -72,6 +73,7 @@
const broadcastDeviceListUpdates = useBroadcastDeviceListUpdates();
const allPeerDevices = useSelector(getAllPeerDevices);
+ const peerPrimaryDevices = useSelector(getPeersPrimaryDeviceIDs);
return React.useCallback(
async (userIDs: $ReadOnlyArray<string>, broadcastUpdates: ?boolean) => {
@@ -87,6 +89,25 @@
if (Object.keys(deviceLists).length === 0) {
return {};
}
+
+ const primaryDeviceChangedUserIDs = userIDs.filter(userID => {
+ const prevPrimaryDeviceID = peerPrimaryDevices[userID];
+ const newPrimaryDeviceID = result.deviceLists[userID]?.devices[0];
+ return (
+ !!prevPrimaryDeviceID &&
+ !!newPrimaryDeviceID &&
+ newPrimaryDeviceID !== prevPrimaryDeviceID
+ );
+ });
+
+ if (primaryDeviceChangedUserIDs.length > 0) {
+ console.log(
+ 'Primary device ID changed for users',
+ primaryDeviceChangedUserIDs,
+ );
+ // TODO: implement
+ }
+
dispatch({
type: setPeerDeviceListsActionType,
payload: { deviceLists, usersPlatformDetails },
@@ -112,6 +133,7 @@
},
[
allPeerDevices,
+ peerPrimaryDevices,
broadcastDeviceListUpdates,
dispatch,
getDeviceListsForUsers,
diff --git a/lib/selectors/user-selectors.js b/lib/selectors/user-selectors.js
--- a/lib/selectors/user-selectors.js
+++ b/lib/selectors/user-selectors.js
@@ -328,6 +328,19 @@
),
);
+const getPeersPrimaryDeviceIDs: (state: BaseAppState<>) => {
+ +[userID: string]: ?string,
+} = createSelector(
+ (state: BaseAppState<>) => state.auxUserStore.auxUserInfos,
+ (auxUserInfos: AuxUserInfos) =>
+ Object.fromEntries(
+ entries(auxUserInfos).map(([userID, { deviceList }]) => [
+ userID,
+ deviceList?.devices?.[0],
+ ]),
+ ),
+);
+
const getOwnPrimaryDeviceID: (state: BaseAppState<>) => ?string =
createSelector(
(state: BaseAppState<>) => state.auxUserStore.auxUserInfos,
@@ -353,6 +366,7 @@
getKeyserverDeviceID,
getAllPeerDevices,
getAllPeerUserIDAndDeviceIDs,
+ getPeersPrimaryDeviceIDs,
getOwnPrimaryDeviceID,
getOwnRawDeviceList,
};

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 6, 11:13 PM (10 m, 35 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5840946
Default Alt Text
D15139.1765062792.diff (2 KB)

Event Timeline