@twilio/conversations 2.4.0-rc.2 → 2.4.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/builds/lib.d.ts CHANGED
@@ -573,6 +573,10 @@ declare class Media {
573
573
  */
574
574
  getContentTemporaryUrl(): CancellablePromise<string | null>;
575
575
  private _fetchMcsMedia;
576
+ /**
577
+ * @internal
578
+ */
579
+ _state(): Record<string, unknown>;
576
580
  }
577
581
  /**
578
582
  * Signifies the amount of participants which have the status for the message.
@@ -1229,9 +1233,9 @@ interface MessageLinks {
1229
1233
  /**
1230
1234
  * The reason for the `updated` event being emitted by a message.
1231
1235
  */
1232
- type MessageUpdateReason = "body" | "lastUpdatedBy" | "dateCreated" | "dateUpdated" | "attributes" | "author" | "deliveryReceipt" | "subject";
1236
+ type MessageUpdateReason = "body" | "lastUpdatedBy" | "dateCreated" | "dateUpdated" | "attributes" | "author" | "deliveryReceipt" | "subject" | "media";
1233
1237
  /**
1234
- * Type of a message.
1238
+ * Type of message.
1235
1239
  */
1236
1240
  type MessageType = "text" | "media";
1237
1241
  interface MessageUpdatedEventArgs {
@@ -1259,6 +1263,7 @@ interface MessageData {
1259
1263
  * A message in a conversation.
1260
1264
  */
1261
1265
  declare class Message extends ReplayEventEmitter<MessageEvents> {
1266
+ #private;
1262
1267
  /**
1263
1268
  * Conversation that the message is in.
1264
1269
  */
package/builds/lib.js CHANGED
@@ -212,6 +212,7 @@ require('isomorphic-form-data');
212
212
  require('core-js/modules/es.array.sort.js');
213
213
  require('core-js/modules/es.string.includes.js');
214
214
  require('core-js/modules/es.string.starts-with.js');
215
+ require('core-js/modules/es.weak-set.js');
215
216
  var deprecationDecorator = require('@twilio/deprecation-decorator');
216
217
  require('core-js/modules/es.object.entries.js');
217
218
  require('core-js/modules/es.array.find.js');
@@ -2102,6 +2103,8 @@ var Media = /*#__PURE__*/function () {
2102
2103
  * @internal
2103
2104
  */
2104
2105
  function Media(data, services) {
2106
+ var _data$filename;
2107
+
2105
2108
  _classCallCheck__default["default"](this, Media);
2106
2109
 
2107
2110
  _defineProperty__default["default"](this, "mcsMedia", null);
@@ -2115,7 +2118,7 @@ var Media = /*#__PURE__*/function () {
2115
2118
  this.state = {
2116
2119
  sid: data.sid,
2117
2120
  category: data.category,
2118
- filename: data.filename,
2121
+ filename: (_data$filename = data.filename) !== null && _data$filename !== void 0 ? _data$filename : null,
2119
2122
  contentType: data.contentType,
2120
2123
  size: data.size
2121
2124
  };
@@ -2310,6 +2313,15 @@ var Media = /*#__PURE__*/function () {
2310
2313
  };
2311
2314
  }());
2312
2315
  }
2316
+ /**
2317
+ * @internal
2318
+ */
2319
+
2320
+ }, {
2321
+ key: "_state",
2322
+ value: function _state() {
2323
+ return this.mcsMedia ? this.mcsMedia._state() : this.state;
2324
+ }
2313
2325
  }]);
2314
2326
 
2315
2327
  return Media;
