sceyt-chat-react-uikit 1.8.8-beta.17 → 1.8.8-beta.18

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.
Files changed (3) hide show
  1. package/index.js +133 -47
  2. package/index.modern.js +133 -47
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -8498,6 +8498,31 @@ var getAllowEditDeleteIncomingMessage = function getAllowEditDeleteIncomingMessa
8498
8498
  var compareMessageBodyAttributes = function compareMessageBodyAttributes(attributes1, attributes2) {
8499
8499
  return JSON.stringify(attributes1) === JSON.stringify(attributes2);
8500
8500
  };
8501
+ var trimMessageBodyWithAttributes = function trimMessageBodyWithAttributes(text, attributes) {
8502
+ var body = text.trim();
8503
+ var leadingTrim = text.length - text.trimStart().length;
8504
+ var bodyAttributes = (attributes || []).map(function (att) {
8505
+ var offset = att.offset - leadingTrim;
8506
+ var length = att.length;
8507
+ if (offset < 0) {
8508
+ length += offset;
8509
+ offset = 0;
8510
+ }
8511
+ if (offset + length > body.length) {
8512
+ length = body.length - offset;
8513
+ }
8514
+ return _extends({}, att, {
8515
+ offset: offset,
8516
+ length: length
8517
+ });
8518
+ }).filter(function (att) {
8519
+ return att.length > 0 && att.offset >= 0 && att.offset < body.length;
8520
+ });
8521
+ return {
8522
+ body: body,
8523
+ bodyAttributes: bodyAttributes
8524
+ };
8525
+ };
8501
8526
  var bodyAttributesMapByType = {
8502
8527
  1: ['bold'],
8503
8528
  2: ['italic'],
@@ -16014,6 +16039,10 @@ var SDKErrorTypeEnum = {
16014
16039
  Authentication: {
16015
16040
  value: 'Authentication',
16016
16041
  isResendable: true
16042
+ },
16043
+ AttachmentUnavailable: {
16044
+ value: 'AttachmentUnavailable',
16045
+ isResendable: false
16017
16046
  }
16018
16047
  };
16019
16048
  var fromValue = function fromValue(value) {
@@ -16031,6 +16060,11 @@ var isResendableError = function isResendableError(value) {
16031
16060
  var errorType = fromValue(value);
16032
16061
  return (_errorType$isResendab = errorType === null || errorType === void 0 ? void 0 : errorType.isResendable) != null ? _errorType$isResendab : true;
16033
16062
  };
16063
+ var createAttachmentUnavailableError = function createAttachmentUnavailableError(message) {
16064
+ var error = new Error(message);
16065
+ error.type = SDKErrorTypeEnum.AttachmentUnavailable.value;
16066
+ return error;
16067
+ };
16034
16068
 
16035
16069
  var _excluded$1 = ["lastMessage"];
16036
16070
  var _marked = /*#__PURE__*/_regenerator().m(setMessageListLoading),
@@ -16093,6 +16127,8 @@ var _marked = /*#__PURE__*/_regenerator().m(setMessageListLoading),
16093
16127
  _marked56 = /*#__PURE__*/_regenerator().m(loadMorePollVotes),
16094
16128
  _marked57 = /*#__PURE__*/_regenerator().m(refreshCacheAroundMessage),
16095
16129
  _marked58 = /*#__PURE__*/_regenerator().m(MessageSaga);
16130
+ var MAX_AUTO_RESEND_ATTEMPTS = 5;
16131
+ var autoResendAttempts = new Map();
16096
16132
  var loadMoreMessagesInFlight = new Set();
16097
16133
  var prefetchInFlight = new Set();
16098
16134
  var queuedPrefetchRequests = new Map();
@@ -16316,6 +16352,7 @@ var handleUploadAttachments = function handleUploadAttachments(attachments, mess
16316
16352
  try {
16317
16353
  return Promise.resolve(Promise.all(attachments.map(function (attachment) {
16318
16354
  try {
16355
+ var _attachment$url, _attachment$url$type;
16319
16356
  var _temp10 = function _temp10() {
16320
16357
  function _temp0() {
16321
16358
  store.dispatch(updateAttachmentUploadingStateAC(UPLOAD_STATE.SUCCESS, attachment.tid));
@@ -16337,14 +16374,15 @@ var handleUploadAttachments = function handleUploadAttachments(attachments, mess
16337
16374
  return attachmentToSend;
16338
16375
  }
16339
16376
  var _temp9 = function () {
16340
- if (!attachment.cachedUrl && attachment.url.type.split('/')[0] === 'image') {
16377
+ if (!attachment.cachedUrl && fileType === 'image') {
16341
16378
  return _catch(function () {
16342
16379
  var _temp2 = function () {
16343
16380
  if (blobLocal && blobLocal.type.startsWith('image/')) {
16381
+ var _attachment, _attachment2;
16344
16382
  var file = attachment.url instanceof File ? attachment.url : new File([attachment.url], attachment.name || 'image', {
16345
16383
  type: attachment.url.type || blobLocal.type
16346
16384
  });
16347
- var _calculateRenderedIma = calculateRenderedImageWidth((attachment === null || attachment === void 0 ? void 0 : attachment.metadata.szw) || 1280, (attachment === null || attachment === void 0 ? void 0 : attachment.metadata.szh) || 1080),
16385
+ var _calculateRenderedIma = calculateRenderedImageWidth(((_attachment = attachment) === null || _attachment === void 0 ? void 0 : _attachment.metadata.szw) || 1280, ((_attachment2 = attachment) === null || _attachment2 === void 0 ? void 0 : _attachment2.metadata.szh) || 1080),
16348
16386
  newWidth = _calculateRenderedIma[0],
16349
16387
  newHeight = _calculateRenderedIma[1];
16350
16388
  return Promise.resolve(resizeImageWithPica(file, newWidth, newHeight, 1)).then(function (_ref) {
@@ -16382,10 +16420,11 @@ var handleUploadAttachments = function handleUploadAttachments(attachments, mess
16382
16420
  });
16383
16421
  } else {
16384
16422
  var _temp11 = function () {
16385
- if (!attachment.cachedUrl && attachment.url.type.split('/')[0] === 'video') {
16423
+ if (!attachment.cachedUrl && fileType === 'video') {
16386
16424
  var _temp7 = function () {
16387
16425
  if (blobLocal) {
16388
- var _calculateRenderedIma2 = calculateRenderedImageWidth((attachment === null || attachment === void 0 ? void 0 : attachment.metadata.szw) || 1280, (attachment === null || attachment === void 0 ? void 0 : attachment.metadata.szh) || 1080),
16426
+ var _attachment3, _attachment4;
16427
+ var _calculateRenderedIma2 = calculateRenderedImageWidth(((_attachment3 = attachment) === null || _attachment3 === void 0 ? void 0 : _attachment3.metadata.szw) || 1280, ((_attachment4 = attachment) === null || _attachment4 === void 0 ? void 0 : _attachment4.metadata.szh) || 1080),
16389
16428
  newWidth = _calculateRenderedIma2[0],
16390
16429
  newHeight = _calculateRenderedIma2[1];
16391
16430
  return Promise.resolve(getVideoFirstFrame(blobLocal, newWidth, newHeight)).then(function (result) {
@@ -16443,7 +16482,19 @@ var handleUploadAttachments = function handleUploadAttachments(attachments, mess
16443
16482
  total = _ref2.total;
16444
16483
  store.dispatch(updateAttachmentUploadingProgressAC(loaded, total, attachment.tid));
16445
16484
  };
16446
- var fileType = attachment.url.type.split('/')[0];
16485
+ if (!attachment.cachedUrl && !(attachment.url instanceof Blob)) {
16486
+ var _getPendingAttachment;
16487
+ var pendingFile = (_getPendingAttachment = getPendingAttachment(attachment.tid)) === null || _getPendingAttachment === void 0 ? void 0 : _getPendingAttachment.file;
16488
+ if (pendingFile instanceof Blob) {
16489
+ attachment = _extends({}, attachment, {
16490
+ url: pendingFile,
16491
+ data: pendingFile
16492
+ });
16493
+ } else {
16494
+ throw createAttachmentUnavailableError("Attachment file for tid " + attachment.tid + " is no longer available for upload");
16495
+ }
16496
+ }
16497
+ var fileType = (_attachment$url = attachment.url) === null || _attachment$url === void 0 ? void 0 : (_attachment$url$type = _attachment$url.type) === null || _attachment$url$type === void 0 ? void 0 : _attachment$url$type.split('/')[0];
16447
16498
  var fileSize = attachment.size;
16448
16499
  var filePath;
16449
16500
  var uriLocal;
@@ -16946,11 +16997,19 @@ function sendMessage(action) {
16946
16997
  break;
16947
16998
  }
16948
16999
  _loop2 = /*#__PURE__*/_regenerator().m(function _callee3() {
16949
- var attachment, uri, attachmentBuilder, messageAttachment, handleUpdateUploadProgress, _messageBuilder, _messageToSend, messageForSend, _pending;
17000
+ var attachment, _getPendingAttachment2, pendingFile, uri, attachmentBuilder, messageAttachment, handleUpdateUploadProgress, _messageBuilder, _messageToSend, messageForSend, _pending;
16950
17001
  return _regenerator().w(function (_context11) {
16951
17002
  while (1) switch (_context11.n) {
16952
17003
  case 0:
16953
17004
  attachment = mediaAttachments[i];
17005
+ if (customUploader && !attachment.cachedUrl && !(attachment.data instanceof Blob)) {
17006
+ pendingFile = (_getPendingAttachment2 = getPendingAttachment(attachment.tid)) === null || _getPendingAttachment2 === void 0 ? void 0 : _getPendingAttachment2.file;
17007
+ if (pendingFile instanceof Blob) {
17008
+ attachment = _extends({}, attachment, {
17009
+ data: pendingFile
17010
+ });
17011
+ }
17012
+ }
16954
17013
  if (attachment.cachedUrl) {
16955
17014
  uri = attachment.cachedUrl;
16956
17015
  }
@@ -17251,6 +17310,9 @@ function sendMessage(action) {
17251
17310
  return effects.call(channel.sendMessage, messageToSend);
17252
17311
  case 5:
17253
17312
  messageResponse = _context12.v;
17313
+ if (messageToSend.tid) {
17314
+ autoResendAttempts["delete"](messageToSend.tid);
17315
+ }
17254
17316
  if (!customUploader) {
17255
17317
  _context12.n = 10;
17256
17318
  break;
@@ -17783,12 +17845,17 @@ function forwardMessage(action) {
17783
17845
  }
17784
17846
  function resendMessage(action) {
17785
17847
  var _message$attachments;
17786
- var payload, message, connectionState, channelId, attachments, sendAttachmentsAsSeparateMessage, isVoiceMessage;
17848
+ var payload, payloadMessage, connectionState, channelId, liveMessage, message, attachments, sendAttachmentsAsSeparateMessage, isVoiceMessage;
17787
17849
  return _regenerator().w(function (_context16) {
17788
17850
  while (1) switch (_context16.n) {
17789
17851
  case 0:
17790
17852
  payload = action.payload;
17791
- message = payload.message, connectionState = payload.connectionState, channelId = payload.channelId;
17853
+ payloadMessage = payload.message, connectionState = payload.connectionState, channelId = payload.channelId;
17854
+ liveMessage = payloadMessage !== null && payloadMessage !== void 0 && payloadMessage.tid || payloadMessage !== null && payloadMessage !== void 0 && payloadMessage.id ? getMessageFromMap(channelId, payloadMessage.tid || payloadMessage.id) : null;
17855
+ message = liveMessage || payloadMessage;
17856
+ if (message !== null && message !== void 0 && message.tid || message !== null && message !== void 0 && message.id) {
17857
+ autoResendAttempts["delete"](message.tid || message.id);
17858
+ }
17792
17859
  attachments = message === null || message === void 0 ? void 0 : (_message$attachments = message.attachments) === null || _message$attachments === void 0 ? void 0 : _message$attachments.filter(function (att) {
17793
17860
  return (att === null || att === void 0 ? void 0 : att.type) !== attachmentTypes.link;
17794
17861
  });
@@ -17983,7 +18050,7 @@ function editMessage(action) {
17983
18050
  }, _marked14, null, [[0, 8]]);
17984
18051
  }
17985
18052
  var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connectionState) {
17986
- var pendingMessagesMap, channelId, _iterator3, _step3, _msg$attachments, msg, attachments, pendingPollActionsMap, _t7, _t8, _t9;
18053
+ var pendingMessagesMap, channelId, _iterator3, _step3, _msg$attachments, msg, attachments, resendKey, attempts, pendingPollActionsMap, _t7, _t8, _t9;
17987
18054
  return _regenerator().w(function (_context19) {
17988
18055
  while (1) switch (_context19.p = _context19.n) {
17989
18056
  case 0:
@@ -17991,26 +18058,41 @@ var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connec
17991
18058
  _t7 = _regeneratorKeys(pendingMessagesMap);
17992
18059
  case 1:
17993
18060
  if ((_t8 = _t7()).done) {
17994
- _context19.n = 12;
18061
+ _context19.n = 13;
17995
18062
  break;
17996
18063
  }
17997
18064
  channelId = _t8.value;
17998
18065
  _iterator3 = _createForOfIteratorHelperLoose(pendingMessagesMap[channelId]);
17999
18066
  case 2:
18000
18067
  if ((_step3 = _iterator3()).done) {
18001
- _context19.n = 11;
18068
+ _context19.n = 12;
18002
18069
  break;
18003
18070
  }
18004
18071
  msg = _step3.value;
18005
18072
  attachments = msg === null || msg === void 0 ? void 0 : (_msg$attachments = msg.attachments) === null || _msg$attachments === void 0 ? void 0 : _msg$attachments.filter(function (att) {
18006
18073
  return (att === null || att === void 0 ? void 0 : att.type) !== attachmentTypes.link;
18007
18074
  });
18008
- _context19.p = 3;
18075
+ resendKey = (msg === null || msg === void 0 ? void 0 : msg.tid) || (msg === null || msg === void 0 ? void 0 : msg.id);
18076
+ if (!resendKey) {
18077
+ _context19.n = 4;
18078
+ break;
18079
+ }
18080
+ attempts = autoResendAttempts.get(resendKey) || 0;
18081
+ if (!(attempts >= MAX_AUTO_RESEND_ATTEMPTS)) {
18082
+ _context19.n = 3;
18083
+ break;
18084
+ }
18085
+ log.info("Skipping auto-resend of message " + resendKey + " after " + attempts + " failed attempts");
18086
+ return _context19.a(3, 11);
18087
+ case 3:
18088
+ autoResendAttempts.set(resendKey, attempts + 1);
18089
+ case 4:
18090
+ _context19.p = 4;
18009
18091
  if (!(msg !== null && msg !== void 0 && msg.forwardingDetails)) {
18010
- _context19.n = 5;
18092
+ _context19.n = 6;
18011
18093
  break;
18012
18094
  }
18013
- _context19.n = 4;
18095
+ _context19.n = 5;
18014
18096
  return effects.call(forwardMessage, {
18015
18097
  type: RESEND_MESSAGE,
18016
18098
  payload: {
@@ -18020,15 +18102,15 @@ var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connec
18020
18102
  isForward: true
18021
18103
  }
18022
18104
  });
18023
- case 4:
18024
- _context19.n = 8;
18025
- break;
18026
18105
  case 5:
18106
+ _context19.n = 9;
18107
+ break;
18108
+ case 6:
18027
18109
  if (!(attachments && attachments.length > 0)) {
18028
- _context19.n = 7;
18110
+ _context19.n = 8;
18029
18111
  break;
18030
18112
  }
18031
- _context19.n = 6;
18113
+ _context19.n = 7;
18032
18114
  return effects.call(sendMessage, {
18033
18115
  type: RESEND_MESSAGE,
18034
18116
  payload: {
@@ -18038,11 +18120,11 @@ var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connec
18038
18120
  sendAttachmentsAsSeparateMessage: false
18039
18121
  }
18040
18122
  });
18041
- case 6:
18042
- _context19.n = 8;
18043
- break;
18044
18123
  case 7:
18045
- _context19.n = 8;
18124
+ _context19.n = 9;
18125
+ break;
18126
+ case 8:
18127
+ _context19.n = 9;
18046
18128
  return effects.call(sendTextMessage, {
18047
18129
  type: RESEND_MESSAGE,
18048
18130
  payload: {
@@ -18051,31 +18133,31 @@ var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connec
18051
18133
  channelId: channelId
18052
18134
  }
18053
18135
  });
18054
- case 8:
18055
- _context19.n = 10;
18056
- break;
18057
18136
  case 9:
18058
- _context19.p = 9;
18137
+ _context19.n = 11;
18138
+ break;
18139
+ case 10:
18140
+ _context19.p = 10;
18059
18141
  _t9 = _context19.v;
18060
18142
  log.error("Failed to send pending message " + (msg.tid || msg.id) + ":", _t9);
18061
- case 10:
18143
+ case 11:
18062
18144
  _context19.n = 2;
18063
18145
  break;
18064
- case 11:
18146
+ case 12:
18065
18147
  _context19.n = 1;
18066
18148
  break;
18067
- case 12:
18149
+ case 13:
18068
18150
  pendingPollActionsMap = store.getState().MessageReducer.pendingPollActions;
18069
18151
  if (!(pendingPollActionsMap && Object.keys(pendingPollActionsMap).length > 0)) {
18070
- _context19.n = 13;
18152
+ _context19.n = 14;
18071
18153
  break;
18072
18154
  }
18073
- _context19.n = 13;
18155
+ _context19.n = 14;
18074
18156
  return effects.put(resendPendingPollActionsAC(connectionState));
18075
- case 13:
18157
+ case 14:
18076
18158
  return _context19.a(2);
18077
18159
  }
18078
- }, _callee5, null, [[3, 9]]);
18160
+ }, _callee5, null, [[4, 10]]);
18079
18161
  });
18080
18162
  var shouldAppendPendingMessages = function shouldAppendPendingMessages(channelOrId, messages, options) {
18081
18163
  var _getStoredChannel9, _getStoredChannel9$la, _channelOrId$lastMess;
@@ -18300,7 +18382,7 @@ function loadOGMetadataForLinkMessages(messages, getFromServer) {
18300
18382
  getFromServer = true;
18301
18383
  }
18302
18384
  return /*#__PURE__*/_regenerator().m(function _callee6() {
18303
- var i, _message$attachments2, message, isOnlyLinkAttachments, firstAttachment, j, _attachment, _firstAttachment, _store$getState$Messa, _firstAttachment2, _firstAttachment3, _firstAttachment4, metadata, storedData;
18385
+ var i, _message$attachments2, message, isOnlyLinkAttachments, firstAttachment, j, _attachment5, _firstAttachment, _store$getState$Messa, _firstAttachment2, _firstAttachment3, _firstAttachment4, metadata, storedData;
18304
18386
  return _regenerator().w(function (_context22) {
18305
18387
  while (1) switch (_context22.n) {
18306
18388
  case 0:
@@ -18329,13 +18411,13 @@ function loadOGMetadataForLinkMessages(messages, getFromServer) {
18329
18411
  _context22.n = 6;
18330
18412
  break;
18331
18413
  }
18332
- _attachment = message.attachments[j];
18333
- if (!(_attachment.type === attachmentTypes.link)) {
18414
+ _attachment5 = message.attachments[j];
18415
+ if (!(_attachment5.type === attachmentTypes.link)) {
18334
18416
  _context22.n = 4;
18335
18417
  break;
18336
18418
  }
18337
18419
  if (!firstAttachment) {
18338
- firstAttachment = _attachment;
18420
+ firstAttachment = _attachment5;
18339
18421
  }
18340
18422
  _context22.n = 5;
18341
18423
  break;
@@ -52382,17 +52464,19 @@ var SendMessageInput = function SendMessageInput(_ref3) {
52382
52464
  if (messageToEdit) {
52383
52465
  handleEditMessage();
52384
52466
  } else if (messageTextForSend !== null && messageTextForSend !== void 0 && messageTextForSend.trim() || attachments.length && attachments.length > 0) {
52385
- var messageTexToSend = messageTextForSend === null || messageTextForSend === void 0 ? void 0 : messageTextForSend.trim();
52467
+ var _trimMessageBodyWithA = trimMessageBodyWithAttributes(messageText, messageBodyAttributes),
52468
+ messageTexToSend = _trimMessageBodyWithA.body,
52469
+ adjustedBodyAttributes = _trimMessageBodyWithA.bodyAttributes;
52386
52470
  var messageToSend = {
52387
52471
  body: messageTexToSend,
52388
- bodyAttributes: messageBodyAttributes,
52472
+ bodyAttributes: adjustedBodyAttributes,
52389
52473
  mentionedUsers: [],
52390
52474
  attachments: [],
52391
52475
  type: 'text'
52392
52476
  };
52393
52477
  var mentionUsersToSend = [];
52394
- if (messageBodyAttributes && messageBodyAttributes.length) {
52395
- messageBodyAttributes.forEach(function (att) {
52478
+ if (adjustedBodyAttributes && adjustedBodyAttributes.length) {
52479
+ adjustedBodyAttributes.forEach(function (att) {
52396
52480
  if (att.type === 'mention') {
52397
52481
  var mentionsToFind = [].concat(mentionedUsers);
52398
52482
  var draftMessage = getDraftMessageFromMap(activeChannel.id);
@@ -52520,12 +52604,14 @@ var SendMessageInput = function SendMessageInput(_ref3) {
52520
52604
  }
52521
52605
  };
52522
52606
  var handleEditMessage = function handleEditMessage() {
52523
- var messageTexToSend = editMessageText.trim();
52607
+ var _trimMessageBodyWithA2 = trimMessageBodyWithAttributes(editMessageText, messageBodyAttributes),
52608
+ messageTexToSend = _trimMessageBodyWithA2.body,
52609
+ adjustedBodyAttributes = _trimMessageBodyWithA2.bodyAttributes;
52524
52610
  var hasTextChanged = messageTexToSend !== messageToEdit.body;
52525
52611
  var normalizeAttrs = function normalizeAttrs(attrs) {
52526
52612
  return !attrs || attrs.length === 0 ? [] : attrs;
52527
52613
  };
52528
- var hasAttributesChanged = !compareMessageBodyAttributes(normalizeAttrs(messageBodyAttributes), normalizeAttrs(messageToEdit.bodyAttributes));
52614
+ var hasAttributesChanged = !compareMessageBodyAttributes(normalizeAttrs(adjustedBodyAttributes), normalizeAttrs(messageToEdit.bodyAttributes));
52529
52615
  if (!hasTextChanged && !hasAttributesChanged) {
52530
52616
  handleCloseEditMode();
52531
52617
  return;
@@ -52569,8 +52655,8 @@ var SendMessageInput = function SendMessageInput(_ref3) {
52569
52655
  var mentionedUsersPositions = [];
52570
52656
  var mentionUsersToSend = [];
52571
52657
  if (mentionedUsers && mentionedUsers.length) {
52572
- if (messageBodyAttributes && messageBodyAttributes.length) {
52573
- messageBodyAttributes.forEach(function (att) {
52658
+ if (adjustedBodyAttributes && adjustedBodyAttributes.length) {
52659
+ adjustedBodyAttributes.forEach(function (att) {
52574
52660
  if (att.type === 'mention') {
52575
52661
  var mentionsToFind = [].concat(mentionedUsers);
52576
52662
  var draftMessage = getDraftMessageFromMap(activeChannel.id);
@@ -52592,7 +52678,7 @@ var SendMessageInput = function SendMessageInput(_ref3) {
52592
52678
  var messageToSend = _extends({}, messageToEdit, {
52593
52679
  attachments: updatedAttachments,
52594
52680
  metadata: mentionedUsersPositions,
52595
- bodyAttributes: messageBodyAttributes,
52681
+ bodyAttributes: adjustedBodyAttributes,
52596
52682
  mentionedUsers: mentionUsersToSend,
52597
52683
  body: messageTexToSend
52598
52684
  });
package/index.modern.js CHANGED
@@ -8478,6 +8478,31 @@ var getAllowEditDeleteIncomingMessage = function getAllowEditDeleteIncomingMessa
8478
8478
  var compareMessageBodyAttributes = function compareMessageBodyAttributes(attributes1, attributes2) {
8479
8479
  return JSON.stringify(attributes1) === JSON.stringify(attributes2);
8480
8480
  };
8481
+ var trimMessageBodyWithAttributes = function trimMessageBodyWithAttributes(text, attributes) {
8482
+ var body = text.trim();
8483
+ var leadingTrim = text.length - text.trimStart().length;
8484
+ var bodyAttributes = (attributes || []).map(function (att) {
8485
+ var offset = att.offset - leadingTrim;
8486
+ var length = att.length;
8487
+ if (offset < 0) {
8488
+ length += offset;
8489
+ offset = 0;
8490
+ }
8491
+ if (offset + length > body.length) {
8492
+ length = body.length - offset;
8493
+ }
8494
+ return _extends({}, att, {
8495
+ offset: offset,
8496
+ length: length
8497
+ });
8498
+ }).filter(function (att) {
8499
+ return att.length > 0 && att.offset >= 0 && att.offset < body.length;
8500
+ });
8501
+ return {
8502
+ body: body,
8503
+ bodyAttributes: bodyAttributes
8504
+ };
8505
+ };
8481
8506
  var bodyAttributesMapByType = {
8482
8507
  1: ['bold'],
8483
8508
  2: ['italic'],
@@ -15994,6 +16019,10 @@ var SDKErrorTypeEnum = {
15994
16019
  Authentication: {
15995
16020
  value: 'Authentication',
15996
16021
  isResendable: true
16022
+ },
16023
+ AttachmentUnavailable: {
16024
+ value: 'AttachmentUnavailable',
16025
+ isResendable: false
15997
16026
  }
15998
16027
  };
15999
16028
  var fromValue = function fromValue(value) {
@@ -16011,6 +16040,11 @@ var isResendableError = function isResendableError(value) {
16011
16040
  var errorType = fromValue(value);
16012
16041
  return (_errorType$isResendab = errorType === null || errorType === void 0 ? void 0 : errorType.isResendable) != null ? _errorType$isResendab : true;
16013
16042
  };
16043
+ var createAttachmentUnavailableError = function createAttachmentUnavailableError(message) {
16044
+ var error = new Error(message);
16045
+ error.type = SDKErrorTypeEnum.AttachmentUnavailable.value;
16046
+ return error;
16047
+ };
16014
16048
 
16015
16049
  var _excluded$1 = ["lastMessage"];
16016
16050
  var _marked = /*#__PURE__*/_regenerator().m(setMessageListLoading),
@@ -16073,6 +16107,8 @@ var _marked = /*#__PURE__*/_regenerator().m(setMessageListLoading),
16073
16107
  _marked56 = /*#__PURE__*/_regenerator().m(loadMorePollVotes),
16074
16108
  _marked57 = /*#__PURE__*/_regenerator().m(refreshCacheAroundMessage),
16075
16109
  _marked58 = /*#__PURE__*/_regenerator().m(MessageSaga);
16110
+ var MAX_AUTO_RESEND_ATTEMPTS = 5;
16111
+ var autoResendAttempts = new Map();
16076
16112
  var loadMoreMessagesInFlight = new Set();
16077
16113
  var prefetchInFlight = new Set();
16078
16114
  var queuedPrefetchRequests = new Map();
@@ -16296,6 +16332,7 @@ var handleUploadAttachments = function handleUploadAttachments(attachments, mess
16296
16332
  try {
16297
16333
  return Promise.resolve(Promise.all(attachments.map(function (attachment) {
16298
16334
  try {
16335
+ var _attachment$url, _attachment$url$type;
16299
16336
  var _temp10 = function _temp10() {
16300
16337
  function _temp0() {
16301
16338
  store.dispatch(updateAttachmentUploadingStateAC(UPLOAD_STATE.SUCCESS, attachment.tid));
@@ -16317,14 +16354,15 @@ var handleUploadAttachments = function handleUploadAttachments(attachments, mess
16317
16354
  return attachmentToSend;
16318
16355
  }
16319
16356
  var _temp9 = function () {
16320
- if (!attachment.cachedUrl && attachment.url.type.split('/')[0] === 'image') {
16357
+ if (!attachment.cachedUrl && fileType === 'image') {
16321
16358
  return _catch(function () {
16322
16359
  var _temp2 = function () {
16323
16360
  if (blobLocal && blobLocal.type.startsWith('image/')) {
16361
+ var _attachment, _attachment2;
16324
16362
  var file = attachment.url instanceof File ? attachment.url : new File([attachment.url], attachment.name || 'image', {
16325
16363
  type: attachment.url.type || blobLocal.type
16326
16364
  });
16327
- var _calculateRenderedIma = calculateRenderedImageWidth((attachment === null || attachment === void 0 ? void 0 : attachment.metadata.szw) || 1280, (attachment === null || attachment === void 0 ? void 0 : attachment.metadata.szh) || 1080),
16365
+ var _calculateRenderedIma = calculateRenderedImageWidth(((_attachment = attachment) === null || _attachment === void 0 ? void 0 : _attachment.metadata.szw) || 1280, ((_attachment2 = attachment) === null || _attachment2 === void 0 ? void 0 : _attachment2.metadata.szh) || 1080),
16328
16366
  newWidth = _calculateRenderedIma[0],
16329
16367
  newHeight = _calculateRenderedIma[1];
16330
16368
  return Promise.resolve(resizeImageWithPica(file, newWidth, newHeight, 1)).then(function (_ref) {
@@ -16362,10 +16400,11 @@ var handleUploadAttachments = function handleUploadAttachments(attachments, mess
16362
16400
  });
16363
16401
  } else {
16364
16402
  var _temp11 = function () {
16365
- if (!attachment.cachedUrl && attachment.url.type.split('/')[0] === 'video') {
16403
+ if (!attachment.cachedUrl && fileType === 'video') {
16366
16404
  var _temp7 = function () {
16367
16405
  if (blobLocal) {
16368
- var _calculateRenderedIma2 = calculateRenderedImageWidth((attachment === null || attachment === void 0 ? void 0 : attachment.metadata.szw) || 1280, (attachment === null || attachment === void 0 ? void 0 : attachment.metadata.szh) || 1080),
16406
+ var _attachment3, _attachment4;
16407
+ var _calculateRenderedIma2 = calculateRenderedImageWidth(((_attachment3 = attachment) === null || _attachment3 === void 0 ? void 0 : _attachment3.metadata.szw) || 1280, ((_attachment4 = attachment) === null || _attachment4 === void 0 ? void 0 : _attachment4.metadata.szh) || 1080),
16369
16408
  newWidth = _calculateRenderedIma2[0],
16370
16409
  newHeight = _calculateRenderedIma2[1];
16371
16410
  return Promise.resolve(getVideoFirstFrame(blobLocal, newWidth, newHeight)).then(function (result) {
@@ -16423,7 +16462,19 @@ var handleUploadAttachments = function handleUploadAttachments(attachments, mess
16423
16462
  total = _ref2.total;
16424
16463
  store.dispatch(updateAttachmentUploadingProgressAC(loaded, total, attachment.tid));
16425
16464
  };
16426
- var fileType = attachment.url.type.split('/')[0];
16465
+ if (!attachment.cachedUrl && !(attachment.url instanceof Blob)) {
16466
+ var _getPendingAttachment;
16467
+ var pendingFile = (_getPendingAttachment = getPendingAttachment(attachment.tid)) === null || _getPendingAttachment === void 0 ? void 0 : _getPendingAttachment.file;
16468
+ if (pendingFile instanceof Blob) {
16469
+ attachment = _extends({}, attachment, {
16470
+ url: pendingFile,
16471
+ data: pendingFile
16472
+ });
16473
+ } else {
16474
+ throw createAttachmentUnavailableError("Attachment file for tid " + attachment.tid + " is no longer available for upload");
16475
+ }
16476
+ }
16477
+ var fileType = (_attachment$url = attachment.url) === null || _attachment$url === void 0 ? void 0 : (_attachment$url$type = _attachment$url.type) === null || _attachment$url$type === void 0 ? void 0 : _attachment$url$type.split('/')[0];
16427
16478
  var fileSize = attachment.size;
16428
16479
  var filePath;
16429
16480
  var uriLocal;
@@ -16926,11 +16977,19 @@ function sendMessage(action) {
16926
16977
  break;
16927
16978
  }
16928
16979
  _loop2 = /*#__PURE__*/_regenerator().m(function _callee3() {
16929
- var attachment, uri, attachmentBuilder, messageAttachment, handleUpdateUploadProgress, _messageBuilder, _messageToSend, messageForSend, _pending;
16980
+ var attachment, _getPendingAttachment2, pendingFile, uri, attachmentBuilder, messageAttachment, handleUpdateUploadProgress, _messageBuilder, _messageToSend, messageForSend, _pending;
16930
16981
  return _regenerator().w(function (_context11) {
16931
16982
  while (1) switch (_context11.n) {
16932
16983
  case 0:
16933
16984
  attachment = mediaAttachments[i];
16985
+ if (customUploader && !attachment.cachedUrl && !(attachment.data instanceof Blob)) {
16986
+ pendingFile = (_getPendingAttachment2 = getPendingAttachment(attachment.tid)) === null || _getPendingAttachment2 === void 0 ? void 0 : _getPendingAttachment2.file;
16987
+ if (pendingFile instanceof Blob) {
16988
+ attachment = _extends({}, attachment, {
16989
+ data: pendingFile
16990
+ });
16991
+ }
16992
+ }
16934
16993
  if (attachment.cachedUrl) {
16935
16994
  uri = attachment.cachedUrl;
16936
16995
  }
@@ -17231,6 +17290,9 @@ function sendMessage(action) {
17231
17290
  return call(channel.sendMessage, messageToSend);
17232
17291
  case 5:
17233
17292
  messageResponse = _context12.v;
17293
+ if (messageToSend.tid) {
17294
+ autoResendAttempts["delete"](messageToSend.tid);
17295
+ }
17234
17296
  if (!customUploader) {
17235
17297
  _context12.n = 10;
17236
17298
  break;
@@ -17763,12 +17825,17 @@ function forwardMessage(action) {
17763
17825
  }
17764
17826
  function resendMessage(action) {
17765
17827
  var _message$attachments;
17766
- var payload, message, connectionState, channelId, attachments, sendAttachmentsAsSeparateMessage, isVoiceMessage;
17828
+ var payload, payloadMessage, connectionState, channelId, liveMessage, message, attachments, sendAttachmentsAsSeparateMessage, isVoiceMessage;
17767
17829
  return _regenerator().w(function (_context16) {
17768
17830
  while (1) switch (_context16.n) {
17769
17831
  case 0:
17770
17832
  payload = action.payload;
17771
- message = payload.message, connectionState = payload.connectionState, channelId = payload.channelId;
17833
+ payloadMessage = payload.message, connectionState = payload.connectionState, channelId = payload.channelId;
17834
+ liveMessage = payloadMessage !== null && payloadMessage !== void 0 && payloadMessage.tid || payloadMessage !== null && payloadMessage !== void 0 && payloadMessage.id ? getMessageFromMap(channelId, payloadMessage.tid || payloadMessage.id) : null;
17835
+ message = liveMessage || payloadMessage;
17836
+ if (message !== null && message !== void 0 && message.tid || message !== null && message !== void 0 && message.id) {
17837
+ autoResendAttempts["delete"](message.tid || message.id);
17838
+ }
17772
17839
  attachments = message === null || message === void 0 ? void 0 : (_message$attachments = message.attachments) === null || _message$attachments === void 0 ? void 0 : _message$attachments.filter(function (att) {
17773
17840
  return (att === null || att === void 0 ? void 0 : att.type) !== attachmentTypes.link;
17774
17841
  });
@@ -17963,7 +18030,7 @@ function editMessage(action) {
17963
18030
  }, _marked14, null, [[0, 8]]);
17964
18031
  }
17965
18032
  var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connectionState) {
17966
- var pendingMessagesMap, channelId, _iterator3, _step3, _msg$attachments, msg, attachments, pendingPollActionsMap, _t7, _t8, _t9;
18033
+ var pendingMessagesMap, channelId, _iterator3, _step3, _msg$attachments, msg, attachments, resendKey, attempts, pendingPollActionsMap, _t7, _t8, _t9;
17967
18034
  return _regenerator().w(function (_context19) {
17968
18035
  while (1) switch (_context19.p = _context19.n) {
17969
18036
  case 0:
@@ -17971,26 +18038,41 @@ var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connec
17971
18038
  _t7 = _regeneratorKeys(pendingMessagesMap);
17972
18039
  case 1:
17973
18040
  if ((_t8 = _t7()).done) {
17974
- _context19.n = 12;
18041
+ _context19.n = 13;
17975
18042
  break;
17976
18043
  }
17977
18044
  channelId = _t8.value;
17978
18045
  _iterator3 = _createForOfIteratorHelperLoose(pendingMessagesMap[channelId]);
17979
18046
  case 2:
17980
18047
  if ((_step3 = _iterator3()).done) {
17981
- _context19.n = 11;
18048
+ _context19.n = 12;
17982
18049
  break;
17983
18050
  }
17984
18051
  msg = _step3.value;
17985
18052
  attachments = msg === null || msg === void 0 ? void 0 : (_msg$attachments = msg.attachments) === null || _msg$attachments === void 0 ? void 0 : _msg$attachments.filter(function (att) {
17986
18053
  return (att === null || att === void 0 ? void 0 : att.type) !== attachmentTypes.link;
17987
18054
  });
17988
- _context19.p = 3;
18055
+ resendKey = (msg === null || msg === void 0 ? void 0 : msg.tid) || (msg === null || msg === void 0 ? void 0 : msg.id);
18056
+ if (!resendKey) {
18057
+ _context19.n = 4;
18058
+ break;
18059
+ }
18060
+ attempts = autoResendAttempts.get(resendKey) || 0;
18061
+ if (!(attempts >= MAX_AUTO_RESEND_ATTEMPTS)) {
18062
+ _context19.n = 3;
18063
+ break;
18064
+ }
18065
+ log.info("Skipping auto-resend of message " + resendKey + " after " + attempts + " failed attempts");
18066
+ return _context19.a(3, 11);
18067
+ case 3:
18068
+ autoResendAttempts.set(resendKey, attempts + 1);
18069
+ case 4:
18070
+ _context19.p = 4;
17989
18071
  if (!(msg !== null && msg !== void 0 && msg.forwardingDetails)) {
17990
- _context19.n = 5;
18072
+ _context19.n = 6;
17991
18073
  break;
17992
18074
  }
17993
- _context19.n = 4;
18075
+ _context19.n = 5;
17994
18076
  return call(forwardMessage, {
17995
18077
  type: RESEND_MESSAGE,
17996
18078
  payload: {
@@ -18000,15 +18082,15 @@ var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connec
18000
18082
  isForward: true
18001
18083
  }
18002
18084
  });
18003
- case 4:
18004
- _context19.n = 8;
18005
- break;
18006
18085
  case 5:
18086
+ _context19.n = 9;
18087
+ break;
18088
+ case 6:
18007
18089
  if (!(attachments && attachments.length > 0)) {
18008
- _context19.n = 7;
18090
+ _context19.n = 8;
18009
18091
  break;
18010
18092
  }
18011
- _context19.n = 6;
18093
+ _context19.n = 7;
18012
18094
  return call(sendMessage, {
18013
18095
  type: RESEND_MESSAGE,
18014
18096
  payload: {
@@ -18018,11 +18100,11 @@ var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connec
18018
18100
  sendAttachmentsAsSeparateMessage: false
18019
18101
  }
18020
18102
  });
18021
- case 6:
18022
- _context19.n = 8;
18023
- break;
18024
18103
  case 7:
18025
- _context19.n = 8;
18104
+ _context19.n = 9;
18105
+ break;
18106
+ case 8:
18107
+ _context19.n = 9;
18026
18108
  return call(sendTextMessage, {
18027
18109
  type: RESEND_MESSAGE,
18028
18110
  payload: {
@@ -18031,31 +18113,31 @@ var sendPendingMessages = /*#__PURE__*/_regenerator().m(function _callee5(connec
18031
18113
  channelId: channelId
18032
18114
  }
18033
18115
  });
18034
- case 8:
18035
- _context19.n = 10;
18036
- break;
18037
18116
  case 9:
18038
- _context19.p = 9;
18117
+ _context19.n = 11;
18118
+ break;
18119
+ case 10:
18120
+ _context19.p = 10;
18039
18121
  _t9 = _context19.v;
18040
18122
  log.error("Failed to send pending message " + (msg.tid || msg.id) + ":", _t9);
18041
- case 10:
18123
+ case 11:
18042
18124
  _context19.n = 2;
18043
18125
  break;
18044
- case 11:
18126
+ case 12:
18045
18127
  _context19.n = 1;
18046
18128
  break;
18047
- case 12:
18129
+ case 13:
18048
18130
  pendingPollActionsMap = store.getState().MessageReducer.pendingPollActions;
18049
18131
  if (!(pendingPollActionsMap && Object.keys(pendingPollActionsMap).length > 0)) {
18050
- _context19.n = 13;
18132
+ _context19.n = 14;
18051
18133
  break;
18052
18134
  }
18053
- _context19.n = 13;
18135
+ _context19.n = 14;
18054
18136
  return put(resendPendingPollActionsAC(connectionState));
18055
- case 13:
18137
+ case 14:
18056
18138
  return _context19.a(2);
18057
18139
  }
18058
- }, _callee5, null, [[3, 9]]);
18140
+ }, _callee5, null, [[4, 10]]);
18059
18141
  });
18060
18142
  var shouldAppendPendingMessages = function shouldAppendPendingMessages(channelOrId, messages, options) {
18061
18143
  var _getStoredChannel9, _getStoredChannel9$la, _channelOrId$lastMess;
@@ -18280,7 +18362,7 @@ function loadOGMetadataForLinkMessages(messages, getFromServer) {
18280
18362
  getFromServer = true;
18281
18363
  }
18282
18364
  return /*#__PURE__*/_regenerator().m(function _callee6() {
18283
- var i, _message$attachments2, message, isOnlyLinkAttachments, firstAttachment, j, _attachment, _firstAttachment, _store$getState$Messa, _firstAttachment2, _firstAttachment3, _firstAttachment4, metadata, storedData;
18365
+ var i, _message$attachments2, message, isOnlyLinkAttachments, firstAttachment, j, _attachment5, _firstAttachment, _store$getState$Messa, _firstAttachment2, _firstAttachment3, _firstAttachment4, metadata, storedData;
18284
18366
  return _regenerator().w(function (_context22) {
18285
18367
  while (1) switch (_context22.n) {
18286
18368
  case 0:
@@ -18309,13 +18391,13 @@ function loadOGMetadataForLinkMessages(messages, getFromServer) {
18309
18391
  _context22.n = 6;
18310
18392
  break;
18311
18393
  }
18312
- _attachment = message.attachments[j];
18313
- if (!(_attachment.type === attachmentTypes.link)) {
18394
+ _attachment5 = message.attachments[j];
18395
+ if (!(_attachment5.type === attachmentTypes.link)) {
18314
18396
  _context22.n = 4;
18315
18397
  break;
18316
18398
  }
18317
18399
  if (!firstAttachment) {
18318
- firstAttachment = _attachment;
18400
+ firstAttachment = _attachment5;
18319
18401
  }
18320
18402
  _context22.n = 5;
18321
18403
  break;
@@ -52362,17 +52444,19 @@ var SendMessageInput = function SendMessageInput(_ref3) {
52362
52444
  if (messageToEdit) {
52363
52445
  handleEditMessage();
52364
52446
  } else if (messageTextForSend !== null && messageTextForSend !== void 0 && messageTextForSend.trim() || attachments.length && attachments.length > 0) {
52365
- var messageTexToSend = messageTextForSend === null || messageTextForSend === void 0 ? void 0 : messageTextForSend.trim();
52447
+ var _trimMessageBodyWithA = trimMessageBodyWithAttributes(messageText, messageBodyAttributes),
52448
+ messageTexToSend = _trimMessageBodyWithA.body,
52449
+ adjustedBodyAttributes = _trimMessageBodyWithA.bodyAttributes;
52366
52450
  var messageToSend = {
52367
52451
  body: messageTexToSend,
52368
- bodyAttributes: messageBodyAttributes,
52452
+ bodyAttributes: adjustedBodyAttributes,
52369
52453
  mentionedUsers: [],
52370
52454
  attachments: [],
52371
52455
  type: 'text'
52372
52456
  };
52373
52457
  var mentionUsersToSend = [];
52374
- if (messageBodyAttributes && messageBodyAttributes.length) {
52375
- messageBodyAttributes.forEach(function (att) {
52458
+ if (adjustedBodyAttributes && adjustedBodyAttributes.length) {
52459
+ adjustedBodyAttributes.forEach(function (att) {
52376
52460
  if (att.type === 'mention') {
52377
52461
  var mentionsToFind = [].concat(mentionedUsers);
52378
52462
  var draftMessage = getDraftMessageFromMap(activeChannel.id);
@@ -52500,12 +52584,14 @@ var SendMessageInput = function SendMessageInput(_ref3) {
52500
52584
  }
52501
52585
  };
52502
52586
  var handleEditMessage = function handleEditMessage() {
52503
- var messageTexToSend = editMessageText.trim();
52587
+ var _trimMessageBodyWithA2 = trimMessageBodyWithAttributes(editMessageText, messageBodyAttributes),
52588
+ messageTexToSend = _trimMessageBodyWithA2.body,
52589
+ adjustedBodyAttributes = _trimMessageBodyWithA2.bodyAttributes;
52504
52590
  var hasTextChanged = messageTexToSend !== messageToEdit.body;
52505
52591
  var normalizeAttrs = function normalizeAttrs(attrs) {
52506
52592
  return !attrs || attrs.length === 0 ? [] : attrs;
52507
52593
  };
52508
- var hasAttributesChanged = !compareMessageBodyAttributes(normalizeAttrs(messageBodyAttributes), normalizeAttrs(messageToEdit.bodyAttributes));
52594
+ var hasAttributesChanged = !compareMessageBodyAttributes(normalizeAttrs(adjustedBodyAttributes), normalizeAttrs(messageToEdit.bodyAttributes));
52509
52595
  if (!hasTextChanged && !hasAttributesChanged) {
52510
52596
  handleCloseEditMode();
52511
52597
  return;
@@ -52549,8 +52635,8 @@ var SendMessageInput = function SendMessageInput(_ref3) {
52549
52635
  var mentionedUsersPositions = [];
52550
52636
  var mentionUsersToSend = [];
52551
52637
  if (mentionedUsers && mentionedUsers.length) {
52552
- if (messageBodyAttributes && messageBodyAttributes.length) {
52553
- messageBodyAttributes.forEach(function (att) {
52638
+ if (adjustedBodyAttributes && adjustedBodyAttributes.length) {
52639
+ adjustedBodyAttributes.forEach(function (att) {
52554
52640
  if (att.type === 'mention') {
52555
52641
  var mentionsToFind = [].concat(mentionedUsers);
52556
52642
  var draftMessage = getDraftMessageFromMap(activeChannel.id);
@@ -52572,7 +52658,7 @@ var SendMessageInput = function SendMessageInput(_ref3) {
52572
52658
  var messageToSend = _extends({}, messageToEdit, {
52573
52659
  attachments: updatedAttachments,
52574
52660
  metadata: mentionedUsersPositions,
52575
- bodyAttributes: messageBodyAttributes,
52661
+ bodyAttributes: adjustedBodyAttributes,
52576
52662
  mentionedUsers: mentionUsersToSend,
52577
52663
  body: messageTexToSend
52578
52664
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-chat-react-uikit",
3
- "version": "1.8.8-beta.17",
3
+ "version": "1.8.8-beta.18",
4
4
  "description": "Interactive React UI Components for Sceyt Chat.",
5
5
  "author": "Sceyt",
6
6
  "license": "MIT",