@wireapp/core 40.9.2 → 41.0.0
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/conversation/ConversationService/ConversationService.d.ts +4 -1
- package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts +10 -2
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +54 -5
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +116 -0
- package/lib/messagingProtocols/proteus/ProteusService/userDomainFilters.d.ts +6 -0
- package/lib/messagingProtocols/proteus/ProteusService/userDomainFilters.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/userDomainFilters.js +31 -0
- package/package.json +3 -3
|
@@ -38,7 +38,10 @@ export declare class ConversationService {
|
|
|
38
38
|
getConversations(conversationIds?: QualifiedId[]): Promise<RemoteConversations>;
|
|
39
39
|
getAsset({ assetId, assetToken, otrKey, sha256 }: RemoteData): Promise<Uint8Array>;
|
|
40
40
|
getUnencryptedAsset(assetId: string, assetToken?: string): Promise<ArrayBuffer>;
|
|
41
|
-
addUsersToProteusConversation(params: AddUsersToProteusConversationParams): Promise<
|
|
41
|
+
addUsersToProteusConversation(params: AddUsersToProteusConversationParams): Promise<{
|
|
42
|
+
event?: import("@wireapp/api-client/lib/event").ConversationMemberJoinEvent | undefined;
|
|
43
|
+
failedToAdd?: QualifiedId[] | undefined;
|
|
44
|
+
}>;
|
|
42
45
|
removeUserFromConversation(conversationId: QualifiedId, userId: QualifiedId): Promise<ConversationMemberLeaveEvent>;
|
|
43
46
|
/**
|
|
44
47
|
* Sends a message to a conversation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,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nF,eAAe,CAAC,cAAc,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAInE,gBAAgB,CAAC,eAAe,CAAC,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO/E,QAAQ,CAAC,EAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAC,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAWhF,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAK/E,6BAA6B,CAAC,MAAM,EAAE,mCAAmC
|
|
1
|
+
{"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,WAAW,EACX,eAAe,EACf,oBAAoB,EAEpB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAC,4BAA4B,EAAC,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAIvD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAI9C,OAAO,EAAC,cAAc,EAAE,aAAa,EAAE,oBAAoB,EAAE,UAAU,EAAC,MAAM,6BAA6B,CAAC;AAE5G,OAAO,EAAC,YAAY,EAAuB,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAEzF,OAAO,EAAC,UAAU,EAAuB,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAkC,cAAc,EAAC,MAAM,kCAAkC,CAAC;AACjG,OAAO,EACL,mCAAmC,EACnC,wBAAwB,EACzB,MAAM,sEAAsE,CAAC;AAG9E,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAGtC,qBA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Client';
|
|
2
2
|
import type { PreKey, Context } from '@wireapp/api-client/lib/auth';
|
|
3
|
-
import
|
|
3
|
+
import { Conversation, QualifiedOTRRecipients, QualifiedUserClients } from '@wireapp/api-client/lib/conversation';
|
|
4
|
+
import type { ConversationMemberJoinEvent } from '@wireapp/api-client/lib/event';
|
|
4
5
|
import type { QualifiedId, QualifiedUserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
|
|
5
6
|
import { CRUDEngine } from '@wireapp/store-engine';
|
|
6
7
|
import { CryptoClient } from './CryptoClient';
|
|
@@ -40,7 +41,14 @@ export declare class ProteusService {
|
|
|
40
41
|
*/
|
|
41
42
|
getRemoteFingerprint(userId: QualifiedId, clientId: string, prekey?: PreKey): Promise<string>;
|
|
42
43
|
createConversation({ conversationData, otherUserIds, }: CreateProteusConversationParams): Promise<Conversation>;
|
|
43
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Tries to add all the given users to the given conversation.
|
|
46
|
+
* If some users are not reachable, it will try to add the remaining users and list them in the `failedToAdd` property of the response.
|
|
47
|
+
*/
|
|
48
|
+
addUsersToConversation({ conversationId, qualifiedUsers }: AddUsersToProteusConversationParams): Promise<{
|
|
49
|
+
event?: ConversationMemberJoinEvent;
|
|
50
|
+
failedToAdd?: QualifiedId[];
|
|
51
|
+
}>;
|
|
44
52
|
sendMessage({ userIds, conversationId, nativePush, targetMode, payload, onClientMismatch, }: SendProteusMessageParams): Promise<SendResult>;
|
|
45
53
|
private decrypt;
|
|
46
54
|
deleteSession(userId: QualifiedId, clientId: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProteusService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,
|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efault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.ProteusService = void 0;
|
|
25
|
+
const conversation_1 = require("@wireapp/api-client/lib/conversation");
|
|
25
26
|
const logdown_1 = __importDefault(require("logdown"));
|
|
26
27
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
27
28
|
const cryptoMigrationStateStore_1 = require("./cryptoMigrationStateStore");
|
|
28
29
|
const DecryptionErrorGenerator_1 = require("./DecryptionErrorGenerator");
|
|
29
30
|
const identityClearer_1 = require("./identityClearer");
|
|
30
31
|
const sessionIdMigrator_1 = require("./sessionIdMigrator");
|
|
31
|
-
const
|
|
32
|
+
const userDomainFilters_1 = require("./userDomainFilters");
|
|
33
|
+
const conversation_2 = require("../../../conversation");
|
|
32
34
|
const MessageService_1 = require("../../../conversation/message/MessageService");
|
|
33
35
|
const EventHandler_1 = require("../EventHandler");
|
|
34
36
|
const getGenericMessageParams_1 = require("../Utility/getGenericMessageParams");
|
|
@@ -45,7 +47,7 @@ class ProteusService {
|
|
|
45
47
|
async handleEvent(params) {
|
|
46
48
|
const handledEvent = await (0, EventHandler_1.handleBackendEvent)(Object.assign(Object.assign({}, params), { decryptMessage: (payload, userId, clientId) => this.decrypt(payload, userId, clientId) }));
|
|
47
49
|
if (handledEvent === null || handledEvent === void 0 ? void 0 : handledEvent.decryptedData) {
|
|
48
|
-
const isSessionReset = handledEvent.decryptedData[
|
|
50
|
+
const isSessionReset = handledEvent.decryptedData[conversation_2.GenericMessageType.CLIENT_ACTION] === protocol_messaging_1.ClientAction.RESET_SESSION;
|
|
49
51
|
if (isSessionReset) {
|
|
50
52
|
this.logger.debug('A session was reset from a remote device');
|
|
51
53
|
// If a session reset message was received, we need to count a consumed prekey (because the sender has created a new session from a new prekey)
|
|
@@ -117,10 +119,57 @@ class ProteusService {
|
|
|
117
119
|
else {
|
|
118
120
|
payload = conversationData;
|
|
119
121
|
}
|
|
120
|
-
return this.apiClient.api.conversation.postConversation(payload)
|
|
122
|
+
return this.apiClient.api.conversation.postConversation(payload).catch(async (error) => {
|
|
123
|
+
var _a;
|
|
124
|
+
if ((0, conversation_1.isFederatedBackendsError)(error)) {
|
|
125
|
+
switch (error.label) {
|
|
126
|
+
case conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS: {
|
|
127
|
+
const { backends } = error;
|
|
128
|
+
const { excludedUsers: unreachableUsers, includedUsers: availableUsers } = (0, userDomainFilters_1.filterUsersFromDomains)((_a = payload.qualified_users) !== null && _a !== void 0 ? _a : [], backends);
|
|
129
|
+
payload = Object.assign(Object.assign({}, payload), { qualified_users: availableUsers });
|
|
130
|
+
// If conversation creation returns an error because a backend is offline,
|
|
131
|
+
// we try creating the conversation again with users from available backends
|
|
132
|
+
const response = await this.apiClient.api.conversation.postConversation(payload).catch((error) => {
|
|
133
|
+
throw error;
|
|
134
|
+
});
|
|
135
|
+
// on a succesfull conversation creation with the available users,
|
|
136
|
+
// we append the users from an unreachable backend to the response
|
|
137
|
+
response.failed_to_add = unreachableUsers;
|
|
138
|
+
return response;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
throw error;
|
|
143
|
+
});
|
|
121
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Tries to add all the given users to the given conversation.
|
|
147
|
+
* If some users are not reachable, it will try to add the remaining users and list them in the `failedToAdd` property of the response.
|
|
148
|
+
*/
|
|
122
149
|
async addUsersToConversation({ conversationId, qualifiedUsers }) {
|
|
123
|
-
|
|
150
|
+
try {
|
|
151
|
+
return { event: await this.apiClient.api.conversation.postMembers(conversationId, qualifiedUsers) };
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
if ((0, conversation_1.isFederatedBackendsError)(error)) {
|
|
155
|
+
switch (error.label) {
|
|
156
|
+
case conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS: {
|
|
157
|
+
const { backends } = error;
|
|
158
|
+
const { excludedUsers: unreachableUsers, includedUsers: availableUsers } = (0, userDomainFilters_1.filterUsersFromDomains)(qualifiedUsers, backends);
|
|
159
|
+
if (availableUsers.length === 0) {
|
|
160
|
+
return { failedToAdd: unreachableUsers };
|
|
161
|
+
}
|
|
162
|
+
// In case the request to add users failed with a `UNREACHABLE_BACKENDS` error, we try again with the users from available backends
|
|
163
|
+
const response = await this.apiClient.api.conversation.postMembers(conversationId, availableUsers);
|
|
164
|
+
return {
|
|
165
|
+
event: response,
|
|
166
|
+
failedToAdd: unreachableUsers,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
124
173
|
}
|
|
125
174
|
async sendMessage({ userIds, conversationId, nativePush, targetMode, payload, onClientMismatch, }) {
|
|
126
175
|
var _a;
|
|
@@ -144,7 +193,7 @@ class ProteusService {
|
|
|
144
193
|
}
|
|
145
194
|
this.logger.log(`Successfully sent Proteus message to conversation '${conversationId.id}'`);
|
|
146
195
|
}
|
|
147
|
-
const sendingState = response.canceled ?
|
|
196
|
+
const sendingState = response.canceled ? conversation_2.MessageSendingState.CANCELED : conversation_2.MessageSendingState.OUTGOING_SENT;
|
|
148
197
|
const failedToSend = response.failed || Object.keys((_a = response.failed_to_confirm_clients) !== null && _a !== void 0 ? _a : {}).length > 0
|
|
149
198
|
? {
|
|
150
199
|
queued: response.failed_to_confirm_clients,
|
|
@@ -474,4 +474,120 @@ describe('ProteusService', () => {
|
|
|
474
474
|
});
|
|
475
475
|
});
|
|
476
476
|
});
|
|
477
|
+
describe('addUsersToConversation', () => {
|
|
478
|
+
const baseResponse = {
|
|
479
|
+
event: {
|
|
480
|
+
conversation: '',
|
|
481
|
+
from: '',
|
|
482
|
+
time: Date.now().toString(),
|
|
483
|
+
data: { users: [], user_ids: [] },
|
|
484
|
+
type: event_1.CONVERSATION_EVENT.MEMBER_JOIN,
|
|
485
|
+
},
|
|
486
|
+
};
|
|
487
|
+
const conversationId = { id: 'conv1', domain: 'domain1' };
|
|
488
|
+
const userDomain1 = { id: 'user-1-1', domain: 'domain1' };
|
|
489
|
+
const user2Domain1 = { id: 'user-2-1', domain: 'domain1' };
|
|
490
|
+
const userDomain2 = { id: 'user-2-2', domain: 'domain2' };
|
|
491
|
+
it('adds all requested users to an existing conversation', async () => {
|
|
492
|
+
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
493
|
+
jest.spyOn(apiClient.api.conversation, 'postMembers').mockResolvedValueOnce(baseResponse.event);
|
|
494
|
+
const event = await proteusService.addUsersToConversation({
|
|
495
|
+
conversationId,
|
|
496
|
+
qualifiedUsers: [userDomain1, user2Domain1, userDomain2],
|
|
497
|
+
});
|
|
498
|
+
expect(event).toEqual(baseResponse);
|
|
499
|
+
});
|
|
500
|
+
it('partially add users if some backends are unreachable', async () => {
|
|
501
|
+
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
502
|
+
const postMembersSpy = jest
|
|
503
|
+
.spyOn(apiClient.api.conversation, 'postMembers')
|
|
504
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [userDomain1.domain]))
|
|
505
|
+
.mockResolvedValueOnce(baseResponse.event);
|
|
506
|
+
const result = await proteusService.addUsersToConversation({
|
|
507
|
+
conversationId,
|
|
508
|
+
qualifiedUsers: [userDomain1, user2Domain1, userDomain2],
|
|
509
|
+
});
|
|
510
|
+
expect(postMembersSpy).toHaveBeenCalledTimes(2);
|
|
511
|
+
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([userDomain1, user2Domain1, userDomain2]));
|
|
512
|
+
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([userDomain2]));
|
|
513
|
+
expect(result.failedToAdd).toEqual([userDomain1, user2Domain1]);
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
describe('createConversation', () => {
|
|
517
|
+
const newConversation = {
|
|
518
|
+
qualified_id: { id: '', domain: '' },
|
|
519
|
+
id: '',
|
|
520
|
+
type: conversation_1.CONVERSATION_TYPE.REGULAR,
|
|
521
|
+
creator: '',
|
|
522
|
+
access: [],
|
|
523
|
+
access_role: [conversation_1.CONVERSATION_ACCESS_ROLE.GUEST],
|
|
524
|
+
members: {
|
|
525
|
+
others: [],
|
|
526
|
+
self: {
|
|
527
|
+
qualified_id: { id: '', domain: '' },
|
|
528
|
+
hidden_ref: null,
|
|
529
|
+
id: '',
|
|
530
|
+
otr_archived_ref: null,
|
|
531
|
+
otr_muted_ref: null,
|
|
532
|
+
otr_muted_status: null,
|
|
533
|
+
service: null,
|
|
534
|
+
status_ref: '',
|
|
535
|
+
status_time: '',
|
|
536
|
+
},
|
|
537
|
+
},
|
|
538
|
+
failed_to_add: [],
|
|
539
|
+
protocol: conversation_1.ConversationProtocol.PROTEUS,
|
|
540
|
+
};
|
|
541
|
+
const userDomain1 = { id: 'user-1-1', domain: 'domain1' };
|
|
542
|
+
const user2Domain1 = { id: 'user-2-1', domain: 'domain1' };
|
|
543
|
+
const userDomain2 = { id: 'user-2-2', domain: 'domain2' };
|
|
544
|
+
it('adds all requested users to a new conversation', async () => {
|
|
545
|
+
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
546
|
+
jest.spyOn(apiClient.api.conversation, 'postConversation').mockResolvedValueOnce(Object.assign({}, newConversation));
|
|
547
|
+
const result = await proteusService.createConversation({
|
|
548
|
+
conversationData: {
|
|
549
|
+
receipt_mode: null,
|
|
550
|
+
qualified_users: [userDomain1, user2Domain1, userDomain2],
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
expect(result).toEqual(newConversation);
|
|
554
|
+
});
|
|
555
|
+
it('partially add users if some backends are unreachable', async () => {
|
|
556
|
+
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
557
|
+
const postConversationSpy = jest
|
|
558
|
+
.spyOn(apiClient.api.conversation, 'postConversation')
|
|
559
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [userDomain1.domain]))
|
|
560
|
+
.mockResolvedValueOnce(newConversation);
|
|
561
|
+
const result = await proteusService.createConversation({
|
|
562
|
+
conversationData: {
|
|
563
|
+
receipt_mode: null,
|
|
564
|
+
qualified_users: [userDomain1, user2Domain1, userDomain2],
|
|
565
|
+
},
|
|
566
|
+
});
|
|
567
|
+
expect(postConversationSpy).toHaveBeenCalledTimes(2);
|
|
568
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [userDomain1, user2Domain1, userDomain2] }));
|
|
569
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [userDomain2] }));
|
|
570
|
+
expect(result.failed_to_add).toEqual([userDomain1, user2Domain1]);
|
|
571
|
+
});
|
|
572
|
+
it('creates an empty conversation if no backend is reachable', async () => {
|
|
573
|
+
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
574
|
+
const postConversationSpy = jest
|
|
575
|
+
.spyOn(apiClient.api.conversation, 'postConversation')
|
|
576
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [
|
|
577
|
+
userDomain1.domain,
|
|
578
|
+
userDomain2.domain,
|
|
579
|
+
]))
|
|
580
|
+
.mockResolvedValueOnce({});
|
|
581
|
+
const result = await proteusService.createConversation({
|
|
582
|
+
conversationData: {
|
|
583
|
+
receipt_mode: null,
|
|
584
|
+
qualified_users: [userDomain1, user2Domain1, userDomain2],
|
|
585
|
+
},
|
|
586
|
+
});
|
|
587
|
+
expect(postConversationSpy).toHaveBeenCalledTimes(2);
|
|
588
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [userDomain1, user2Domain1, userDomain2] }));
|
|
589
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [] }));
|
|
590
|
+
expect(result.failed_to_add).toEqual([userDomain1, user2Domain1, userDomain2]);
|
|
591
|
+
});
|
|
592
|
+
});
|
|
477
593
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { QualifiedId } from '@wireapp/api-client/lib/user';
|
|
2
|
+
export declare function filterUsersFromDomains(userIds: QualifiedId[], domainsToExclude: string[]): {
|
|
3
|
+
excludedUsers: QualifiedId[];
|
|
4
|
+
includedUsers: QualifiedId[];
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=userDomainFilters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userDomainFilters.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/userDomainFilters.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAEzD,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,WAAW,EAAE,EACtB,gBAAgB,EAAE,MAAM,EAAE,GACzB;IAAC,aAAa,EAAE,WAAW,EAAE,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAC,CAW9D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2023 Wire Swiss GmbH
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.filterUsersFromDomains = void 0;
|
|
22
|
+
function filterUsersFromDomains(userIds, domainsToExclude) {
|
|
23
|
+
const excludedUsers = [];
|
|
24
|
+
const includedUsers = [];
|
|
25
|
+
userIds.forEach(user => domainsToExclude.includes(user.domain) ? excludedUsers.push(user) : includedUsers.push(user));
|
|
26
|
+
return {
|
|
27
|
+
excludedUsers,
|
|
28
|
+
includedUsers,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.filterUsersFromDomains = filterUsersFromDomains;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"./lib/cryptography/AssetCryptography/crypto.node": "./lib/cryptography/AssetCryptography/crypto.browser.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@wireapp/api-client": "^
|
|
14
|
+
"@wireapp/api-client": "^25.0.0",
|
|
15
15
|
"@wireapp/commons": "^5.1.0",
|
|
16
16
|
"@wireapp/core-crypto": "1.0.0-rc.6",
|
|
17
17
|
"@wireapp/cryptobox": "12.8.0",
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"test:coverage": "jest --coverage",
|
|
61
61
|
"watch": "tsc --watch"
|
|
62
62
|
},
|
|
63
|
-
"version": "
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"version": "41.0.0",
|
|
64
|
+
"gitHead": "7d3f425539e2e8a549fa813c1b6d5d19598475d8"
|
|
65
65
|
}
|