Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3185553
D11843.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D11843.diff
View Options
diff --git a/lib/hooks/peer-list-hooks.js b/lib/hooks/peer-list-hooks.js
new file mode 100644
--- /dev/null
+++ b/lib/hooks/peer-list-hooks.js
@@ -0,0 +1,40 @@
+// @flow
+
+import invariant from 'invariant';
+import * as React from 'react';
+
+import { setPeerDeviceListsActionType } from '../actions/aux-user-actions.js';
+import { getRelativeUserIDs } from '../selectors/user-selectors.js';
+import { IdentityClientContext } from '../shared/identity-client-context.js';
+import { convertSignedDeviceListsToRawDeviceLists } from '../utils/device-list-utils.js';
+import { useDispatch, useSelector } from '../utils/redux-utils.js';
+
+function useCreateInitialPeerList(): () => Promise<void> {
+ const dispatch = useDispatch();
+ const relativeUserIDs = useSelector(getRelativeUserIDs);
+
+ const identityContext = React.useContext(IdentityClientContext);
+ invariant(identityContext, 'Identity context should be set');
+
+ return React.useCallback(async () => {
+ if (!identityContext) {
+ return;
+ }
+ try {
+ const userDeviceLists =
+ await identityContext.identityClient.getDeviceListsForUsers(
+ relativeUserIDs,
+ );
+ const usersRawDeviceLists =
+ convertSignedDeviceListsToRawDeviceLists(userDeviceLists);
+ dispatch({
+ type: setPeerDeviceListsActionType,
+ payload: { deviceLists: usersRawDeviceLists },
+ });
+ } catch (e) {
+ console.log(`Error creating initial peer list: ${e.message}`);
+ }
+ }, [dispatch, identityContext, relativeUserIDs]);
+}
+
+export { useCreateInitialPeerList };
diff --git a/native/profile/tunnelbroker-menu.react.js b/native/profile/tunnelbroker-menu.react.js
--- a/native/profile/tunnelbroker-menu.react.js
+++ b/native/profile/tunnelbroker-menu.react.js
@@ -5,6 +5,7 @@
import { Text, View } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
+import { useCreateInitialPeerList } from 'lib/hooks/peer-list-hooks.js';
import { IdentityClientContext } from 'lib/shared/identity-client-context.js';
import { useTunnelbroker } from 'lib/tunnelbroker/tunnelbroker-context.js';
import {
@@ -89,6 +90,8 @@
}
}, [identityContext, sendMessage]);
+ const onCreateInitialPeerList = useCreateInitialPeerList();
+
const onSendEncryptedMessage = React.useCallback(async () => {
try {
if (!currentUserID) {
@@ -183,6 +186,15 @@
Create session with own devices
</Text>
</Button>
+ <Button
+ onPress={onCreateInitialPeerList}
+ style={styles.row}
+ iosFormat="highlight"
+ iosHighlightUnderlayColor={colors.panelIosHighlightUnderlay}
+ iosActiveOpacity={0.85}
+ >
+ <Text style={styles.submenuText}>Create initial peer list</Text>
+ </Button>
<Button
onPress={onSendEncryptedMessage}
style={styles.row}
diff --git a/web/settings/account-settings.react.js b/web/settings/account-settings.react.js
--- a/web/settings/account-settings.react.js
+++ b/web/settings/account-settings.react.js
@@ -2,12 +2,11 @@
import * as React from 'react';
-import { setPeerDeviceListsActionType } from 'lib/actions/aux-user-actions.js';
import { useLogOut, logOutActionTypes } from 'lib/actions/user-actions.js';
import { useModalContext } from 'lib/components/modal-provider.react.js';
import SWMansionIcon from 'lib/components/swmansion-icon.react.js';
import { useStringForUser } from 'lib/hooks/ens-cache.js';
-import { getRelativeUserIDs } from 'lib/selectors/user-selectors.js';
+import { useCreateInitialPeerList } from 'lib/hooks/peer-list-hooks.js';
import { accountHasPassword } from 'lib/shared/account-utils.js';
import { IdentityClientContext } from 'lib/shared/identity-client-context.js';
import { useTunnelbroker } from 'lib/tunnelbroker/tunnelbroker-context.js';
@@ -15,9 +14,7 @@
createOlmSessionsWithOwnDevices,
getContentSigningKey,
} from 'lib/utils/crypto-utils.js';
-import { convertSignedDeviceListsToRawDeviceLists } from 'lib/utils/device-list-utils.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
-import { useDispatch } from 'lib/utils/redux-utils.js';
import css from './account-settings.css';
import AppearanceChangeModal from './appearance-change-modal.react.js';
@@ -113,29 +110,7 @@
}
}, [identityContext, sendMessage]);
- const dispatch = useDispatch();
- const relativeUserIDs = useSelector(getRelativeUserIDs);
-
- const onCreateInitialPeerList = React.useCallback(async () => {
- if (!identityContext) {
- return;
- }
-
- try {
- const userDeviceLists =
- await identityContext.identityClient.getDeviceListsForUsers(
- relativeUserIDs,
- );
- const usersRawDeviceLists =
- convertSignedDeviceListsToRawDeviceLists(userDeviceLists);
- dispatch({
- type: setPeerDeviceListsActionType,
- payload: { deviceLists: usersRawDeviceLists },
- });
- } catch (e) {
- console.log(`Error creating initial peer list: ${e.message}`);
- }
- }, [dispatch, identityContext, relativeUserIDs]);
+ const onCreateInitialPeerList = useCreateInitialPeerList();
const openBackupTestRestoreModal = React.useCallback(
() => pushModal(<BackupTestRestoreModal onClose={popModal} />),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 12:59 PM (18 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2444021
Default Alt Text
D11843.diff (5 KB)
Attached To
Mode
D11843: [native] add test button to create initial peer list
Attached
Detach File
Event Timeline
Log In to Comment