Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32559084
D14033.1767277814.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D14033.1767277814.diff
View Options
diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js
--- a/lib/actions/user-actions.js
+++ b/lib/actions/user-actions.js
@@ -35,7 +35,10 @@
permissionsAndAuthRelatedRequestTimeout,
callIdentityServiceTimeout,
} from '../shared/timeouts.js';
-import { usePeerToPeerCommunication } from '../tunnelbroker/peer-to-peer-context.js';
+import {
+ PeerToPeerContext,
+ usePeerToPeerCommunication,
+} from '../tunnelbroker/peer-to-peer-context.js';
import type {
LegacyLogInInfo,
LegacyLogInResult,
@@ -358,20 +361,24 @@
]);
}
-const secondaryDeviceLogOutOptions = Object.freeze({
- logOutType: 'secondary_device',
-});
-
-function useSecondaryDeviceLogOut(): () => Promise<LogOutResult> {
- const logOut = useLogOut(secondaryDeviceLogOutOptions);
-
+function useSendLogoutMessageToPrimaryDevice(
+ mandatory?: boolean = true,
+): () => Promise<void> {
const identityContext = React.useContext(IdentityClientContext);
if (!identityContext) {
throw new Error('Identity service client is not initialized');
}
- const { broadcastEphemeralMessage } = usePeerToPeerCommunication();
+ const peerToPeerContext = React.useContext(PeerToPeerContext);
return React.useCallback(async () => {
+ if (!peerToPeerContext) {
+ if (mandatory) {
+ throw new Error('PeerToPeerContext not set');
+ }
+ return;
+ }
+
+ const { broadcastEphemeralMessage } = peerToPeerContext;
const { identityClient, getAuthMetadata } = identityContext;
const authMetadata = await getAuthMetadata();
const { userID, deviceID } = authMetadata;
@@ -398,10 +405,23 @@
[recipient],
authMetadata,
);
+ }, [identityContext, peerToPeerContext, mandatory]);
+}
+
+const secondaryDeviceLogOutOptions = Object.freeze({
+ logOutType: 'secondary_device',
+});
+
+function useSecondaryDeviceLogOut(): () => Promise<LogOutResult> {
+ const logOut = useLogOut(secondaryDeviceLogOutOptions);
+ const sendLogoutMessage = useSendLogoutMessageToPrimaryDevice();
+
+ return React.useCallback(async () => {
+ await sendLogoutMessage();
// log out of identity service, keyserver and visually
return logOut();
- }, [identityContext, broadcastEphemeralMessage, logOut]);
+ }, [sendLogoutMessage, logOut]);
}
const claimUsernameActionTypes = Object.freeze({
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
@@ -447,4 +447,4 @@
return context;
}
-export { PeerToPeerProvider, usePeerToPeerCommunication };
+export { PeerToPeerContext, PeerToPeerProvider, usePeerToPeerCommunication };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 1, 2:30 PM (20 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5876408
Default Alt Text
D14033.1767277814.diff (2 KB)
Attached To
Mode
D14033: [lib] Extract hook to send logout message to primary device
Attached
Detach File
Event Timeline
Log In to Comment