sceyt-chat-react-uikit 1.8.8-beta.6 → 1.8.8-beta.8

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/index.js CHANGED
@@ -1,5 +1,24 @@
1
1
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
2
2
 
3
+ function _interopNamespace(e) {
4
+ if (e && e.__esModule) { return e; } else {
5
+ var n = {};
6
+ if (e) {
7
+ Object.keys(e).forEach(function (k) {
8
+ var d = Object.getOwnPropertyDescriptor(e, k);
9
+ Object.defineProperty(n, k, d.get ? d : {
10
+ enumerable: true,
11
+ get: function () {
12
+ return e[k];
13
+ }
14
+ });
15
+ });
16
+ }
17
+ n['default'] = e;
18
+ return n;
19
+ }
20
+ }
21
+
3
22
  var React = require('react');
4
23
  var React__default = _interopDefault(React);
5
24
  var reactRedux = require('react-redux');
@@ -14849,198 +14868,677 @@ function calculateSize(width, height, maxWidth, maxHeight) {
14849
14868
  }
14850
14869
  var pica = new Pica();
14851
14870
 
14852
- var getVideoFirstFrame = function getVideoFirstFrame(videoSrc, maxWidth, maxHeight, quality) {
14853
- if (quality === void 0) {
14854
- quality = 0.8;
14871
+ var dbg = function dbg() {
14872
+ var _console;
14873
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
14874
+ args[_key] = arguments[_key];
14875
+ }
14876
+ return (_console = console).log.apply(_console, ['[VIDEO_FIRST_FRAME]'].concat(args));
14877
+ };
14878
+ var toHex = function toHex(bytes) {
14879
+ return Array.from(bytes).map(function (b) {
14880
+ return b.toString(16).padStart(2, '0');
14881
+ }).join(' ');
14882
+ };
14883
+ var NATIVE_VIDEO_TYPES = new Set(['video/mp4', 'video/webm', 'video/ogg']);
14884
+ var findFourccs = function findFourccs(bytes, fourccs) {
14885
+ var found = [];
14886
+ for (var _iterator = _createForOfIteratorHelperLoose(fourccs), _step; !(_step = _iterator()).done;) {
14887
+ var cc = _step.value;
14888
+ var c0 = cc.charCodeAt(0);
14889
+ var c1 = cc.charCodeAt(1);
14890
+ var c2 = cc.charCodeAt(2);
14891
+ var c3 = cc.charCodeAt(3);
14892
+ for (var i = 0; i <= bytes.length - 4; i++) {
14893
+ if (bytes[i] === c0 && bytes[i + 1] === c1 && bytes[i + 2] === c2 && bytes[i + 3] === c3) {
14894
+ found.push(cc);
14895
+ break;
14896
+ }
14897
+ }
14855
14898
  }
14899
+ return found;
14900
+ };
14901
+ var VIDEO_CODEC_FOURCCS = ['avc1', 'avc3', 'hvc1', 'hev1', 'av01', 'vp09', 'mp4v', 'apcn', 'apch', 'ap4h'];
14902
+ var isQuickTimeContainer = function isQuickTimeContainer(info) {
14903
+ return info.isoBrand === 'qt ';
14904
+ };
14905
+ var inspectVideoBlob = function inspectVideoBlob(blob) {
14856
14906
  try {
14857
- return Promise.resolve(new Promise(function (resolve) {
14858
- try {
14859
- var video = document.createElement('video');
14860
- video.preload = 'metadata';
14861
- video.muted = true;
14862
- video.setAttribute('playsinline', 'true');
14863
- if (videoSrc instanceof Blob) {
14864
- video.src = URL.createObjectURL(videoSrc);
14865
- } else {
14866
- video.src = videoSrc;
14867
- }
14868
- var videoUrlCreated = false;
14869
- var cleanup = function cleanup() {
14870
- if (videoUrlCreated && videoSrc instanceof Blob) {
14871
- URL.revokeObjectURL(video.src);
14907
+ var info = {
14908
+ mimeType: null,
14909
+ isoBrand: null,
14910
+ codecs: []
14911
+ };
14912
+ return Promise.resolve(_catch(function () {
14913
+ return Promise.resolve(blob.slice(0, 16).arrayBuffer()).then(function (_blob$slice$arrayBuff) {
14914
+ var _exit = false;
14915
+ function _temp4(_result) {
14916
+ if (_exit) return _result;
14917
+ if (head.length >= 4 && head[0] === 0x1a && head[1] === 0x45 && head[2] === 0xdf && head[3] === 0xa3) {
14918
+ dbg('sniff: EBML (webm/mkv) detected');
14919
+ info.mimeType = 'video/webm';
14920
+ return info;
14872
14921
  }
14873
- };
14874
- var extractFrame = function extractFrame() {
14875
- try {
14876
- if (video.videoWidth === 0 || video.videoHeight === 0) {
14877
- cleanup();
14878
- resolve(null);
14879
- return;
14880
- }
14881
- var canvasWidth = maxWidth || video.videoWidth / 2;
14882
- var canvasHeight = maxHeight || video.videoHeight / 2;
14883
- var canvas = document.createElement('canvas');
14884
- canvas.width = canvasWidth;
14885
- canvas.height = canvasHeight;
14886
- var ctx = canvas.getContext('2d');
14887
- if (!ctx) {
14888
- cleanup();
14889
- resolve(null);
14890
- return;
14891
- }
14892
- ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
14893
- canvas.toBlob(function (blob) {
14894
- if (!blob) {
14895
- cleanup();
14896
- resolve(null);
14897
- return;
14922
+ if (head.length >= 4 && head[0] === 0x4f && head[1] === 0x67 && head[2] === 0x67 && head[3] === 0x53) {
14923
+ dbg('sniff: Ogg detected');
14924
+ info.mimeType = 'video/ogg';
14925
+ return info;
14926
+ }
14927
+ dbg('sniff: unknown container');
14928
+ return info;
14929
+ }
14930
+ var head = new Uint8Array(_blob$slice$arrayBuff);
14931
+ dbg('sniff: first bytes =', toHex(head));
14932
+ var _temp3 = function () {
14933
+ if (head.length >= 8 && head[4] === 0x66 && head[5] === 0x74 && head[6] === 0x79 && head[7] === 0x70) {
14934
+ info.mimeType = 'video/mp4';
14935
+ info.isoBrand = String.fromCharCode(head[8] || 0, head[9] || 0, head[10] || 0, head[11] || 0);
14936
+ var scanSize = 512 * 1024;
14937
+ return Promise.resolve(blob.slice(0, Math.min(scanSize, blob.size)).arrayBuffer()).then(function (_blob$slice$arrayBuff2) {
14938
+ function _temp2() {
14939
+ dbg('sniff: ISO-BMFF, major brand =', JSON.stringify(info.isoBrand), 'codecs =', info.codecs.join(',') || 'none-found');
14940
+ _exit = true;
14941
+ return info;
14898
14942
  }
14899
- var frameBlobUrl = URL.createObjectURL(blob);
14900
- cleanup();
14901
- resolve({
14902
- frameBlobUrl: frameBlobUrl,
14903
- blob: blob
14904
- });
14905
- }, 'image/jpeg', quality);
14906
- } catch (error) {
14907
- log.error('Error extracting video frame:', error);
14908
- cleanup();
14909
- resolve(null);
14943
+ var headChunk = new Uint8Array(_blob$slice$arrayBuff2);
14944
+ info.codecs = findFourccs(headChunk, VIDEO_CODEC_FOURCCS);
14945
+ var _temp = function () {
14946
+ if (!info.codecs.length && blob.size > scanSize) {
14947
+ return Promise.resolve(blob.slice(Math.max(0, blob.size - scanSize)).arrayBuffer()).then(function (_blob$slice$arrayBuff3) {
14948
+ var tailChunk = new Uint8Array(_blob$slice$arrayBuff3);
14949
+ info.codecs = findFourccs(tailChunk, VIDEO_CODEC_FOURCCS);
14950
+ });
14951
+ }
14952
+ }();
14953
+ return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
14954
+ });
14910
14955
  }
14911
- };
14912
- video.onloadedmetadata = function () {
14913
- videoUrlCreated = true;
14914
- video.currentTime = 0.01;
14915
- video.onseeked = function () {
14916
- video.onseeked = null;
14917
- var capture = function capture() {
14918
- return requestAnimationFrame(extractFrame);
14919
- };
14920
- video.play().then(function () {
14921
- var done = false;
14922
- var _finish = function finish() {
14923
- if (done) return;
14924
- done = true;
14925
- video.removeEventListener('timeupdate', _finish);
14926
- video.removeEventListener('ended', _finish);
14927
- video.pause();
14928
- capture();
14929
- };
14930
- video.addEventListener('timeupdate', _finish);
14931
- video.addEventListener('ended', _finish);
14932
- setTimeout(_finish, 500);
14933
- })["catch"](capture);
14934
- };
14935
- video.onerror = function (error) {
14936
- log.error('Error seeking video for frame extraction', error);
14937
- cleanup();
14938
- resolve(null);
14956
+ }();
14957
+ return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
14958
+ });
14959
+ }, function (error) {
14960
+ log.error('Failed to sniff video container:', error);
14961
+ return info;
14962
+ }));
14963
+ } catch (e) {
14964
+ return Promise.reject(e);
14965
+ }
14966
+ };
14967
+ var isFirefox = function isFirefox() {
14968
+ return typeof navigator !== 'undefined' && /firefox/i.test(navigator.userAgent);
14969
+ };
14970
+
14971
+ var dbg$1 = function dbg() {
14972
+ var _console;
14973
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
14974
+ args[_key] = arguments[_key];
14975
+ }
14976
+ return (_console = console).log.apply(_console, ['[VIDEO_FIRST_FRAME]'].concat(args));
14977
+ };
14978
+ var REMUX_MAX_BYTES = 200 * 1024 * 1024;
14979
+ var remuxCounter = 0;
14980
+ var remuxToMp4 = function remuxToMp4(blob) {
14981
+ try {
14982
+ if (blob.size > REMUX_MAX_BYTES) {
14983
+ dbg$1('remux: skipped, file too large:', blob.size);
14984
+ log.warn('remuxToMp4: file too large to remux in browser:', blob.size);
14985
+ return Promise.resolve(null);
14986
+ }
14987
+ var id = Date.now() + "_" + remuxCounter++;
14988
+ var inputName = "remux_" + id + "_in.mov";
14989
+ var outputName = "remux_" + id + "_out.mp4";
14990
+ var ffmpeg = null;
14991
+ return Promise.resolve(_finallyRethrows(function () {
14992
+ return _catch(function () {
14993
+ dbg$1('remux: starting ffmpeg -c copy remux, size =', blob.size);
14994
+ return Promise.resolve(Promise.all([Promise.resolve().then(function () { return audioConversion; }), new Promise(function (resolve) { resolve(_interopNamespace(require('@ffmpeg/util'))); })])).then(function (_ref) {
14995
+ var initFFmpeg = _ref[0].initFFmpeg,
14996
+ fetchFile = _ref[1].fetchFile;
14997
+ return Promise.resolve(initFFmpeg()).then(function (_initFFmpeg) {
14998
+ ffmpeg = _initFFmpeg;
14999
+ var _ffmpeg = ffmpeg,
15000
+ _writeFile = _ffmpeg.writeFile;
15001
+ return Promise.resolve(fetchFile(blob)).then(function (_fetchFile) {
15002
+ return Promise.resolve(_writeFile.call(_ffmpeg, inputName, _fetchFile)).then(function () {
15003
+ return Promise.resolve(ffmpeg.exec(['-i', inputName, '-c', 'copy', '-movflags', '+faststart', outputName])).then(function () {
15004
+ return Promise.resolve(ffmpeg.readFile(outputName)).then(function (data) {
15005
+ var bytes;
15006
+ if (data instanceof Uint8Array) {
15007
+ bytes = data;
15008
+ } else if (typeof data === 'string') {
15009
+ var binaryString = atob(data);
15010
+ bytes = new Uint8Array(binaryString.length);
15011
+ for (var i = 0; i < binaryString.length; i++) {
15012
+ bytes[i] = binaryString.charCodeAt(i);
15013
+ }
15014
+ } else {
15015
+ bytes = new Uint8Array(data);
15016
+ }
15017
+ if (!bytes.length) {
15018
+ dbg$1('remux: ffmpeg produced empty output');
15019
+ return null;
15020
+ }
15021
+ var arrayBuffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
15022
+ dbg$1('remux: done, output size =', bytes.length);
15023
+ return new Blob([arrayBuffer], {
15024
+ type: 'video/mp4'
15025
+ });
15026
+ });
15027
+ });
15028
+ });
15029
+ });
15030
+ });
15031
+ });
15032
+ }, function (error) {
15033
+ dbg$1('remux: FAILED', error);
15034
+ log.error('remuxToMp4: remux failed:', error);
15035
+ return null;
15036
+ });
15037
+ }, function (_wasThrown, _result) {
15038
+ function _temp5() {
15039
+ if (_wasThrown) throw _result;
15040
+ return _result;
15041
+ }
15042
+ var _temp4 = function () {
15043
+ if (ffmpeg) {
15044
+ var _temp3 = function _temp3() {
15045
+ var _temp = _catch(function () {
15046
+ return Promise.resolve(ffmpeg.deleteFile(outputName)).then(function () {});
15047
+ }, function () {});
15048
+ if (_temp && _temp.then) return _temp.then(function () {});
14939
15049
  };
15050
+ var _temp2 = _catch(function () {
15051
+ return Promise.resolve(ffmpeg.deleteFile(inputName)).then(function () {});
15052
+ }, function () {});
15053
+ return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2);
15054
+ }
15055
+ }();
15056
+ return _temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4);
15057
+ }));
15058
+ } catch (e) {
15059
+ return Promise.reject(e);
15060
+ }
15061
+ };
15062
+ var remuxVideoFileForUpload = function remuxVideoFileForUpload(file) {
15063
+ try {
15064
+ return Promise.resolve(_catch(function () {
15065
+ return Promise.resolve(inspectVideoBlob(file)).then(function (info) {
15066
+ if (!isQuickTimeContainer(info)) {
15067
+ return file;
15068
+ }
15069
+ dbg$1('upload: QuickTime file picked, remuxing before upload:', file.name);
15070
+ return Promise.resolve(remuxToMp4(file)).then(function (remuxed) {
15071
+ if (!remuxed) {
15072
+ log.warn('remuxVideoFileForUpload: remux failed, uploading original file');
15073
+ return file;
15074
+ }
15075
+ var newName = /\.(mov|qt)$/i.test(file.name) ? file.name.replace(/\.(mov|qt)$/i, '.mp4') : file.name + ".mp4";
15076
+ return new File([remuxed], newName, {
15077
+ type: 'video/mp4',
15078
+ lastModified: file.lastModified
15079
+ });
15080
+ });
15081
+ });
15082
+ }, function (error) {
15083
+ log.error('remuxVideoFileForUpload failed, uploading original file:', error);
15084
+ return file;
15085
+ }));
15086
+ } catch (e) {
15087
+ return Promise.reject(e);
15088
+ }
15089
+ };
15090
+ var ensurePlayableVideoBlob = function ensurePlayableVideoBlob(blob) {
15091
+ try {
15092
+ return Promise.resolve(_catch(function () {
15093
+ return isFirefox() ? Promise.resolve(inspectVideoBlob(blob)).then(function (info) {
15094
+ if (!isQuickTimeContainer(info)) {
15095
+ return blob;
15096
+ }
15097
+ dbg$1('download: QuickTime blob in Firefox, remuxing for playback');
15098
+ return Promise.resolve(remuxToMp4(blob)).then(function (remuxed) {
15099
+ return remuxed || blob;
15100
+ });
15101
+ }) : blob;
15102
+ }, function (error) {
15103
+ log.error('ensurePlayableVideoBlob failed, using original blob:', error);
15104
+ return blob;
15105
+ }));
15106
+ } catch (e) {
15107
+ return Promise.reject(e);
15108
+ }
15109
+ };
15110
+
15111
+ var getFrame = function getFrame(videoSrc, _time) {
15112
+ try {
15113
+ if (!videoSrc) {
15114
+ throw new Error('src not found');
15115
+ }
15116
+ return Promise.resolve(getVideoFirstFrame(videoSrc)).then(function (frameResult) {
15117
+ if (!frameResult) {
15118
+ throw new Error('Failed to extract video frame');
15119
+ }
15120
+ var frameBlobUrl = frameResult.frameBlobUrl,
15121
+ origWidth = frameResult.width,
15122
+ origHeight = frameResult.height;
15123
+ var duration = Number(frameResult.duration.toFixed(0));
15124
+ var _calculateSize = calculateSize(origWidth, origHeight, 100, 100),
15125
+ newWidth = _calculateSize[0],
15126
+ newHeight = _calculateSize[1];
15127
+ return new Promise(function (resolve, reject) {
15128
+ var img = document.createElement('img');
15129
+ img.onload = function () {
15130
+ var canvas = document.createElement('canvas');
15131
+ canvas.width = newWidth;
15132
+ canvas.height = newHeight;
15133
+ var ctx = canvas.getContext('2d');
15134
+ if (!ctx) {
15135
+ URL.revokeObjectURL(frameBlobUrl);
15136
+ reject(new Error('Failed to get canvas context'));
15137
+ return;
15138
+ }
15139
+ ctx.drawImage(img, 0, 0, newWidth, newHeight);
15140
+ var pixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
15141
+ var binaryThumbHash = rgbaToThumbHash(pixels.width, pixels.height, pixels.data);
15142
+ var thumb = binaryToBase64(binaryThumbHash);
15143
+ URL.revokeObjectURL(frameBlobUrl);
15144
+ resolve({
15145
+ thumb: thumb,
15146
+ width: origWidth,
15147
+ height: origHeight,
15148
+ duration: duration
15149
+ });
14940
15150
  };
14941
- video.onerror = function () {
14942
- log.error('Error loading video metadata for frame extraction');
14943
- cleanup();
14944
- resolve(null);
15151
+ img.onerror = function () {
15152
+ URL.revokeObjectURL(frameBlobUrl);
15153
+ reject(new Error('Failed to load frame image'));
14945
15154
  };
14946
- } catch (error) {
14947
- log.error('Error in getVideoFirstFrame:', error);
14948
- resolve(null);
15155
+ img.src = frameBlobUrl;
15156
+ });
15157
+ });
15158
+ } catch (e) {
15159
+ return Promise.reject(e);
15160
+ }
15161
+ };
15162
+ var getVideoFirstFrame = function getVideoFirstFrame(videoSrc, maxWidth, maxHeight, quality) {
15163
+ if (quality === void 0) {
15164
+ quality = 0.8;
15165
+ }
15166
+ try {
15167
+ var _exit3 = false;
15168
+ return Promise.resolve(_catch(function () {
15169
+ function _temp0(_result3) {
15170
+ var _exit4 = false;
15171
+ if (_exit3) return _result3;
15172
+ function _temp8(_result4) {
15173
+ if (_exit4) return _result4;
15174
+ dbg$2('source: remote URL —', videoSrc.slice(0, 150));
15175
+ return Promise.resolve(extractFrameFromUrl(videoSrc, maxWidth, maxHeight, quality)).then(function (direct) {
15176
+ if (direct) {
15177
+ return direct;
15178
+ }
15179
+ dbg$2('source: direct remote load failed, retrying via fetch + relabel');
15180
+ return _catch(function () {
15181
+ return Promise.resolve(fetch(videoSrc)).then(function (response) {
15182
+ return Promise.resolve(response.blob()).then(function (blob) {
15183
+ dbg$2('source: remote fetched, Content-Type =', JSON.stringify(response.headers.get('content-type')), 'blob type =', JSON.stringify(blob.type), 'size =', blob.size);
15184
+ return Promise.resolve(_extractFrameFromBlob2(blob, maxWidth, maxHeight, quality));
15185
+ });
15186
+ });
15187
+ }, function (error) {
15188
+ dbg$2('source: remote fetch retry FAILED', error);
15189
+ log.error('getVideoFirstFrame: fetch retry failed:', error);
15190
+ return null;
15191
+ });
15192
+ });
15193
+ }
15194
+ var _temp7 = function () {
15195
+ if (videoSrc.startsWith('blob:')) {
15196
+ dbg$2('source: blob URL string —', videoSrc.slice(0, 100));
15197
+ return _catch(function () {
15198
+ return Promise.resolve(fetch(videoSrc)).then(function (_fetch) {
15199
+ return Promise.resolve(_fetch.blob()).then(function (blob) {
15200
+ dbg$2('source: blob URL re-fetched, type =', JSON.stringify(blob.type), 'size =', blob.size);
15201
+ return Promise.resolve(_extractFrameFromBlob2(blob, maxWidth, maxHeight, quality)).then(function (_await$_extractFrameF2) {
15202
+ _exit4 = true;
15203
+ return _await$_extractFrameF2;
15204
+ });
15205
+ });
15206
+ });
15207
+ }, function (error) {
15208
+ dbg$2('source: blob URL re-fetch FAILED, falling back to direct', error);
15209
+ log.warn('getVideoFirstFrame: failed to re-fetch blob url, trying directly', error);
15210
+ return Promise.resolve(extractFrameFromUrl(videoSrc, maxWidth, maxHeight, quality)).then(function (_await$extractFrameFr) {
15211
+ _exit4 = true;
15212
+ return _await$extractFrameFr;
15213
+ });
15214
+ });
15215
+ }
15216
+ }();
15217
+ return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7);
14949
15218
  }
15219
+ var _temp9 = function () {
15220
+ if (videoSrc instanceof Blob) {
15221
+ dbg$2('source: Blob, type =', JSON.stringify(videoSrc.type), 'size =', videoSrc.size);
15222
+ return Promise.resolve(_extractFrameFromBlob2(videoSrc, maxWidth, maxHeight, quality)).then(function (_await$_extractFrameF) {
15223
+ _exit3 = true;
15224
+ return _await$_extractFrameF;
15225
+ });
15226
+ }
15227
+ }();
15228
+ return _temp9 && _temp9.then ? _temp9.then(_temp0) : _temp0(_temp9);
15229
+ }, function (error) {
15230
+ log.error('Error in getVideoFirstFrame:', error);
15231
+ return null;
14950
15232
  }));
14951
15233
  } catch (e) {
14952
15234
  return Promise.reject(e);
14953
15235
  }
14954
15236
  };
14955
- var getFrame = function getFrame(videoSrc, _time) {
15237
+ var dbg$2 = function dbg() {
15238
+ var _console;
15239
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15240
+ args[_key] = arguments[_key];
15241
+ }
15242
+ return (_console = console).log.apply(_console, ['[VIDEO_FIRST_FRAME]'].concat(args));
15243
+ };
15244
+ var normalizeVideoBlob = function normalizeVideoBlob(blob) {
14956
15245
  try {
14957
- return Promise.resolve(new Promise(function (resolve, reject) {
14958
- if (!videoSrc) {
14959
- reject(new Error('src not found'));
14960
- return;
15246
+ return Promise.resolve(inspectVideoBlob(blob)).then(function (info) {
15247
+ var baseType = (blob.type || '').split(';')[0].trim().toLowerCase();
15248
+ if (NATIVE_VIDEO_TYPES.has(baseType)) {
15249
+ dbg$2('normalize: declared type is native:', JSON.stringify(blob.type), '→', JSON.stringify(baseType));
15250
+ return {
15251
+ safeBlob: baseType === blob.type ? blob : new Blob([blob], {
15252
+ type: baseType
15253
+ }),
15254
+ info: info
15255
+ };
14961
15256
  }
15257
+ var relabeledType = info.mimeType || 'video/mp4';
15258
+ dbg$2('normalize: declared', JSON.stringify(blob.type), '→ relabeled to', JSON.stringify(relabeledType));
15259
+ return {
15260
+ safeBlob: new Blob([blob], {
15261
+ type: relabeledType
15262
+ }),
15263
+ info: info
15264
+ };
15265
+ });
15266
+ } catch (e) {
15267
+ return Promise.reject(e);
15268
+ }
15269
+ };
15270
+ var FRAME_LOAD_TIMEOUT_MS = 8000;
15271
+ var READY_STATES = ['HAVE_NOTHING', 'HAVE_METADATA', 'HAVE_CURRENT_DATA', 'HAVE_FUTURE_DATA', 'HAVE_ENOUGH_DATA'];
15272
+ var NETWORK_STATES = ['NETWORK_EMPTY', 'NETWORK_IDLE', 'NETWORK_LOADING', 'NETWORK_NO_SOURCE'];
15273
+ var describeVideoState = function describeVideoState(video) {
15274
+ var buffered = 'none';
15275
+ try {
15276
+ var ranges = [];
15277
+ for (var i = 0; i < video.buffered.length; i++) {
15278
+ ranges.push(video.buffered.start(i).toFixed(2) + "-" + video.buffered.end(i).toFixed(2));
15279
+ }
15280
+ buffered = ranges.join(',') || 'empty';
15281
+ } catch (e) {
15282
+ buffered = 'unavailable';
15283
+ }
15284
+ return "readyState=" + (READY_STATES[video.readyState] || video.readyState) + " " + ("networkState=" + (NETWORK_STATES[video.networkState] || video.networkState) + " ") + ("currentTime=" + video.currentTime + " duration=" + video.duration + " ") + ("videoWidth=" + video.videoWidth + " videoHeight=" + video.videoHeight + " ") + ("buffered=[" + buffered + "] error=" + (video.error ? video.error.code + ":" + video.error.message : 'null'));
15285
+ };
15286
+ var extractFrameFromUrl = function extractFrameFromUrl(srcUrl, maxWidth, maxHeight, quality) {
15287
+ if (quality === void 0) {
15288
+ quality = 0.8;
15289
+ }
15290
+ return new Promise(function (resolve) {
15291
+ try {
15292
+ dbg$2('extract: start, src =', srcUrl.slice(0, 100));
14962
15293
  var video = document.createElement('video');
14963
- video.preload = 'metadata';
15294
+ video.preload = 'auto';
14964
15295
  video.muted = true;
14965
15296
  video.setAttribute('playsinline', 'true');
14966
- video.src = videoSrc;
14967
- video.onloadedmetadata = function () {
15297
+ if (!srcUrl.startsWith('blob:') && !srcUrl.startsWith('data:')) {
15298
+ video.crossOrigin = 'anonymous';
15299
+ }
15300
+ video.style.position = 'fixed';
15301
+ video.style.bottom = '0';
15302
+ video.style.left = '0';
15303
+ video.style.width = '2px';
15304
+ video.style.height = '2px';
15305
+ video.style.opacity = '0';
15306
+ video.style.pointerEvents = 'none';
15307
+ video.style.zIndex = '-1';
15308
+ document.body.appendChild(video);
15309
+ var settled = false;
15310
+ var finishOnce = function finishOnce(result) {
15311
+ if (settled) return;
15312
+ settled = true;
15313
+ clearTimeout(stallTimer);
15314
+ if (video.parentNode) {
15315
+ video.parentNode.removeChild(video);
15316
+ }
15317
+ dbg$2('extract: finished,', result ? 'SUCCESS' : 'NULL');
15318
+ resolve(result);
15319
+ };
15320
+ var stallTimer = setTimeout(function () {
15321
+ dbg$2('extract: TIMEOUT —', describeVideoState(video));
15322
+ log.warn('getVideoFirstFrame: timed out waiting for video to load');
15323
+ finishOnce(null);
15324
+ }, FRAME_LOAD_TIMEOUT_MS);
15325
+ var extractFrame = function extractFrame() {
14968
15326
  try {
14969
- var _video$duration;
14970
- var origWidth = video.videoWidth;
14971
- var origHeight = video.videoHeight;
14972
- var duration = Number((_video$duration = video.duration) === null || _video$duration === void 0 ? void 0 : _video$duration.toFixed(0));
14973
- var _calculateSize = calculateSize(origWidth, origHeight, 100, 100),
14974
- newWidth = _calculateSize[0],
14975
- newHeight = _calculateSize[1];
14976
- return Promise.resolve(_catch(function () {
14977
- return Promise.resolve(getVideoFirstFrame(videoSrc, newWidth, newHeight)).then(function (frameResult) {
14978
- if (!frameResult) {
14979
- reject(new Error('Failed to extract video frame'));
14980
- return;
14981
- }
14982
- var img = document.createElement('img');
14983
- img.onload = function () {
14984
- var canvas = document.createElement('canvas');
14985
- canvas.width = newWidth;
14986
- canvas.height = newHeight;
14987
- var ctx = canvas.getContext('2d');
14988
- if (!ctx) {
14989
- URL.revokeObjectURL(frameResult.frameBlobUrl);
14990
- reject(new Error('Failed to get canvas context'));
14991
- return;
14992
- }
14993
- ctx.drawImage(img, 0, 0, newWidth, newHeight);
14994
- var pixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
14995
- var binaryThumbHash = rgbaToThumbHash(pixels.width, pixels.height, pixels.data);
14996
- var thumb = binaryToBase64(binaryThumbHash);
14997
- URL.revokeObjectURL(frameResult.frameBlobUrl);
14998
- resolve({
14999
- thumb: thumb,
15000
- width: origWidth,
15001
- height: origHeight,
15002
- duration: duration
15003
- });
15004
- };
15005
- img.onerror = function () {
15006
- URL.revokeObjectURL(frameResult.frameBlobUrl);
15007
- reject(new Error('Failed to load frame image'));
15008
- };
15009
- img.src = frameResult.frameBlobUrl;
15327
+ dbg$2('extract: extractFrame,', describeVideoState(video));
15328
+ if (video.videoWidth === 0 || video.videoHeight === 0) {
15329
+ finishOnce(null);
15330
+ return;
15331
+ }
15332
+ var width = video.videoWidth;
15333
+ var height = video.videoHeight;
15334
+ var duration = Number.isFinite(video.duration) ? video.duration : 0;
15335
+ var canvasWidth = maxWidth || width / 2;
15336
+ var canvasHeight = maxHeight || height / 2;
15337
+ var canvas = document.createElement('canvas');
15338
+ canvas.width = canvasWidth;
15339
+ canvas.height = canvasHeight;
15340
+ var ctx = canvas.getContext('2d');
15341
+ if (!ctx) {
15342
+ finishOnce(null);
15343
+ return;
15344
+ }
15345
+ ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
15346
+ canvas.toBlob(function (blob) {
15347
+ if (!blob) {
15348
+ dbg$2('extract: canvas.toBlob returned null');
15349
+ finishOnce(null);
15350
+ return;
15351
+ }
15352
+ var frameBlobUrl = URL.createObjectURL(blob);
15353
+ finishOnce({
15354
+ frameBlobUrl: frameBlobUrl,
15355
+ blob: blob,
15356
+ width: width,
15357
+ height: height,
15358
+ duration: duration
15010
15359
  });
15011
- }, function (err) {
15012
- reject(err);
15013
- }));
15014
- } catch (e) {
15015
- return Promise.reject(e);
15360
+ }, 'image/jpeg', quality);
15361
+ } catch (error) {
15362
+ dbg$2('extract: extractFrame threw', error);
15363
+ log.error('Error extracting video frame:', error);
15364
+ finishOnce(null);
15016
15365
  }
15017
15366
  };
15367
+ video.addEventListener('loadstart', function () {
15368
+ return dbg$2('event: loadstart,', describeVideoState(video));
15369
+ });
15370
+ video.addEventListener('loadeddata', function () {
15371
+ return dbg$2('event: loadeddata,', describeVideoState(video));
15372
+ });
15373
+ video.addEventListener('canplay', function () {
15374
+ return dbg$2('event: canplay,', describeVideoState(video));
15375
+ });
15376
+ video.addEventListener('canplaythrough', function () {
15377
+ return dbg$2('event: canplaythrough');
15378
+ });
15379
+ video.addEventListener('seeking', function () {
15380
+ return dbg$2('event: seeking, currentTime =', video.currentTime);
15381
+ });
15382
+ video.addEventListener('stalled', function () {
15383
+ return dbg$2('event: stalled,', describeVideoState(video));
15384
+ });
15385
+ video.addEventListener('suspend', function () {
15386
+ return dbg$2('event: suspend,', describeVideoState(video));
15387
+ });
15388
+ video.addEventListener('waiting', function () {
15389
+ return dbg$2('event: waiting,', describeVideoState(video));
15390
+ });
15391
+ video.addEventListener('emptied', function () {
15392
+ return dbg$2('event: emptied,', describeVideoState(video));
15393
+ });
15394
+ video.onloadedmetadata = function () {
15395
+ dbg$2('event: loadedmetadata,', describeVideoState(video));
15396
+ video.currentTime = 0.01;
15397
+ video.onseeked = function () {
15398
+ dbg$2('event: seeked,', describeVideoState(video));
15399
+ video.onseeked = null;
15400
+ var capture = function capture() {
15401
+ return requestAnimationFrame(extractFrame);
15402
+ };
15403
+ video.play().then(function () {
15404
+ dbg$2('play(): resolved');
15405
+ var done = false;
15406
+ var _finish = function finish() {
15407
+ if (done) return;
15408
+ done = true;
15409
+ video.removeEventListener('timeupdate', _finish);
15410
+ video.removeEventListener('ended', _finish);
15411
+ video.pause();
15412
+ capture();
15413
+ };
15414
+ video.addEventListener('timeupdate', _finish);
15415
+ video.addEventListener('ended', _finish);
15416
+ setTimeout(_finish, 500);
15417
+ })["catch"](function (err) {
15418
+ dbg$2('play(): rejected —', err === null || err === void 0 ? void 0 : err.name, err === null || err === void 0 ? void 0 : err.message);
15419
+ capture();
15420
+ });
15421
+ };
15422
+ };
15018
15423
  video.onerror = function () {
15019
- reject(new Error('Failed to load video'));
15424
+ dbg$2('event: error,', describeVideoState(video));
15425
+ log.warn('getVideoFirstFrame: video failed to load', video.error);
15426
+ finishOnce(null);
15020
15427
  };
15021
- }));
15022
- } catch (e) {
15023
- return Promise.reject(e);
15428
+ video.onabort = function () {
15429
+ dbg$2('event: abort,', describeVideoState(video));
15430
+ finishOnce(null);
15431
+ };
15432
+ video.src = srcUrl;
15433
+ dbg$2('extract: src assigned,', describeVideoState(video));
15434
+ } catch (error) {
15435
+ log.error('Error in extractFrameFromUrl:', error);
15436
+ resolve(null);
15437
+ }
15438
+ });
15439
+ };
15440
+ var DATA_URL_MAX_BYTES = 64 * 1024 * 1024;
15441
+ var blobToDataUrl = function blobToDataUrl(blob) {
15442
+ return new Promise(function (resolve, reject) {
15443
+ var reader = new FileReader();
15444
+ reader.onload = function () {
15445
+ return resolve(reader.result);
15446
+ };
15447
+ reader.onerror = function () {
15448
+ return reject(reader.error);
15449
+ };
15450
+ reader.readAsDataURL(blob);
15451
+ });
15452
+ };
15453
+ var _extractFrameFromBlob2 = function extractFrameFromBlob(blob, maxWidth, maxHeight, quality, allowRemux) {
15454
+ if (quality === void 0) {
15455
+ quality = 0.8;
15024
15456
  }
15457
+ if (allowRemux === void 0) {
15458
+ allowRemux = true;
15459
+ }
15460
+ return Promise.resolve(normalizeVideoBlob(blob)).then(function (_ref) {
15461
+ var _exit = false;
15462
+ var safeBlob = _ref.safeBlob,
15463
+ info = _ref.info;
15464
+ function _temp6(_result) {
15465
+ var _exit2 = false;
15466
+ if (_exit) return _result;
15467
+ function _temp4(_result2) {
15468
+ if (_exit2) return _result2;
15469
+ if (safeBlob.size > DATA_URL_MAX_BYTES) {
15470
+ dbg$2('fallback: blob too large for data URL fallback, size =', safeBlob.size);
15471
+ return null;
15472
+ }
15473
+ return _catch(function () {
15474
+ dbg$2('fallback: retrying via data URL, size =', safeBlob.size);
15475
+ return Promise.resolve(blobToDataUrl(safeBlob)).then(function (dataUrl) {
15476
+ return Promise.resolve(extractFrameFromUrl(dataUrl, maxWidth, maxHeight, quality));
15477
+ });
15478
+ }, function (error) {
15479
+ dbg$2('fallback: data URL conversion failed', error);
15480
+ log.error('getVideoFirstFrame: data URL fallback failed:', error);
15481
+ return null;
15482
+ });
15483
+ }
15484
+ var url = URL.createObjectURL(safeBlob);
15485
+ var _temp3 = _finallyRethrows(function () {
15486
+ return Promise.resolve(extractFrameFromUrl(url, maxWidth, maxHeight, quality)).then(function (result) {
15487
+ if (result) {
15488
+ _exit2 = true;
15489
+ return result;
15490
+ }
15491
+ });
15492
+ }, function (_wasThrown, _result2) {
15493
+ URL.revokeObjectURL(url);
15494
+ if (_wasThrown) throw _result2;
15495
+ return _result2;
15496
+ });
15497
+ return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
15498
+ }
15499
+ var _temp5 = function () {
15500
+ if (isQuickTimeContainer(info) && isFirefox()) {
15501
+ if (!allowRemux) {
15502
+ dbg$2('skip: remuxed output is still a QuickTime container — giving up');
15503
+ var _temp = null;
15504
+ _exit = true;
15505
+ return _temp;
15506
+ }
15507
+ dbg$2('skip: QuickTime (qt brand) container — Firefox cannot demux this, remuxing. codecs =', info.codecs.join(',') || '?');
15508
+ return Promise.resolve(remuxToMp4(safeBlob)).then(function (remuxed) {
15509
+ if (!remuxed) {
15510
+ log.warn('getVideoFirstFrame: QuickTime container is not supported by Firefox and remux failed');
15511
+ var _temp2 = null;
15512
+ _exit = true;
15513
+ return _temp2;
15514
+ }
15515
+ var _extractFrameFromBlob = _extractFrameFromBlob2(remuxed, maxWidth, maxHeight, quality, false);
15516
+ _exit = true;
15517
+ return _extractFrameFromBlob;
15518
+ });
15519
+ }
15520
+ }();
15521
+ return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
15522
+ });
15025
15523
  };
15026
15524
  var compressAndCacheImage = function compressAndCacheImage(url, cacheKey, maxWidth, maxHeight, quality) {
15027
15525
  try {
15028
15526
  return Promise.resolve(_catch(function () {
15029
15527
  return Promise.resolve(fetch(url)).then(function (response) {
15030
15528
  return response.ok ? Promise.resolve(response.blob()).then(function (blob) {
15031
- var _exit = false;
15032
- function _temp2(_result2) {
15033
- if (_exit) return _result2;
15529
+ var _exit5 = false;
15530
+ function _temp10(_result5) {
15531
+ if (_exit5) return _result5;
15034
15532
  setAttachmentToCache(cacheKey, response);
15035
15533
  return '';
15036
15534
  }
15037
- var _temp = function () {
15535
+ var _temp1 = function () {
15038
15536
  if (blob.type.startsWith('image/')) {
15039
15537
  var file = new File([blob], 'image.jpeg', {
15040
15538
  type: blob.type
15041
15539
  });
15042
- return Promise.resolve(resizeImageWithPica(file, maxWidth || 1280, maxHeight || 1080, quality || 1)).then(function (_ref) {
15043
- var compressedBlob = _ref.blob;
15540
+ return Promise.resolve(resizeImageWithPica(file, maxWidth || 1280, maxHeight || 1080, quality || 1)).then(function (_ref2) {
15541
+ var compressedBlob = _ref2.blob;
15044
15542
  var returningUrl = compressedBlob ? URL.createObjectURL(compressedBlob) : '';
15045
15543
  if (compressedBlob) {
15046
15544
  var compressedResponse = new Response(compressedBlob, {
@@ -15049,13 +15547,13 @@ var compressAndCacheImage = function compressAndCacheImage(url, cacheKey, maxWid
15049
15547
  }
15050
15548
  });
15051
15549
  setAttachmentToCache(cacheKey, compressedResponse);
15052
- _exit = true;
15550
+ _exit5 = true;
15053
15551
  return returningUrl;
15054
15552
  }
15055
15553
  });
15056
15554
  }
15057
15555
  }();
15058
- return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
15556
+ return _temp1 && _temp1.then ? _temp1.then(_temp10) : _temp10(_temp1);
15059
15557
  }) : '';
15060
15558
  });
15061
15559
  }, function (error) {
@@ -20943,7 +21441,7 @@ function loadMorePollVotes(action) {
20943
21441
  }
20944
21442
  var REFRESH_WINDOW_HALF = 30;
20945
21443
  function refreshCacheAroundMessage(action) {
20946
- var _action$payload0, channelId, messageId, _action$payload0$appl, applyVisibleWindow, connectionState, activeChannelId, activeMessages, activeConfirmedMessages, centerMessageIndex, refreshAnchorId, previousLimit, nextLimit, SceytChatClient, messageQueryBuilder, messageQuery, prevResult, pivotId, nextResult, loadedMessages, firstId, lastId, activeById, changed, filteredPendingMessages, _t53, _t54, _t55;
21444
+ var _action$payload0, channelId, messageId, _action$payload0$appl, applyVisibleWindow, connectionState, activeChannelId, activeMessages, activeConfirmedMessages, centerMessageIndex, refreshAnchorId, previousLimit, nextLimit, SceytChatClient, messageQueryBuilder, messageQuery, prevResult, pivotId, nextResult, loadedMessages, firstId, lastId, currentActiveMessages, currentActiveConfirmedMessages, activeById, changed, filteredPendingMessages, _t53, _t54, _t55;
20947
21445
  return _regenerator().w(function (_context63) {
20948
21446
  while (1) switch (_context63.p = _context63.n) {
20949
21447
  case 0:
@@ -21045,8 +21543,18 @@ function refreshCacheAroundMessage(action) {
21045
21543
  _context63.n = 13;
21046
21544
  return effects.call(loadOGMetadataForLinkMessages, loadedMessages, true);
21047
21545
  case 13:
21546
+ currentActiveMessages = store.getState().MessageReducer.activeChannelMessages || [];
21547
+ currentActiveConfirmedMessages = currentActiveMessages.filter(function (message) {
21548
+ return !!message.id;
21549
+ });
21550
+ if (sameConfirmedWindow(currentActiveConfirmedMessages, activeConfirmedMessages)) {
21551
+ _context63.n = 14;
21552
+ break;
21553
+ }
21554
+ return _context63.a(2);
21555
+ case 14:
21048
21556
  if (!sameConfirmedWindow(activeConfirmedMessages, loadedMessages)) {
21049
- _context63.n = 15;
21557
+ _context63.n = 16;
21050
21558
  break;
21051
21559
  }
21052
21560
  activeById = new Map(activeConfirmedMessages.map(function (currentMessage) {
@@ -21059,44 +21567,44 @@ function refreshCacheAroundMessage(action) {
21059
21567
  return JSON.stringify(existing) !== JSON.stringify(loaded);
21060
21568
  });
21061
21569
  if (!(changed.length > 0)) {
21062
- _context63.n = 14;
21570
+ _context63.n = 15;
21063
21571
  break;
21064
21572
  }
21065
- _context63.n = 14;
21573
+ _context63.n = 15;
21066
21574
  return effects.put(patchMessagesAC(changed));
21067
- case 14:
21068
- return _context63.a(2);
21069
21575
  case 15:
21576
+ return _context63.a(2);
21577
+ case 16:
21070
21578
  if (applyVisibleWindow) {
21071
- _context63.n = 16;
21579
+ _context63.n = 17;
21072
21580
  break;
21073
21581
  }
21074
21582
  return _context63.a(2);
21075
- case 16:
21076
- _context63.n = 17;
21077
- return effects.put(setMessagesAC(JSON.parse(JSON.stringify(loadedMessages)), channelId));
21078
21583
  case 17:
21584
+ _context63.n = 18;
21585
+ return effects.put(setMessagesAC(JSON.parse(JSON.stringify(loadedMessages)), channelId));
21586
+ case 18:
21079
21587
  filteredPendingMessages = getFilteredPendingMessages(channelId, loadedMessages);
21080
21588
  if (!(filteredPendingMessages.length > 0)) {
21081
- _context63.n = 19;
21589
+ _context63.n = 20;
21082
21590
  break;
21083
21591
  }
21084
- _context63.n = 18;
21085
- return effects.put(addMessagesAC(filteredPendingMessages, MESSAGE_LOAD_DIRECTION.NEXT));
21086
- case 18:
21087
21592
  _context63.n = 19;
21088
- return effects.call(loadOGMetadataForLinkMessages, filteredPendingMessages, true);
21593
+ return effects.put(addMessagesAC(filteredPendingMessages, MESSAGE_LOAD_DIRECTION.NEXT));
21089
21594
  case 19:
21090
- _context63.n = 21;
21091
- break;
21595
+ _context63.n = 20;
21596
+ return effects.call(loadOGMetadataForLinkMessages, filteredPendingMessages, true);
21092
21597
  case 20:
21093
- _context63.p = 20;
21598
+ _context63.n = 22;
21599
+ break;
21600
+ case 21:
21601
+ _context63.p = 21;
21094
21602
  _t55 = _context63.v;
21095
21603
  log.error('error in refreshCacheAroundMessage', _t55);
21096
- case 21:
21604
+ case 22:
21097
21605
  return _context63.a(2);
21098
21606
  }
21099
- }, _marked57, null, [[0, 20]]);
21607
+ }, _marked57, null, [[0, 21]]);
21100
21608
  }
21101
21609
  function MessageSaga() {
21102
21610
  return _regenerator().w(function (_context64) {
@@ -21989,6 +22497,42 @@ var MessageStatusIcon = function MessageStatusIcon(_ref) {
21989
22497
  });
21990
22498
  }
21991
22499
  };
22500
+ function extractUrlMatches(text) {
22501
+ var results = [];
22502
+ var protocolRegex = /https?:\/\/\S+/g;
22503
+ var m;
22504
+ while ((m = protocolRegex.exec(text)) !== null) {
22505
+ results.push({
22506
+ text: m[0],
22507
+ url: m[0],
22508
+ index: m.index
22509
+ });
22510
+ }
22511
+ var linkifyResults = new LinkifyIt().match(text);
22512
+ if (linkifyResults) {
22513
+ for (var _iterator = _createForOfIteratorHelperLoose(linkifyResults), _step; !(_step = _iterator()).done;) {
22514
+ var lm = _step.value;
22515
+ if (lm.schema === '') {
22516
+ results.push({
22517
+ text: lm.text,
22518
+ url: lm.url.replace(/^http:\/\//, 'https://'),
22519
+ index: lm.index
22520
+ });
22521
+ }
22522
+ }
22523
+ }
22524
+ results.sort(function (a, b) {
22525
+ return a.index - b.index;
22526
+ });
22527
+ return results.length > 0 ? results.map(function (_ref2) {
22528
+ var text = _ref2.text,
22529
+ url = _ref2.url;
22530
+ return {
22531
+ text: text,
22532
+ url: url
22533
+ };
22534
+ }) : null;
22535
+ }
21992
22536
  var linkifyTextPart = function linkifyTextPart(textPart, match, target, isInviteLink, onInviteLinkClick) {
21993
22537
  if (target === void 0) {
21994
22538
  target = '_blank';
@@ -22037,26 +22581,25 @@ var linkifyTextPart = function linkifyTextPart(textPart, match, target, isInvite
22037
22581
  });
22038
22582
  return newMessageText || textPart;
22039
22583
  };
22040
- var MessageTextFormat = function MessageTextFormat(_ref2) {
22041
- var text = _ref2.text,
22042
- message = _ref2.message,
22043
- contactsMap = _ref2.contactsMap,
22044
- getFromContacts = _ref2.getFromContacts,
22045
- isLastMessage = _ref2.isLastMessage,
22046
- asSampleText = _ref2.asSampleText,
22047
- accentColor = _ref2.accentColor,
22048
- textSecondary = _ref2.textSecondary,
22049
- onMentionNameClick = _ref2.onMentionNameClick,
22050
- shouldOpenUserProfileForMention = _ref2.shouldOpenUserProfileForMention,
22051
- unsupportedMessage = _ref2.unsupportedMessage,
22052
- _ref2$target = _ref2.target,
22053
- target = _ref2$target === void 0 ? '_blank' : _ref2$target,
22054
- _ref2$isInviteLink = _ref2.isInviteLink,
22055
- isInviteLink = _ref2$isInviteLink === void 0 ? false : _ref2$isInviteLink,
22056
- onInviteLinkClick = _ref2.onInviteLinkClick;
22584
+ var MessageTextFormat = function MessageTextFormat(_ref3) {
22585
+ var text = _ref3.text,
22586
+ message = _ref3.message,
22587
+ contactsMap = _ref3.contactsMap,
22588
+ getFromContacts = _ref3.getFromContacts,
22589
+ isLastMessage = _ref3.isLastMessage,
22590
+ asSampleText = _ref3.asSampleText,
22591
+ accentColor = _ref3.accentColor,
22592
+ textSecondary = _ref3.textSecondary,
22593
+ onMentionNameClick = _ref3.onMentionNameClick,
22594
+ shouldOpenUserProfileForMention = _ref3.shouldOpenUserProfileForMention,
22595
+ unsupportedMessage = _ref3.unsupportedMessage,
22596
+ _ref3$target = _ref3.target,
22597
+ target = _ref3$target === void 0 ? '_blank' : _ref3$target,
22598
+ _ref3$isInviteLink = _ref3.isInviteLink,
22599
+ isInviteLink = _ref3$isInviteLink === void 0 ? false : _ref3$isInviteLink,
22600
+ onInviteLinkClick = _ref3.onInviteLinkClick;
22057
22601
  try {
22058
22602
  var messageText = [];
22059
- var linkify = new LinkifyIt();
22060
22603
  var messageBodyAttributes = message.bodyAttributes && JSON.parse(JSON.stringify(message.bodyAttributes));
22061
22604
  if (unsupportedMessage) {
22062
22605
  return 'This message is not supported. Update your app to view this message.';
@@ -22069,12 +22612,12 @@ var MessageTextFormat = function MessageTextFormat(_ref2) {
22069
22612
  var attributeOffset = attribute.offset;
22070
22613
  try {
22071
22614
  var firstPart = "" + (textPart ? textPart === null || textPart === void 0 ? void 0 : textPart.substring(nextPartIndex || 0, attributeOffset) : '');
22072
- var firstPartMatch = firstPart ? linkify.match(firstPart) : '';
22615
+ var firstPartMatch = firstPart ? extractUrlMatches(firstPart) : null;
22073
22616
  if (!isLastMessage && !asSampleText && firstPartMatch) {
22074
22617
  firstPart = linkifyTextPart(firstPart, firstPartMatch, target, isInviteLink, onInviteLinkClick);
22075
22618
  }
22076
22619
  var secondPart = "" + (textPart ? textPart === null || textPart === void 0 ? void 0 : textPart.substring(attributeOffset + attribute.length) : '');
22077
- var secondPartMatch = secondPart ? linkify.match(secondPart) : '';
22620
+ var secondPartMatch = secondPart ? extractUrlMatches(secondPart) : null;
22078
22621
  if (!isLastMessage && !asSampleText && secondPartMatch) {
22079
22622
  secondPart = linkifyTextPart(secondPart, secondPartMatch, target, isInviteLink, onInviteLinkClick);
22080
22623
  }
@@ -22134,7 +22677,7 @@ var MessageTextFormat = function MessageTextFormat(_ref2) {
22134
22677
  } else {
22135
22678
  nextPartIndex = attributeOffset + attribute.length;
22136
22679
  var _textPart = "" + text.slice(attributeOffset, attributeOffset + attribute.length);
22137
- var match = linkify.match(_textPart);
22680
+ var match = extractUrlMatches(_textPart);
22138
22681
  var newTextPart = _textPart;
22139
22682
  if (!isLastMessage && !asSampleText && match) {
22140
22683
  newTextPart = linkifyTextPart(_textPart, match, target, isInviteLink, onInviteLinkClick);
@@ -22151,7 +22694,7 @@ var MessageTextFormat = function MessageTextFormat(_ref2) {
22151
22694
  }
22152
22695
  });
22153
22696
  } else {
22154
- var match = linkify.match(text);
22697
+ var match = extractUrlMatches(text);
22155
22698
  if (!isLastMessage && !asSampleText && match) {
22156
22699
  messageText = linkifyTextPart(text, match, target, isInviteLink, onInviteLinkClick);
22157
22700
  }
@@ -37146,6 +37689,7 @@ var convertToAac = function convertToAac(file, messageId) {
37146
37689
  return Promise.reject(e);
37147
37690
  }
37148
37691
  };
37692
+ var convertMp3ToAac = convertToAac;
37149
37693
  var SAFARI_SUPPORTED_TYPES = new Set(['audio/mp4', 'audio/aac', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'audio/aiff']);
37150
37694
  var convertAudioForSafari = function convertAudioForSafari(file, messageId) {
37151
37695
  try {
@@ -37167,6 +37711,15 @@ var convertAudioForSafari = function convertAudioForSafari(file, messageId) {
37167
37711
  }
37168
37712
  };
37169
37713
 
37714
+ var audioConversion = {
37715
+ __proto__: null,
37716
+ isSafari: isSafari,
37717
+ initFFmpeg: initFFmpeg,
37718
+ convertToAac: convertToAac,
37719
+ convertMp3ToAac: convertMp3ToAac,
37720
+ convertAudioForSafari: convertAudioForSafari
37721
+ };
37722
+
37170
37723
  var _templateObject$v, _templateObject2$r, _templateObject3$l, _templateObject4$h, _templateObject5$e, _templateObject6$b, _templateObject7$a;
37171
37724
  var AudioPlayer = function AudioPlayer(_ref) {
37172
37725
  var _file$metadata6, _file$metadata7;
@@ -38154,80 +38707,82 @@ var Attachment = function Attachment(_ref) {
38154
38707
  }, messageType);
38155
38708
  setDownloadFilePromise(attachment.id, urlPromise);
38156
38709
  return Promise.resolve(urlPromise).then(function (result) {
38157
- function _temp5() {
38158
- setIsCached(true);
38159
- setDownloadingFile(false);
38160
- setAttachmentUrl(downloadingUrl);
38161
- }
38162
- var url = URL.createObjectURL(result.Body);
38163
- setSizeProgress(undefined);
38164
- var downloadingUrl = url;
38165
- var _temp4 = function () {
38166
- if (attachment.type === attachmentTypes.image) {
38167
- return Promise.resolve(compressAndCacheImage(url, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
38168
- if (compressedUrl) {
38169
- downloadingUrl = compressedUrl;
38170
- }
38171
- setAttachmentToCache(attachment.url + '_original_image_url', new Response(result.Body, {
38172
- headers: {
38173
- 'Content-Type': 'image/jpeg'
38710
+ function _temp7(body) {
38711
+ function _temp6() {
38712
+ setIsCached(true);
38713
+ setDownloadingFile(false);
38714
+ setAttachmentUrl(downloadingUrl);
38715
+ }
38716
+ var url = URL.createObjectURL(body);
38717
+ setSizeProgress(undefined);
38718
+ var downloadingUrl = url;
38719
+ var _temp5 = function () {
38720
+ if (attachment.type === attachmentTypes.image) {
38721
+ return Promise.resolve(compressAndCacheImage(url, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
38722
+ if (compressedUrl) {
38723
+ downloadingUrl = compressedUrl;
38174
38724
  }
38175
- }));
38176
- dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_image_url', url));
38177
- });
38178
- } else {
38179
- var _temp3 = function _temp3() {
38180
- if (attachment.type === attachmentTypes.video) {
38181
- setAttachmentToCache(attachment.url + "_original_video_url", new Response(result.Body, {
38182
- headers: {
38183
- 'Content-Type': attachment.type || 'application/octet-stream'
38184
- }
38185
- }));
38186
- dispatch(setUpdateMessageAttachmentAC(attachment.url + "_original_video_url", url));
38187
- } else {
38188
- setAttachmentToCache(attachment.url, new Response(result.Body, {
38725
+ setAttachmentToCache(attachment.url + '_original_image_url', new Response(result.Body, {
38189
38726
  headers: {
38190
- 'Content-Type': attachment.type || 'application/octet-stream'
38727
+ 'Content-Type': 'image/jpeg'
38191
38728
  }
38192
38729
  }));
38193
- dispatch(setUpdateMessageAttachmentAC(attachment.url, url));
38194
- }
38195
- };
38196
- var _temp2 = function () {
38197
- if (attachment.type === attachmentTypes.video) {
38198
- return Promise.resolve(getVideoFirstFrame(url, renderWidth, renderHeight, 0.8)).then(function (result) {
38199
- var _temp = function () {
38200
- if (result) {
38201
- var frameBlobUrl = result.frameBlobUrl,
38202
- blob = result.blob;
38203
- var response = new Response(blob, {
38730
+ dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_image_url', url));
38731
+ });
38732
+ } else {
38733
+ var _temp4 = function () {
38734
+ if (attachment.type === attachmentTypes.video) {
38735
+ return Promise.resolve(getVideoFirstFrame(body, renderWidth, renderHeight, 0.8)).then(function (frameResult) {
38736
+ function _temp3() {
38737
+ setAttachmentToCache(attachment.url + "_original_video_url", new Response(body, {
38204
38738
  headers: {
38205
- 'Content-Type': 'image/jpeg'
38739
+ 'Content-Type': body.type || 'application/octet-stream'
38206
38740
  }
38207
- });
38208
- var key = attachment.url;
38209
- return Promise.resolve(setAttachmentToCache(key, response)).then(function () {
38210
- dispatch(setUpdateMessageAttachmentAC(key, frameBlobUrl));
38211
- });
38741
+ }));
38742
+ dispatch(setUpdateMessageAttachmentAC(attachment.url + "_original_video_url", url));
38212
38743
  }
38213
- }();
38214
- if (_temp && _temp.then) return _temp.then(function () {});
38215
- });
38216
- }
38217
- }();
38218
- return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2);
38219
- }
38220
- }();
38221
- return _temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4);
38744
+ var _temp2 = function () {
38745
+ if (frameResult) {
38746
+ var frameBlobUrl = frameResult.frameBlobUrl,
38747
+ blob = frameResult.blob;
38748
+ var response = new Response(blob, {
38749
+ headers: {
38750
+ 'Content-Type': 'image/jpeg'
38751
+ }
38752
+ });
38753
+ var key = attachment.url;
38754
+ return Promise.resolve(setAttachmentToCache(key, response)).then(function () {
38755
+ dispatch(setUpdateMessageAttachmentAC(key, frameBlobUrl));
38756
+ });
38757
+ }
38758
+ }();
38759
+ return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2);
38760
+ });
38761
+ } else {
38762
+ setAttachmentToCache(attachment.url, new Response(result.Body, {
38763
+ headers: {
38764
+ 'Content-Type': attachment.type || 'application/octet-stream'
38765
+ }
38766
+ }));
38767
+ dispatch(setUpdateMessageAttachmentAC(attachment.url, url));
38768
+ }
38769
+ }();
38770
+ if (_temp4 && _temp4.then) return _temp4.then(function () {});
38771
+ }
38772
+ }();
38773
+ return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
38774
+ }
38775
+ var _temp = attachment.type === attachmentTypes.video;
38776
+ return _temp ? Promise.resolve(ensurePlayableVideoBlob(result.Body)).then(_temp7) : _temp7(result.Body);
38222
38777
  });
38223
38778
  } else {
38224
- var _temp7 = function _temp7(_result2) {
38779
+ var _temp9 = function _temp9(_result2) {
38225
38780
  if (_exit) return _result2;
38226
38781
  setAttachmentUrl(downloadingUrl);
38227
38782
  };
38228
38783
  var _exit = false;
38229
38784
  var downloadingUrl = attachment.url;
38230
- var _temp6 = function () {
38785
+ var _temp8 = function () {
38231
38786
  if (attachment.type === attachmentTypes.image) {
38232
38787
  return Promise.resolve(compressAndCacheImage(attachment.url, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
38233
38788
  if (compressedUrl) {
@@ -38238,47 +38793,51 @@ var Attachment = function Attachment(_ref) {
38238
38793
  } else {
38239
38794
  fetch(attachment.url).then(function (response) {
38240
38795
  try {
38241
- return Promise.resolve(response.blob()).then(function (blob) {
38242
- function _temp1() {
38243
- setAttachmentUrl(blobUrl);
38244
- setIsCached(true);
38245
- }
38246
- var blobUrl = URL.createObjectURL(blob);
38247
- var _temp0 = function () {
38248
- if (attachment.type === attachmentTypes.video) {
38249
- return Promise.resolve(getVideoFirstFrame(blobUrl, renderWidth, renderHeight, 0.8)).then(function (frameResult) {
38250
- function _temp9() {
38251
- setAttachmentToCache(attachment.url + '_original_video_url', new Response(blob, {
38252
- headers: {
38253
- 'Content-Type': blob.type || 'video/mp4'
38254
- }
38255
- }));
38256
- dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_video_url', blobUrl));
38257
- }
38258
- var _temp8 = function () {
38259
- if (frameResult) {
38260
- var frameBlobUrl = frameResult.frameBlobUrl,
38261
- frameBlob = frameResult.blob;
38262
- return Promise.resolve(setAttachmentToCache(attachment.url, new Response(frameBlob, {
38796
+ return Promise.resolve(response.blob()).then(function (rawBlob) {
38797
+ function _temp13(blob) {
38798
+ function _temp12() {
38799
+ setAttachmentUrl(blobUrl);
38800
+ setIsCached(true);
38801
+ }
38802
+ var blobUrl = URL.createObjectURL(blob);
38803
+ var _temp11 = function () {
38804
+ if (attachment.type === attachmentTypes.video) {
38805
+ return Promise.resolve(getVideoFirstFrame(blob, renderWidth, renderHeight, 0.8)).then(function (frameResult) {
38806
+ function _temp10() {
38807
+ setAttachmentToCache(attachment.url + '_original_video_url', new Response(blob, {
38263
38808
  headers: {
38264
- 'Content-Type': 'image/jpeg'
38809
+ 'Content-Type': blob.type || 'video/mp4'
38265
38810
  }
38266
- }))).then(function () {
38267
- dispatch(setUpdateMessageAttachmentAC(getAttachmentURLWithVersion(attachment.url), frameBlobUrl));
38268
- });
38811
+ }));
38812
+ dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_video_url', blobUrl));
38269
38813
  }
38270
- }();
38271
- return _temp8 && _temp8.then ? _temp8.then(_temp9) : _temp9(_temp8);
38272
- });
38273
- } else {
38274
- setAttachmentToCache(attachment.url, new Response(blob, {
38275
- headers: {
38276
- 'Content-Type': blob.type || 'application/octet-stream'
38277
- }
38278
- }));
38279
- }
38280
- }();
38281
- return _temp0 && _temp0.then ? _temp0.then(_temp1) : _temp1(_temp0);
38814
+ var _temp1 = function () {
38815
+ if (frameResult) {
38816
+ var frameBlobUrl = frameResult.frameBlobUrl,
38817
+ frameBlob = frameResult.blob;
38818
+ return Promise.resolve(setAttachmentToCache(attachment.url, new Response(frameBlob, {
38819
+ headers: {
38820
+ 'Content-Type': 'image/jpeg'
38821
+ }
38822
+ }))).then(function () {
38823
+ dispatch(setUpdateMessageAttachmentAC(getAttachmentURLWithVersion(attachment.url), frameBlobUrl));
38824
+ });
38825
+ }
38826
+ }();
38827
+ return _temp1 && _temp1.then ? _temp1.then(_temp10) : _temp10(_temp1);
38828
+ });
38829
+ } else {
38830
+ setAttachmentToCache(attachment.url, new Response(blob, {
38831
+ headers: {
38832
+ 'Content-Type': blob.type || 'application/octet-stream'
38833
+ }
38834
+ }));
38835
+ }
38836
+ }();
38837
+ return _temp11 && _temp11.then ? _temp11.then(_temp12) : _temp12(_temp11);
38838
+ }
38839
+ var _temp0 = attachment.type === attachmentTypes.video;
38840
+ return _temp0 ? Promise.resolve(ensurePlayableVideoBlob(rawBlob)).then(_temp13) : _temp13(rawBlob);
38282
38841
  });
38283
38842
  } catch (e) {
38284
38843
  return Promise.reject(e);
@@ -38289,7 +38848,7 @@ var Attachment = function Attachment(_ref) {
38289
38848
  _exit = true;
38290
38849
  }
38291
38850
  }();
38292
- return _temp6 && _temp6.then ? _temp6.then(_temp7) : _temp7(_temp6);
38851
+ return _temp8 && _temp8.then ? _temp8.then(_temp9) : _temp9(_temp8);
38293
38852
  }
38294
38853
  }());
38295
38854
  } catch (e) {
@@ -38305,9 +38864,9 @@ var Attachment = function Attachment(_ref) {
38305
38864
  if (!attachment.attachmentUrl && connectionStatus === CONNECTION_STATUS.CONNECTED && attachment.id && !attachmentUrlFromMap && !(attachment.type === attachmentTypes.file || attachment.type === attachmentTypes.link)) {
38306
38865
  getAttachmentUrlFromCache(attachment.url).then(function (cachedUrl) {
38307
38866
  try {
38308
- var _temp12 = function () {
38867
+ var _temp16 = function () {
38309
38868
  if (attachment.type === attachmentTypes.image && !isPreview) {
38310
- var _temp11 = function () {
38869
+ var _temp15 = function () {
38311
38870
  if (cachedUrl) {
38312
38871
  setAttachmentUrl(cachedUrl);
38313
38872
  dispatch(setUpdateMessageAttachmentAC(attachment.url, cachedUrl));
@@ -38315,7 +38874,7 @@ var Attachment = function Attachment(_ref) {
38315
38874
  } else {
38316
38875
  setIsCached(false);
38317
38876
  setDownloadingFile(true);
38318
- var _temp10 = function () {
38877
+ var _temp14 = function () {
38319
38878
  if (customDownloader) {
38320
38879
  customDownloader(attachment.url, false, function (progress) {
38321
38880
  var loadedRes = progress.loaded && progress.loaded / progress.total;
@@ -38367,10 +38926,10 @@ var Attachment = function Attachment(_ref) {
38367
38926
  });
38368
38927
  }
38369
38928
  }();
38370
- if (_temp10 && _temp10.then) return _temp10.then(function () {});
38929
+ if (_temp14 && _temp14.then) return _temp14.then(function () {});
38371
38930
  }
38372
38931
  }();
38373
- if (_temp11 && _temp11.then) return _temp11.then(function () {});
38932
+ if (_temp15 && _temp15.then) return _temp15.then(function () {});
38374
38933
  } else {
38375
38934
  if (cachedUrl) {
38376
38935
  setAttachmentUrl(cachedUrl);
@@ -38384,7 +38943,7 @@ var Attachment = function Attachment(_ref) {
38384
38943
  }
38385
38944
  }
38386
38945
  }();
38387
- return Promise.resolve(_temp12 && _temp12.then ? _temp12.then(function () {}) : void 0);
38946
+ return Promise.resolve(_temp16 && _temp16.then ? _temp16.then(function () {}) : void 0);
38388
38947
  } catch (e) {
38389
38948
  return Promise.reject(e);
38390
38949
  }
@@ -38402,13 +38961,13 @@ var Attachment = function Attachment(_ref) {
38402
38961
  setProgress(uploadPercent);
38403
38962
  }, messageType).then(function (url) {
38404
38963
  try {
38405
- var _temp14 = function _temp14() {
38964
+ var _temp18 = function _temp18() {
38406
38965
  setAttachmentUrl(downloadingUrl);
38407
38966
  dispatch(setUpdateMessageAttachmentAC(attachment.url, attachment.url));
38408
38967
  setDownloadingFile(false);
38409
38968
  };
38410
38969
  var downloadingUrl = url;
38411
- var _temp13 = function () {
38970
+ var _temp17 = function () {
38412
38971
  if (attachment.type === attachmentTypes.image) {
38413
38972
  return Promise.resolve(compressAndCacheImage(url, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
38414
38973
  if (compressedUrl) {
@@ -38421,7 +38980,7 @@ var Attachment = function Attachment(_ref) {
38421
38980
  });
38422
38981
  }
38423
38982
  }();
38424
- return Promise.resolve(_temp13 && _temp13.then ? _temp13.then(_temp14) : _temp14(_temp13));
38983
+ return Promise.resolve(_temp17 && _temp17.then ? _temp17.then(_temp18) : _temp18(_temp17));
38425
38984
  } catch (e) {
38426
38985
  return Promise.reject(e);
38427
38986
  }
@@ -44670,6 +45229,7 @@ function useChatController(_ref5) {
44670
45229
  restoreRef.current = null;
44671
45230
  pendingNewestCountRef.current = 0;
44672
45231
  setPendingNewestCount(0);
45232
+ unreadRestoreCompletedRef.current = true;
44673
45233
  var container = scrollRef.current;
44674
45234
  var currentChannelId = (_channelRef$current = channelRef.current) === null || _channelRef$current === void 0 ? void 0 : _channelRef$current.id;
44675
45235
  var pendingLatestServerSync = ((_pendingLatestJumpRef = pendingLatestJumpRef.current) === null || _pendingLatestJumpRef === void 0 ? void 0 : _pendingLatestJumpRef.channelId) === currentChannelId && ((_pendingLatestJumpRef2 = pendingLatestJumpRef.current) === null || _pendingLatestJumpRef2 === void 0 ? void 0 : _pendingLatestJumpRef2.needsServerSync);
@@ -45536,6 +46096,7 @@ function useChatController(_ref5) {
45536
46096
  restoreRef.current = null;
45537
46097
  viewIsAtLatestRef.current = true;
45538
46098
  setIsViewingLatest(true);
46099
+ lockJumpScrolling(true, 'latest');
45539
46100
  scrollToLatestEdge(container, 'smooth');
45540
46101
  rememberLatestEdge();
45541
46102
  return;
@@ -45596,7 +46157,7 @@ function useChatController(_ref5) {
45596
46157
  }
45597
46158
  rememberLatestEdge();
45598
46159
  }
45599
- }, [channel.id, unreadMessageId, isActiveEdgeRequestCurrent, dispatch, messages, unreadScrollTo, clearJumpBlur, hasNext, isScrollInteractionActive]);
46160
+ }, [channel.id, unreadMessageId, isActiveEdgeRequestCurrent, dispatch, messages, unreadScrollTo, clearJumpBlur, hasNext, isScrollInteractionActive, lockJumpScrolling]);
45600
46161
  React.useEffect(function () {
45601
46162
  if (!unreadScrollTo || !unreadMessageId || !messages.length || unreadRestoreCompletedRef.current) {
45602
46163
  return;
@@ -50751,10 +51312,10 @@ var SendMessageInput = function SendMessageInput(_ref3) {
50751
51312
  editorState.read(function () {
50752
51313
  var root = lexical.$getRoot();
50753
51314
  var textContent = root.getTextContent();
50754
- var matches = linkify.match(textContent);
50755
- if (matches && matches.length > 0) {
50756
- var rawUrl = matches[0].url;
50757
- var firstUrl = matches[0].schema === '' ? rawUrl.replace(/^http:\/\//, 'https://') : rawUrl;
51315
+ var protocolMatch = /https?:\/\/\S+/.exec(textContent);
51316
+ var linkifyMatchResult = !protocolMatch ? linkify.match(textContent) : null;
51317
+ var firstUrl = protocolMatch ? protocolMatch[0] : linkifyMatchResult !== null && linkifyMatchResult !== void 0 && linkifyMatchResult[0] ? linkifyMatchResult[0].schema === '' ? linkifyMatchResult[0].url.replace(/^http:\/\//, 'https://') : linkifyMatchResult[0].url : null;
51318
+ if (firstUrl) {
50758
51319
  if (firstUrl !== detectedUrl) {
50759
51320
  closePreviewWithAnimation(function () {
50760
51321
  if (!dismissedUrls.has(firstUrl)) {
@@ -50914,11 +51475,11 @@ var SendMessageInput = function SendMessageInput(_ref3) {
50914
51475
  }
50915
51476
  var linkAttachment;
50916
51477
  if (messageTexToSend) {
50917
- var _linkify = new LinkifyIt();
50918
- var match = _linkify.match(messageTexToSend);
50919
- if (match) {
50920
- var rawUrl = match[0].url;
50921
- var url = match[0].schema === '' ? rawUrl.replace(/^http:\/\//, 'https://') : rawUrl;
51478
+ var _LinkifyIt$match;
51479
+ var protocolMatch = /https?:\/\/\S+/.exec(messageTexToSend);
51480
+ var linkifyMatchResult = !protocolMatch ? (_LinkifyIt$match = new LinkifyIt().match(messageTexToSend)) === null || _LinkifyIt$match === void 0 ? void 0 : _LinkifyIt$match[0] : null;
51481
+ var url = protocolMatch ? protocolMatch[0] : linkifyMatchResult ? linkifyMatchResult.schema === '' ? linkifyMatchResult.url.replace(/^http:\/\//, 'https://') : linkifyMatchResult.url : null;
51482
+ if (url) {
50922
51483
  var urlMetadata = oGMetadata === null || oGMetadata === void 0 ? void 0 : oGMetadata[url];
50923
51484
  var metadata = {};
50924
51485
  if (urlMetadata) {
@@ -51033,11 +51594,11 @@ var SendMessageInput = function SendMessageInput(_ref3) {
51033
51594
  if (messageTexToSend) {
51034
51595
  var linkAttachment;
51035
51596
  if (messageTexToSend) {
51036
- var _linkify2 = new LinkifyIt();
51037
- var match = _linkify2.match(messageTexToSend);
51038
- if (match) {
51039
- var rawUrl = match[0].url;
51040
- var url = match[0].schema === '' ? rawUrl.replace(/^http:\/\//, 'https://') : rawUrl;
51597
+ var _LinkifyIt$match2;
51598
+ var protocolMatch = /https?:\/\/\S+/.exec(messageTexToSend);
51599
+ var linkifyMatchResult = !protocolMatch ? (_LinkifyIt$match2 = new LinkifyIt().match(messageTexToSend)) === null || _LinkifyIt$match2 === void 0 ? void 0 : _LinkifyIt$match2[0] : null;
51600
+ var url = protocolMatch ? protocolMatch[0] : linkifyMatchResult ? linkifyMatchResult.schema === '' ? linkifyMatchResult.url.replace(/^http:\/\//, 'https://') : linkifyMatchResult.url : null;
51601
+ if (url) {
51041
51602
  var urlMetadata = oGMetadata === null || oGMetadata === void 0 ? void 0 : oGMetadata[url];
51042
51603
  var metadata = {};
51043
51604
  if (urlMetadata) {
@@ -51337,252 +51898,260 @@ var SendMessageInput = function SendMessageInput(_ref3) {
51337
51898
  };
51338
51899
  var handleAddAttachment = function handleAddAttachment(file, isMediaAttachment) {
51339
51900
  try {
51340
- var customUploader = getCustomUploader();
51341
- var fileType = file.type.split('/')[0];
51342
- var tid = uuid.v4();
51343
- var reader = new FileReader();
51344
- var handleAttachmentImageForCache = function handleAttachmentImageForCache(attachment) {
51345
- try {
51346
- var _attachment$metadata;
51347
- var url = URL.createObjectURL(attachment.data);
51348
- dispatch(setUpdateMessageAttachmentAC((attachment === null || attachment === void 0 ? void 0 : (_attachment$metadata = attachment.metadata) === null || _attachment$metadata === void 0 ? void 0 : _attachment$metadata.tmb) || '', url));
51349
- return Promise.resolve();
51350
- } catch (e) {
51351
- return Promise.reject(e);
51352
- }
51353
- };
51354
- var handleAttachmentVideoForCache = function handleAttachmentVideoForCache(attachment) {
51355
- try {
51356
- var _calculateRenderedIma = calculateRenderedImageWidth(attachment.metadata.szh || 400, attachment.metadata.szh || 400),
51357
- newWidth = _calculateRenderedIma[0],
51358
- newHeight = _calculateRenderedIma[1];
51359
- var url = URL.createObjectURL(attachment.data);
51360
- return Promise.resolve(getVideoFirstFrame(url, newWidth, newHeight, 0.8)).then(function (result) {
51361
- if (result) {
51362
- var _attachment$metadata2;
51363
- var frameBlobUrl = result.frameBlobUrl;
51364
- dispatch(setUpdateMessageAttachmentAC((attachment === null || attachment === void 0 ? void 0 : (_attachment$metadata2 = attachment.metadata) === null || _attachment$metadata2 === void 0 ? void 0 : _attachment$metadata2.tmb) || '', frameBlobUrl));
51365
- }
51366
- });
51367
- } catch (e) {
51368
- return Promise.reject(e);
51369
- }
51370
- };
51371
- reader.onload = function () {
51372
- try {
51373
- setPendingAttachment(tid, {
51374
- file: file
51375
- });
51376
- var _temp8 = function () {
51377
- if (customUploader) {
51378
- var _temp4 = function () {
51379
- if (fileType === 'image') {
51380
- resizeImage(file).then(function (resizedFile) {
51381
- try {
51382
- return Promise.resolve(createImageThumbnail(file)).then(function (_ref4) {
51383
- var _resizedFile$blob;
51384
- var thumbnail = _ref4.thumbnail,
51385
- imageWidth = _ref4.imageWidth,
51386
- imageHeight = _ref4.imageHeight;
51387
- var attachment = {
51388
- data: file,
51389
- upload: false,
51390
- type: isMediaAttachment ? fileType : 'file',
51391
- attachmentUrl: URL.createObjectURL(resizedFile.blob),
51392
- tid: tid,
51393
- size: isMediaAttachment ? resizedFile !== null && resizedFile !== void 0 && resizedFile.blob ? resizedFile === null || resizedFile === void 0 ? void 0 : (_resizedFile$blob = resizedFile.blob) === null || _resizedFile$blob === void 0 ? void 0 : _resizedFile$blob.size : file.size : file.size,
51394
- metadata: {
51395
- szw: imageWidth,
51396
- szh: imageHeight,
51397
- tmb: thumbnail
51398
- }
51399
- };
51400
- handleAttachmentImageForCache(attachment);
51901
+ var _temp4 = function _temp4() {
51902
+ var fileType = file.type.split('/')[0];
51903
+ var tid = uuid.v4();
51904
+ var reader = new FileReader();
51905
+ var handleAttachmentImageForCache = function handleAttachmentImageForCache(attachment) {
51906
+ try {
51907
+ var _attachment$metadata;
51908
+ var url = URL.createObjectURL(attachment.data);
51909
+ dispatch(setUpdateMessageAttachmentAC((attachment === null || attachment === void 0 ? void 0 : (_attachment$metadata = attachment.metadata) === null || _attachment$metadata === void 0 ? void 0 : _attachment$metadata.tmb) || '', url));
51910
+ return Promise.resolve();
51911
+ } catch (e) {
51912
+ return Promise.reject(e);
51913
+ }
51914
+ };
51915
+ var handleAttachmentVideoForCache = function handleAttachmentVideoForCache(attachment) {
51916
+ try {
51917
+ var _calculateRenderedIma = calculateRenderedImageWidth(attachment.metadata.szh || 400, attachment.metadata.szh || 400),
51918
+ newWidth = _calculateRenderedIma[0],
51919
+ newHeight = _calculateRenderedIma[1];
51920
+ return Promise.resolve(getVideoFirstFrame(attachment.data, newWidth, newHeight, 0.8)).then(function (result) {
51921
+ if (result) {
51922
+ var _attachment$metadata2;
51923
+ var frameBlobUrl = result.frameBlobUrl;
51924
+ dispatch(setUpdateMessageAttachmentAC((attachment === null || attachment === void 0 ? void 0 : (_attachment$metadata2 = attachment.metadata) === null || _attachment$metadata2 === void 0 ? void 0 : _attachment$metadata2.tmb) || '', frameBlobUrl));
51925
+ }
51926
+ });
51927
+ } catch (e) {
51928
+ return Promise.reject(e);
51929
+ }
51930
+ };
51931
+ reader.onload = function () {
51932
+ try {
51933
+ setPendingAttachment(tid, {
51934
+ file: file
51935
+ });
51936
+ var _temp0 = function () {
51937
+ if (customUploader) {
51938
+ var _temp6 = function () {
51939
+ if (fileType === 'image') {
51940
+ resizeImage(file).then(function (resizedFile) {
51941
+ try {
51942
+ return Promise.resolve(createImageThumbnail(file)).then(function (_ref4) {
51943
+ var _resizedFile$blob;
51944
+ var thumbnail = _ref4.thumbnail,
51945
+ imageWidth = _ref4.imageWidth,
51946
+ imageHeight = _ref4.imageHeight;
51947
+ var attachment = {
51948
+ data: file,
51949
+ upload: false,
51950
+ type: isMediaAttachment ? fileType : 'file',
51951
+ attachmentUrl: URL.createObjectURL(resizedFile.blob),
51952
+ tid: tid,
51953
+ size: isMediaAttachment ? resizedFile !== null && resizedFile !== void 0 && resizedFile.blob ? resizedFile === null || resizedFile === void 0 ? void 0 : (_resizedFile$blob = resizedFile.blob) === null || _resizedFile$blob === void 0 ? void 0 : _resizedFile$blob.size : file.size : file.size,
51954
+ metadata: {
51955
+ szw: imageWidth,
51956
+ szh: imageHeight,
51957
+ tmb: thumbnail
51958
+ }
51959
+ };
51960
+ handleAttachmentImageForCache(attachment);
51961
+ setAttachments(function (prevState) {
51962
+ return [].concat(prevState, [attachment]);
51963
+ });
51964
+ });
51965
+ } catch (e) {
51966
+ return Promise.reject(e);
51967
+ }
51968
+ });
51969
+ } else {
51970
+ var _temp1 = function () {
51971
+ if (fileType === 'video') {
51972
+ return Promise.resolve(getFrame(file, 0)).then(function (_ref5) {
51973
+ var thumb = _ref5.thumb,
51974
+ width = _ref5.width,
51975
+ height = _ref5.height,
51976
+ duration = _ref5.duration;
51977
+ var attachment = {
51978
+ data: file,
51979
+ upload: false,
51980
+ type: isMediaAttachment ? fileType : 'file',
51981
+ attachmentUrl: URL.createObjectURL(file),
51982
+ tid: tid,
51983
+ size: file.size,
51984
+ metadata: {
51985
+ szw: width,
51986
+ szh: height,
51987
+ tmb: thumb,
51988
+ dur: duration
51989
+ }
51990
+ };
51991
+ handleAttachmentVideoForCache(attachment);
51992
+ setAttachments(function (prevState) {
51993
+ return [].concat(prevState, [attachment]);
51994
+ });
51995
+ });
51996
+ } else {
51401
51997
  setAttachments(function (prevState) {
51402
- return [].concat(prevState, [attachment]);
51998
+ return [].concat(prevState, [{
51999
+ data: file,
52000
+ upload: false,
52001
+ type: 'file',
52002
+ tid: tid,
52003
+ size: file.size
52004
+ }]);
51403
52005
  });
51404
- });
51405
- } catch (e) {
51406
- return Promise.reject(e);
51407
- }
51408
- });
51409
- } else {
51410
- var _temp9 = function () {
51411
- if (fileType === 'video') {
51412
- return Promise.resolve(getFrame(URL.createObjectURL(file), 0)).then(function (_ref5) {
51413
- var thumb = _ref5.thumb,
51414
- width = _ref5.width,
51415
- height = _ref5.height,
51416
- duration = _ref5.duration;
51417
- var attachment = {
51418
- data: file,
51419
- upload: false,
51420
- type: isMediaAttachment ? fileType : 'file',
51421
- attachmentUrl: URL.createObjectURL(file),
51422
- tid: tid,
51423
- size: file.size,
51424
- metadata: {
51425
- szw: width,
51426
- szh: height,
51427
- tmb: thumb,
51428
- dur: duration
52006
+ }
52007
+ }();
52008
+ if (_temp1 && _temp1.then) return _temp1.then(function () {});
52009
+ }
52010
+ }();
52011
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
52012
+ } else {
52013
+ var _temp9 = function () {
52014
+ if (fileType === 'image') {
52015
+ var _temp7 = function () {
52016
+ if (isMediaAttachment) {
52017
+ return Promise.resolve(createImageThumbnail(file)).then(function (_ref6) {
52018
+ var thumbnail = _ref6.thumbnail,
52019
+ imageWidth = _ref6.imageWidth,
52020
+ imageHeight = _ref6.imageHeight;
52021
+ var metas = {
52022
+ thumbnail: thumbnail,
52023
+ imageWidth: imageWidth,
52024
+ imageHeight: imageHeight
52025
+ };
52026
+ if (file.type === 'image/gif') {
52027
+ setAttachments(function (prevState) {
52028
+ return [].concat(prevState, [{
52029
+ data: file,
52030
+ upload: true,
52031
+ attachmentUrl: URL.createObjectURL(file),
52032
+ tid: tid,
52033
+ type: fileType,
52034
+ size: file.size,
52035
+ metadata: JSON.stringify({
52036
+ tmb: metas.thumbnail,
52037
+ szw: metas.imageWidth,
52038
+ szh: metas.imageHeight
52039
+ })
52040
+ }]);
52041
+ });
52042
+ } else {
52043
+ resizeImage(file).then(function (resizedFileData) {
52044
+ try {
52045
+ var resizedFile = new File([resizedFileData.blob], resizedFileData.file.name);
52046
+ var attachment = {
52047
+ data: resizedFile,
52048
+ upload: true,
52049
+ attachmentUrl: URL.createObjectURL(resizedFile),
52050
+ tid: tid,
52051
+ type: fileType,
52052
+ size: resizedFile.size,
52053
+ metadata: JSON.stringify({
52054
+ tmb: metas.thumbnail,
52055
+ szw: resizedFileData.newWidth,
52056
+ szh: resizedFileData.newHeight
52057
+ })
52058
+ };
52059
+ handleAttachmentImageForCache(attachment);
52060
+ setAttachments(function (prevState) {
52061
+ return [].concat(prevState, [attachment]);
52062
+ });
52063
+ return Promise.resolve();
52064
+ } catch (e) {
52065
+ return Promise.reject(e);
52066
+ }
52067
+ });
51429
52068
  }
51430
- };
51431
- handleAttachmentVideoForCache(attachment);
51432
- setAttachments(function (prevState) {
51433
- return [].concat(prevState, [attachment]);
51434
52069
  });
51435
- });
51436
- } else {
51437
- setAttachments(function (prevState) {
51438
- return [].concat(prevState, [{
51439
- data: file,
51440
- upload: false,
51441
- type: 'file',
51442
- tid: tid,
51443
- size: file.size
51444
- }]);
51445
- });
51446
- }
51447
- }();
51448
- if (_temp9 && _temp9.then) return _temp9.then(function () {});
51449
- }
51450
- }();
51451
- if (_temp4 && _temp4.then) return _temp4.then(function () {});
51452
- } else {
51453
- var _temp7 = function () {
51454
- if (fileType === 'image') {
51455
- var _temp5 = function () {
51456
- if (isMediaAttachment) {
51457
- return Promise.resolve(createImageThumbnail(file)).then(function (_ref6) {
51458
- var thumbnail = _ref6.thumbnail,
51459
- imageWidth = _ref6.imageWidth,
51460
- imageHeight = _ref6.imageHeight;
51461
- var metas = {
51462
- thumbnail: thumbnail,
51463
- imageWidth: imageWidth,
51464
- imageHeight: imageHeight
51465
- };
51466
- if (file.type === 'image/gif') {
52070
+ } else {
52071
+ return Promise.resolve(createImageThumbnail(file, undefined, 50, 50)).then(function (_ref7) {
52072
+ var thumbnail = _ref7.thumbnail;
51467
52073
  setAttachments(function (prevState) {
51468
52074
  return [].concat(prevState, [{
51469
52075
  data: file,
52076
+ type: 'file',
51470
52077
  upload: true,
51471
52078
  attachmentUrl: URL.createObjectURL(file),
51472
52079
  tid: tid,
51473
- type: fileType,
51474
52080
  size: file.size,
51475
52081
  metadata: JSON.stringify({
51476
- tmb: metas.thumbnail,
51477
- szw: metas.imageWidth,
51478
- szh: metas.imageHeight
52082
+ tmb: thumbnail
51479
52083
  })
51480
52084
  }]);
51481
52085
  });
51482
- } else {
51483
- resizeImage(file).then(function (resizedFileData) {
51484
- try {
51485
- var resizedFile = new File([resizedFileData.blob], resizedFileData.file.name);
51486
- var attachment = {
51487
- data: resizedFile,
51488
- upload: true,
51489
- attachmentUrl: URL.createObjectURL(resizedFile),
51490
- tid: tid,
51491
- type: fileType,
51492
- size: resizedFile.size,
51493
- metadata: JSON.stringify({
51494
- tmb: metas.thumbnail,
51495
- szw: resizedFileData.newWidth,
51496
- szh: resizedFileData.newHeight
51497
- })
51498
- };
51499
- handleAttachmentImageForCache(attachment);
51500
- setAttachments(function (prevState) {
51501
- return [].concat(prevState, [attachment]);
51502
- });
51503
- return Promise.resolve();
51504
- } catch (e) {
51505
- return Promise.reject(e);
51506
- }
52086
+ });
52087
+ }
52088
+ }();
52089
+ if (_temp7 && _temp7.then) return _temp7.then(function () {});
52090
+ } else {
52091
+ var _temp10 = function () {
52092
+ if (fileType === 'video') {
52093
+ return Promise.resolve(getFrame(file, 0)).then(function (_ref8) {
52094
+ var thumb = _ref8.thumb,
52095
+ width = _ref8.width,
52096
+ height = _ref8.height,
52097
+ duration = _ref8.duration;
52098
+ var metas = JSON.stringify({
52099
+ tmb: thumb,
52100
+ width: width,
52101
+ height: height,
52102
+ dur: duration
51507
52103
  });
51508
- }
51509
- });
51510
- } else {
51511
- return Promise.resolve(createImageThumbnail(file, undefined, 50, 50)).then(function (_ref7) {
51512
- var thumbnail = _ref7.thumbnail;
51513
- setAttachments(function (prevState) {
51514
- return [].concat(prevState, [{
52104
+ var attachment = {
51515
52105
  data: file,
51516
- type: 'file',
52106
+ type: 'video',
51517
52107
  upload: true,
52108
+ size: file.size,
51518
52109
  attachmentUrl: URL.createObjectURL(file),
51519
52110
  tid: tid,
51520
- size: file.size,
51521
- metadata: JSON.stringify({
51522
- tmb: thumbnail
51523
- })
51524
- }]);
51525
- });
51526
- });
51527
- }
51528
- }();
51529
- if (_temp5 && _temp5.then) return _temp5.then(function () {});
51530
- } else {
51531
- var _temp0 = function () {
51532
- if (fileType === 'video') {
51533
- return Promise.resolve(getFrame(URL.createObjectURL(file), 0)).then(function (_ref8) {
51534
- var thumb = _ref8.thumb,
51535
- width = _ref8.width,
51536
- height = _ref8.height,
51537
- duration = _ref8.duration;
51538
- var metas = JSON.stringify({
51539
- tmb: thumb,
51540
- width: width,
51541
- height: height,
51542
- dur: duration
52111
+ metadata: metas
52112
+ };
52113
+ handleAttachmentVideoForCache(attachment);
52114
+ setAttachments(function (prevState) {
52115
+ return [].concat(prevState, [attachment]);
52116
+ });
51543
52117
  });
51544
- var attachment = {
51545
- data: file,
51546
- type: 'video',
51547
- upload: true,
51548
- size: file.size,
51549
- attachmentUrl: URL.createObjectURL(file),
51550
- tid: tid,
51551
- metadata: metas
51552
- };
51553
- handleAttachmentVideoForCache(attachment);
52118
+ } else {
51554
52119
  setAttachments(function (prevState) {
51555
- return [].concat(prevState, [attachment]);
52120
+ return [].concat(prevState, [{
52121
+ data: file,
52122
+ upload: true,
52123
+ type: 'file',
52124
+ size: file.size,
52125
+ tid: tid
52126
+ }]);
51556
52127
  });
51557
- });
51558
- } else {
51559
- setAttachments(function (prevState) {
51560
- return [].concat(prevState, [{
51561
- data: file,
51562
- upload: true,
51563
- type: 'file',
51564
- size: file.size,
51565
- tid: tid
51566
- }]);
51567
- });
51568
- }
51569
- }();
51570
- if (_temp0 && _temp0.then) return _temp0.then(function () {});
51571
- }
51572
- }();
51573
- if (_temp7 && _temp7.then) return _temp7.then(function () {});
51574
- }
51575
- }();
51576
- return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(function () {}) : void 0);
51577
- } catch (e) {
51578
- return Promise.reject(e);
51579
- }
51580
- };
51581
- reader.onerror = function (e) {
51582
- log.info(' error on read file onError', e);
52128
+ }
52129
+ }();
52130
+ if (_temp10 && _temp10.then) return _temp10.then(function () {});
52131
+ }
52132
+ }();
52133
+ if (_temp9 && _temp9.then) return _temp9.then(function () {});
52134
+ }
52135
+ }();
52136
+ return Promise.resolve(_temp0 && _temp0.then ? _temp0.then(function () {}) : void 0);
52137
+ } catch (e) {
52138
+ return Promise.reject(e);
52139
+ }
52140
+ };
52141
+ reader.onerror = function (e) {
52142
+ log.info(' error on read file onError', e);
52143
+ };
52144
+ reader.readAsBinaryString(file);
51583
52145
  };
51584
- reader.readAsBinaryString(file);
51585
- return Promise.resolve();
52146
+ var customUploader = getCustomUploader();
52147
+ var _temp3 = function () {
52148
+ if (file.type.split('/')[0] === 'video') {
52149
+ return Promise.resolve(remuxVideoFileForUpload(file)).then(function (_remuxVideoFileForUpl) {
52150
+ file = _remuxVideoFileForUpl;
52151
+ });
52152
+ }
52153
+ }();
52154
+ return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3));
51586
52155
  } catch (e) {
51587
52156
  return Promise.reject(e);
51588
52157
  }
@@ -51641,14 +52210,14 @@ var SendMessageInput = function SendMessageInput(_ref3) {
51641
52210
  }
51642
52211
  }
51643
52212
  }
51644
- var _temp1 = function () {
52213
+ var _temp11 = function () {
51645
52214
  if (allowUpload) {
51646
52215
  return Promise.resolve(handleAddAttachmentWithViewOnceCheck(file, isMediaAttachment)).then(function () {});
51647
52216
  } else {
51648
52217
  showFileUploadError(errorMessage);
51649
52218
  }
51650
52219
  }();
51651
- return Promise.resolve(_temp1 && _temp1.then ? _temp1.then(function () {}) : void 0);
52220
+ return Promise.resolve(_temp11 && _temp11.then ? _temp11.then(function () {}) : void 0);
51652
52221
  } catch (e) {
51653
52222
  return Promise.reject(e);
51654
52223
  }
@@ -58018,6 +58587,7 @@ exports.SendMessage = SendMessageInput;
58018
58587
  exports.THEME_COLORS = THEME_COLORS;
58019
58588
  exports.blockUsers = blockUsers;
58020
58589
  exports.createOrGetDirectChannel = createOrGetDirectChannel;
58590
+ exports.extractUrlMatches = extractUrlMatches;
58021
58591
  exports.handleGetMessage = handleGetMessage;
58022
58592
  exports.handleSendMessage = handleSendMessage;
58023
58593
  exports.switchChannelActiveChannel = switchChannelActiveChannel;