@wireapp/core 32.0.5 → 32.0.7
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/package.json +2 -2
- package/src/main/Account.js +7 -2
- package/src/main/conversation/ConversationService/ConversationService.d.ts +2 -32
- package/src/main/conversation/ConversationService/ConversationService.js +0 -80
- package/src/main/conversation/message/MessageBuilder.d.ts +4 -0
- package/src/main/conversation/message/MessageBuilder.js +35 -1
- package/src/main/cryptography/CryptographyService.js +1 -1
- package/src/main/cryptography/GenericMessageMapper.js +1 -1
- package/src/main/notification/NotificationService.d.ts +5 -1
- package/src/main/notification/NotificationService.js +26 -11
- package/src/main/util/TaskScheduler/TaskScheduler.js +1 -1
package/package.json
CHANGED
package/src/main/Account.js
CHANGED
|
@@ -434,15 +434,20 @@ class Account extends events_1.EventEmitter {
|
|
|
434
434
|
// Lock websocket in order to buffer any message that arrives while we handle the notification stream
|
|
435
435
|
onConnectionStateChanged(ConnectionState.PROCESSING_NOTIFICATIONS);
|
|
436
436
|
this.apiClient.transport.ws.lock();
|
|
437
|
-
await this.service.notification.
|
|
437
|
+
const results = await this.service.notification.processNotificationStream(async (notification, source, progress) => {
|
|
438
438
|
await handleNotification(notification, source);
|
|
439
439
|
onNotificationStreamProgress(progress);
|
|
440
440
|
}, onMissedNotifications, abortHandler);
|
|
441
|
+
this.logger.log(`Finished processing notifications ${JSON.stringify(results)}`, results);
|
|
442
|
+
if (abortHandler.isAborted()) {
|
|
443
|
+
this.logger.warn('Ending connection process as websocket was closed');
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
441
446
|
// We can now unlock the websocket and let the new messages being handled and decrypted
|
|
442
447
|
this.apiClient.transport.ws.unlock();
|
|
443
448
|
// We need to wait for the notification stream to be fully handled before releasing the message sending queue.
|
|
444
449
|
// This is due to the nature of how message are encrypted, any change in mls epoch needs to happen before we start encrypting any kind of messages
|
|
445
|
-
this.logger.
|
|
450
|
+
this.logger.info(`Resuming message sending. ${(0, messageSender_1.getQueueLength)()} messages to be sent`);
|
|
446
451
|
(0, messageSender_1.resumeMessageSending)();
|
|
447
452
|
onConnectionStateChanged(ConnectionState.LIVE);
|
|
448
453
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIClient } from '@wireapp/api-client';
|
|
2
|
-
import {
|
|
2
|
+
import { Conversation, DefaultConversationRoleName, MutedStatus, NewConversation, QualifiedUserClients, UserClients } from '@wireapp/api-client/src/conversation';
|
|
3
3
|
import { ConversationMemberLeaveEvent } from '@wireapp/api-client/src/event';
|
|
4
4
|
import { QualifiedId, UserPreKeyBundleMap } from '@wireapp/api-client/src/user';
|
|
5
5
|
import { MessageTimer, PayloadBundleState, RemoveUsersParams } from '../../conversation/';
|
|
@@ -7,9 +7,8 @@ import { RemoteData } from '../content';
|
|
|
7
7
|
import { CryptographyService } from '../../cryptography/';
|
|
8
8
|
import { MLSService } from '../../mls';
|
|
9
9
|
import { NotificationService } from '../../notification';
|
|
10
|
-
import { ClearConversationMessage } from '../message/OtrMessage';
|
|
11
10
|
import { XOR } from '@wireapp/commons/src/main/util/TypeUtil';
|
|
12
|
-
import { AddUsersParams,
|
|
11
|
+
import { AddUsersParams, MLSReturnType, SendMlsMessageParams, SendProteusMessageParams } from './ConversationService.types';
|
|
13
12
|
declare type SendResult = {
|
|
14
13
|
/** The id of the message sent */
|
|
15
14
|
id: string;
|
|
@@ -25,7 +24,6 @@ export declare class ConversationService {
|
|
|
25
24
|
private readonly mlsService;
|
|
26
25
|
readonly messageTimer: MessageTimer;
|
|
27
26
|
private readonly messageService;
|
|
28
|
-
private selfConversationId?;
|
|
29
27
|
constructor(apiClient: APIClient, cryptographyService: CryptographyService, config: {
|
|
30
28
|
useQualifiedIds?: boolean;
|
|
31
29
|
}, notificationService: NotificationService, mlsService: MLSService);
|
|
@@ -40,7 +38,6 @@ export declare class ConversationService {
|
|
|
40
38
|
*/
|
|
41
39
|
private getQualifiedPreKeyBundle;
|
|
42
40
|
getPreKeyBundleMap(conversationId: QualifiedId, userIds?: string[] | UserClients): Promise<UserPreKeyBundleMap>;
|
|
43
|
-
private getSelfConversationId;
|
|
44
41
|
private getQualifiedRecipientsForConversation;
|
|
45
42
|
private getRecipientsForConversation;
|
|
46
43
|
/**
|
|
@@ -54,33 +51,6 @@ export declare class ConversationService {
|
|
|
54
51
|
private sendGenericMessage;
|
|
55
52
|
private extractUserIds;
|
|
56
53
|
private extractQualifiedUserIds;
|
|
57
|
-
clearConversation(conversationId: string, timestamp?: number | Date, messageId?: string, sendAsProtobuf?: boolean): Promise<ClearConversationMessage>;
|
|
58
|
-
/**
|
|
59
|
-
* Sends a LastRead message to the current user's self conversation.
|
|
60
|
-
* This will allow all the user's devices to compute which messages are unread
|
|
61
|
-
*
|
|
62
|
-
* @param conversationId The conversation which has been read
|
|
63
|
-
* @param lastReadTimestamp The timestamp at which the conversation was read
|
|
64
|
-
* @param sendingOptions?
|
|
65
|
-
* @return Resolves when the message has been sent
|
|
66
|
-
*/
|
|
67
|
-
sendLastRead(conversationId: QualifiedId, lastReadTimestamp: number, sendingOptions?: MessageSendingOptions): Promise<(MessageSendingStatus & {
|
|
68
|
-
errored?: boolean | undefined;
|
|
69
|
-
}) | (ClientMismatch & {
|
|
70
|
-
errored?: boolean | undefined;
|
|
71
|
-
})>;
|
|
72
|
-
/**
|
|
73
|
-
* Syncs all self user's devices with the countly id
|
|
74
|
-
*
|
|
75
|
-
* @param countlyId The countly id of the current device
|
|
76
|
-
* @param sendingOptions?
|
|
77
|
-
* @return Resolves when the message has been sent
|
|
78
|
-
*/
|
|
79
|
-
sendCountlySync(countlyId: string, sendingOptions: MessageSendingOptions): Promise<(MessageSendingStatus & {
|
|
80
|
-
errored?: boolean | undefined;
|
|
81
|
-
}) | (ClientMismatch & {
|
|
82
|
-
errored?: boolean | undefined;
|
|
83
|
-
})>;
|
|
84
54
|
/**
|
|
85
55
|
* Get a fresh list from backend of clients for all the participants of the conversation.
|
|
86
56
|
* This is a hacky way of getting all the clients for a conversation.
|
|
@@ -26,7 +26,6 @@ const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
|
26
26
|
const conversation_2 = require("../../conversation/");
|
|
27
27
|
const AssetCryptography_1 = require("../../cryptography/AssetCryptography");
|
|
28
28
|
const TypePredicateUtil_1 = require("../../util/TypePredicateUtil");
|
|
29
|
-
const MessageBuilder_1 = require("../message/MessageBuilder");
|
|
30
29
|
const MessageService_1 = require("../message/MessageService");
|
|
31
30
|
const ConversationService_types_1 = require("./ConversationService.types");
|
|
32
31
|
const bazinga64_1 = require("bazinga64");
|
|
@@ -124,15 +123,6 @@ class ConversationService {
|
|
|
124
123
|
return bundleMap;
|
|
125
124
|
}, {});
|
|
126
125
|
}
|
|
127
|
-
async getSelfConversationId() {
|
|
128
|
-
if (!this.selfConversationId) {
|
|
129
|
-
const { userId } = this.apiClient.context;
|
|
130
|
-
const { qualified_id, id } = await this.apiClient.api.conversation.getConversation(userId);
|
|
131
|
-
const domain = this.config.useQualifiedIds ? qualified_id.domain : '';
|
|
132
|
-
this.selfConversationId = { id, domain };
|
|
133
|
-
}
|
|
134
|
-
return this.selfConversationId;
|
|
135
|
-
}
|
|
136
126
|
async getQualifiedRecipientsForConversation(conversationId, userIds) {
|
|
137
127
|
if ((0, TypePredicateUtil_1.isQualifiedUserClients)(userIds)) {
|
|
138
128
|
return userIds;
|
|
@@ -219,76 +209,6 @@ class ConversationService {
|
|
|
219
209
|
}
|
|
220
210
|
return userIds;
|
|
221
211
|
}
|
|
222
|
-
async clearConversation(conversationId, timestamp = new Date(), messageId = (0, MessageBuilder_1.createId)(), sendAsProtobuf) {
|
|
223
|
-
if (timestamp instanceof Date) {
|
|
224
|
-
timestamp = timestamp.getTime();
|
|
225
|
-
}
|
|
226
|
-
const content = {
|
|
227
|
-
clearedTimestamp: timestamp,
|
|
228
|
-
conversationId,
|
|
229
|
-
};
|
|
230
|
-
const clearedMessage = protocol_messaging_1.Cleared.create(content);
|
|
231
|
-
const genericMessage = protocol_messaging_1.GenericMessage.create({
|
|
232
|
-
[conversation_2.GenericMessageType.CLEARED]: clearedMessage,
|
|
233
|
-
messageId,
|
|
234
|
-
});
|
|
235
|
-
const selfConversationId = await this.getSelfConversationId();
|
|
236
|
-
await this.sendGenericMessage(selfConversationId, this.apiClient.validatedClientId, genericMessage, {
|
|
237
|
-
sendAsProtobuf,
|
|
238
|
-
});
|
|
239
|
-
return {
|
|
240
|
-
content,
|
|
241
|
-
conversation: conversationId,
|
|
242
|
-
from: this.apiClient.context.userId,
|
|
243
|
-
id: messageId,
|
|
244
|
-
messageTimer: 0,
|
|
245
|
-
source: conversation_2.PayloadBundleSource.LOCAL,
|
|
246
|
-
state: conversation_2.PayloadBundleState.OUTGOING_SENT,
|
|
247
|
-
timestamp: Date.now(),
|
|
248
|
-
type: conversation_2.PayloadBundleType.CONVERSATION_CLEAR,
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Sends a LastRead message to the current user's self conversation.
|
|
253
|
-
* This will allow all the user's devices to compute which messages are unread
|
|
254
|
-
*
|
|
255
|
-
* @param conversationId The conversation which has been read
|
|
256
|
-
* @param lastReadTimestamp The timestamp at which the conversation was read
|
|
257
|
-
* @param sendingOptions?
|
|
258
|
-
* @return Resolves when the message has been sent
|
|
259
|
-
*/
|
|
260
|
-
async sendLastRead(conversationId, lastReadTimestamp, sendingOptions) {
|
|
261
|
-
const lastRead = new protocol_messaging_1.LastRead({
|
|
262
|
-
conversationId: conversationId.id,
|
|
263
|
-
lastReadTimestamp,
|
|
264
|
-
});
|
|
265
|
-
const genericMessage = protocol_messaging_1.GenericMessage.create({
|
|
266
|
-
[conversation_2.GenericMessageType.LAST_READ]: lastRead,
|
|
267
|
-
messageId: (0, MessageBuilder_1.createId)(),
|
|
268
|
-
});
|
|
269
|
-
const selfConversationId = await this.getSelfConversationId();
|
|
270
|
-
return this.sendGenericMessage(selfConversationId, this.apiClient.validatedClientId, genericMessage, Object.assign({}, sendingOptions));
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Syncs all self user's devices with the countly id
|
|
274
|
-
*
|
|
275
|
-
* @param countlyId The countly id of the current device
|
|
276
|
-
* @param sendingOptions?
|
|
277
|
-
* @return Resolves when the message has been sent
|
|
278
|
-
*/
|
|
279
|
-
async sendCountlySync(countlyId, sendingOptions) {
|
|
280
|
-
const dataTransfer = new protocol_messaging_1.DataTransfer({
|
|
281
|
-
trackingIdentifier: {
|
|
282
|
-
identifier: countlyId,
|
|
283
|
-
},
|
|
284
|
-
});
|
|
285
|
-
const genericMessage = new protocol_messaging_1.GenericMessage({
|
|
286
|
-
[conversation_2.GenericMessageType.DATA_TRANSFER]: dataTransfer,
|
|
287
|
-
messageId: (0, MessageBuilder_1.createId)(),
|
|
288
|
-
});
|
|
289
|
-
const selfConversationId = await this.getSelfConversationId();
|
|
290
|
-
return this.sendGenericMessage(selfConversationId, this.apiClient.validatedClientId, genericMessage, Object.assign({}, sendingOptions));
|
|
291
|
-
}
|
|
292
212
|
/**
|
|
293
213
|
* Get a fresh list from backend of clients for all the participants of the conversation.
|
|
294
214
|
* This is a hacky way of getting all the clients for a conversation.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ButtonActionConfirmationMessage, ButtonActionMessage, CallMessage, ConfirmationMessage, DeleteMessage, EditedTextMessage, FileAssetAbortMessage, FileAssetMessage, FileAssetMetaDataMessage, HideMessage, ImageAssetMessageOutgoing, LocationMessage, PingMessage, ReactionMessage, TextMessage } from './OtrMessage';
|
|
2
2
|
import { IComposite, GenericMessage } from '@wireapp/protocol-messaging';
|
|
3
|
+
import { QualifiedId } from '@wireapp/api-client/src/user';
|
|
3
4
|
export declare function createId(): string;
|
|
4
5
|
export declare function buildButtonActionMessage(payloadBundle: ButtonActionMessage['content']): GenericMessage;
|
|
5
6
|
export declare function buildButtonActionConfirmationMessage(payloadBundle: ButtonActionConfirmationMessage['content']): GenericMessage;
|
|
@@ -9,6 +10,9 @@ export declare function buildEditedTextMessage(payloadBundle: EditedTextMessage[
|
|
|
9
10
|
export declare function buildFileDataMessage(payloadBundle: FileAssetMessage['content'], messageId?: string): GenericMessage;
|
|
10
11
|
export declare function buildFileMetaDataMessage(payloadBundle: FileAssetMetaDataMessage['content']): GenericMessage;
|
|
11
12
|
export declare function buildFileAbortMessage(payloadBundle: FileAssetAbortMessage['content'], messageId?: string): GenericMessage;
|
|
13
|
+
export declare function buildLastReadMessage(conversationId: QualifiedId, lastReadTimestamp: number): GenericMessage;
|
|
14
|
+
export declare function buildDataTransferMessage(identifier: string): GenericMessage;
|
|
15
|
+
export declare function buildClearedMessage(conversationId: QualifiedId, timestamp?: number): GenericMessage;
|
|
12
16
|
export declare function buildImageMessage(payloadBundle: ImageAssetMessageOutgoing['content'], messageId?: string): GenericMessage;
|
|
13
17
|
export declare function buildLocationMessage(payloadBundle: LocationMessage['content']): GenericMessage;
|
|
14
18
|
export declare function buildPingMessage(payloadBundle: PingMessage['content']): GenericMessage;
|
|
@@ -21,7 +21,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
21
21
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
22
|
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.wrapInEphemeral = exports.buildTextMessage = exports.buildHideMessage = exports.buildDeleteMessage = exports.buildCallMessage = exports.buildSessionResetMessage = exports.buildReactionMessage = exports.buildPingMessage = exports.buildLocationMessage = exports.buildImageMessage = exports.buildFileAbortMessage = exports.buildFileMetaDataMessage = exports.buildFileDataMessage = exports.buildEditedTextMessage = exports.buildConfirmationMessage = exports.buildCompositeMessage = exports.buildButtonActionConfirmationMessage = exports.buildButtonActionMessage = exports.createId = void 0;
|
|
24
|
+
exports.wrapInEphemeral = exports.buildTextMessage = exports.buildHideMessage = exports.buildDeleteMessage = exports.buildCallMessage = exports.buildSessionResetMessage = exports.buildReactionMessage = exports.buildPingMessage = exports.buildLocationMessage = exports.buildImageMessage = exports.buildClearedMessage = exports.buildDataTransferMessage = exports.buildLastReadMessage = exports.buildFileAbortMessage = exports.buildFileMetaDataMessage = exports.buildFileDataMessage = exports.buildEditedTextMessage = exports.buildConfirmationMessage = exports.buildCompositeMessage = exports.buildButtonActionConfirmationMessage = exports.buildButtonActionMessage = exports.createId = void 0;
|
|
25
25
|
const uuidjs_1 = __importDefault(require("uuidjs"));
|
|
26
26
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
27
27
|
const MessageToProtoMapper_1 = require("../message/MessageToProtoMapper");
|
|
@@ -130,6 +130,40 @@ function buildFileAbortMessage(payloadBundle, messageId = createId()) {
|
|
|
130
130
|
return genericMessage;
|
|
131
131
|
}
|
|
132
132
|
exports.buildFileAbortMessage = buildFileAbortMessage;
|
|
133
|
+
function buildLastReadMessage(conversationId, lastReadTimestamp) {
|
|
134
|
+
const lastRead = new protocol_messaging_1.LastRead({
|
|
135
|
+
conversationId: conversationId.id,
|
|
136
|
+
lastReadTimestamp,
|
|
137
|
+
});
|
|
138
|
+
return protocol_messaging_1.GenericMessage.create({
|
|
139
|
+
[GenericMessageType_1.GenericMessageType.LAST_READ]: lastRead,
|
|
140
|
+
messageId: createId(),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
exports.buildLastReadMessage = buildLastReadMessage;
|
|
144
|
+
function buildDataTransferMessage(identifier) {
|
|
145
|
+
const dataTransfer = new protocol_messaging_1.DataTransfer({
|
|
146
|
+
trackingIdentifier: {
|
|
147
|
+
identifier,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
return new protocol_messaging_1.GenericMessage({
|
|
151
|
+
[GenericMessageType_1.GenericMessageType.DATA_TRANSFER]: dataTransfer,
|
|
152
|
+
messageId: createId(),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
exports.buildDataTransferMessage = buildDataTransferMessage;
|
|
156
|
+
function buildClearedMessage(conversationId, timestamp = Date.now()) {
|
|
157
|
+
const clearedMessage = protocol_messaging_1.Cleared.create({
|
|
158
|
+
clearedTimestamp: timestamp,
|
|
159
|
+
conversationId: conversationId.id,
|
|
160
|
+
});
|
|
161
|
+
return protocol_messaging_1.GenericMessage.create({
|
|
162
|
+
[GenericMessageType_1.GenericMessageType.CLEARED]: clearedMessage,
|
|
163
|
+
messageId: createId(),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
exports.buildClearedMessage = buildClearedMessage;
|
|
133
167
|
function buildImageMessage(payloadBundle, messageId = createId()) {
|
|
134
168
|
const imageAsset = buildAsset(payloadBundle);
|
|
135
169
|
const genericMessage = protocol_messaging_1.GenericMessage.create({
|
|
@@ -38,7 +38,7 @@ class CryptographyService {
|
|
|
38
38
|
this.config = config;
|
|
39
39
|
this.cryptobox = new cryptobox_1.Cryptobox(this.storeEngine, config.nbPrekeys);
|
|
40
40
|
this.database = new CryptographyDatabaseRepository_1.CryptographyDatabaseRepository(this.storeEngine);
|
|
41
|
-
this.logger = (0, logdown_1.default)('@wireapp/core/
|
|
41
|
+
this.logger = (0, logdown_1.default)('@wireapp/core/CryptographyService', {
|
|
42
42
|
logger: console,
|
|
43
43
|
markdown: false,
|
|
44
44
|
});
|
|
@@ -153,7 +153,7 @@ class GenericMessageMapper {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
exports.GenericMessageMapper = GenericMessageMapper;
|
|
156
|
-
GenericMessageMapper.logger = (0, logdown_1.default)('@wireapp/core/
|
|
156
|
+
GenericMessageMapper.logger = (0, logdown_1.default)('@wireapp/core/GenericMessageMapper', {
|
|
157
157
|
logger: console,
|
|
158
158
|
markdown: false,
|
|
159
159
|
});
|
|
@@ -46,7 +46,11 @@ export declare class NotificationService extends EventEmitter {
|
|
|
46
46
|
getNotificationEventList(): Promise<Events.BackendEvent[]>;
|
|
47
47
|
setLastEventDate(eventDate: Date): Promise<Date>;
|
|
48
48
|
setLastNotificationId(lastNotification: Notification): Promise<string>;
|
|
49
|
-
|
|
49
|
+
processNotificationStream(notificationHandler: NotificationHandler, onMissedNotifications: (notificationId: string) => void, abortHandler: AbortHandler): Promise<{
|
|
50
|
+
total: number;
|
|
51
|
+
error: number;
|
|
52
|
+
success: number;
|
|
53
|
+
}>;
|
|
50
54
|
/**
|
|
51
55
|
* Checks if an event should be ignored.
|
|
52
56
|
* An event that has a date prior to that last event that we have parsed should be ignored
|
|
@@ -84,7 +84,7 @@ class NotificationService extends events_1.EventEmitter {
|
|
|
84
84
|
constructor(apiClient, cryptographyService, mlsService, storeEngine) {
|
|
85
85
|
super();
|
|
86
86
|
this.mlsService = mlsService;
|
|
87
|
-
this.logger = (0, logdown_1.default)('@wireapp/core/
|
|
87
|
+
this.logger = (0, logdown_1.default)('@wireapp/core/NotificationService', {
|
|
88
88
|
logger: console,
|
|
89
89
|
markdown: false,
|
|
90
90
|
});
|
|
@@ -93,10 +93,9 @@ class NotificationService extends events_1.EventEmitter {
|
|
|
93
93
|
this.backend = new NotificationBackendRepository_1.NotificationBackendRepository(this.apiClient);
|
|
94
94
|
this.database = new NotificationDatabaseRepository_1.NotificationDatabaseRepository(storeEngine);
|
|
95
95
|
}
|
|
96
|
-
async getAllNotifications() {
|
|
96
|
+
async getAllNotifications(since) {
|
|
97
97
|
const clientId = this.apiClient.clientId;
|
|
98
|
-
|
|
99
|
-
return this.backend.getAllNotifications(clientId, lastNotificationId);
|
|
98
|
+
return this.backend.getAllNotifications(clientId, since);
|
|
100
99
|
}
|
|
101
100
|
/** Should only be called with a completely new client. */
|
|
102
101
|
async initializeNotificationStream() {
|
|
@@ -132,23 +131,39 @@ class NotificationService extends events_1.EventEmitter {
|
|
|
132
131
|
async setLastNotificationId(lastNotification) {
|
|
133
132
|
return this.database.updateLastNotificationId(lastNotification);
|
|
134
133
|
}
|
|
135
|
-
async
|
|
136
|
-
const
|
|
134
|
+
async processNotificationStream(notificationHandler, onMissedNotifications, abortHandler) {
|
|
135
|
+
const lastNotificationId = await this.database.getLastNotificationId();
|
|
136
|
+
const { notifications, missedNotification } = await this.getAllNotifications(lastNotificationId);
|
|
137
137
|
if (missedNotification) {
|
|
138
138
|
onMissedNotifications(missedNotification);
|
|
139
139
|
}
|
|
140
|
+
const results = { total: notifications.length, error: 0, success: 0 };
|
|
141
|
+
const logMessage = notifications.length > 0
|
|
142
|
+
? `Start processing ${notifications.length} notifications since notification id ${lastNotificationId}`
|
|
143
|
+
: `No notification to process from the stream`;
|
|
144
|
+
this.logger.log(logMessage);
|
|
140
145
|
for (const [index, notification] of notifications.entries()) {
|
|
141
146
|
if (abortHandler.isAborted()) {
|
|
142
147
|
/* Stop handling notifications if the websocket has been disconnected.
|
|
143
148
|
* Upon reconnecting we are going to restart handling the notification stream for where we left of
|
|
144
149
|
*/
|
|
145
|
-
|
|
150
|
+
this.logger.warn(`Stop processing notifications as connection to websocket was closed`);
|
|
151
|
+
return results;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
await notificationHandler(notification, conversation_1.PayloadBundleSource.NOTIFICATION_STREAM, {
|
|
155
|
+
done: index + 1,
|
|
156
|
+
total: notifications.length,
|
|
157
|
+
});
|
|
158
|
+
results.success++;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
const message = error instanceof Error ? error.message : error;
|
|
162
|
+
this.logger.error(`Error while processing notification ${notification.id}: ${message}`, error);
|
|
163
|
+
results.error++;
|
|
146
164
|
}
|
|
147
|
-
await notificationHandler(notification, conversation_1.PayloadBundleSource.NOTIFICATION_STREAM, {
|
|
148
|
-
done: index + 1,
|
|
149
|
-
total: notifications.length,
|
|
150
|
-
}).catch(error => this.logger.error(error));
|
|
151
165
|
}
|
|
166
|
+
return results;
|
|
152
167
|
}
|
|
153
168
|
/**
|
|
154
169
|
* Checks if an event should be ignored.
|
|
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.TaskScheduler = void 0;
|
|
25
25
|
const logdown_1 = __importDefault(require("logdown"));
|
|
26
|
-
const logger = (0, logdown_1.default)('@wireapp/core/
|
|
26
|
+
const logger = (0, logdown_1.default)('@wireapp/core/TaskScheduler', {
|
|
27
27
|
logger: console,
|
|
28
28
|
markdown: false,
|
|
29
29
|
});
|