sceyt-chat-react-uikit 1.8.3-beta.3 → 1.8.3-beta.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.
package/index.js CHANGED
@@ -10389,6 +10389,7 @@ var queryDirection = {
10389
10389
  };
10390
10390
 
10391
10391
  var ATTACHMENTS_CACHE = 'attachments-cache';
10392
+ var ATTACHMENT_VERSION_KEY = 'sceyt_attachment_cache_version';
10392
10393
  var isBrowser = typeof window !== 'undefined';
10393
10394
  var cacheAvailable;
10394
10395
  if (isBrowser) {
@@ -10396,7 +10397,7 @@ if (isBrowser) {
10396
10397
  } else {
10397
10398
  cacheAvailable = 'caches' in global;
10398
10399
  }
10399
- var ATTACHMENT_VERSION = "_1_0_0";
10400
+ var ATTACHMENT_VERSION = "_1_0_1";
10400
10401
  var setAttachmentToCache = function setAttachmentToCache(attachmentUrl, attachmentResponse) {
10401
10402
  try {
10402
10403
  var attachmentURLVersion = attachmentUrl + ATTACHMENT_VERSION;
@@ -10475,6 +10476,49 @@ var getAttachmentUrlFromCache = function getAttachmentUrlFromCache(attachmentUrl
10475
10476
  var getAttachmentURLWithVersion = function getAttachmentURLWithVersion(attachmentUrl) {
10476
10477
  return attachmentUrl + ATTACHMENT_VERSION;
10477
10478
  };
10479
+ var cleanupOldAttachmentCache = function cleanupOldAttachmentCache() {
10480
+ try {
10481
+ if (!cacheAvailable || !isBrowser) {
10482
+ return Promise.resolve();
10483
+ }
10484
+ return Promise.resolve(_catch(function () {
10485
+ function _temp0() {
10486
+ localStorage.setItem(ATTACHMENT_VERSION_KEY, ATTACHMENT_VERSION);
10487
+ }
10488
+ var storedVersion = localStorage.getItem(ATTACHMENT_VERSION_KEY) || '_1_0_0';
10489
+ var _temp9 = function () {
10490
+ if (storedVersion && storedVersion !== ATTACHMENT_VERSION) {
10491
+ log.info("Attachment cache version changed from " + storedVersion + " to " + ATTACHMENT_VERSION + ", cleaning up old cache...");
10492
+ return Promise.resolve(caches.open(ATTACHMENTS_CACHE)).then(function (cache) {
10493
+ return Promise.resolve(cache.keys()).then(function (requests) {
10494
+ function _temp8() {
10495
+ log.info("Cleaned up " + deletedCount + " old cached attachments");
10496
+ }
10497
+ var deletedCount = 0;
10498
+ var _temp7 = _forOf(requests, function (request) {
10499
+ var url = request.url;
10500
+ var _temp6 = function () {
10501
+ if (url.includes(storedVersion)) {
10502
+ return Promise.resolve(cache["delete"](request)).then(function () {
10503
+ deletedCount++;
10504
+ });
10505
+ }
10506
+ }();
10507
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
10508
+ });
10509
+ return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7);
10510
+ });
10511
+ });
10512
+ }
10513
+ }();
10514
+ return _temp9 && _temp9.then ? _temp9.then(_temp0) : _temp0(_temp9);
10515
+ }, function (error) {
10516
+ log.error('Error cleaning up old attachment cache:', error);
10517
+ }));
10518
+ } catch (e) {
10519
+ return Promise.reject(e);
10520
+ }
10521
+ };
10478
10522
 
10479
10523
  function sendMessageAC(message, channelId, connectionState, sendAttachmentsAsSeparateMessage, isResend) {
10480
10524
  return {
@@ -20071,16 +20115,21 @@ var resizeImageWithPica = function resizeImageWithPica(file, maxWidth, maxHeight
20071
20115
  newHeight: img.height
20072
20116
  };
20073
20117
  }
20118
+ var srcCanvas = document.createElement('canvas');
20119
+ srcCanvas.width = img.width;
20120
+ srcCanvas.height = img.height;
20121
+ var srcCtx = srcCanvas.getContext('2d');
20122
+ srcCtx.drawImage(img, 0, 0);
20123
+ URL.revokeObjectURL(url);
20074
20124
  var canvas = document.createElement('canvas');
20075
20125
  canvas.width = newWidth;
20076
20126
  canvas.height = newHeight;
20077
- return Promise.resolve(pica.resize(img, canvas, {
20127
+ return Promise.resolve(pica.resize(srcCanvas, canvas, {
20078
20128
  quality: 3,
20079
20129
  unsharpAmount: 80,
20080
20130
  unsharpRadius: 0.6,
20081
20131
  unsharpThreshold: 2
20082
20132
  })).then(function () {
20083
- URL.revokeObjectURL(url);
20084
20133
  var originalType = file.type || 'image/jpeg';
20085
20134
  var outputType = type || 'image/webp';
20086
20135
  if (outputType === 'image/webp' && !canvas.toDataURL('image/webp').includes('webp')) {
@@ -25986,6 +26035,7 @@ var SceytChat = function SceytChat(_ref) {
25986
26035
  React.useEffect(function () {
25987
26036
  log.info('client is changed.... ', client);
25988
26037
  if (client) {
26038
+ cleanupOldAttachmentCache();
25989
26039
  setClient(client);
25990
26040
  setSceytChatClient(client);
25991
26041
  dispatch(setUserAC(client.user));
package/index.modern.js CHANGED
@@ -10388,6 +10388,7 @@ var queryDirection = {
10388
10388
  };
10389
10389
 
10390
10390
  var ATTACHMENTS_CACHE = 'attachments-cache';
10391
+ var ATTACHMENT_VERSION_KEY = 'sceyt_attachment_cache_version';
10391
10392
  var isBrowser = typeof window !== 'undefined';
10392
10393
  var cacheAvailable;
10393
10394
  if (isBrowser) {
@@ -10395,7 +10396,7 @@ if (isBrowser) {
10395
10396
  } else {
10396
10397
  cacheAvailable = 'caches' in global;
10397
10398
  }
10398
- var ATTACHMENT_VERSION = "_1_0_0";
10399
+ var ATTACHMENT_VERSION = "_1_0_1";
10399
10400
  var setAttachmentToCache = function setAttachmentToCache(attachmentUrl, attachmentResponse) {
10400
10401
  try {
10401
10402
  var attachmentURLVersion = attachmentUrl + ATTACHMENT_VERSION;
@@ -10474,6 +10475,49 @@ var getAttachmentUrlFromCache = function getAttachmentUrlFromCache(attachmentUrl
10474
10475
  var getAttachmentURLWithVersion = function getAttachmentURLWithVersion(attachmentUrl) {
10475
10476
  return attachmentUrl + ATTACHMENT_VERSION;
10476
10477
  };
10478
+ var cleanupOldAttachmentCache = function cleanupOldAttachmentCache() {
10479
+ try {
10480
+ if (!cacheAvailable || !isBrowser) {
10481
+ return Promise.resolve();
10482
+ }
10483
+ return Promise.resolve(_catch(function () {
10484
+ function _temp0() {
10485
+ localStorage.setItem(ATTACHMENT_VERSION_KEY, ATTACHMENT_VERSION);
10486
+ }
10487
+ var storedVersion = localStorage.getItem(ATTACHMENT_VERSION_KEY) || '_1_0_0';
10488
+ var _temp9 = function () {
10489
+ if (storedVersion && storedVersion !== ATTACHMENT_VERSION) {
10490
+ log.info("Attachment cache version changed from " + storedVersion + " to " + ATTACHMENT_VERSION + ", cleaning up old cache...");
10491
+ return Promise.resolve(caches.open(ATTACHMENTS_CACHE)).then(function (cache) {
10492
+ return Promise.resolve(cache.keys()).then(function (requests) {
10493
+ function _temp8() {
10494
+ log.info("Cleaned up " + deletedCount + " old cached attachments");
10495
+ }
10496
+ var deletedCount = 0;
10497
+ var _temp7 = _forOf(requests, function (request) {
10498
+ var url = request.url;
10499
+ var _temp6 = function () {
10500
+ if (url.includes(storedVersion)) {
10501
+ return Promise.resolve(cache["delete"](request)).then(function () {
10502
+ deletedCount++;
10503
+ });
10504
+ }
10505
+ }();
10506
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
10507
+ });
10508
+ return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7);
10509
+ });
10510
+ });
10511
+ }
10512
+ }();
10513
+ return _temp9 && _temp9.then ? _temp9.then(_temp0) : _temp0(_temp9);
10514
+ }, function (error) {
10515
+ log.error('Error cleaning up old attachment cache:', error);
10516
+ }));
10517
+ } catch (e) {
10518
+ return Promise.reject(e);
10519
+ }
10520
+ };
10477
10521
 
10478
10522
  function sendMessageAC(message, channelId, connectionState, sendAttachmentsAsSeparateMessage, isResend) {
10479
10523
  return {
@@ -20070,16 +20114,21 @@ var resizeImageWithPica = function resizeImageWithPica(file, maxWidth, maxHeight
20070
20114
  newHeight: img.height
20071
20115
  };
20072
20116
  }
20117
+ var srcCanvas = document.createElement('canvas');
20118
+ srcCanvas.width = img.width;
20119
+ srcCanvas.height = img.height;
20120
+ var srcCtx = srcCanvas.getContext('2d');
20121
+ srcCtx.drawImage(img, 0, 0);
20122
+ URL.revokeObjectURL(url);
20073
20123
  var canvas = document.createElement('canvas');
20074
20124
  canvas.width = newWidth;
20075
20125
  canvas.height = newHeight;
20076
- return Promise.resolve(pica.resize(img, canvas, {
20126
+ return Promise.resolve(pica.resize(srcCanvas, canvas, {
20077
20127
  quality: 3,
20078
20128
  unsharpAmount: 80,
20079
20129
  unsharpRadius: 0.6,
20080
20130
  unsharpThreshold: 2
20081
20131
  })).then(function () {
20082
- URL.revokeObjectURL(url);
20083
20132
  var originalType = file.type || 'image/jpeg';
20084
20133
  var outputType = type || 'image/webp';
20085
20134
  if (outputType === 'image/webp' && !canvas.toDataURL('image/webp').includes('webp')) {
@@ -25985,6 +26034,7 @@ var SceytChat = function SceytChat(_ref) {
25985
26034
  useEffect(function () {
25986
26035
  log.info('client is changed.... ', client);
25987
26036
  if (client) {
26037
+ cleanupOldAttachmentCache();
25988
26038
  setClient(client);
25989
26039
  setSceytChatClient(client);
25990
26040
  dispatch(setUserAC(client.user));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-chat-react-uikit",
3
- "version": "1.8.3-beta.3",
3
+ "version": "1.8.3-beta.4",
4
4
  "description": "Interactive React UI Components for Sceyt Chat.",
5
5
  "author": "Sceyt",
6
6
  "license": "MIT",