Page MenuHomePhabricator

D12225.id40755.diff
No OneTemporary

D12225.id40755.diff

diff --git a/lib/handlers/peer-to-peer-message-handler.js b/lib/handlers/peer-to-peer-message-handler.js
--- a/lib/handlers/peer-to-peer-message-handler.js
+++ b/lib/handlers/peer-to-peer-message-handler.js
@@ -2,7 +2,10 @@
import _isEqual from 'lodash/fp/isEqual.js';
-import { verifyAndGetDeviceList } from '../shared/device-list-utils.js';
+import {
+ verifyAndGetDeviceList,
+ removeDeviceFromDeviceList,
+} from '../shared/device-list-utils.js';
import type {
IdentityServiceClient,
DeviceOlmInboundKeys,
@@ -11,6 +14,7 @@
peerToPeerMessageTypes,
type PeerToPeerMessage,
} from '../types/tunnelbroker/peer-to-peer-message-types.js';
+import { secondaryDeviceLogoutP2PMessageValidator } from '../types/tunnelbroker/user-actions-peer-to-peer-message-types.js';
import { getConfig } from '../utils/config.js';
import { getContentSigningKey } from '../utils/crypto-utils.js';
import { getMessageForException } from '../utils/errors.js';
@@ -106,6 +110,24 @@
'Decrypted message from device ' +
`${message.senderInfo.deviceID}: ${decrypted}`,
);
+
+ try {
+ const parsedMessageToDevice = JSON.parse(decrypted);
+ if (
+ !secondaryDeviceLogoutP2PMessageValidator.is(parsedMessageToDevice)
+ ) {
+ return;
+ }
+ const { userID, deviceID: deviceIDToLogOut } = message.senderInfo;
+ await removeDeviceFromDeviceList(
+ identityClient,
+ userID,
+ deviceIDToLogOut,
+ );
+ // TODO: broadcast device list update here
+ } catch (e) {
+ console.log(e);
+ }
} catch (e) {
if (e.message?.includes(olmSessionErrors.messageAlreadyDecrypted)) {
console.log(

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 4:05 AM (13 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2587700
Default Alt Text
D12225.id40755.diff (1 KB)

Event Timeline