@twilio/conversations 3.0.0-canary.13 → 3.0.0-canary.2
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/README.md +22 -18
- package/builds/browser.js +729 -1639
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +72 -64
- package/builds/lib.js +729 -1639
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +17697 -17435
- package/builds/twilio-conversations.min.js +1 -1
- package/dist/aggregated-delivery-receipt.js +1 -1
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/client.js +69 -65
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +38 -13
- package/dist/command-executor.js.map +1 -1
- package/dist/conversation.js +81 -13
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +16 -3
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +13 -19
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +5 -3
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +2 -2
- package/dist/data/users.js.map +1 -1
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +7 -9
- package/dist/message.js.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/conversations/package.json.js +1 -1
- package/dist/participant.js +33 -33
- package/dist/participant.js.map +1 -1
- package/dist/rest-paginator.js +11 -11
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +103 -11
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +13 -5
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +1 -1
- package/dist/user.js.map +1 -1
- package/dist/util/index.js.map +1 -1
- package/package.json +16 -14
- package/docs/assets/css/main.css +0 -2660
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -248
- package/docs/assets/js/search.js +0 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +0 -3184
- package/docs/classes/Client.html +0 -4239
- package/docs/classes/Conversation.html +0 -4354
- package/docs/classes/DetailedDeliveryReceipt.html +0 -3163
- package/docs/classes/Media.html +0 -3167
- package/docs/classes/Message.html +0 -3732
- package/docs/classes/MessageBuilder.html +0 -3277
- package/docs/classes/Participant.html +0 -3444
- package/docs/classes/PushNotification.html +0 -3130
- package/docs/classes/RestPaginator.html +0 -3160
- package/docs/classes/UnsentMessage.html +0 -3042
- package/docs/classes/User.html +0 -3349
- package/docs/index.html +0 -3505
- package/docs/interfaces/ClientOptions.html +0 -3034
- package/docs/interfaces/ConversationBindings.html +0 -3001
- package/docs/interfaces/ConversationEmailBinding.html +0 -3001
- package/docs/interfaces/ConversationLimits.html +0 -3098
- package/docs/interfaces/ConversationState.html +0 -3050
- package/docs/interfaces/ConversationUpdatedEventArgs.html +0 -3001
- package/docs/interfaces/CreateConversationOptions.html +0 -3066
- package/docs/interfaces/LastMessage.html +0 -3050
- package/docs/interfaces/Paginator.html +0 -3141
- package/docs/interfaces/ParticipantBindings.html +0 -3001
- package/docs/interfaces/ParticipantEmailBinding.html +0 -3001
- package/docs/interfaces/PushNotificationData.html +0 -3114
- package/docs/interfaces/SendEmailOptions.html +0 -3034
- package/docs/interfaces/SendMediaOptions.html +0 -3068
- package/docs/modules.html +0 -3506
package/dist/command-executor.js
CHANGED
@@ -130,11 +130,12 @@ This software includes platform.js under the following license.
|
|
130
130
|
|
131
131
|
Object.defineProperty(exports, '__esModule', { value: true });
|
132
132
|
|
133
|
-
var
|
133
|
+
var twilsock = require('twilsock');
|
134
134
|
var operationRetrier = require('@twilio/operation-retrier');
|
135
|
+
var nanoid = require('nanoid');
|
135
136
|
|
136
137
|
const trimSlashes = (url) => url.replace(/(^\/+|\/+$)/g, "");
|
137
|
-
const isMutationConflictResponse = (response) => response.
|
138
|
+
const isMutationConflictResponse = (response) => response.statusCode === 202;
|
138
139
|
class CommandExecutor {
|
139
140
|
constructor(_serviceUrl, _services, _productId) {
|
140
141
|
this._serviceUrl = _serviceUrl;
|
@@ -159,45 +160,69 @@ class CommandExecutor {
|
|
159
160
|
getUrl +=
|
160
161
|
"?" +
|
161
162
|
Object.entries(requestBody)
|
162
|
-
.map((entry) => entry
|
163
|
+
.map((entry) => entry
|
164
|
+
.map((component) => encodeURIComponent(String(component)))
|
165
|
+
.join("="))
|
163
166
|
.join("&");
|
164
167
|
}
|
165
|
-
response = await this._services.transport.
|
168
|
+
response = await this._services.transport.sendRequest(new twilsock.HttpRequest({
|
169
|
+
url: getUrl,
|
170
|
+
headers: finalHeaders,
|
171
|
+
grant: this._productId,
|
172
|
+
}));
|
166
173
|
break;
|
167
174
|
case "post":
|
168
|
-
response = await this._services.transport.
|
175
|
+
response = await this._services.transport.sendRequest(new twilsock.HttpRequest({
|
176
|
+
method: "POST",
|
177
|
+
url: preProcessedUrl,
|
178
|
+
headers: finalHeaders,
|
179
|
+
payload: JSON.stringify(requestBody),
|
180
|
+
grant: this._productId,
|
181
|
+
}));
|
169
182
|
break;
|
170
183
|
case "delete":
|
171
|
-
response = await this._services.transport.
|
184
|
+
response = await this._services.transport.sendRequest(new twilsock.HttpRequest({
|
185
|
+
method: "DELETE",
|
186
|
+
url: preProcessedUrl,
|
187
|
+
headers: finalHeaders,
|
188
|
+
grant: this._productId,
|
189
|
+
}));
|
172
190
|
break;
|
173
191
|
}
|
174
|
-
if (response.
|
175
|
-
throw new Error(`Request responded with a non-success code ${response.
|
192
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
193
|
+
throw new Error(`Request responded with a non-success code ${response.statusCode}`);
|
176
194
|
}
|
177
195
|
return response;
|
178
196
|
}
|
179
197
|
async fetchResource(url, requestBody) {
|
180
198
|
const maxAttemptsCount = 6;
|
181
199
|
try {
|
200
|
+
// todo: remove any after the release of new Twilsock
|
182
201
|
const result = await new operationRetrier.AsyncRetrier({
|
183
202
|
min: 50,
|
184
203
|
max: 1600,
|
185
204
|
maxAttemptsCount,
|
186
205
|
}).run(() => this._makeRequest("get", url, requestBody));
|
187
|
-
return result.
|
206
|
+
return JSON.parse(result.payload);
|
188
207
|
}
|
189
|
-
catch (
|
208
|
+
catch (E) {
|
190
209
|
throw new Error(`Fetch resource from "${url}" failed.`);
|
191
210
|
}
|
192
211
|
}
|
193
212
|
async mutateResource(method, url, requestBody) {
|
213
|
+
// todo: remove any after the release of new Twilsock
|
194
214
|
const result = await this._makeRequest(method, url, requestBody, {
|
195
|
-
"X-Twilio-Mutation-Id":
|
215
|
+
"X-Twilio-Mutation-Id": nanoid.nanoid(),
|
196
216
|
});
|
217
|
+
let parsedPayload = {};
|
218
|
+
try {
|
219
|
+
parsedPayload = JSON.parse(result.payload);
|
220
|
+
}
|
221
|
+
catch (_a) { }
|
197
222
|
if (isMutationConflictResponse(result)) {
|
198
|
-
return await this.fetchResource(
|
223
|
+
return await this.fetchResource(parsedPayload.resource_url);
|
199
224
|
}
|
200
|
-
return
|
225
|
+
return parsedPayload;
|
201
226
|
}
|
202
227
|
}
|
203
228
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"command-executor.js","sources":["../src/command-executor.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"file":"command-executor.js","sources":["../src/command-executor.ts"],"sourcesContent":["import { TwilsockClient, HttpResponse, HttpRequest } from \"twilsock\";\nimport { AsyncRetrier } from \"@twilio/operation-retrier\";\nimport { nanoid } from \"nanoid\";\n\nexport interface CommandExecutorServices {\n transport: TwilsockClient;\n}\n\nconst trimSlashes = (url: string): string => url.replace(/(^\\/+|\\/+$)/g, \"\");\n\nconst isMutationConflictResponse = (response: HttpResponse): boolean =>\n response.statusCode === 202;\n\nclass CommandExecutor {\n constructor(\n private _serviceUrl: string,\n private _services: CommandExecutorServices,\n private _productId?: string\n ) {}\n\n private _preProcessUrl(url: string): string {\n const trimmedUrl = trimSlashes(url);\n\n if (/^https?:\\/\\//.test(url)) {\n return trimmedUrl;\n }\n\n return `${trimSlashes(this._serviceUrl)}/${trimmedUrl}`;\n }\n\n private async _makeRequest<REQ = void, RESP = void>(\n method: \"get\" | \"post\" | \"delete\",\n url: string,\n requestBody?: REQ,\n headers?: Record<string, string>\n ): Promise<HttpResponse> {\n const preProcessedUrl = this._preProcessUrl(url);\n const finalHeaders = {\n \"Content-Type\": \"application/json; charset=utf-8\",\n ...(headers || {}),\n };\n let response: HttpResponse;\n\n switch (method) {\n case \"get\":\n let getUrl = preProcessedUrl;\n\n if (requestBody) {\n getUrl +=\n \"?\" +\n Object.entries(requestBody)\n .map((entry) =>\n entry\n .map((component) => encodeURIComponent(String(component)))\n .join(\"=\")\n )\n .join(\"&\");\n }\n\n response = await this._services.transport.sendRequest(\n new HttpRequest({\n url: getUrl,\n headers: finalHeaders,\n grant: this._productId,\n })\n );\n break;\n case \"post\":\n response = await this._services.transport.sendRequest(\n new HttpRequest({\n method: \"POST\",\n url: preProcessedUrl,\n headers: finalHeaders,\n payload: JSON.stringify(requestBody),\n grant: this._productId,\n })\n );\n break;\n case \"delete\":\n response = await this._services.transport.sendRequest(\n new HttpRequest({\n method: \"DELETE\",\n url: preProcessedUrl,\n headers: finalHeaders,\n grant: this._productId,\n })\n );\n break;\n }\n\n if (response.statusCode < 200 || response.statusCode >= 300) {\n throw new Error(\n `Request responded with a non-success code ${response.statusCode}`\n );\n }\n\n return response;\n }\n\n public async fetchResource<REQ = void, RESP = void>(\n url: string,\n requestBody?: REQ\n ): Promise<RESP> {\n const maxAttemptsCount = 6;\n try {\n // todo: remove any after the release of new Twilsock\n const result = await new AsyncRetrier({\n min: 50,\n max: 1600,\n maxAttemptsCount,\n }).run(() => this._makeRequest<REQ, RESP>(\"get\", url, requestBody));\n return JSON.parse(result.payload);\n } catch (E) {\n throw new Error(`Fetch resource from \"${url}\" failed.`);\n }\n }\n\n public async mutateResource<REQ = void, RESP = void>(\n method: \"post\" | \"delete\",\n url: string,\n requestBody?: REQ\n ): Promise<RESP> {\n // todo: remove any after the release of new Twilsock\n const result = await this._makeRequest<REQ, RESP>(\n method,\n url,\n requestBody,\n {\n \"X-Twilio-Mutation-Id\": nanoid(),\n }\n );\n\n let parsedPayload: any = {};\n try {\n parsedPayload = JSON.parse(result.payload);\n } catch {}\n\n if (isMutationConflictResponse(result)) {\n return await this.fetchResource<undefined, RESP>(\n parsedPayload.resource_url\n );\n }\n\n return parsedPayload;\n }\n}\n\nexport { CommandExecutor };\n"],"names":["HttpRequest","AsyncRetrier","nanoid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,WAAW,GAAG,CAAC,GAAW,KAAa,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;AAE7E,MAAM,0BAA0B,GAAG,CAAC,QAAsB,KACxD,QAAQ,CAAC,UAAU,KAAK,GAAG,CAAC;AAE9B,MAAM,eAAe,CAAA;AACnB,IAAA,WAAA,CACU,WAAmB,EACnB,SAAkC,EAClC,UAAmB,EAAA;QAFnB,IAAW,CAAA,WAAA,GAAX,WAAW,CAAQ;QACnB,IAAS,CAAA,SAAA,GAAT,SAAS,CAAyB;QAClC,IAAU,CAAA,UAAA,GAAV,UAAU,CAAS;KACzB;AAEI,IAAA,cAAc,CAAC,GAAW,EAAA;AAChC,QAAA,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;AAEpC,QAAA,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAC5B,YAAA,OAAO,UAAU,CAAC;AACnB,SAAA;QAED,OAAO,CAAA,EAAG,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAA,EAAI,UAAU,CAAA,CAAE,CAAC;KACzD;IAEO,MAAM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jB,QAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CACpC,MAAM,EACN,GAAG,EACH,WAAW,EACX;YACE,sBAAsB,EAAEC,aAAM,EAAE;AACjC,SAAA,CACF,CAAC;QAEF,IAAI,aAAa,GAAQ,EAAE,CAAC;QAC5B,IAAI;YACF,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC5C,SAAA;AAAC,QAAA,OAAA,EAAA,EAAM,GAAE;AAEV,QAAA,IAAI,0BAA0B,CAAC,MAAM,CAAC,EAAE;YACtC,OAAO,MAAM,IAAI,CAAC,aAAa,CAC7B,aAAa,CAAC,YAAY,CAC3B,CAAC;AACH,SAAA;AAED,QAAA,OAAO,aAAa,CAAC;KACtB;AACF;;;;"}
|
package/dist/conversation.js
CHANGED
@@ -443,6 +443,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
443
443
|
const url = new index.UriBuilder(this._configuration.links.conversations)
|
444
444
|
.path(this.sid)
|
445
445
|
.build();
|
446
|
+
// todo: remove any after the release of new Twilsock
|
446
447
|
const response = await this._services.network.get(url);
|
447
448
|
return (_a = response.body.participants_count) !== null && _a !== void 0 ? _a : 0;
|
448
449
|
}
|
@@ -476,11 +477,12 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
476
477
|
const url = new index.UriBuilder(this._configuration.links.conversations)
|
477
478
|
.path(this.sid)
|
478
479
|
.build();
|
480
|
+
// todo: remove any after the release of new Twilsock
|
479
481
|
const response = await this._services.network.get(url);
|
480
482
|
return (_a = response.body.messages_count) !== null && _a !== void 0 ? _a : 0;
|
481
483
|
}
|
482
484
|
/**
|
483
|
-
* Get unread messages
|
485
|
+
* Get count of unread messages for the user if they are a participant of this
|
484
486
|
* conversation. Rejects if the user is not a participant of the conversation.
|
485
487
|
*
|
486
488
|
* Use this method to obtain the number of unread messages together with
|
@@ -488,17 +490,25 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
488
490
|
* message indices which may have gaps. See {@link Message.index} for details.
|
489
491
|
*
|
490
492
|
* This method is semi-realtime. This means that this data will be eventually
|
491
|
-
* correct, but will also be possibly incorrect for a few seconds. The
|
493
|
+
* correct, but it will also be possibly incorrect for a few seconds. The
|
492
494
|
* Conversations system does not provide real time events for counter values
|
493
495
|
* changes.
|
494
496
|
*
|
495
497
|
* This is useful for any UI badges, but it is not recommended to build any
|
496
498
|
* core application logic based on these counters being accurate in real time.
|
499
|
+
*
|
500
|
+
* If the read horizon is not set, this function will return null. This could mean
|
501
|
+
* that all messages in the conversation are unread, or that the read horizon system
|
502
|
+
* is not being used. How to interpret this `null` value is up to the customer application.
|
503
|
+
*
|
504
|
+
* @return Number of unread messages based on the current read horizon set for
|
505
|
+
* the user or `null` if the read horizon is not set.
|
497
506
|
*/
|
498
507
|
async getUnreadMessagesCount() {
|
499
508
|
const url = new index.UriBuilder(this._configuration.links.myConversations)
|
500
509
|
.path(this.sid)
|
501
510
|
.build();
|
511
|
+
// todo: remove any after the release of new Twilsock
|
502
512
|
const response = await this._services.network.get(url);
|
503
513
|
if (response.body.conversation_sid !== this.sid) {
|
504
514
|
throw new Error("Conversation was not found in the user conversations list");
|
@@ -545,13 +555,48 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
545
555
|
* @return Index of the new message.
|
546
556
|
*/
|
547
557
|
async sendMessage(message, messageAttributes, emailOptions) {
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
558
|
+
const response = typeof message === "string" || message === null
|
559
|
+
? await this._messagesEntity.send(message, messageAttributes, emailOptions)
|
560
|
+
: await this._messagesEntity.sendMedia(message, messageAttributes, emailOptions);
|
561
|
+
const type = typeof message === "string" || message === null ? "text" : "media";
|
562
|
+
let responseAttributes;
|
563
|
+
try {
|
564
|
+
responseAttributes = JSON.parse(response.attributes);
|
552
565
|
}
|
553
|
-
|
554
|
-
|
566
|
+
catch (e) { }
|
567
|
+
const messageData = {
|
568
|
+
sid: response.sid,
|
569
|
+
text: response.body,
|
570
|
+
type,
|
571
|
+
author: response.author,
|
572
|
+
subject: response.subject,
|
573
|
+
lastUpdatedBy: response.participant_sid,
|
574
|
+
attributes: responseAttributes,
|
575
|
+
dateUpdated: response.date_updated,
|
576
|
+
timestamp: response.date_created,
|
577
|
+
memberSid: response.participant_sid,
|
578
|
+
medias: Array.isArray(response.media)
|
579
|
+
? response.media.map((media) => ({
|
580
|
+
sid: media["sid"],
|
581
|
+
size: Number(media["size"]),
|
582
|
+
category: media["category"],
|
583
|
+
filename: media["filename"],
|
584
|
+
contentType: media["content_type"],
|
585
|
+
}))
|
586
|
+
: null,
|
587
|
+
media: response.media &&
|
588
|
+
typeof response.media === "object" &&
|
589
|
+
!Array.isArray(response.media)
|
590
|
+
? {
|
591
|
+
sid: response.media["sid"],
|
592
|
+
size: Number(response.media["size"]),
|
593
|
+
category: response.media["category"],
|
594
|
+
filename: response.media["filename"],
|
595
|
+
contentType: response.media["content_type"],
|
596
|
+
}
|
597
|
+
: null,
|
598
|
+
};
|
599
|
+
return this._messagesEntity._upsertMessage(response.index, messageData);
|
555
600
|
}
|
556
601
|
/**
|
557
602
|
* New interface to prepare for sending a message.
|
@@ -576,7 +621,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
576
621
|
}
|
577
622
|
/**
|
578
623
|
* Set all messages in the conversation unread.
|
579
|
-
* @
|
624
|
+
* @returns New count of unread messages after this update.
|
580
625
|
*/
|
581
626
|
async setAllMessagesUnread() {
|
582
627
|
await this._subscribeStreams();
|
@@ -624,7 +669,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
624
669
|
* Set the last read message index to the current read horizon.
|
625
670
|
* @param index Message index to set as last read. If null is provided, then
|
626
671
|
* the behavior is identical to {@link Conversation.setAllMessagesUnread}.
|
627
|
-
* @returns
|
672
|
+
* @returns New count of unread messages after this update.
|
628
673
|
*/
|
629
674
|
async updateLastReadMessageIndex(index) {
|
630
675
|
await this._subscribeStreams();
|
@@ -675,6 +720,29 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
675
720
|
throw err;
|
676
721
|
}
|
677
722
|
}
|
723
|
+
/**
|
724
|
+
* Fetch participants and messages of the conversation. This method needs to
|
725
|
+
* be called during conversation initialization to catch broken conversations
|
726
|
+
* (broken conversations are conversations that have essential Sync entities
|
727
|
+
* missing, i.e. the conversation document, the messages list or the
|
728
|
+
* participant map). In case of this conversation being broken, the method
|
729
|
+
* will throw an exception that will be caught and handled gracefully.
|
730
|
+
* @internal
|
731
|
+
*/
|
732
|
+
async _fetchStreams() {
|
733
|
+
var _a, _b;
|
734
|
+
await this._subscribe();
|
735
|
+
Conversation._logger.trace("_streamsAvailable, this.entity.data=", (_a = this._entity) === null || _a === void 0 ? void 0 : _a.data);
|
736
|
+
const data = (_b = this._entity) === null || _b === void 0 ? void 0 : _b.data;
|
737
|
+
this._messagesList = await this._services.syncClient.list({
|
738
|
+
id: data.messages,
|
739
|
+
mode: "open_existing",
|
740
|
+
});
|
741
|
+
this._participantsMap = await this._services.syncClient.map({
|
742
|
+
id: data.roster,
|
743
|
+
mode: "open_existing",
|
744
|
+
});
|
745
|
+
}
|
678
746
|
/**
|
679
747
|
* Load the attributes of this conversation and instantiate its participants
|
680
748
|
* and messages. This or _subscribe will need to be called before any events
|
@@ -683,7 +751,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
683
751
|
* @internal
|
684
752
|
*/
|
685
753
|
async _subscribeStreams() {
|
686
|
-
var _a, _b;
|
754
|
+
var _a, _b, _c, _d;
|
687
755
|
try {
|
688
756
|
await this._subscribe();
|
689
757
|
Conversation._logger.trace("_subscribeStreams, this.entity.data=", (_a = this._entity) === null || _a === void 0 ? void 0 : _a.data);
|
@@ -691,8 +759,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
691
759
|
const messagesObjectName = data.messages;
|
692
760
|
const rosterObjectName = data.roster;
|
693
761
|
await Promise.all([
|
694
|
-
this._messagesEntity.subscribe(messagesObjectName),
|
695
|
-
this._participantsEntity.subscribe(rosterObjectName),
|
762
|
+
this._messagesEntity.subscribe((_c = this._messagesList) !== null && _c !== void 0 ? _c : messagesObjectName),
|
763
|
+
this._participantsEntity.subscribe((_d = this._participantsMap) !== null && _d !== void 0 ? _d : rosterObjectName),
|
696
764
|
]);
|
697
765
|
}
|
698
766
|
catch (err) {
|