stream-chat-react 9.5.2 → 9.5.4

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.
@@ -34906,7 +34906,7 @@ var StreamChatReact = (function (exports, React, streamChat, reactDom) {
34906
34906
  }, unwrapDisallowed: true }));
34907
34907
  };
34908
34908
  function escapeRegExp(text) {
34909
- return text.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&');
34909
+ return text.replace(/[-[\]{}()*+?.,/\\^$|#]/g, '\\$&');
34910
34910
  }
34911
34911
  /**
34912
34912
  * @deprecated will be removed in the next major release
@@ -42184,9 +42184,10 @@ var StreamChatReact = (function (exports, React, streamChat, reactDom) {
42184
42184
  };
42185
42185
  var isUserResponseArray = function (output) { var _a; return ((_a = output[0]) === null || _a === void 0 ? void 0 : _a.id) != null; };
42186
42186
  var doSendMessage = function (message, customMessageData) { return __awaiter$1(void 0, void 0, void 0, function () {
42187
- var attachments, id, _a, mentioned_users, parent_id, text, mentions, messageData, messageResponse, error_1, stringError, parsedError;
42188
- return __generator$1(this, function (_b) {
42189
- switch (_b.label) {
42187
+ var attachments, id, _a, mentioned_users, parent_id, text, mentions, messageData, messageResponse, existingMessage, i, msg, responseTimestamp, existingMessageTimestamp, responseIsTheNewest, error_1, stringError, parsedError;
42188
+ var _b, _c;
42189
+ return __generator$1(this, function (_d) {
42190
+ switch (_d.label) {
42190
42191
  case 0:
42191
42192
  attachments = message.attachments, id = message.id, _a = message.mentioned_users, mentioned_users = _a === void 0 ? [] : _a, parent_id = message.parent_id, text = message.text;
42192
42193
  mentions = isUserResponseArray(mentioned_users)
@@ -42196,29 +42197,43 @@ var StreamChatReact = (function (exports, React, streamChat, reactDom) {
42196
42197
  })
42197
42198
  : mentioned_users;
42198
42199
  messageData = __assign$2({ attachments: attachments, id: id, mentioned_users: mentions, parent_id: parent_id, quoted_message_id: parent_id === (quotedMessage === null || quotedMessage === void 0 ? void 0 : quotedMessage.parent_id) ? quotedMessage === null || quotedMessage === void 0 ? void 0 : quotedMessage.id : undefined, text: text }, customMessageData);
42199
- _b.label = 1;
42200
+ _d.label = 1;
42200
42201
  case 1:
42201
- _b.trys.push([1, 6, , 7]);
42202
+ _d.trys.push([1, 6, , 7]);
42202
42203
  messageResponse = void 0;
42203
42204
  if (!doSendMessageRequest) return [3 /*break*/, 3];
42204
42205
  return [4 /*yield*/, doSendMessageRequest(channel.cid, messageData)];
42205
42206
  case 2:
42206
- messageResponse = _b.sent();
42207
+ messageResponse = _d.sent();
42207
42208
  return [3 /*break*/, 5];
42208
42209
  case 3: return [4 /*yield*/, channel.sendMessage(messageData)];
42209
42210
  case 4:
42210
- messageResponse = _b.sent();
42211
- _b.label = 5;
42211
+ messageResponse = _d.sent();
42212
+ _d.label = 5;
42212
42213
  case 5:
42213
- // replace it after send is completed
42214
- if (messageResponse === null || messageResponse === void 0 ? void 0 : messageResponse.message) {
42214
+ existingMessage = void 0;
42215
+ for (i = channel.state.messages.length - 1; i >= 0; i--) {
42216
+ msg = channel.state.messages[i];
42217
+ if (msg.id === messageData.id) {
42218
+ existingMessage = msg;
42219
+ break;
42220
+ }
42221
+ }
42222
+ responseTimestamp = new Date(((_b = messageResponse === null || messageResponse === void 0 ? void 0 : messageResponse.message) === null || _b === void 0 ? void 0 : _b.updated_at) || 0).getTime();
42223
+ existingMessageTimestamp = ((_c = existingMessage === null || existingMessage === void 0 ? void 0 : existingMessage.updated_at) === null || _c === void 0 ? void 0 : _c.getTime()) || 0;
42224
+ responseIsTheNewest = responseTimestamp > existingMessageTimestamp;
42225
+ // Replace the message payload after send is completed
42226
+ // We need to check for the newest message payload, because on slow network, the response can arrive later than WS events message.new, message.updated.
42227
+ // Always override existing message in status "sending"
42228
+ if ((messageResponse === null || messageResponse === void 0 ? void 0 : messageResponse.message) &&
42229
+ (responseIsTheNewest || (existingMessage === null || existingMessage === void 0 ? void 0 : existingMessage.status) === 'sending')) {
42215
42230
  updateMessage(__assign$2(__assign$2({}, messageResponse.message), { status: 'received' }));
42216
42231
  }
42217
42232
  if (quotedMessage && parent_id === (quotedMessage === null || quotedMessage === void 0 ? void 0 : quotedMessage.parent_id))
42218
42233
  setQuotedMessage(undefined);
42219
42234
  return [3 /*break*/, 7];
42220
42235
  case 6:
42221
- error_1 = _b.sent();
42236
+ error_1 = _d.sent();
42222
42237
  stringError = JSON.stringify(error_1);
42223
42238
  parsedError = stringError ? JSON.parse(stringError) : {};
42224
42239
  updateMessage(__assign$2(__assign$2({}, message), { error: parsedError, errorStatusCode: parsedError.status || undefined, status: 'failed' }));
@@ -43384,7 +43399,7 @@ var StreamChatReact = (function (exports, React, streamChat, reactDom) {
43384
43399
 
43385
43400
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};
43386
43401
 
43387
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version = '9.5.2';
43402
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version = '9.5.4';
43388
43403
 
43389
43404
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var useChat = function (_a) {
43390
43405
  var _b, _c;