@twilio/conversations 3.0.0-rc.9 → 3.0.1-rc.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/README.md +39 -29
- package/builds/browser.esm.js +10846 -0
- package/builds/browser.esm.js.map +1 -0
- package/builds/browser.js +2505 -479
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +805 -70
- package/builds/lib.esm.d.ts +3178 -0
- package/builds/lib.esm.js +10845 -0
- package/builds/lib.js +2505 -479
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +25853 -24412
- package/builds/twilio-conversations.js.map +1 -0
- package/builds/twilio-conversations.min.js +2 -1
- package/builds/twilio-conversations.min.js.map +1 -0
- package/dist/aggregated-delivery-receipt.js +10 -5
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/channel-metadata-client.js +187 -0
- package/dist/channel-metadata-client.js.map +1 -0
- package/dist/client.js +266 -192
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +53 -15
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +23 -12
- package/dist/configuration.js.map +1 -1
- package/dist/content-client.js +180 -0
- package/dist/content-client.js.map +1 -0
- package/dist/content-template.js +304 -0
- package/dist/content-template.js.map +1 -0
- package/dist/conversation.js +213 -134
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +70 -50
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +40 -27
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +38 -32
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +19 -14
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js +9 -4
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/index.js +26 -41
- package/dist/index.js.map +1 -1
- package/dist/interfaces/notification-types.js +9 -4
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/interfaces/rules.js +160 -0
- package/dist/interfaces/rules.js.map +1 -0
- package/dist/logger.js +17 -28
- package/dist/logger.js.map +1 -1
- package/dist/media.js +40 -24
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +79 -12
- package/dist/message-builder.js.map +1 -1
- package/dist/message-recipients-client.js +231 -0
- package/dist/message-recipients-client.js.map +1 -0
- package/dist/message.js +258 -92
- package/dist/message.js.map +1 -1
- package/dist/node_modules/quick-lru/index.js +261 -0
- package/dist/node_modules/quick-lru/index.js.map +1 -0
- package/dist/node_modules/tslib/tslib.es6.js +15 -5
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/conversations/package.json.js +12 -7
- package/dist/packages/conversations/package.json.js.map +1 -1
- package/dist/participant.js +42 -38
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js +9 -4
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js +9 -4
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +11 -6
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +17 -11
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js +14 -9
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +40 -32
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js +9 -4
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js +44 -8
- package/dist/util/index.js.map +1 -1
- package/dist/{interfaces/attributes.js → utils/uuid.js} +17 -19
- package/dist/utils/uuid.js.map +1 -0
- package/package.json +21 -20
- package/CHANGELOG.md +0 -509
- package/dist/interfaces/attributes.js.map +0 -1
- 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/CancellablePromise.html +0 -3213
- 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 -3509
- 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 -3510
package/dist/conversation.js
CHANGED
|
@@ -126,26 +126,26 @@ This software includes platform.js under the following license.
|
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
127
127
|
|
|
128
128
|
*/
|
|
129
|
-
|
|
129
|
+
var global =
|
|
130
|
+
typeof global !== "undefined"
|
|
131
|
+
? global
|
|
132
|
+
: typeof self !== "undefined"
|
|
133
|
+
? self
|
|
134
|
+
: typeof window !== "undefined"
|
|
135
|
+
? window
|
|
136
|
+
: {};
|
|
130
137
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var messageBuilder = require('./message-builder.js');
|
|
143
|
-
var replayEventEmitter = require('@twilio/replay-event-emitter');
|
|
144
|
-
var isEqual = require('lodash.isequal');
|
|
145
|
-
|
|
146
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
147
|
-
|
|
148
|
-
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
138
|
+
import { __decorate, __metadata } from './node_modules/tslib/tslib.es6.js';
|
|
139
|
+
import { Logger } from './logger.js';
|
|
140
|
+
import { Participants } from './data/participants.js';
|
|
141
|
+
import { Participant } from './participant.js';
|
|
142
|
+
import { Messages } from './data/messages.js';
|
|
143
|
+
import { parseTime, UriBuilder, parseToNumber, isEqual } from './util/index.js';
|
|
144
|
+
import { SyncDocument } from 'twilio-sync';
|
|
145
|
+
import { validateTypesAsync, nonEmptyString, nonNegativeInteger, literal, objectSchema, custom } from '@twilio/declarative-type-validator';
|
|
146
|
+
import { optionalJson, json } from './interfaces/rules.js';
|
|
147
|
+
import { MessageBuilder } from './message-builder.js';
|
|
148
|
+
import { ReplayEventEmitter } from '@twilio/replay-event-emitter';
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
151
|
* Map of the fields that will be processed with update messages.
|
|
@@ -169,7 +169,7 @@ const fieldMappings = {
|
|
|
169
169
|
* A conversation represents communication between multiple Conversations
|
|
170
170
|
* clients.
|
|
171
171
|
*/
|
|
172
|
-
class Conversation extends
|
|
172
|
+
class Conversation extends ReplayEventEmitter {
|
|
173
173
|
/**
|
|
174
174
|
* @param descriptor Conversation descriptor.
|
|
175
175
|
* @param sid Conversation SID.
|
|
@@ -191,8 +191,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
191
191
|
status: "notParticipating",
|
|
192
192
|
attributes: (_a = descriptor.attributes) !== null && _a !== void 0 ? _a : {},
|
|
193
193
|
createdBy: descriptor.createdBy,
|
|
194
|
-
dateCreated:
|
|
195
|
-
dateUpdated:
|
|
194
|
+
dateCreated: parseTime(descriptor.dateCreated),
|
|
195
|
+
dateUpdated: parseTime(descriptor.dateUpdated),
|
|
196
196
|
friendlyName: descriptor.friendlyName || null,
|
|
197
197
|
lastReadMessageIndex: Number.isInteger(descriptor.lastConsumedMessageIndex)
|
|
198
198
|
? descriptor.lastConsumedMessageIndex
|
|
@@ -206,14 +206,21 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
206
206
|
participants: this._links.participants,
|
|
207
207
|
};
|
|
208
208
|
this._participants = new Map();
|
|
209
|
-
this._participantsEntity = new
|
|
210
|
-
|
|
211
|
-
this._participantsEntity.on(
|
|
212
|
-
|
|
213
|
-
this.
|
|
214
|
-
this.
|
|
215
|
-
|
|
216
|
-
this.
|
|
209
|
+
this._participantsEntity = new Participants(this, this._participants, // state leak
|
|
210
|
+
participantsLinks, this._services);
|
|
211
|
+
this._participantsEntity.on(Conversation.participantJoined, (participant) =>
|
|
212
|
+
// @todo update participants map here??
|
|
213
|
+
this.emit(Conversation.participantJoined, participant));
|
|
214
|
+
this._participantsEntity.on(Conversation.participantLeft, (participant) =>
|
|
215
|
+
// @todo update participants map here??
|
|
216
|
+
this.emit(Conversation.participantLeft, participant));
|
|
217
|
+
this._participantsEntity.on(Conversation.participantUpdated, (args) =>
|
|
218
|
+
// @todo update participants map here??
|
|
219
|
+
this.emit(Conversation.participantUpdated, args));
|
|
220
|
+
this._messagesEntity = new Messages(this, configuration, services);
|
|
221
|
+
this._messagesEntity.on(Conversation.messageAdded, (message) => this._onMessageAdded(message));
|
|
222
|
+
this._messagesEntity.on(Conversation.messageUpdated, (args) => this.emit(Conversation.messageUpdated, args));
|
|
223
|
+
this._messagesEntity.on(Conversation.messageRemoved, (message) => this.emit(Conversation.messageRemoved, message));
|
|
217
224
|
}
|
|
218
225
|
/**
|
|
219
226
|
* Unique name of the conversation.
|
|
@@ -279,7 +286,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
279
286
|
return (_a = this._internalState.notificationLevel) !== null && _a !== void 0 ? _a : "default";
|
|
280
287
|
}
|
|
281
288
|
/**
|
|
282
|
-
* Conversation bindings.
|
|
289
|
+
* Conversation bindings. An undocumented feature (for now).
|
|
283
290
|
* @internal
|
|
284
291
|
*/
|
|
285
292
|
get bindings() {
|
|
@@ -324,7 +331,9 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
324
331
|
update.attributes = {};
|
|
325
332
|
}
|
|
326
333
|
try {
|
|
327
|
-
|
|
334
|
+
if (update.dateCreated) {
|
|
335
|
+
update.dateCreated = new Date(update.dateCreated);
|
|
336
|
+
}
|
|
328
337
|
}
|
|
329
338
|
catch (e) {
|
|
330
339
|
Conversation._logger.warn("Retrieved malformed dateCreated from the server for conversation: " +
|
|
@@ -332,7 +341,9 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
332
341
|
delete update.dateCreated;
|
|
333
342
|
}
|
|
334
343
|
try {
|
|
335
|
-
|
|
344
|
+
if (update.dateUpdated) {
|
|
345
|
+
update.dateUpdated = new Date(update.dateUpdated);
|
|
346
|
+
}
|
|
336
347
|
}
|
|
337
348
|
catch (e) {
|
|
338
349
|
Conversation._logger.warn("Retrieved malformed dateUpdated from the server for conversation: " +
|
|
@@ -436,7 +447,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
436
447
|
*/
|
|
437
448
|
async getParticipantsCount() {
|
|
438
449
|
var _a;
|
|
439
|
-
const url = new
|
|
450
|
+
const url = new UriBuilder(this._configuration.links.conversations)
|
|
440
451
|
.path(this.sid)
|
|
441
452
|
.build();
|
|
442
453
|
const response = await this._services.network.get(url);
|
|
@@ -469,14 +480,14 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
469
480
|
*/
|
|
470
481
|
async getMessagesCount() {
|
|
471
482
|
var _a;
|
|
472
|
-
const url = new
|
|
483
|
+
const url = new UriBuilder(this._configuration.links.conversations)
|
|
473
484
|
.path(this.sid)
|
|
474
485
|
.build();
|
|
475
486
|
const response = await this._services.network.get(url);
|
|
476
487
|
return (_a = response.body.messages_count) !== null && _a !== void 0 ? _a : 0;
|
|
477
488
|
}
|
|
478
489
|
/**
|
|
479
|
-
* Get unread messages
|
|
490
|
+
* Get count of unread messages for the user if they are a participant of this
|
|
480
491
|
* conversation. Rejects if the user is not a participant of the conversation.
|
|
481
492
|
*
|
|
482
493
|
* Use this method to obtain the number of unread messages together with
|
|
@@ -484,15 +495,22 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
484
495
|
* message indices which may have gaps. See {@link Message.index} for details.
|
|
485
496
|
*
|
|
486
497
|
* This method is semi-realtime. This means that this data will be eventually
|
|
487
|
-
* correct, but will also be possibly incorrect for a few seconds. The
|
|
498
|
+
* correct, but it will also be possibly incorrect for a few seconds. The
|
|
488
499
|
* Conversations system does not provide real time events for counter values
|
|
489
500
|
* changes.
|
|
490
501
|
*
|
|
491
502
|
* This is useful for any UI badges, but it is not recommended to build any
|
|
492
503
|
* core application logic based on these counters being accurate in real time.
|
|
504
|
+
*
|
|
505
|
+
* If the read horizon is not set, this function will return null. This could mean
|
|
506
|
+
* that all messages in the conversation are unread, or that the read horizon system
|
|
507
|
+
* is not being used. How to interpret this `null` value is up to the customer application.
|
|
508
|
+
*
|
|
509
|
+
* @return Number of unread messages based on the current read horizon set for
|
|
510
|
+
* the user or `null` if the read horizon is not set.
|
|
493
511
|
*/
|
|
494
512
|
async getUnreadMessagesCount() {
|
|
495
|
-
const url = new
|
|
513
|
+
const url = new UriBuilder(this._configuration.links.myConversations)
|
|
496
514
|
.path(this.sid)
|
|
497
515
|
.build();
|
|
498
516
|
const response = await this._services.network.get(url);
|
|
@@ -519,7 +537,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
519
537
|
*/
|
|
520
538
|
async leave() {
|
|
521
539
|
if (this._internalState.status === "joined") {
|
|
522
|
-
await this._services.commandExecutor.mutateResource("delete", `${this._links.participants}/${this._configuration.userIdentity}`);
|
|
540
|
+
await this._services.commandExecutor.mutateResource("delete", `${this._links.participants}/${encodeURIComponent(this._configuration.userIdentity)}`);
|
|
523
541
|
}
|
|
524
542
|
return this;
|
|
525
543
|
}
|
|
@@ -544,18 +562,18 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
544
562
|
var _a, _b;
|
|
545
563
|
if (typeof message === "string" || message === null) {
|
|
546
564
|
const response = await this._messagesEntity.send(message, messageAttributes, emailOptions);
|
|
547
|
-
return (_a =
|
|
565
|
+
return (_a = parseToNumber(response.index)) !== null && _a !== void 0 ? _a : 0;
|
|
548
566
|
}
|
|
549
567
|
const response = await this._messagesEntity.sendMedia(message, messageAttributes, emailOptions);
|
|
550
|
-
return (_b =
|
|
568
|
+
return (_b = parseToNumber(response.index)) !== null && _b !== void 0 ? _b : 0;
|
|
551
569
|
}
|
|
552
570
|
/**
|
|
553
571
|
* New interface to prepare for sending a message.
|
|
554
|
-
* Use this instead of {@link
|
|
572
|
+
* Use this instead of {@link Conversation.sendMessage}.
|
|
555
573
|
* @return A MessageBuilder to help set all message sending options.
|
|
556
574
|
*/
|
|
557
575
|
prepareMessage() {
|
|
558
|
-
return new
|
|
576
|
+
return new MessageBuilder(this.limits, this._messagesEntity);
|
|
559
577
|
}
|
|
560
578
|
/**
|
|
561
579
|
* Set last read message index of the conversation to the index of the last
|
|
@@ -572,7 +590,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
572
590
|
}
|
|
573
591
|
/**
|
|
574
592
|
* Set all messages in the conversation unread.
|
|
575
|
-
* @
|
|
593
|
+
* @returns New count of unread messages after this update.
|
|
576
594
|
*/
|
|
577
595
|
async setAllMessagesUnread() {
|
|
578
596
|
await this._subscribeStreams();
|
|
@@ -620,7 +638,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
620
638
|
* Set the last read message index to the current read horizon.
|
|
621
639
|
* @param index Message index to set as last read. If null is provided, then
|
|
622
640
|
* the behavior is identical to {@link Conversation.setAllMessagesUnread}.
|
|
623
|
-
* @returns
|
|
641
|
+
* @returns New count of unread messages after this update.
|
|
624
642
|
*/
|
|
625
643
|
async updateLastReadMessageIndex(index) {
|
|
626
644
|
await this._subscribeStreams();
|
|
@@ -640,10 +658,17 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
640
658
|
}
|
|
641
659
|
return this;
|
|
642
660
|
}
|
|
661
|
+
/**
|
|
662
|
+
* Get recipients of all messages in the conversation.
|
|
663
|
+
* @param options Optional configuration, set pageSize to request a specific pagination page size. Page size specifies a number of messages to include in a single batch. Each message may include multiple recipients.
|
|
664
|
+
*/
|
|
665
|
+
async getMessageRecipients(options) {
|
|
666
|
+
return await this._services.messageRecipientsClient.getRecipientsFromConversation(this.sid, options);
|
|
667
|
+
}
|
|
643
668
|
/**
|
|
644
669
|
* Load and subscribe to this conversation and do not subscribe to its
|
|
645
670
|
* participants and messages. This or _subscribeStreams will need to be called
|
|
646
|
-
* before any events
|
|
671
|
+
* before any events in the conversation will fire.
|
|
647
672
|
* @internal
|
|
648
673
|
*/
|
|
649
674
|
async _subscribe() {
|
|
@@ -656,8 +681,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
656
681
|
});
|
|
657
682
|
try {
|
|
658
683
|
this._entity = await this._entityPromise;
|
|
659
|
-
this._entity.on(
|
|
660
|
-
this._entity.on(
|
|
684
|
+
this._entity.on(SyncDocument.updated, (args) => this._update(args.data));
|
|
685
|
+
this._entity.on(SyncDocument.removed, () => this.emit(Conversation.removed, this));
|
|
661
686
|
this._update(this._entity.data);
|
|
662
687
|
return this._entity;
|
|
663
688
|
}
|
|
@@ -671,6 +696,60 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
671
696
|
throw err;
|
|
672
697
|
}
|
|
673
698
|
}
|
|
699
|
+
/**
|
|
700
|
+
* Fetch participants and messages of the conversation. This method needs to
|
|
701
|
+
* be called during conversation initialization to catch broken conversations
|
|
702
|
+
* (broken conversations are conversations that have essential Sync entities
|
|
703
|
+
* missing, i.e. the conversation document, the messages list or the
|
|
704
|
+
* participant map). In case of this conversation being broken, the method
|
|
705
|
+
* will throw an exception that will be caught and handled gracefully.
|
|
706
|
+
* @internal
|
|
707
|
+
*/
|
|
708
|
+
async _fetchStreams() {
|
|
709
|
+
if (this._streamsPromise) {
|
|
710
|
+
return this._streamsPromise;
|
|
711
|
+
}
|
|
712
|
+
this._streamsPromise = new Promise(async (resolve, reject) => {
|
|
713
|
+
var _a, _b;
|
|
714
|
+
try {
|
|
715
|
+
await this._subscribe();
|
|
716
|
+
}
|
|
717
|
+
catch (err) {
|
|
718
|
+
Conversation._logger.trace("Failed to subscribe to conversation", err);
|
|
719
|
+
return reject(err);
|
|
720
|
+
}
|
|
721
|
+
Conversation._logger.trace("_streamsAvailable, this.entity.data=", (_a = this._entity) === null || _a === void 0 ? void 0 : _a.data);
|
|
722
|
+
const data = (_b = this._entity) === null || _b === void 0 ? void 0 : _b.data;
|
|
723
|
+
const messagesPromise = this._services.syncClient
|
|
724
|
+
.list({
|
|
725
|
+
id: data.messages,
|
|
726
|
+
mode: "open_existing",
|
|
727
|
+
})
|
|
728
|
+
.then((list) => {
|
|
729
|
+
this._messagesList = list;
|
|
730
|
+
return list;
|
|
731
|
+
});
|
|
732
|
+
const participantsPromise = this._services.syncClient
|
|
733
|
+
.map({
|
|
734
|
+
id: data.roster,
|
|
735
|
+
mode: "open_existing",
|
|
736
|
+
})
|
|
737
|
+
.then((map) => {
|
|
738
|
+
this._participantsMap = map;
|
|
739
|
+
return map;
|
|
740
|
+
});
|
|
741
|
+
Promise.all([messagesPromise, participantsPromise])
|
|
742
|
+
.then(() => resolve(true))
|
|
743
|
+
.catch((err) => {
|
|
744
|
+
Conversation._logger.trace("Failed to fetch conversation streams for conversation", this.sid, err);
|
|
745
|
+
reject(err);
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
return this._streamsPromise.catch((err) => {
|
|
749
|
+
this._streamsPromise = null;
|
|
750
|
+
throw err;
|
|
751
|
+
});
|
|
752
|
+
}
|
|
674
753
|
/**
|
|
675
754
|
* Load the attributes of this conversation and instantiate its participants
|
|
676
755
|
* and messages. This or _subscribe will need to be called before any events
|
|
@@ -679,16 +758,16 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
679
758
|
* @internal
|
|
680
759
|
*/
|
|
681
760
|
async _subscribeStreams() {
|
|
682
|
-
var _a, _b;
|
|
761
|
+
var _a, _b, _c, _d;
|
|
683
762
|
try {
|
|
684
|
-
await this.
|
|
763
|
+
await this._fetchStreams();
|
|
685
764
|
Conversation._logger.trace("_subscribeStreams, this.entity.data=", (_a = this._entity) === null || _a === void 0 ? void 0 : _a.data);
|
|
686
765
|
const data = (_b = this._entity) === null || _b === void 0 ? void 0 : _b.data;
|
|
687
766
|
const messagesObjectName = data.messages;
|
|
688
767
|
const rosterObjectName = data.roster;
|
|
689
768
|
await Promise.all([
|
|
690
|
-
this._messagesEntity.subscribe(messagesObjectName),
|
|
691
|
-
this._participantsEntity.subscribe(rosterObjectName),
|
|
769
|
+
this._messagesEntity.subscribe((_c = this._messagesList) !== null && _c !== void 0 ? _c : messagesObjectName),
|
|
770
|
+
this._participantsEntity.subscribe((_d = this._participantsMap) !== null && _d !== void 0 ? _d : rosterObjectName),
|
|
692
771
|
]);
|
|
693
772
|
}
|
|
694
773
|
catch (err) {
|
|
@@ -705,7 +784,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
705
784
|
*/
|
|
706
785
|
async _unsubscribe() {
|
|
707
786
|
if (this._entity) {
|
|
708
|
-
|
|
787
|
+
this._entity.close();
|
|
709
788
|
this._entity = null;
|
|
710
789
|
this._entityPromise = null;
|
|
711
790
|
}
|
|
@@ -767,7 +846,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
767
846
|
updateReasons.add(localKey);
|
|
768
847
|
break;
|
|
769
848
|
case fieldMappings.attributes:
|
|
770
|
-
if (
|
|
849
|
+
if (isEqual(this._internalState.attributes, update.attributes)) {
|
|
771
850
|
break;
|
|
772
851
|
}
|
|
773
852
|
this._internalState.attributes = update.attributes;
|
|
@@ -803,7 +882,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
803
882
|
update.lastMessage.timestamp;
|
|
804
883
|
updateReasons.add(localKey);
|
|
805
884
|
}
|
|
806
|
-
if (
|
|
885
|
+
if (isEqual(this._internalState.lastMessage, {})) {
|
|
807
886
|
delete this._internalState.lastMessage;
|
|
808
887
|
}
|
|
809
888
|
break;
|
|
@@ -812,14 +891,14 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
812
891
|
if (state !== undefined) {
|
|
813
892
|
state.dateUpdated = new Date(state.dateUpdated);
|
|
814
893
|
}
|
|
815
|
-
if (
|
|
894
|
+
if (isEqual(this._internalState.state, state)) {
|
|
816
895
|
break;
|
|
817
896
|
}
|
|
818
897
|
this._internalState.state = state;
|
|
819
898
|
updateReasons.add(localKey);
|
|
820
899
|
break;
|
|
821
900
|
case fieldMappings.bindings:
|
|
822
|
-
if (
|
|
901
|
+
if (isEqual(this._internalState.bindings, update.bindings)) {
|
|
823
902
|
break;
|
|
824
903
|
}
|
|
825
904
|
this._internalState.bindings = update.bindings;
|
|
@@ -838,7 +917,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
838
917
|
}
|
|
839
918
|
}
|
|
840
919
|
if (updateReasons.size > 0) {
|
|
841
|
-
this.emit(
|
|
920
|
+
this.emit(Conversation.updated, {
|
|
842
921
|
conversation: this,
|
|
843
922
|
updateReasons: [...updateReasons],
|
|
844
923
|
});
|
|
@@ -854,7 +933,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
|
854
933
|
break;
|
|
855
934
|
}
|
|
856
935
|
}
|
|
857
|
-
this.emit(
|
|
936
|
+
this.emit(Conversation.messageAdded, message);
|
|
858
937
|
}
|
|
859
938
|
/**
|
|
860
939
|
* Set last read message index.
|
|
@@ -969,57 +1048,57 @@ Conversation.removed = "removed";
|
|
|
969
1048
|
/**
|
|
970
1049
|
* Logger instance.
|
|
971
1050
|
*/
|
|
972
|
-
Conversation._logger =
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1051
|
+
Conversation._logger = Logger.scope("Conversation");
|
|
1052
|
+
__decorate([
|
|
1053
|
+
validateTypesAsync(nonEmptyString, optionalJson),
|
|
1054
|
+
__metadata("design:type", Function),
|
|
1055
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
1056
|
+
__metadata("design:returntype", Promise)
|
|
978
1057
|
], Conversation.prototype, "add", null);
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1058
|
+
__decorate([
|
|
1059
|
+
validateTypesAsync(nonEmptyString, nonEmptyString, optionalJson, optionalJson),
|
|
1060
|
+
__metadata("design:type", Function),
|
|
1061
|
+
__metadata("design:paramtypes", [String, String, Object, Object]),
|
|
1062
|
+
__metadata("design:returntype", Promise)
|
|
984
1063
|
], Conversation.prototype, "addNonChatParticipant", null);
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1064
|
+
__decorate([
|
|
1065
|
+
validateTypesAsync(nonNegativeInteger),
|
|
1066
|
+
__metadata("design:type", Function),
|
|
1067
|
+
__metadata("design:paramtypes", [Number]),
|
|
1068
|
+
__metadata("design:returntype", Promise)
|
|
990
1069
|
], Conversation.prototype, "advanceLastReadMessageIndex", null);
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1070
|
+
__decorate([
|
|
1071
|
+
validateTypesAsync(["undefined", nonNegativeInteger], ["undefined", nonNegativeInteger], ["undefined", literal("backwards", "forward")]),
|
|
1072
|
+
__metadata("design:type", Function),
|
|
1073
|
+
__metadata("design:paramtypes", [Number, Number, String]),
|
|
1074
|
+
__metadata("design:returntype", Promise)
|
|
996
1075
|
], Conversation.prototype, "getMessages", null);
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1076
|
+
__decorate([
|
|
1077
|
+
validateTypesAsync(nonEmptyString),
|
|
1078
|
+
__metadata("design:type", Function),
|
|
1079
|
+
__metadata("design:paramtypes", [String]),
|
|
1080
|
+
__metadata("design:returntype", Promise)
|
|
1002
1081
|
], Conversation.prototype, "getParticipantBySid", null);
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1082
|
+
__decorate([
|
|
1083
|
+
validateTypesAsync(nonEmptyString),
|
|
1084
|
+
__metadata("design:type", Function),
|
|
1085
|
+
__metadata("design:paramtypes", [String]),
|
|
1086
|
+
__metadata("design:returntype", Promise)
|
|
1008
1087
|
], Conversation.prototype, "getParticipantByIdentity", null);
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1088
|
+
__decorate([
|
|
1089
|
+
validateTypesAsync([nonEmptyString, Participant]),
|
|
1090
|
+
__metadata("design:type", Function),
|
|
1091
|
+
__metadata("design:paramtypes", [Object]),
|
|
1092
|
+
__metadata("design:returntype", Promise)
|
|
1014
1093
|
], Conversation.prototype, "removeParticipant", null);
|
|
1015
|
-
|
|
1016
|
-
|
|
1094
|
+
__decorate([
|
|
1095
|
+
validateTypesAsync([
|
|
1017
1096
|
"string",
|
|
1018
1097
|
FormData,
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
contentType:
|
|
1022
|
-
media:
|
|
1098
|
+
literal(null),
|
|
1099
|
+
objectSchema("media options", {
|
|
1100
|
+
contentType: nonEmptyString,
|
|
1101
|
+
media: custom((value) => {
|
|
1023
1102
|
let isValid = (typeof value === "string" && value.length > 0) ||
|
|
1024
1103
|
value instanceof Uint8Array ||
|
|
1025
1104
|
value instanceof ArrayBuffer;
|
|
@@ -1032,47 +1111,47 @@ tslib_es6.__decorate([
|
|
|
1032
1111
|
];
|
|
1033
1112
|
}),
|
|
1034
1113
|
}),
|
|
1035
|
-
],
|
|
1114
|
+
], optionalJson, [
|
|
1036
1115
|
"undefined",
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
subject: [
|
|
1116
|
+
literal(null),
|
|
1117
|
+
objectSchema("email attributes", {
|
|
1118
|
+
subject: [nonEmptyString, "undefined"],
|
|
1040
1119
|
}),
|
|
1041
1120
|
]),
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1121
|
+
__metadata("design:type", Function),
|
|
1122
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
1123
|
+
__metadata("design:returntype", Promise)
|
|
1045
1124
|
], Conversation.prototype, "sendMessage", null);
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1125
|
+
__decorate([
|
|
1126
|
+
validateTypesAsync(literal("default", "muted")),
|
|
1127
|
+
__metadata("design:type", Function),
|
|
1128
|
+
__metadata("design:paramtypes", [String]),
|
|
1129
|
+
__metadata("design:returntype", Promise)
|
|
1051
1130
|
], Conversation.prototype, "setUserNotificationLevel", null);
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1131
|
+
__decorate([
|
|
1132
|
+
validateTypesAsync(json),
|
|
1133
|
+
__metadata("design:type", Function),
|
|
1134
|
+
__metadata("design:paramtypes", [Object]),
|
|
1135
|
+
__metadata("design:returntype", Promise)
|
|
1057
1136
|
], Conversation.prototype, "updateAttributes", null);
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1137
|
+
__decorate([
|
|
1138
|
+
validateTypesAsync("string"),
|
|
1139
|
+
__metadata("design:type", Function),
|
|
1140
|
+
__metadata("design:paramtypes", [String]),
|
|
1141
|
+
__metadata("design:returntype", Promise)
|
|
1063
1142
|
], Conversation.prototype, "updateFriendlyName", null);
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1143
|
+
__decorate([
|
|
1144
|
+
validateTypesAsync([literal(null), nonNegativeInteger]),
|
|
1145
|
+
__metadata("design:type", Function),
|
|
1146
|
+
__metadata("design:paramtypes", [Number]),
|
|
1147
|
+
__metadata("design:returntype", Promise)
|
|
1069
1148
|
], Conversation.prototype, "updateLastReadMessageIndex", null);
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1149
|
+
__decorate([
|
|
1150
|
+
validateTypesAsync(["string", literal(null)]),
|
|
1151
|
+
__metadata("design:type", Function),
|
|
1152
|
+
__metadata("design:paramtypes", [String]),
|
|
1153
|
+
__metadata("design:returntype", Promise)
|
|
1075
1154
|
], Conversation.prototype, "updateUniqueName", null);
|
|
1076
1155
|
|
|
1077
|
-
|
|
1156
|
+
export { Conversation };
|
|
1078
1157
|
//# sourceMappingURL=conversation.js.map
|