sceyt-chat-react-uikit 1.6.9-beta.1 → 1.6.9-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +150 -32
  2. package/index.modern.js +150 -32
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -10403,7 +10403,79 @@ var getShowOnlyContactUsers = function getShowOnlyContactUsers() {
10403
10403
  var contactsMap = {};
10404
10404
  var logoSrc = '';
10405
10405
  var showNotifications = true;
10406
+ var notificationPermission = 'default';
10407
+ var isNotificationSupported = function isNotificationSupported() {
10408
+ return 'Notification' in window;
10409
+ };
10410
+ var requestNotificationPermission = function requestNotificationPermission() {
10411
+ try {
10412
+ if (!isNotificationSupported()) {
10413
+ console.warn('Notifications are not supported in this browser');
10414
+ return Promise.resolve('denied');
10415
+ }
10416
+ return Promise.resolve(_catch(function () {
10417
+ return Promise.resolve(Notification.requestPermission()).then(function (permission) {
10418
+ notificationPermission = permission;
10419
+ return permission;
10420
+ });
10421
+ }, function (error) {
10422
+ console.error('Error requesting notification permission:', error);
10423
+ notificationPermission = 'denied';
10424
+ return 'denied';
10425
+ }));
10426
+ } catch (e) {
10427
+ return Promise.reject(e);
10428
+ }
10429
+ };
10430
+ var createCustomNotification = function createCustomNotification(title, body) {
10431
+ var notificationElement = document.createElement('div');
10432
+ notificationElement.style.cssText = "\n position: fixed;\n top: 20px;\n right: 20px;\n background: white;\n border: 1px solid #ddd;\n border-radius: 8px;\n padding: 16px;\n box-shadow: 0 4px 12px rgba(0,0,0,0.15);\n z-index: 10000;\n max-width: 300px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n animation: slideIn 0.3s ease-out;\n ";
10433
+ var style = document.createElement('style');
10434
+ style.textContent = "\n @keyframes slideIn {\n from { transform: translateX(100%); opacity: 0; }\n to { transform: translateX(0); opacity: 1; }\n }\n ";
10435
+ document.head.appendChild(style);
10436
+ var titleElement = document.createElement('div');
10437
+ titleElement.style.cssText = 'font-weight: bold; margin-bottom: 8px; color: #333;';
10438
+ titleElement.textContent = title;
10439
+ var bodyElement = document.createElement('div');
10440
+ bodyElement.style.cssText = 'color: #666; font-size: 14px; line-height: 1.4;';
10441
+ bodyElement.textContent = body;
10442
+ var closeButton = document.createElement('button');
10443
+ closeButton.textContent = '×';
10444
+ closeButton.style.cssText = "\n position: absolute;\n top: 8px;\n right: 8px;\n background: none;\n border: none;\n font-size: 18px;\n cursor: pointer;\n color: #999;\n padding: 0;\n width: 20px;\n height: 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n ";
10445
+ notificationElement.appendChild(titleElement);
10446
+ notificationElement.appendChild(bodyElement);
10447
+ notificationElement.appendChild(closeButton);
10448
+ notificationElement.addEventListener('click', function (event) {
10449
+ if (event.target !== closeButton) {
10450
+ window.focus();
10451
+ store.dispatch({
10452
+ type: SWITCH_CHANNEL,
10453
+ payload: {
10454
+ channel: null
10455
+ }
10456
+ });
10457
+ }
10458
+ });
10459
+ var closeNotification = function closeNotification() {
10460
+ notificationElement.style.animation = 'slideOut 0.3s ease-in';
10461
+ setTimeout(function () {
10462
+ if (notificationElement.parentNode) {
10463
+ notificationElement.parentNode.removeChild(notificationElement);
10464
+ }
10465
+ }, 300);
10466
+ };
10467
+ closeButton.addEventListener('click', closeNotification);
10468
+ setTimeout(closeNotification, 5000);
10469
+ document.body.appendChild(notificationElement);
10470
+ return {
10471
+ close: closeNotification,
10472
+ onclick: function onclick(handler) {
10473
+ notificationElement.addEventListener('click', handler);
10474
+ }
10475
+ };
10476
+ };
10406
10477
  var setNotification = function setNotification(body, user, channel, reaction, attachment) {
10478
+ if (!showNotifications) return;
10407
10479
  var getFromContacts = getShowOnlyContactUsers();
10408
10480
  var attachmentType;
10409
10481
  if (attachment) {
@@ -10411,35 +10483,60 @@ var setNotification = function setNotification(body, user, channel, reaction, at
10411
10483
  attachmentType = attType === attachmentTypes.voice ? 'Voice' : attType === attachmentTypes.image ? 'Photo' : attType === attachmentTypes.video ? 'Video' : 'File';
10412
10484
  }
10413
10485
  var isDirectChannel = channel.type === DEFAULT_CHANNEL_TYPE.DIRECT;
10486
+ var title = (isDirectChannel ? makeUsername(contactsMap[user.id], user, getFromContacts) : channel.subject) || 'New Message';
10487
+ var notificationBody = '';
10488
+ if (reaction) {
10489
+ notificationBody = (channel.type !== DEFAULT_CHANNEL_TYPE.DIRECT ? makeUsername(contactsMap[user.id], user, getFromContacts) + ': ' : '') + " reacted " + reaction + " to \"" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body + "\"";
10490
+ } else {
10491
+ notificationBody = isDirectChannel ? "" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body : makeUsername(contactsMap[user.id], user, getFromContacts) + "\n" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body;
10492
+ }
10414
10493
  var notification;
10415
- if (showNotifications) {
10416
- if (reaction) {
10417
- notification = new Notification("" + (isDirectChannel ? makeUsername(contactsMap[user.id], user, getFromContacts) : channel.subject), {
10418
- body: (channel.type !== DEFAULT_CHANNEL_TYPE.DIRECT ? makeUsername(contactsMap[user.id], user, getFromContacts) + ': ' : '') + " reacted " + reaction + " to \"" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body + "\"",
10419
- icon: logoSrc
10420
- });
10494
+ if (isNotificationSupported()) {
10495
+ if (notificationPermission === 'granted') {
10496
+ try {
10497
+ notification = new Notification(title, {
10498
+ body: notificationBody,
10499
+ icon: logoSrc || '',
10500
+ tag: 'sceyt-notification',
10501
+ requireInteraction: false
10502
+ });
10503
+ notification.onclick = function (event) {
10504
+ event.preventDefault();
10505
+ window.focus();
10506
+ store.dispatch({
10507
+ type: SWITCH_CHANNEL,
10508
+ payload: {
10509
+ channel: channel
10510
+ }
10511
+ });
10512
+ notification.close();
10513
+ };
10514
+ setTimeout(function () {
10515
+ if (notification) {
10516
+ notification.close();
10517
+ }
10518
+ }, 5000);
10519
+ } catch (error) {
10520
+ console.error('Error creating native notification:', error);
10521
+ notification = createCustomNotification(title, notificationBody);
10522
+ }
10523
+ } else if (notificationPermission === 'default') {
10524
+ requestPermissionOnUserInteraction();
10525
+ notification = createCustomNotification(title, notificationBody);
10421
10526
  } else {
10422
- notification = new Notification("" + (isDirectChannel ? makeUsername(contactsMap[user.id], user, getFromContacts) : channel.subject), {
10423
- body: isDirectChannel ? "" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body : makeUsername(contactsMap[user.id], user, getFromContacts) + "\n" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body,
10424
- icon: logoSrc
10425
- });
10527
+ notification = createCustomNotification(title, notificationBody);
10426
10528
  }
10427
- notification.onclick = function (event) {
10428
- event.preventDefault();
10429
- window.focus();
10430
- store.dispatch({
10431
- type: SWITCH_CHANNEL,
10432
- payload: {
10433
- channel: channel
10434
- }
10435
- });
10436
- notification.close();
10437
- };
10438
- if (window.sceytTabNotifications) {
10529
+ } else {
10530
+ notification = createCustomNotification(title, notificationBody);
10531
+ }
10532
+ if (window.sceytTabNotifications) {
10533
+ try {
10439
10534
  window.sceytTabNotifications.close();
10535
+ } catch (error) {
10536
+ console.warn('Error closing previous notification:', error);
10440
10537
  }
10441
- window.sceytTabNotifications = notification;
10442
10538
  }
10539
+ window.sceytTabNotifications = notification;
10443
10540
  };
10444
10541
  var setNotificationLogoSrc = function setNotificationLogoSrc(src) {
10445
10542
  logoSrc = src;
@@ -10453,6 +10550,31 @@ var setShowNotifications = function setShowNotifications(show) {
10453
10550
  var getShowNotifications = function getShowNotifications() {
10454
10551
  return showNotifications;
10455
10552
  };
10553
+ var initializeNotifications = function initializeNotifications() {
10554
+ try {
10555
+ if (isNotificationSupported()) {
10556
+ notificationPermission = Notification.permission;
10557
+ if (notificationPermission === 'default') {
10558
+ console.log('Notification permission not yet requested');
10559
+ }
10560
+ }
10561
+ return Promise.resolve();
10562
+ } catch (e) {
10563
+ return Promise.reject(e);
10564
+ }
10565
+ };
10566
+ var requestPermissionOnUserInteraction = function requestPermissionOnUserInteraction() {
10567
+ try {
10568
+ var _temp = function () {
10569
+ if (notificationPermission === 'default') {
10570
+ return Promise.resolve(requestNotificationPermission()).then(function () {});
10571
+ }
10572
+ }();
10573
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
10574
+ } catch (e) {
10575
+ return Promise.reject(e);
10576
+ }
10577
+ };
10456
10578
 
10457
10579
  function getMembersAC(channelId) {
10458
10580
  return {
@@ -18873,6 +18995,9 @@ var SceytChat = function SceytChat(_ref) {
18873
18995
  dispatch(setIsDraggingAC(true));
18874
18996
  }
18875
18997
  };
18998
+ var handleUserInteraction = function handleUserInteraction() {
18999
+ requestPermissionOnUserInteraction();
19000
+ };
18876
19001
  var handleVisibilityChange = function handleVisibilityChange() {
18877
19002
  if (document[hidden]) {
18878
19003
  setTabIsActive(false);
@@ -18964,15 +19089,7 @@ var SceytChat = function SceytChat(_ref) {
18964
19089
  setChannelTypesFilter(channelTypeFilter);
18965
19090
  }
18966
19091
  if (showNotifications) {
18967
- try {
18968
- if (window.Notification && Notification.permission === 'default') {
18969
- Promise.resolve(Notification.requestPermission()).then(function (permission) {
18970
- log.info('permission:', permission);
18971
- });
18972
- }
18973
- } catch (e) {
18974
- log.error('safari Notification request permission', e);
18975
- }
19092
+ initializeNotifications();
18976
19093
  window.sceytTabNotifications = null;
18977
19094
  window.sceytTabUrl = window.location.href;
18978
19095
  window.addEventListener('focus', function () {
@@ -19048,6 +19165,7 @@ var SceytChat = function SceytChat(_ref) {
19048
19165
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, SceytChatClient ? (/*#__PURE__*/React__default.createElement(ChatContainer, {
19049
19166
  onDrop: handleDropFile,
19050
19167
  onDragOver: handleDragOver,
19168
+ onClick: handleUserInteraction,
19051
19169
  withChannelsList: channelsListWidth && channelsListWidth > 0,
19052
19170
  backgroundColor: backgroundColor,
19053
19171
  highlightedBackground: highlightedBackground,
package/index.modern.js CHANGED
@@ -10380,7 +10380,79 @@ var getShowOnlyContactUsers = function getShowOnlyContactUsers() {
10380
10380
  var contactsMap = {};
10381
10381
  var logoSrc = '';
10382
10382
  var showNotifications = true;
10383
+ var notificationPermission = 'default';
10384
+ var isNotificationSupported = function isNotificationSupported() {
10385
+ return 'Notification' in window;
10386
+ };
10387
+ var requestNotificationPermission = function requestNotificationPermission() {
10388
+ try {
10389
+ if (!isNotificationSupported()) {
10390
+ console.warn('Notifications are not supported in this browser');
10391
+ return Promise.resolve('denied');
10392
+ }
10393
+ return Promise.resolve(_catch(function () {
10394
+ return Promise.resolve(Notification.requestPermission()).then(function (permission) {
10395
+ notificationPermission = permission;
10396
+ return permission;
10397
+ });
10398
+ }, function (error) {
10399
+ console.error('Error requesting notification permission:', error);
10400
+ notificationPermission = 'denied';
10401
+ return 'denied';
10402
+ }));
10403
+ } catch (e) {
10404
+ return Promise.reject(e);
10405
+ }
10406
+ };
10407
+ var createCustomNotification = function createCustomNotification(title, body) {
10408
+ var notificationElement = document.createElement('div');
10409
+ notificationElement.style.cssText = "\n position: fixed;\n top: 20px;\n right: 20px;\n background: white;\n border: 1px solid #ddd;\n border-radius: 8px;\n padding: 16px;\n box-shadow: 0 4px 12px rgba(0,0,0,0.15);\n z-index: 10000;\n max-width: 300px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n animation: slideIn 0.3s ease-out;\n ";
10410
+ var style = document.createElement('style');
10411
+ style.textContent = "\n @keyframes slideIn {\n from { transform: translateX(100%); opacity: 0; }\n to { transform: translateX(0); opacity: 1; }\n }\n ";
10412
+ document.head.appendChild(style);
10413
+ var titleElement = document.createElement('div');
10414
+ titleElement.style.cssText = 'font-weight: bold; margin-bottom: 8px; color: #333;';
10415
+ titleElement.textContent = title;
10416
+ var bodyElement = document.createElement('div');
10417
+ bodyElement.style.cssText = 'color: #666; font-size: 14px; line-height: 1.4;';
10418
+ bodyElement.textContent = body;
10419
+ var closeButton = document.createElement('button');
10420
+ closeButton.textContent = '×';
10421
+ closeButton.style.cssText = "\n position: absolute;\n top: 8px;\n right: 8px;\n background: none;\n border: none;\n font-size: 18px;\n cursor: pointer;\n color: #999;\n padding: 0;\n width: 20px;\n height: 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n ";
10422
+ notificationElement.appendChild(titleElement);
10423
+ notificationElement.appendChild(bodyElement);
10424
+ notificationElement.appendChild(closeButton);
10425
+ notificationElement.addEventListener('click', function (event) {
10426
+ if (event.target !== closeButton) {
10427
+ window.focus();
10428
+ store.dispatch({
10429
+ type: SWITCH_CHANNEL,
10430
+ payload: {
10431
+ channel: null
10432
+ }
10433
+ });
10434
+ }
10435
+ });
10436
+ var closeNotification = function closeNotification() {
10437
+ notificationElement.style.animation = 'slideOut 0.3s ease-in';
10438
+ setTimeout(function () {
10439
+ if (notificationElement.parentNode) {
10440
+ notificationElement.parentNode.removeChild(notificationElement);
10441
+ }
10442
+ }, 300);
10443
+ };
10444
+ closeButton.addEventListener('click', closeNotification);
10445
+ setTimeout(closeNotification, 5000);
10446
+ document.body.appendChild(notificationElement);
10447
+ return {
10448
+ close: closeNotification,
10449
+ onclick: function onclick(handler) {
10450
+ notificationElement.addEventListener('click', handler);
10451
+ }
10452
+ };
10453
+ };
10383
10454
  var setNotification = function setNotification(body, user, channel, reaction, attachment) {
10455
+ if (!showNotifications) return;
10384
10456
  var getFromContacts = getShowOnlyContactUsers();
10385
10457
  var attachmentType;
10386
10458
  if (attachment) {
@@ -10388,35 +10460,60 @@ var setNotification = function setNotification(body, user, channel, reaction, at
10388
10460
  attachmentType = attType === attachmentTypes.voice ? 'Voice' : attType === attachmentTypes.image ? 'Photo' : attType === attachmentTypes.video ? 'Video' : 'File';
10389
10461
  }
10390
10462
  var isDirectChannel = channel.type === DEFAULT_CHANNEL_TYPE.DIRECT;
10463
+ var title = (isDirectChannel ? makeUsername(contactsMap[user.id], user, getFromContacts) : channel.subject) || 'New Message';
10464
+ var notificationBody = '';
10465
+ if (reaction) {
10466
+ notificationBody = (channel.type !== DEFAULT_CHANNEL_TYPE.DIRECT ? makeUsername(contactsMap[user.id], user, getFromContacts) + ': ' : '') + " reacted " + reaction + " to \"" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body + "\"";
10467
+ } else {
10468
+ notificationBody = isDirectChannel ? "" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body : makeUsername(contactsMap[user.id], user, getFromContacts) + "\n" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body;
10469
+ }
10391
10470
  var notification;
10392
- if (showNotifications) {
10393
- if (reaction) {
10394
- notification = new Notification("" + (isDirectChannel ? makeUsername(contactsMap[user.id], user, getFromContacts) : channel.subject), {
10395
- body: (channel.type !== DEFAULT_CHANNEL_TYPE.DIRECT ? makeUsername(contactsMap[user.id], user, getFromContacts) + ': ' : '') + " reacted " + reaction + " to \"" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body + "\"",
10396
- icon: logoSrc
10397
- });
10471
+ if (isNotificationSupported()) {
10472
+ if (notificationPermission === 'granted') {
10473
+ try {
10474
+ notification = new Notification(title, {
10475
+ body: notificationBody,
10476
+ icon: logoSrc || '',
10477
+ tag: 'sceyt-notification',
10478
+ requireInteraction: false
10479
+ });
10480
+ notification.onclick = function (event) {
10481
+ event.preventDefault();
10482
+ window.focus();
10483
+ store.dispatch({
10484
+ type: SWITCH_CHANNEL,
10485
+ payload: {
10486
+ channel: channel
10487
+ }
10488
+ });
10489
+ notification.close();
10490
+ };
10491
+ setTimeout(function () {
10492
+ if (notification) {
10493
+ notification.close();
10494
+ }
10495
+ }, 5000);
10496
+ } catch (error) {
10497
+ console.error('Error creating native notification:', error);
10498
+ notification = createCustomNotification(title, notificationBody);
10499
+ }
10500
+ } else if (notificationPermission === 'default') {
10501
+ requestPermissionOnUserInteraction();
10502
+ notification = createCustomNotification(title, notificationBody);
10398
10503
  } else {
10399
- notification = new Notification("" + (isDirectChannel ? makeUsername(contactsMap[user.id], user, getFromContacts) : channel.subject), {
10400
- body: isDirectChannel ? "" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body : makeUsername(contactsMap[user.id], user, getFromContacts) + "\n" + (attachmentType || '') + (attachmentType && body ? ': ' : '') + body,
10401
- icon: logoSrc
10402
- });
10504
+ notification = createCustomNotification(title, notificationBody);
10403
10505
  }
10404
- notification.onclick = function (event) {
10405
- event.preventDefault();
10406
- window.focus();
10407
- store.dispatch({
10408
- type: SWITCH_CHANNEL,
10409
- payload: {
10410
- channel: channel
10411
- }
10412
- });
10413
- notification.close();
10414
- };
10415
- if (window.sceytTabNotifications) {
10506
+ } else {
10507
+ notification = createCustomNotification(title, notificationBody);
10508
+ }
10509
+ if (window.sceytTabNotifications) {
10510
+ try {
10416
10511
  window.sceytTabNotifications.close();
10512
+ } catch (error) {
10513
+ console.warn('Error closing previous notification:', error);
10417
10514
  }
10418
- window.sceytTabNotifications = notification;
10419
10515
  }
10516
+ window.sceytTabNotifications = notification;
10420
10517
  };
10421
10518
  var setNotificationLogoSrc = function setNotificationLogoSrc(src) {
10422
10519
  logoSrc = src;
@@ -10430,6 +10527,31 @@ var setShowNotifications = function setShowNotifications(show) {
10430
10527
  var getShowNotifications = function getShowNotifications() {
10431
10528
  return showNotifications;
10432
10529
  };
10530
+ var initializeNotifications = function initializeNotifications() {
10531
+ try {
10532
+ if (isNotificationSupported()) {
10533
+ notificationPermission = Notification.permission;
10534
+ if (notificationPermission === 'default') {
10535
+ console.log('Notification permission not yet requested');
10536
+ }
10537
+ }
10538
+ return Promise.resolve();
10539
+ } catch (e) {
10540
+ return Promise.reject(e);
10541
+ }
10542
+ };
10543
+ var requestPermissionOnUserInteraction = function requestPermissionOnUserInteraction() {
10544
+ try {
10545
+ var _temp = function () {
10546
+ if (notificationPermission === 'default') {
10547
+ return Promise.resolve(requestNotificationPermission()).then(function () {});
10548
+ }
10549
+ }();
10550
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
10551
+ } catch (e) {
10552
+ return Promise.reject(e);
10553
+ }
10554
+ };
10433
10555
 
10434
10556
  function getMembersAC(channelId) {
10435
10557
  return {
@@ -18850,6 +18972,9 @@ var SceytChat = function SceytChat(_ref) {
18850
18972
  dispatch(setIsDraggingAC(true));
18851
18973
  }
18852
18974
  };
18975
+ var handleUserInteraction = function handleUserInteraction() {
18976
+ requestPermissionOnUserInteraction();
18977
+ };
18853
18978
  var handleVisibilityChange = function handleVisibilityChange() {
18854
18979
  if (document[hidden]) {
18855
18980
  setTabIsActive(false);
@@ -18941,15 +19066,7 @@ var SceytChat = function SceytChat(_ref) {
18941
19066
  setChannelTypesFilter(channelTypeFilter);
18942
19067
  }
18943
19068
  if (showNotifications) {
18944
- try {
18945
- if (window.Notification && Notification.permission === 'default') {
18946
- Promise.resolve(Notification.requestPermission()).then(function (permission) {
18947
- log.info('permission:', permission);
18948
- });
18949
- }
18950
- } catch (e) {
18951
- log.error('safari Notification request permission', e);
18952
- }
19069
+ initializeNotifications();
18953
19070
  window.sceytTabNotifications = null;
18954
19071
  window.sceytTabUrl = window.location.href;
18955
19072
  window.addEventListener('focus', function () {
@@ -19025,6 +19142,7 @@ var SceytChat = function SceytChat(_ref) {
19025
19142
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, SceytChatClient ? (/*#__PURE__*/React__default.createElement(ChatContainer, {
19026
19143
  onDrop: handleDropFile,
19027
19144
  onDragOver: handleDragOver,
19145
+ onClick: handleUserInteraction,
19028
19146
  withChannelsList: channelsListWidth && channelsListWidth > 0,
19029
19147
  backgroundColor: backgroundColor,
19030
19148
  highlightedBackground: highlightedBackground,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-chat-react-uikit",
3
- "version": "1.6.9-beta.1",
3
+ "version": "1.6.9-beta.2",
4
4
  "description": "Interactive React UI Components for Sceyt Chat.",
5
5
  "author": "Sceyt",
6
6
  "license": "MIT",