@@ -2807,6 +2819,12 @@ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) {
2807
2819
  function _createSuper$6(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$6(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
2808
2820
 
2809
2821
  function _isNativeReflectConstruct$6() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2822
+
2823
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
2824
+
2825
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
2826
+
2827
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
2810
2828
  var log$3 = Logger.scope("Message");
2811
2829
 
2812
2830
  var XHR = // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -2816,6 +2834,10 @@ global["XMLHttpRequest"] || require("xmlhttprequest").XMLHttpRequest;
2816
2834
  */
2817
2835
 
2818
2836
 
2837
+ var _wrapMedia = /*#__PURE__*/new WeakSet();
2838
+
2839
+ var _assignMedias = /*#__PURE__*/new WeakSet();
2840
+
2819
2841
  var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2820
2842
  _inherits__default["default"](Message, _ReplayEventEmitter);
2821
2843
 
@@ -2829,13 +2851,18 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2829
2851
  * @internal
2830
2852
  */
2831
2853
  function Message(index, data, conversation, links, configuration, services) {
2832
- var _data$text, _data$lastUpdatedBy, _data$type, _data$memberSid, _data$channelMetadata;
2854
+ var _data$text, _data$lastUpdatedBy, _data$type, _data$memberSid, _data$channelMetadata, _data$medias, _data$media;
2833
2855
 
2834
2856
  var _this;
2835
2857
 
2836
2858
  _classCallCheck__default["default"](this, Message);
2837
2859
 
2838
2860
  _this = _super.call(this);
2861
+
2862
+ _classPrivateMethodInitSpec(_assertThisInitialized__default["default"](_this), _assignMedias);
2863
+
2864
+ _classPrivateMethodInitSpec(_assertThisInitialized__default["default"](_this), _wrapMedia);
2865
+
2839
2866
  _this.conversation = conversation;
2840
2867
  _this.links = links;
2841
2868
  _this.configuration = configuration;
@@ -2852,27 +2879,17 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2852
2879
  lastUpdatedBy: (_data$lastUpdatedBy = data.lastUpdatedBy) !== null && _data$lastUpdatedBy !== void 0 ? _data$lastUpdatedBy : null,
2853
2880
  attributes: parseAttributes(data.attributes, "Got malformed attributes for the message ".concat(data.sid), log$3),
2854
2881
  type: (_data$type = data.type) !== null && _data$type !== void 0 ? _data$type : "text",
2855
- media: data.type === "media" && data.media ? new Media(data.media, _this.services) : null,
2856
- medias: data.type === "media" && data.medias ? data.medias.map(function (m) {
2857
- return new Media(m, _this.services);
2858
- }) : data.type === "media" && data.media && !data.medias ? [new Media(_objectSpread$4(_objectSpread$4({}, data.media), {}, {
2859
- category: "media"
2860
- }), _this.services)] : null,
2882
+ media: null,
2883
+ medias: null,
2861
2884
  participantSid: (_data$memberSid = data.memberSid) !== null && _data$memberSid !== void 0 ? _data$memberSid : null,
2862
2885
  aggregatedDeliveryReceipt: data.delivery ? new AggregatedDeliveryReceipt(data.delivery) : null,
2863
2886
  hasChannelMetadata: (_data$channelMetadata = data.channelMetadata) !== null && _data$channelMetadata !== void 0 ? _data$channelMetadata : false
2864
2887
  };
2888
+
2889
+ _classPrivateMethodGet(_assertThisInitialized__default["default"](_this), _assignMedias, _assignMedias2).call(_assertThisInitialized__default["default"](_this), (_data$medias = data.medias) !== null && _data$medias !== void 0 ? _data$medias : null, (_data$media = data.media) !== null && _data$media !== void 0 ? _data$media : null);
2890
+
2865
2891
  return _this;
2866
2892
  }
2867
- /**
2868
- * Fired when the properties or the body of the message has been updated.
2869
- *
2870
- * Parameters:
2871
- * 1. object `data` - info object provided with the event. It has the following properties:
2872
- * * {@link Message} message - the message in question
2873
- * * {@link MessageUpdateReason}[] updateReasons - array of reasons for the update
2874
- */
2875
-
2876
2893
 
2877
2894
  _createClass__default["default"](Message, [{
2878
2895
  key: "sid",
@@ -3083,6 +3100,12 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3083
3100
  }, {
3084
3101
  key: "_update",
3085
3102
  value: function _update(data) {
3103
+ var _data$medias2,
3104
+ _this2 = this,
3105
+ _this$state$medias2,
3106
+ _classPrivateMethodGe2,
3107
+ _this$state$media;
3108
+
3086
3109
  var updateReasons = [];
3087
3110
 
3088
3111
  if ((data.text || typeof data.text === "string") && data.text !== this.state.body) {
@@ -3135,6 +3158,29 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3135
3158
 
3136
3159
  updateReasons.push("deliveryReceipt");
3137
3160
  }
3161
+ } // @fixme: This is a fairly heavy check.
3162
+ // Map data back and forth to perform a necessary field massage.
3163
+
3164
+
3165
+ var input = ((_data$medias2 = data.medias) !== null && _data$medias2 !== void 0 ? _data$medias2 : []).map(function (value) {
3166
+ var _classPrivateMethodGe;
3167
+
3168
+ return (_classPrivateMethodGe = _classPrivateMethodGet(_this2, _wrapMedia, _wrapMedia2).call(_this2, value)) === null || _classPrivateMethodGe === void 0 ? void 0 : _classPrivateMethodGe._state();
3169
+ }).filter(function (el) {
3170
+ return !(el === null);
3171
+ });
3172
+ var current = ((_this$state$medias2 = this.state.medias) !== null && _this$state$medias2 !== void 0 ? _this$state$medias2 : []).map(function (value) {
3173
+ return value._state();
3174
+ }).filter(function (el) {
3175
+ return !(el === null);
3176
+ });
3177
+
3178
+ if (!isEqual__default["default"](input, current) || !isEqual__default["default"]((_classPrivateMethodGe2 = _classPrivateMethodGet(this, _wrapMedia, _wrapMedia2).call(this, data.media)) === null || _classPrivateMethodGe2 === void 0 ? void 0 : _classPrivateMethodGe2._state(), (_this$state$media = this.state.media) === null || _this$state$media === void 0 ? void 0 : _this$state$media._state())) {
3179
+ var _data$medias3, _data$media2;
3180
+
3181
+ _classPrivateMethodGet(this, _assignMedias, _assignMedias2).call(this, (_data$medias3 = data.medias) !== null && _data$medias3 !== void 0 ? _data$medias3 : null, (_data$media2 = data.media) !== null && _data$media2 !== void 0 ? _data$media2 : null);
3182
+
3183
+ updateReasons.push("media");
3138
3184
  }
3139
3185
 
3140
3186
  if (updateReasons.length > 0) {
@@ -3152,7 +3198,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3152
3198
  key: "getParticipant",
3153
3199
  value: function () {
3154
3200
  var _getParticipant = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
3155
- var _this2 = this;
3201
+ var _this3 = this;
3156
3202
 
3157
3203
  var participant, errorMesage;
3158
3204
  return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
@@ -3168,7 +3214,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3168
3214
 
3169
3215
  _context.next = 4;
3170
3216
  return this.conversation.getParticipantBySid(this.state.participantSid).catch(function () {
3171
- log$3.debug("Participant with sid \"".concat(_this2.participantSid, "\" not found for message ").concat(_this2.sid));
3217
+ log$3.debug("Participant with sid \"".concat(_this3.participantSid, "\" not found for message ").concat(_this3.sid));
3172
3218
  return null;
3173
3219
  });
3174
3220
 
@@ -3183,7 +3229,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3183
3229
 
3184
3230
  _context.next = 8;
3185
3231
  return this.conversation.getParticipantByIdentity(this.state.author).catch(function () {
3186
- log$3.debug("Participant with identity \"".concat(_this2.author, "\" not found for message ").concat(_this2.sid));
3232
+ log$3.debug("Participant with identity \"".concat(_this3.author, "\" not found for message ").concat(_this3.sid));
3187
3233
  return null;
3188
3234
  });
3189
3235
 
@@ -3398,7 +3444,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3398
3444
  key: "attachTemporaryUrlsFor",
3399
3445
  value: function () {
3400
3446
  var _attachTemporaryUrlsFor = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(contentSet) {
3401
- var _this3 = this;
3447
+ var _this4 = this;
3402
3448
 
3403
3449
  var sids;
3404
3450
  return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
@@ -3421,7 +3467,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3421
3467
 
3422
3468
  case 4:
3423
3469
  return _context6.abrupt("return", _context6.sent.map(function (item) {
3424
- return new Media(item, _this3.services);
3470
+ return new Media(item, _this4.services);
3425
3471
  }));
3426
3472
 
3427
3473
  case 7:
@@ -3464,7 +3510,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3464
3510
  }, {
3465
3511
  key: "getTemporaryContentUrlsForMediaSids",
3466
3512
  value: function getTemporaryContentUrlsForMediaSids(mediaSids) {
3467
- var _this4 = this;
3513
+ var _this5 = this;
3468
3514
 
3469
3515
  return new mcsClient.CancellablePromise( /*#__PURE__*/function () {
3470
3516
  var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7(resolve, reject, onCancel) {
@@ -3473,9 +3519,9 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3473
3519
  while (1) {
3474
3520
  switch (_context7.prev = _context7.next) {
3475
3521
  case 0:
3476
- mediaGetRequest = _this4.services.mcsClient.mediaSetGetContentUrls(mediaSids !== null && mediaSids !== void 0 ? mediaSids : []);
3522
+ mediaGetRequest = _this5.services.mcsClient.mediaSetGetContentUrls(mediaSids !== null && mediaSids !== void 0 ? mediaSids : []);
3477
3523
 
3478
- if (!(!_this4.services.mcsClient || !mediaSids)) {
3524
+ if (!(!_this5.services.mcsClient || !mediaSids)) {
3479
3525
  _context7.next = 4;
3480
3526
  break;
3481
3527
  }
@@ -3534,7 +3580,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3534
3580
  key: "_getDetailedDeliveryReceiptsPaginator",
3535
3581
  value: function () {
3536
3582
  var _getDetailedDeliveryReceiptsPaginator2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee8(options) {
3537
- var _this5 = this;
3583
+ var _this6 = this;
3538
3584
 
3539
3585
  var messagesReceiptsUrl, url, response;
3540
3586
  return _regeneratorRuntime__default["default"].wrap(function _callee8$(_context8) {
@@ -3551,7 +3597,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3551
3597
  return _context8.abrupt("return", new RestPaginator(response.body.delivery_receipts.map(function (x) {
3552
3598
  return new DetailedDeliveryReceipt(x);
3553
3599
  }), function (pageToken, pageSize) {
3554
- return _this5._getDetailedDeliveryReceiptsPaginator({
3600
+ return _this6._getDetailedDeliveryReceiptsPaginator({
3555
3601
  pageToken: pageToken,
3556
3602
  pageSize: pageSize
3557
3603
  });
@@ -3579,7 +3625,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3579
3625
  }, {
3580
3626
  key: "getContentData",
3581
3627
  value: function getContentData() {
3582
- var _this6 = this;
3628
+ var _this7 = this;
3583
3629
 
3584
3630
  return new mcsClient.CancellablePromise( /*#__PURE__*/function () {
3585
3631
  var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee9(resolve, reject, onCancel) {
@@ -3588,7 +3634,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3588
3634
  while (1) {
3589
3635
  switch (_context9.prev = _context9.next) {
3590
3636
  case 0:
3591
- if (!(_this6.state.contentSid === null)) {
3637
+ if (!(_this7.state.contentSid === null)) {
3592
3638
  _context9.next = 3;
3593
3639
  break;
3594
3640
  }
@@ -3597,7 +3643,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3597
3643
  return _context9.abrupt("return");
3598
3644
 
3599
3645
  case 3:
3600
- bodies = _this6.getMediaByCategories(["body"]);
3646
+ bodies = _this7.getMediaByCategories(["body"]);
3601
3647
 
3602
3648
  if (!(bodies === null)) {
3603
3649
  _context9.next = 7;
@@ -3758,6 +3804,28 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3758
3804
  return Message;
3759
3805
  }(replayEventEmitter.ReplayEventEmitter);
3760
3806
 
3807
+ function _wrapMedia2(media) {
3808
+ var category = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
3809
+ return media ? category ? new Media(_objectSpread$4(_objectSpread$4({}, media), {}, {
3810
+ category: category
3811
+ }), this.services) : new Media(media, this.services) : null;
3812
+ }
3813
+
3814
+ function _assignMedias2(medias, media) {
3815
+ var _this8 = this;
3816
+
3817
+ this.state.media = _classPrivateMethodGet(this, _wrapMedia, _wrapMedia2).call(this, media); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3818
+ // @ts-ignore
3819
+
3820
+ this.state.medias = medias ? medias.map(function (m) {
3821
+ return _classPrivateMethodGet(_this8, _wrapMedia, _wrapMedia2).call(_this8, m);
3822
+ }).filter(function (el) {
3823
+ return el !== null;
3824
+ }) : media && !medias ? [_classPrivateMethodGet(this, _wrapMedia, _wrapMedia2).call(this, media, "media")].filter(function (el) {
3825
+ return el !== null;
3826
+ }) : null;
3827
+ }
3828
+
3761
3829
  _defineProperty__default["default"](Message, "updated", "updated");
3762
3830
 
3763
3831
  __decorate([deprecationDecorator.deprecated("getMediaByCategory", "getMediaByCategories"), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", Array)], Message.prototype, "getMediaByCategory", null);
@@ -7815,7 +7883,7 @@ function PushNotification(data) {
7815
7883
  this.data = data.data || {};
7816
7884
  });
7817
7885
 
7818
- var version = "2.4.0-rc.2";
7886
+ var version = "2.4.1-rc.0";
7819
7887
 
7820
7888
  function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7821
7889