@wireapp/core 46.0.16 → 46.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Account.js +43 -56
- package/lib/account/AccountService.js +1 -0
- package/lib/broadcast/BroadcastService.js +3 -0
- package/lib/client/ClientBackendRepository.js +1 -0
- package/lib/client/ClientDatabaseRepository.js +16 -7
- package/lib/client/ClientService.d.ts.map +1 -1
- package/lib/client/ClientService.js +14 -13
- package/lib/connection/ConnectionService.js +1 -0
- package/lib/conversation/AssetService/AssetService.d.ts +0 -1
- package/lib/conversation/AssetService/AssetService.d.ts.map +1 -1
- package/lib/conversation/AssetService/AssetService.js +13 -6
- package/lib/conversation/AssetService/AssetService.test.js +1 -1
- package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
- package/lib/conversation/ConversationService/ConversationService.js +90 -80
- package/lib/conversation/ConversationService/ConversationService.test.js +12 -5
- package/lib/conversation/ConversationService/Utility/getConversationQualifiedMembers.d.ts.map +1 -1
- package/lib/conversation/MessageTimer/MessageTimer.js +2 -0
- package/lib/conversation/SubconversationService/SubconversationService.d.ts.map +1 -1
- package/lib/conversation/SubconversationService/SubconversationService.js +23 -17
- package/lib/conversation/content/AssetContent.d.ts +0 -1
- package/lib/conversation/content/AssetContent.d.ts.map +1 -1
- package/lib/conversation/content/ContentType.js +18 -19
- package/lib/conversation/content/FileContent.d.ts +0 -1
- package/lib/conversation/content/FileContent.d.ts.map +1 -1
- package/lib/conversation/content/ImageContent.d.ts +0 -1
- package/lib/conversation/content/ImageContent.d.ts.map +1 -1
- package/lib/conversation/message/MessageBuilder.js +22 -23
- package/lib/conversation/message/MessageService.js +5 -4
- package/lib/conversation/message/MessageService.test.js +20 -9
- package/lib/conversation/message/MessageToProtoMapper.js +2 -2
- package/lib/conversation/message/RecipientsHelper.js +1 -2
- package/lib/conversation/message/TextContentBuilder.js +3 -2
- package/lib/conversation/message/UserClientsUtil.js +2 -3
- package/lib/conversation/message/messageSender.js +5 -6
- package/lib/cryptography/AssetCryptography/AssetCryptography.d.ts.map +1 -1
- package/lib/cryptography/GenericMessageMapper.js +74 -22
- package/lib/cryptography/MessageHashService.d.ts +0 -1
- package/lib/cryptography/MessageHashService.d.ts.map +1 -1
- package/lib/cryptography/MessageHashService.js +2 -0
- package/lib/errors/DecryptionError.js +2 -0
- package/lib/errors/FederatedBackendsError.js +3 -2
- package/lib/giphy/GiphyService.js +1 -0
- package/lib/linkPreview/LinkPreviewService.js +2 -12
- package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.d.ts +4 -4
- package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.js +9 -8
- package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/schema.d.ts +8 -8
- package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.js +33 -3
- package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.test.js +11 -11
- package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.js +15 -5
- package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Account.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Account.js +1 -1
- package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.d.ts +1 -1
- package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.js +2 -3
- package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Certificate.js +1 -1
- package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Order.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Order.js +2 -2
- package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.js +1 -2
- package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.schema.d.ts +4 -4
- package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/IncomingMessagesQueue/IncomingMesssagesQueue.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.js +1 -1
- package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.js +1 -1
- package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.test.js +7 -3
- package/lib/messagingProtocols/mls/MLSService/ClientMLSError.js +1 -0
- package/lib/messagingProtocols/mls/MLSService/CoreCryptoMLSError.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/MLSService/MLSService.js +109 -114
- package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +28 -9
- package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.js +1 -2
- package/lib/messagingProtocols/mls/conversationRejoinQueue.js +3 -4
- package/lib/messagingProtocols/mls/utils/MLSId.js +2 -3
- package/lib/messagingProtocols/proteus/EventHandler/events/otrMessageAdd/otrMessageAdd.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +6 -2
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.js +3 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.js +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.js +5 -4
- package/lib/messagingProtocols/proteus/ProteusService/DecryptionErrorGenerator/DecryptionErrorGenerator.js +1 -2
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +20 -16
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts +4 -7
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +15 -15
- package/lib/messagingProtocols/proteus/ProteusService/cryptoMigrationStateStore.js +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/identityClearer.js +1 -2
- package/lib/messagingProtocols/proteus/ProteusService/sessionIdMigrator.js +2 -3
- package/lib/messagingProtocols/proteus/ProteusService/userDomainFilters.js +1 -2
- package/lib/messagingProtocols/proteus/Utility/Recipients.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.js +14 -14
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.test.js +5 -2
- package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.d.ts.map +1 -1
- package/lib/notification/NotificationBackendRepository.d.ts +1 -1
- package/lib/notification/NotificationBackendRepository.js +1 -0
- package/lib/notification/NotificationDatabaseRepository.js +1 -0
- package/lib/notification/NotificationService.js +38 -49
- package/lib/secretStore/encryptedStore.js +10 -22
- package/lib/secretStore/secretKeyGenerator.js +2 -2
- package/lib/secretStore/secretKeyGenerator.test.js +1 -1
- package/lib/self/SelfService.js +2 -1
- package/lib/storage/CoreDB.js +2 -3
- package/lib/team/TeamService.js +1 -0
- package/lib/test/PayloadHelper.js +3 -4
- package/lib/testUtils/index.js +2 -3
- package/lib/user/UserService.d.ts +2 -2
- package/lib/user/UserService.js +1 -0
- package/lib/util/LocalStorageStore/index.d.ts.map +1 -1
- package/lib/util/LowPrecisionTaskScheduler/LowPrecisionTaskScheduler.js +4 -6
- package/lib/util/RecurringTaskScheduler/RecurringTaskScheduler.d.ts.map +1 -1
- package/lib/util/RecurringTaskScheduler/RecurringTaskScheduler.js +34 -33
- package/lib/util/TaskScheduler/TaskScheduler.d.ts +1 -1
- package/lib/util/TaskScheduler/TaskScheduler.d.ts.map +1 -1
- package/lib/util/TypePredicateUtil.js +7 -10
- package/lib/util/fullyQualifiedClientIdUtils.js +1 -2
- package/package.json +3 -3
|
@@ -37,11 +37,15 @@ const getGenericMessageParams_1 = require("../Utility/getGenericMessageParams");
|
|
|
37
37
|
const isClearFromMismatch_1 = require("../Utility/isClearFromMismatch");
|
|
38
38
|
const SessionHandler_1 = require("../Utility/SessionHandler");
|
|
39
39
|
class ProteusService {
|
|
40
|
+
apiClient;
|
|
41
|
+
cryptoClient;
|
|
42
|
+
config;
|
|
43
|
+
messageService;
|
|
44
|
+
logger = (0, logdown_1.default)('@wireapp/core/ProteusService');
|
|
40
45
|
constructor(apiClient, cryptoClient, config) {
|
|
41
46
|
this.apiClient = apiClient;
|
|
42
47
|
this.cryptoClient = cryptoClient;
|
|
43
48
|
this.config = config;
|
|
44
|
-
this.logger = (0, logdown_1.default)('@wireapp/core/ProteusService');
|
|
45
49
|
this.messageService = new MessageService_1.MessageService(this.apiClient, this);
|
|
46
50
|
}
|
|
47
51
|
async handleOtrMessageAddEvent(event) {
|
|
@@ -51,7 +55,6 @@ class ProteusService {
|
|
|
51
55
|
});
|
|
52
56
|
}
|
|
53
57
|
async initClient(storeEngine, context) {
|
|
54
|
-
var _a;
|
|
55
58
|
const dbName = storeEngine.storeName;
|
|
56
59
|
if (context.domain) {
|
|
57
60
|
// We want sessions to be fully qualified from now on
|
|
@@ -63,17 +66,18 @@ class ProteusService {
|
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
if (!cryptoMigrationStateStore_1.cryptoMigrationStore.coreCrypto.isReady(dbName) && this.cryptoClient.migrateFromCryptobox) {
|
|
66
|
-
this.logger.info(`Migrating
|
|
69
|
+
this.logger.info(`Migrating from cryptobox to corecrypto.`);
|
|
67
70
|
try {
|
|
71
|
+
const startTime = Date.now();
|
|
68
72
|
await this.cryptoClient.migrateFromCryptobox(dbName);
|
|
69
73
|
cryptoMigrationStateStore_1.cryptoMigrationStore.coreCrypto.markAsReady(dbName);
|
|
70
|
-
this.logger.info(`Successfully migrated from cryptobox
|
|
74
|
+
this.logger.info(`Successfully migrated from cryptobox to corecrypto (took ${Date.now() - startTime}ms).`);
|
|
71
75
|
}
|
|
72
76
|
catch (error) {
|
|
73
77
|
this.logger.error('Client was not able to perform DB migration: ', error);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
|
-
const backendPrekeys = await this.apiClient.api.client.getClientPreKeys(
|
|
80
|
+
const backendPrekeys = await this.apiClient.api.client.getClientPreKeys(context.clientId ?? '');
|
|
77
81
|
const totalUsableBackedPrekeys = backendPrekeys.length - 1; // we remove the last resort prekey from the total number of available prekeys
|
|
78
82
|
return this.cryptoClient.init(totalUsableBackedPrekeys);
|
|
79
83
|
}
|
|
@@ -101,7 +105,6 @@ class ProteusService {
|
|
|
101
105
|
return this.cryptoClient.getRemoteFingerprint(sessionId);
|
|
102
106
|
}
|
|
103
107
|
async createConversation(conversationData) {
|
|
104
|
-
var _a;
|
|
105
108
|
try {
|
|
106
109
|
const conversation = await this.apiClient.api.conversation.postConversation(conversationData);
|
|
107
110
|
return { conversation };
|
|
@@ -115,8 +118,8 @@ class ProteusService {
|
|
|
115
118
|
}
|
|
116
119
|
case conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS: {
|
|
117
120
|
const { backends } = error;
|
|
118
|
-
const { excludedUsers: unreachableUsers, includedUsers: availableUsers } = (0, userDomainFilters_1.filterUsersFromDomains)(
|
|
119
|
-
conversationData =
|
|
121
|
+
const { excludedUsers: unreachableUsers, includedUsers: availableUsers } = (0, userDomainFilters_1.filterUsersFromDomains)(conversationData.qualified_users ?? [], backends);
|
|
122
|
+
conversationData = { ...conversationData, qualified_users: availableUsers };
|
|
120
123
|
// If conversation creation returns an error because a backend is offline,
|
|
121
124
|
// we try creating the conversation again with users from available backends
|
|
122
125
|
const response = await this.apiClient.api.conversation.postConversation(conversationData);
|
|
@@ -188,7 +191,6 @@ class ProteusService {
|
|
|
188
191
|
}
|
|
189
192
|
}
|
|
190
193
|
async sendMessage({ userIds, conversationId, nativePush, targetMode, payload, onClientMismatch, }) {
|
|
191
|
-
var _a;
|
|
192
194
|
const messageParams = await (0, getGenericMessageParams_1.getGenericMessageParams)({
|
|
193
195
|
apiClient: this.apiClient,
|
|
194
196
|
sendingClientId: this.apiClient.validatedClientId,
|
|
@@ -201,16 +203,19 @@ class ProteusService {
|
|
|
201
203
|
},
|
|
202
204
|
});
|
|
203
205
|
const { sendingClientId, recipients, plainText, options } = messageParams;
|
|
204
|
-
const response = await this.messageService.sendMessage(sendingClientId, recipients, plainText,
|
|
206
|
+
const response = await this.messageService.sendMessage(sendingClientId, recipients, plainText, {
|
|
207
|
+
...options,
|
|
208
|
+
onClientMismatch: mismatch => onClientMismatch?.(mismatch, false),
|
|
209
|
+
});
|
|
205
210
|
if (!response.canceled) {
|
|
206
211
|
if (!(0, isClearFromMismatch_1.isClearFromMismatch)(response)) {
|
|
207
212
|
// We warn the consumer that there is a mismatch that did not prevent message sending
|
|
208
|
-
await
|
|
213
|
+
await onClientMismatch?.(response, true);
|
|
209
214
|
}
|
|
210
215
|
this.logger.log(`Successfully sent Proteus message to conversation '${conversationId.id}'`);
|
|
211
216
|
}
|
|
212
217
|
const sendingState = response.canceled ? conversation_2.MessageSendingState.CANCELED : conversation_2.MessageSendingState.OUTGOING_SENT;
|
|
213
|
-
const failedToSend = response.failed || Object.keys(
|
|
218
|
+
const failedToSend = response.failed || Object.keys(response.failed_to_confirm_clients ?? {}).length > 0
|
|
214
219
|
? {
|
|
215
220
|
queued: response.failed_to_confirm_clients,
|
|
216
221
|
failed: response.failed,
|
|
@@ -224,7 +229,6 @@ class ProteusService {
|
|
|
224
229
|
};
|
|
225
230
|
}
|
|
226
231
|
async decrypt(encryptedText, userId, clientId) {
|
|
227
|
-
var _a, _b;
|
|
228
232
|
const sessionId = this.constructSessionId(userId, clientId);
|
|
229
233
|
const sessionExists = await this.cryptoClient.sessionExists(sessionId);
|
|
230
234
|
try {
|
|
@@ -233,11 +237,11 @@ class ProteusService {
|
|
|
233
237
|
: await this.cryptoClient.decrypt(sessionId, encryptedText);
|
|
234
238
|
if (!sessionExists) {
|
|
235
239
|
await this.cryptoClient.saveSession(sessionId);
|
|
236
|
-
|
|
237
|
-
this.logger.
|
|
240
|
+
this.config.onNewClient?.({ userId, clientId });
|
|
241
|
+
this.logger.debug(`Created a new session from message for session ID "${sessionId}" and decrypted the message`);
|
|
238
242
|
}
|
|
239
243
|
else {
|
|
240
|
-
this.logger.
|
|
244
|
+
this.logger.debug(`Decrypted message for session ID "${sessionId}"`);
|
|
241
245
|
}
|
|
242
246
|
return decryptedMessage;
|
|
243
247
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { APIClient } from '@wireapp/api-client';
|
|
2
2
|
import { CryptoClient } from './CryptoClient';
|
|
3
3
|
import { ProteusService } from './ProteusService';
|
|
4
|
-
export declare const buildProteusService: () => Promise<[
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
cryptoClient: CryptoClient;
|
|
9
|
-
}
|
|
10
|
-
]>;
|
|
4
|
+
export declare const buildProteusService: () => Promise<[ProteusService, {
|
|
5
|
+
apiClient: APIClient;
|
|
6
|
+
cryptoClient: CryptoClient;
|
|
7
|
+
}]>;
|
|
11
8
|
//# sourceMappingURL=ProteusService.mocks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProteusService.mocks.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.mocks.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,mBAAmB,QAAa,
|
|
1
|
+
{"version":3,"file":"ProteusService.mocks.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.mocks.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,mBAAmB,QAAa,OAAO,CAClD,CAAC,cAAc,EAAE;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAC,CAAC,CAgBrE,CAAC"}
|
|
@@ -63,7 +63,11 @@ jest.mock('./CryptoClient/CoreCryptoWrapper/PrekeysTracker', () => {
|
|
|
63
63
|
}),
|
|
64
64
|
};
|
|
65
65
|
});
|
|
66
|
-
jest.mock('../Utility/Recipients', () => (
|
|
66
|
+
jest.mock('../Utility/Recipients', () => ({
|
|
67
|
+
...jest.requireActual('../Utility/Recipients'),
|
|
68
|
+
getRecipientsForConversation: jest.fn(),
|
|
69
|
+
getQualifiedRecipientsForConversation: jest.fn(),
|
|
70
|
+
}));
|
|
67
71
|
const MockedRecipients = Recipients;
|
|
68
72
|
const prepareDataForEncryption = async () => {
|
|
69
73
|
const [proteusService, { cryptoClient, apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
@@ -206,7 +210,7 @@ describe('ProteusService', () => {
|
|
|
206
210
|
const result = await proteusService.handleOtrMessageAddEvent(eventPayload);
|
|
207
211
|
expect(result).toBeDefined();
|
|
208
212
|
expect(createSessionSpy).not.toHaveBeenCalled();
|
|
209
|
-
expect(result
|
|
213
|
+
expect(result?.decryptedData).toBe(decryptedMessage);
|
|
210
214
|
});
|
|
211
215
|
it('decrypts incoming proteus encrypted and creates session if not already existing', async () => {
|
|
212
216
|
const [proteusService, { cryptoClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
@@ -219,7 +223,7 @@ describe('ProteusService', () => {
|
|
|
219
223
|
expect(result).toBeDefined();
|
|
220
224
|
expect(createSessionSpy).toHaveBeenCalled();
|
|
221
225
|
expect(decryptSpy).not.toHaveBeenCalled();
|
|
222
|
-
expect(result
|
|
226
|
+
expect(result?.decryptedData).toBe(decryptedMessage);
|
|
223
227
|
});
|
|
224
228
|
});
|
|
225
229
|
describe('"encrypt"', () => {
|
|
@@ -455,7 +459,6 @@ describe('ProteusService', () => {
|
|
|
455
459
|
});
|
|
456
460
|
});
|
|
457
461
|
it(`returns the recipients that will receive the message later`, async () => {
|
|
458
|
-
var _a;
|
|
459
462
|
const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
460
463
|
const recipients = {
|
|
461
464
|
domain1: { user1: ['client1'], user2: ['client11', 'client12'] },
|
|
@@ -477,7 +480,7 @@ describe('ProteusService', () => {
|
|
|
477
480
|
userIds: recipients,
|
|
478
481
|
});
|
|
479
482
|
expect(result.state).toBe(conversation_2.MessageSendingState.OUTGOING_SENT);
|
|
480
|
-
expect(
|
|
483
|
+
expect(result.failedToSend?.queued).toEqual({ domain2: recipients.domain2 });
|
|
481
484
|
});
|
|
482
485
|
});
|
|
483
486
|
});
|
|
@@ -502,7 +505,6 @@ describe('ProteusService', () => {
|
|
|
502
505
|
expect(event).toEqual(baseResponse);
|
|
503
506
|
});
|
|
504
507
|
it('partially add users if some backends are unreachable', async () => {
|
|
505
|
-
var _a, _b, _c, _d;
|
|
506
508
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
507
509
|
const postMembersSpy = jest
|
|
508
510
|
.spyOn(apiClient.api.conversation, 'postMembers')
|
|
@@ -515,11 +517,10 @@ describe('ProteusService', () => {
|
|
|
515
517
|
expect(postMembersSpy).toHaveBeenCalledTimes(2);
|
|
516
518
|
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([...usersDomain1, ...usersDomain2]));
|
|
517
519
|
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(usersDomain2));
|
|
518
|
-
expect(
|
|
519
|
-
expect(
|
|
520
|
+
expect(result.failedToAdd?.[0]?.reason).toBe(conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS);
|
|
521
|
+
expect(result.failedToAdd?.[0]?.users).toEqual([...usersDomain1]);
|
|
520
522
|
});
|
|
521
523
|
it('completely fails to add users if some backends are unreachable', async () => {
|
|
522
|
-
var _a, _b, _c, _d;
|
|
523
524
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
524
525
|
const allUsers = [...usersDomain1, ...usersDomain2];
|
|
525
526
|
const postMembersSpy = jest
|
|
@@ -532,11 +533,10 @@ describe('ProteusService', () => {
|
|
|
532
533
|
expect(postMembersSpy).toHaveBeenCalledTimes(2);
|
|
533
534
|
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(allUsers));
|
|
534
535
|
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(usersDomain2));
|
|
535
|
-
expect(
|
|
536
|
-
expect(
|
|
536
|
+
expect(result.failedToAdd?.[0]?.reason).toBe(conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS);
|
|
537
|
+
expect(result.failedToAdd?.[0]?.users).toEqual(allUsers);
|
|
537
538
|
});
|
|
538
539
|
it('partially add users if some users are part of not-connected backends', async () => {
|
|
539
|
-
var _a, _b, _c, _d;
|
|
540
540
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
541
541
|
const postMembersSpy = jest
|
|
542
542
|
.spyOn(apiClient.api.conversation, 'postMembers')
|
|
@@ -549,8 +549,8 @@ describe('ProteusService', () => {
|
|
|
549
549
|
expect(postMembersSpy).toHaveBeenCalledTimes(2);
|
|
550
550
|
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([...usersDomain1, ...usersDomain2]));
|
|
551
551
|
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(usersDomain1));
|
|
552
|
-
expect(
|
|
553
|
-
expect(
|
|
552
|
+
expect(result.failedToAdd?.[0]?.reason).toBe(conversation_2.AddUsersFailureReasons.NON_FEDERATING_BACKENDS);
|
|
553
|
+
expect(result.failedToAdd?.[0]?.users).toEqual([...usersDomain2, ...usersDomain3]);
|
|
554
554
|
});
|
|
555
555
|
});
|
|
556
556
|
describe('createConversation', () => {
|
|
@@ -579,7 +579,7 @@ describe('ProteusService', () => {
|
|
|
579
579
|
};
|
|
580
580
|
it('adds all requested users to a new conversation', async () => {
|
|
581
581
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
582
|
-
jest.spyOn(apiClient.api.conversation, 'postConversation').mockResolvedValueOnce(
|
|
582
|
+
jest.spyOn(apiClient.api.conversation, 'postConversation').mockResolvedValueOnce({ ...newConversation });
|
|
583
583
|
const result = await proteusService.createConversation({
|
|
584
584
|
receipt_mode: null,
|
|
585
585
|
qualified_users: [...usersDomain1, ...usersDomain2, ...usersDomain3],
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.deleteIdentity =
|
|
21
|
+
exports.deleteIdentity = deleteIdentity;
|
|
22
22
|
/** all the tables in the database that stores information relative to the client identity */
|
|
23
23
|
const IDENTITY_STORES = ['amplify', 'clients', 'keys', 'prekeys', 'sessions', 'group_ids'];
|
|
24
24
|
/**
|
|
@@ -30,4 +30,3 @@ function deleteIdentity(storeEngine) {
|
|
|
30
30
|
//make sure we use enum's lowercase values, not uppercase keys
|
|
31
31
|
IDENTITY_STORES.map(store => storeEngine.deleteAll(store)));
|
|
32
32
|
}
|
|
33
|
-
exports.deleteIdentity = deleteIdentity;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.migrateToQualifiedSessionIds =
|
|
21
|
+
exports.migrateToQualifiedSessionIds = migrateToQualifiedSessionIds;
|
|
22
22
|
const sessionTableName = 'sessions';
|
|
23
23
|
/**
|
|
24
24
|
* Will migrate all the session ids in the database to fully qualified ids (from 'user-id@device-id` to `domain@user-id@device-id`)
|
|
@@ -34,7 +34,7 @@ async function migrateToQualifiedSessionIds(storeEngine, defaultDomain) {
|
|
|
34
34
|
.reduce((acc, session) => {
|
|
35
35
|
return acc.concat({
|
|
36
36
|
oldId: session.id,
|
|
37
|
-
newSession:
|
|
37
|
+
newSession: { ...session, id: `${defaultDomain}@${session.id}` },
|
|
38
38
|
});
|
|
39
39
|
}, []);
|
|
40
40
|
for (const { oldId, newSession } of updatedSessions) {
|
|
@@ -43,4 +43,3 @@ async function migrateToQualifiedSessionIds(storeEngine, defaultDomain) {
|
|
|
43
43
|
await storeEngine.create(sessionTableName, newSession.id, newSession);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
exports.migrateToQualifiedSessionIds = migrateToQualifiedSessionIds;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.filterUsersFromDomains =
|
|
21
|
+
exports.filterUsersFromDomains = filterUsersFromDomains;
|
|
22
22
|
function filterUsersFromDomains(userIds, domainsToExclude) {
|
|
23
23
|
const excludedUsers = [];
|
|
24
24
|
const includedUsers = [];
|
|
@@ -28,4 +28,3 @@ function filterUsersFromDomains(userIds, domainsToExclude) {
|
|
|
28
28
|
includedUsers,
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
exports.filterUsersFromDomains = filterUsersFromDomains;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Recipients.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/Recipients.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAE5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAczD,UAAU,2CAA2C;IACnD,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,WAAW,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAC;CAChD;AAED,QAAA,MAAM,4BAA4B,4CAI/B,2CAA2C,KAAG,
|
|
1
|
+
{"version":3,"file":"Recipients.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/Recipients.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAE5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAczD,UAAU,2CAA2C;IACnD,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,WAAW,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAC;CAChD;AAED,QAAA,MAAM,4BAA4B,4CAI/B,2CAA2C,KAAG,OAAO,CAAC,oBAAoB,CAW5E,CAAC;AAEF,OAAO,EAAC,4BAA4B,EAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAK9C,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,UAAU,wBAAwB;IAChC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,kBAAkB,GAAG;IACxB,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,8GAA8G;IAC9G,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,kBAAkB,yBAAwB,wBAAwB,KAAG,MAI1E,CAAC;AA6BF;;;GAGG;AACH,QAAA,MAAM,WAAW,wCACoB;IAAC,MAAM,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAC,+BACvE;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAC,KAC5E,
|
|
1
|
+
{"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAK9C,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,UAAU,wBAAwB;IAChC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,kBAAkB,GAAG;IACxB,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,8GAA8G;IAC9G,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,kBAAkB,yBAAwB,wBAAwB,KAAG,MAI1E,CAAC;AA6BF;;;GAGG;AACH,QAAA,MAAM,WAAW,wCACoB;IAAC,MAAM,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAC,+BACvE;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAC,KAC5E,OAAO,CAAC,MAAM,CAUhB,CAAC;AAqBF,UAAU,wCAAwC;IAChD,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,CAAC;IAChE,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,QAAA,MAAM,YAAY,qDAKf,wCAAwC,KAAG,OAAO,CAAC,kBAAkB,CAwDvE,CAAC;AAEF,UAAU,mBAAmB;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;CAC5B;AACD,iBAAe,aAAa,CAAC,MAAM,EAAE,mBAAmB,iBAGvD;AA4CD,KAAK,iBAAiB,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E;;GAEG;AACH,QAAA,MAAM,sBAAsB,GAAI,CAAC,YAAY,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,CAYhF,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAC,CAAC"}
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.buildEncryptedPayloads = exports.
|
|
21
|
+
exports.buildEncryptedPayloads = exports.initSessions = exports.initSession = exports.constructSessionId = void 0;
|
|
22
|
+
exports.deleteSession = deleteSession;
|
|
22
23
|
const bazinga64_1 = require("bazinga64");
|
|
23
24
|
const UserClientsUtil_1 = require("../../../../conversation/message/UserClientsUtil");
|
|
24
25
|
const constructSessionId = ({ userId, clientId }) => {
|
|
@@ -68,13 +69,15 @@ const createSessions = async ({ recipients, apiClient, cryptoClient }) => {
|
|
|
68
69
|
recipients: prekeysBundle,
|
|
69
70
|
cryptoClient,
|
|
70
71
|
});
|
|
71
|
-
return
|
|
72
|
+
return {
|
|
73
|
+
...result,
|
|
74
|
+
failed: failed?.length ? failed : undefined,
|
|
75
|
+
};
|
|
72
76
|
};
|
|
73
77
|
/**
|
|
74
78
|
* Will make sure all the sessions need to encrypt for those user/clients pair are set
|
|
75
79
|
*/
|
|
76
80
|
const initSessions = async ({ recipients, apiClient, cryptoClient, logger, }) => {
|
|
77
|
-
var _a, _b, _c;
|
|
78
81
|
const missingClients = {};
|
|
79
82
|
const missingClientsWithPrekeys = {};
|
|
80
83
|
const existingSessions = [];
|
|
@@ -89,13 +92,13 @@ const initSessions = async ({ recipients, apiClient, cryptoClient, logger, }) =>
|
|
|
89
92
|
continue;
|
|
90
93
|
}
|
|
91
94
|
if (!Array.isArray(data)) {
|
|
92
|
-
const domainMissingWithPrekey =
|
|
93
|
-
domainMissingWithPrekey[userId.id] =
|
|
95
|
+
const domainMissingWithPrekey = missingClientsWithPrekeys[userId.domain] ?? {};
|
|
96
|
+
domainMissingWithPrekey[userId.id] = domainMissingWithPrekey[userId.id] ?? {};
|
|
94
97
|
domainMissingWithPrekey[userId.id][clientId] = data[clientId];
|
|
95
98
|
missingClientsWithPrekeys[userId.domain] = domainMissingWithPrekey;
|
|
96
99
|
continue;
|
|
97
100
|
}
|
|
98
|
-
const domainMissing =
|
|
101
|
+
const domainMissing = missingClients[userId.domain] ?? {};
|
|
99
102
|
domainMissing[userId.id] = domainMissing[userId.id] || [];
|
|
100
103
|
domainMissing[userId.id].push(clientId);
|
|
101
104
|
missingClients[userId.domain] = domainMissing;
|
|
@@ -115,7 +118,7 @@ const initSessions = async ({ recipients, apiClient, cryptoClient, logger, }) =>
|
|
|
115
118
|
logger,
|
|
116
119
|
})
|
|
117
120
|
: { sessions: [], failed: undefined, unknowns: undefined };
|
|
118
|
-
const allUnknowns =
|
|
121
|
+
const allUnknowns = { ...prekeyUnknows, ...unknowns };
|
|
119
122
|
return {
|
|
120
123
|
sessions: [...existingSessions, ...prekeyCreated, ...created],
|
|
121
124
|
failed,
|
|
@@ -127,9 +130,7 @@ async function deleteSession(params) {
|
|
|
127
130
|
const sessionId = constructSessionId(params);
|
|
128
131
|
await params.cryptoClient.deleteSession(sessionId);
|
|
129
132
|
}
|
|
130
|
-
exports.deleteSession = deleteSession;
|
|
131
133
|
const createSessionsFromPreKeys = async ({ recipients, cryptoClient, }) => {
|
|
132
|
-
var _a, _b;
|
|
133
134
|
const sessions = [];
|
|
134
135
|
const unknowns = {};
|
|
135
136
|
for (const domain in recipients) {
|
|
@@ -139,8 +140,8 @@ const createSessionsFromPreKeys = async ({ recipients, cryptoClient, }) => {
|
|
|
139
140
|
const sessionId = constructSessionId({ userId: { id: userId, domain }, clientId });
|
|
140
141
|
const prekey = userClients[clientId];
|
|
141
142
|
if (!prekey) {
|
|
142
|
-
const domainUnknowns =
|
|
143
|
-
domainUnknowns[userId] =
|
|
143
|
+
const domainUnknowns = unknowns[domain] ?? {};
|
|
144
|
+
domainUnknowns[userId] = domainUnknowns[userId] ?? [];
|
|
144
145
|
domainUnknowns[userId].push(clientId);
|
|
145
146
|
unknowns[domain] = domainUnknowns;
|
|
146
147
|
continue;
|
|
@@ -159,13 +160,12 @@ const createSessionsFromPreKeys = async ({ recipients, cryptoClient, }) => {
|
|
|
159
160
|
*/
|
|
160
161
|
const buildEncryptedPayloads = (payloads) => {
|
|
161
162
|
return [...payloads].reduce((acc, [sessionId, payload]) => {
|
|
162
|
-
var _a, _b;
|
|
163
163
|
const { userId, domain, clientId } = parseSessionId(sessionId);
|
|
164
164
|
if (!domain) {
|
|
165
165
|
throw new Error('Invalid session ID');
|
|
166
166
|
}
|
|
167
|
-
const domainPayloads =
|
|
168
|
-
domainPayloads[userId] =
|
|
167
|
+
const domainPayloads = acc[domain] ?? {};
|
|
168
|
+
domainPayloads[userId] = domainPayloads[userId] ?? {};
|
|
169
169
|
domainPayloads[userId][clientId] = payload;
|
|
170
170
|
acc[domain] = domainPayloads;
|
|
171
171
|
return acc;
|
|
@@ -37,7 +37,10 @@ function generatePrekeys(recipients) {
|
|
|
37
37
|
id: index,
|
|
38
38
|
key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
|
|
39
39
|
};
|
|
40
|
-
return
|
|
40
|
+
return {
|
|
41
|
+
...acc,
|
|
42
|
+
[clientId]: payload,
|
|
43
|
+
};
|
|
41
44
|
}, {});
|
|
42
45
|
prekeys[domain] = domainUsers;
|
|
43
46
|
});
|
|
@@ -111,7 +114,7 @@ describe('SessionHandler', () => {
|
|
|
111
114
|
.mockImplementation(sessionId => Promise.resolve(sessionId.includes('missing')));
|
|
112
115
|
const sessionFromPrekeySpy = jest.spyOn(cryptoClient, 'sessionFromPrekey');
|
|
113
116
|
const { sessions } = await (0, SessionHandler_1.initSessions)({
|
|
114
|
-
recipients: { domain:
|
|
117
|
+
recipients: { domain: { ...existingUserClients, ...missingUserClients } },
|
|
115
118
|
apiClient,
|
|
116
119
|
cryptoClient,
|
|
117
120
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGenericMessageParams.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/getGenericMessageParams.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAK3D,OAAO,EAAoB,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AAG/E,MAAM,MAAM,aAAa,GAAG;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,CAAC;IAChE,SAAS,EAAE,UAAU,CAAC;IACtB,OAAO,EAAE;QACP,cAAc,EAAE,WAAW,CAAC;QAC5B,UAAU,EAAE,OAAO,GAAG,SAAS,CAAC;QAChC,aAAa,EAAE,OAAO,GAAG,WAAW,EAAE,GAAG,SAAS,CAAC;KACpD,CAAC;CACH,CAAC;AACF,UAAU,6BAA6B;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,WAAW,CAAC;IAC5B,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,qBAAqB,CAAC;IAC/B,SAAS,EAAE,SAAS,CAAC;CACtB;AACD,KAAK,iCAAiC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAEhE,QAAA,MAAM,uBAAuB,kHAM1B,6BAA6B,
|
|
1
|
+
{"version":3,"file":"getGenericMessageParams.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/getGenericMessageParams.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAK3D,OAAO,EAAoB,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AAG/E,MAAM,MAAM,aAAa,GAAG;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,CAAC;IAChE,SAAS,EAAE,UAAU,CAAC;IACtB,OAAO,EAAE;QACP,cAAc,EAAE,WAAW,CAAC;QAC5B,UAAU,EAAE,OAAO,GAAG,SAAS,CAAC;QAChC,aAAa,EAAE,OAAO,GAAG,WAAW,EAAE,GAAG,SAAS,CAAC;KACpD,CAAC;CACH,CAAC;AACF,UAAU,6BAA6B;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,WAAW,CAAC;IAC5B,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,qBAAqB,CAAC;IAC/B,SAAS,EAAE,SAAS,CAAC;CACtB;AACD,KAAK,iCAAiC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAEhE,QAAA,MAAM,uBAAuB,kHAM1B,6BAA6B,KAAG,iCA0BlC,CAAC;AAEF,OAAO,EAAC,uBAAuB,EAAC,CAAC"}
|
|
@@ -5,7 +5,7 @@ export declare class NotificationBackendRepository {
|
|
|
5
5
|
constructor(apiClient: APIClient);
|
|
6
6
|
getAllNotifications(clientId?: string, lastNotificationId?: string): Promise<{
|
|
7
7
|
notifications: Notification[];
|
|
8
|
-
missedNotification?: string
|
|
8
|
+
missedNotification?: string;
|
|
9
9
|
}>;
|
|
10
10
|
getLastNotification(clientId?: string): Promise<Notification>;
|
|
11
11
|
}
|
|
@@ -17,19 +17,6 @@
|
|
|
17
17
|
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
21
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
22
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
23
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
24
|
-
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
25
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
26
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
27
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
28
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
29
|
-
function fulfill(value) { resume("next", value); }
|
|
30
|
-
function reject(value) { resume("throw", value); }
|
|
31
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
32
|
-
};
|
|
33
20
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
34
21
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
35
22
|
};
|
|
@@ -47,13 +34,18 @@ var TOPIC;
|
|
|
47
34
|
TOPIC["NOTIFICATION_ERROR"] = "NotificationService.TOPIC.NOTIFICATION_ERROR";
|
|
48
35
|
})(TOPIC || (TOPIC = {}));
|
|
49
36
|
class NotificationService extends commons_1.TypedEventEmitter {
|
|
37
|
+
conversationService;
|
|
38
|
+
apiClient;
|
|
39
|
+
backend;
|
|
40
|
+
database;
|
|
41
|
+
logger = (0, logdown_1.default)('@wireapp/core/NotificationService', {
|
|
42
|
+
logger: console,
|
|
43
|
+
markdown: false,
|
|
44
|
+
});
|
|
45
|
+
static TOPIC = TOPIC;
|
|
50
46
|
constructor(apiClient, storeEngine, conversationService) {
|
|
51
47
|
super();
|
|
52
48
|
this.conversationService = conversationService;
|
|
53
|
-
this.logger = (0, logdown_1.default)('@wireapp/core/NotificationService', {
|
|
54
|
-
logger: console,
|
|
55
|
-
markdown: false,
|
|
56
|
-
});
|
|
57
49
|
this.apiClient = apiClient;
|
|
58
50
|
this.backend = new NotificationBackendRepository_1.NotificationBackendRepository(this.apiClient);
|
|
59
51
|
this.database = new NotificationDatabaseRepository_1.NotificationDatabaseRepository(storeEngine);
|
|
@@ -147,40 +139,38 @@ class NotificationService extends commons_1.TypedEventEmitter {
|
|
|
147
139
|
}
|
|
148
140
|
return false;
|
|
149
141
|
}
|
|
150
|
-
handleNotification(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
yield yield __await(handledEventResult.payload);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
this.logger.error(`There was an error with notification ID "${notification.id}": ${error.message}`, error);
|
|
171
|
-
const notificationError = {
|
|
172
|
-
error: error,
|
|
173
|
-
notification,
|
|
174
|
-
type: CoreError_1.CoreError.NOTIFICATION_ERROR,
|
|
175
|
-
};
|
|
176
|
-
this.emit(NotificationService.TOPIC.NOTIFICATION_ERROR, notificationError);
|
|
142
|
+
async *handleNotification(notification, source, dryRun = false) {
|
|
143
|
+
for (const event of notification.payload) {
|
|
144
|
+
this.logger.debug(`Handling event of type "${event.type}"`, event);
|
|
145
|
+
let lastEventDate = undefined;
|
|
146
|
+
try {
|
|
147
|
+
lastEventDate = await this.database.getLastEventDate();
|
|
148
|
+
}
|
|
149
|
+
catch { }
|
|
150
|
+
if ('time' in event && this.isOutdatedEvent(event, source, lastEventDate)) {
|
|
151
|
+
this.logger.info(`Ignored outdated event type: '${event.type}'`);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const handledEventResult = await this.handleEvent(event, dryRun);
|
|
156
|
+
if (handledEventResult.status === 'handled' && handledEventResult.payload) {
|
|
157
|
+
yield handledEventResult.payload;
|
|
177
158
|
}
|
|
178
159
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
160
|
+
catch (error) {
|
|
161
|
+
this.logger.error(`There was an error with notification ID "${notification.id}": ${error.message}`, error);
|
|
162
|
+
const notificationError = {
|
|
163
|
+
error: error,
|
|
164
|
+
notification,
|
|
165
|
+
type: CoreError_1.CoreError.NOTIFICATION_ERROR,
|
|
166
|
+
};
|
|
167
|
+
this.emit(NotificationService.TOPIC.NOTIFICATION_ERROR, notificationError);
|
|
182
168
|
}
|
|
183
|
-
}
|
|
169
|
+
}
|
|
170
|
+
if (!dryRun && !notification.transient) {
|
|
171
|
+
// keep track of the last handled notification for next time we fetch the notification stream
|
|
172
|
+
await this.setLastNotificationId(notification);
|
|
173
|
+
}
|
|
184
174
|
}
|
|
185
175
|
/**
|
|
186
176
|
* Will process one event
|
|
@@ -202,4 +192,3 @@ class NotificationService extends commons_1.TypedEventEmitter {
|
|
|
202
192
|
}
|
|
203
193
|
}
|
|
204
194
|
exports.NotificationService = NotificationService;
|
|
205
|
-
NotificationService.TOPIC = TOPIC;
|