@realtimexsco/live-chat 1.4.5 → 1.4.7
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/dist/index.cjs +88 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +89 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1648,6 +1648,6 @@ interface ForegroundPushBridgeProps {
|
|
|
1648
1648
|
*/
|
|
1649
1649
|
onPush?: (payload: ForegroundPushPayload) => void | boolean;
|
|
1650
1650
|
}
|
|
1651
|
-
declare const ForegroundPushBridge: ({ onPush }: ForegroundPushBridgeProps) =>
|
|
1651
|
+
declare const ForegroundPushBridge: ({ onPush }: ForegroundPushBridgeProps) => React.JSX.Element;
|
|
1652
1652
|
|
|
1653
1653
|
export { type ActiveChannelMessagesSlotProps, type AdminsDrawerSlotProps, type AttachmentsDrawerSlotProps, type AvatarSlotProps, CHAT_API_KEYS, CHAT_GET_API_KEYS, Calendar, CalendarDayButton, Channel, type ChannelDetailsDrawerSlotProps, ChannelHeaderView as ChannelHeader, type ChannelHeaderSlotProps, ChannelListView as ChannelList, ChannelListItem, type ChannelListItemSlotProps, type ChannelListSlotProps, type ChannelMessageBoxSlotProps, Chat, type ChatActionModalSlotProps, ChatAlertsProvider, type ChatApiKey, ChatAvatar, type ChatCallContext, type ChatClassNames, type ChatColorMode, type ChatComponents, type ChatCustomizationConfig, ChatCustomizationProvider, ChatDateJumpMenu, type ChatDateTimePreferences, type ChatFeatures, type ChatGetApiKey, ChatLayout, type ChatLayoutConfig, type ChatLayoutSlotProps, ChatLocaleProvider, ChatMain, type ChatPanelAlertsSlotProps, type ChatQueryParams, type ChatQueryParamsByApi, ChatThemeProvider, ChatViewport, type ChatViewportHeight, DefaultChannelListItem, DefaultChatAvatar, DefaultChatLayout, ForegroundPushBridge, type ForegroundPushBridgeProps, type ForegroundPushPayload, ForwardModalView as ForwardModal, type ForwardModalSlotProps, HeaderCallActions, type HeaderCallActionsSlotProps, type HeaderLeftSideSlotProps, type HeaderRightSideSlotProps, type HeaderSearchOverlaySlotProps, type IAttachment, type IChannel, type IDMDelete, type IDMEditMessage, type IDMForward, type IDMMessage, type IDMPin, type IDMReaction, type IDMRead, type IDMStar, type IDMTyping, type IDMUnstar, type IMessage, type ISocketConfig, type JumpToPreset, LoggedUserDetails, type LoggedUserDetailsSlotProps, type MembersDrawerSlotProps, type MessageAttachmentsSlotProps, ChannelMessageBoxView as MessageInput, MessageItemView as MessageItem, type MessageItemSlotProps, ActiveChannelMessagesView as MessageList, type MessageReactionsSlotProps, type MessageReplySnippetSlotProps, type MessageStatusSlotProps, type MessageToolbarSlotProps, PUSH_CHANGED_EVENT, type PendingJump, type PermissionDrawerSlotProps, type PhoneCallButtonSlotProps, type PinnedMessagesDrawerSlotProps, type PushConfig, PushNotificationToggle, type PushNotificationToggleProps, type PushNotificationsState, type PushPreference, type StarredMessagesDrawerSlotProps, type UIConfig, type UsePushNotifications, type VideoCallButtonSlotProps, apiGetPushConfig, apiGetPushPreference, apiRegisterPushToken, apiRemovePushToken, apiUpdatePushPreference, capitalizeFirst, clampJumpDate, ChatMain as default, defaultChatClassNames, defaultChatComponents, defaultChatFeatures, defaultChatLayoutConfig, disablePushOnThisDevice, downloadFile, enablePushOnThisDevice, getChatBaseUrl, getChatQueryParamApis, getChatQueryParams, getChatQueryParamsByApi, getChatSocketUrl, getFirstAndLastNameOneCharacter, getResponsiveWidth, getSocketConfig, getStoredPushToken, isEmpty, isPushSupported, mergeChatCustomization, mergeChatLayoutConfig, onForegroundPush, packageDefaultComponents, resolveApiUrl, resolveChatApiKey, resolveJumpDateBounds, resolveJumpPreset, resolveJumpStep, resolveSocketUrl, setChatAccessToken, setChatBaseURL, setChatClientId, setChatQueryParamApis, setChatQueryParams, setChatQueryParamsByApi, setChatSocketUrl, showNotification, smoothScrollToMessage, socketService, startOfLocalDay, toDateInputValue, uniqueList, useChatAlerts, useChatContext, useChatController, useChatCustomization, useChatCustomizationOptional, useChatFeatures, useChatFeaturesOptional, useChatLocale, useStore as useChatStore, useChatTheme, usePushNotifications };
|
package/dist/index.d.ts
CHANGED
|
@@ -1648,6 +1648,6 @@ interface ForegroundPushBridgeProps {
|
|
|
1648
1648
|
*/
|
|
1649
1649
|
onPush?: (payload: ForegroundPushPayload) => void | boolean;
|
|
1650
1650
|
}
|
|
1651
|
-
declare const ForegroundPushBridge: ({ onPush }: ForegroundPushBridgeProps) =>
|
|
1651
|
+
declare const ForegroundPushBridge: ({ onPush }: ForegroundPushBridgeProps) => React.JSX.Element;
|
|
1652
1652
|
|
|
1653
1653
|
export { type ActiveChannelMessagesSlotProps, type AdminsDrawerSlotProps, type AttachmentsDrawerSlotProps, type AvatarSlotProps, CHAT_API_KEYS, CHAT_GET_API_KEYS, Calendar, CalendarDayButton, Channel, type ChannelDetailsDrawerSlotProps, ChannelHeaderView as ChannelHeader, type ChannelHeaderSlotProps, ChannelListView as ChannelList, ChannelListItem, type ChannelListItemSlotProps, type ChannelListSlotProps, type ChannelMessageBoxSlotProps, Chat, type ChatActionModalSlotProps, ChatAlertsProvider, type ChatApiKey, ChatAvatar, type ChatCallContext, type ChatClassNames, type ChatColorMode, type ChatComponents, type ChatCustomizationConfig, ChatCustomizationProvider, ChatDateJumpMenu, type ChatDateTimePreferences, type ChatFeatures, type ChatGetApiKey, ChatLayout, type ChatLayoutConfig, type ChatLayoutSlotProps, ChatLocaleProvider, ChatMain, type ChatPanelAlertsSlotProps, type ChatQueryParams, type ChatQueryParamsByApi, ChatThemeProvider, ChatViewport, type ChatViewportHeight, DefaultChannelListItem, DefaultChatAvatar, DefaultChatLayout, ForegroundPushBridge, type ForegroundPushBridgeProps, type ForegroundPushPayload, ForwardModalView as ForwardModal, type ForwardModalSlotProps, HeaderCallActions, type HeaderCallActionsSlotProps, type HeaderLeftSideSlotProps, type HeaderRightSideSlotProps, type HeaderSearchOverlaySlotProps, type IAttachment, type IChannel, type IDMDelete, type IDMEditMessage, type IDMForward, type IDMMessage, type IDMPin, type IDMReaction, type IDMRead, type IDMStar, type IDMTyping, type IDMUnstar, type IMessage, type ISocketConfig, type JumpToPreset, LoggedUserDetails, type LoggedUserDetailsSlotProps, type MembersDrawerSlotProps, type MessageAttachmentsSlotProps, ChannelMessageBoxView as MessageInput, MessageItemView as MessageItem, type MessageItemSlotProps, ActiveChannelMessagesView as MessageList, type MessageReactionsSlotProps, type MessageReplySnippetSlotProps, type MessageStatusSlotProps, type MessageToolbarSlotProps, PUSH_CHANGED_EVENT, type PendingJump, type PermissionDrawerSlotProps, type PhoneCallButtonSlotProps, type PinnedMessagesDrawerSlotProps, type PushConfig, PushNotificationToggle, type PushNotificationToggleProps, type PushNotificationsState, type PushPreference, type StarredMessagesDrawerSlotProps, type UIConfig, type UsePushNotifications, type VideoCallButtonSlotProps, apiGetPushConfig, apiGetPushPreference, apiRegisterPushToken, apiRemovePushToken, apiUpdatePushPreference, capitalizeFirst, clampJumpDate, ChatMain as default, defaultChatClassNames, defaultChatComponents, defaultChatFeatures, defaultChatLayoutConfig, disablePushOnThisDevice, downloadFile, enablePushOnThisDevice, getChatBaseUrl, getChatQueryParamApis, getChatQueryParams, getChatQueryParamsByApi, getChatSocketUrl, getFirstAndLastNameOneCharacter, getResponsiveWidth, getSocketConfig, getStoredPushToken, isEmpty, isPushSupported, mergeChatCustomization, mergeChatLayoutConfig, onForegroundPush, packageDefaultComponents, resolveApiUrl, resolveChatApiKey, resolveJumpDateBounds, resolveJumpPreset, resolveJumpStep, resolveSocketUrl, setChatAccessToken, setChatBaseURL, setChatClientId, setChatQueryParamApis, setChatQueryParams, setChatQueryParamsByApi, setChatSocketUrl, showNotification, smoothScrollToMessage, socketService, startOfLocalDay, toDateInputValue, uniqueList, useChatAlerts, useChatContext, useChatController, useChatCustomization, useChatCustomizationOptional, useChatFeatures, useChatFeaturesOptional, useChatLocale, useStore as useChatStore, useChatTheme, usePushNotifications };
|
package/dist/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { Sun, Moon, Search, X, Loader2, UserPlus, ChevronDown, ArrowLeft, Users,
|
|
|
13
13
|
import { cva } from 'class-variance-authority';
|
|
14
14
|
import EmojiPicker, { Theme } from 'emoji-picker-react';
|
|
15
15
|
import { getDefaultClassNames, DayPicker } from 'react-day-picker';
|
|
16
|
-
import { toast } from 'react-hot-toast';
|
|
16
|
+
import { toast, Toaster } from 'react-hot-toast';
|
|
17
17
|
|
|
18
18
|
var __defProp = Object.defineProperty;
|
|
19
19
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -17431,6 +17431,7 @@ var getFirstAndLastNameOneCharacter = (name) => {
|
|
|
17431
17431
|
};
|
|
17432
17432
|
|
|
17433
17433
|
// src/notifications/ForegroundPushBridge.tsx
|
|
17434
|
+
init_normalize_helpers();
|
|
17434
17435
|
init_useStore();
|
|
17435
17436
|
|
|
17436
17437
|
// src/notifications/push.service.ts
|
|
@@ -17589,17 +17590,89 @@ var onForegroundPush = async (callback) => {
|
|
|
17589
17590
|
});
|
|
17590
17591
|
});
|
|
17591
17592
|
};
|
|
17592
|
-
|
|
17593
|
-
// src/notifications/ForegroundPushBridge.tsx
|
|
17594
17593
|
var RETRY_DELAYS_MS = [1e3, 3e3, 8e3, 2e4];
|
|
17594
|
+
var recentToastIds = /* @__PURE__ */ new Set();
|
|
17595
|
+
var rememberToastId = (id) => {
|
|
17596
|
+
if (!id) return true;
|
|
17597
|
+
if (recentToastIds.has(id)) return false;
|
|
17598
|
+
recentToastIds.add(id);
|
|
17599
|
+
if (recentToastIds.size > 100) {
|
|
17600
|
+
const keep = [...recentToastIds].slice(-50);
|
|
17601
|
+
recentToastIds.clear();
|
|
17602
|
+
keep.forEach((value) => recentToastIds.add(value));
|
|
17603
|
+
}
|
|
17604
|
+
return true;
|
|
17605
|
+
};
|
|
17606
|
+
var resolveIncomingConversationId = (data) => String(
|
|
17607
|
+
data?.conversationId || data?.conversation_id || data?.conversationID || ""
|
|
17608
|
+
);
|
|
17609
|
+
var resolveToastText = (title, body) => {
|
|
17610
|
+
if (title && body) return `${title}: ${body}`;
|
|
17611
|
+
return title || body || "";
|
|
17612
|
+
};
|
|
17613
|
+
var emitToast = (payload, onPush) => {
|
|
17614
|
+
if (onPush && onPush(payload) !== false) return;
|
|
17615
|
+
const title = payload.title || payload.data?.title;
|
|
17616
|
+
const body = payload.body || payload.data?.body || payload.data?.message;
|
|
17617
|
+
const text = resolveToastText(title, body);
|
|
17618
|
+
if (text) showNotification(text, "info");
|
|
17619
|
+
};
|
|
17595
17620
|
var ForegroundPushBridge = ({ onPush }) => {
|
|
17621
|
+
const lastDM = useStore((s) => s.lastDM);
|
|
17622
|
+
const onPushRef = useRef(onPush);
|
|
17623
|
+
onPushRef.current = onPush;
|
|
17624
|
+
useEffect(() => {
|
|
17625
|
+
if (!lastDM) return;
|
|
17626
|
+
if (typeof document !== "undefined" && document.visibilityState !== "visible") {
|
|
17627
|
+
return;
|
|
17628
|
+
}
|
|
17629
|
+
const state = useStore.getState();
|
|
17630
|
+
const loggedUserId = String(state.loggedUserDetails?._id || "");
|
|
17631
|
+
const conversationId = String(
|
|
17632
|
+
resolveConversationIdForIncomingMessage(
|
|
17633
|
+
lastDM,
|
|
17634
|
+
state.conversations,
|
|
17635
|
+
loggedUserId
|
|
17636
|
+
) || lastDM.conversationId || ""
|
|
17637
|
+
);
|
|
17638
|
+
const messageId2 = String(lastDM._id || lastDM.id || "");
|
|
17639
|
+
const activeId = String(state.activeConversationId || "");
|
|
17640
|
+
const senderId = String(
|
|
17641
|
+
lastDM.sender?._id || lastDM.sender || lastDM.fromUserId || ""
|
|
17642
|
+
);
|
|
17643
|
+
if (!conversationId) return;
|
|
17644
|
+
if (loggedUserId && senderId && senderId === loggedUserId) return;
|
|
17645
|
+
if (activeId && conversationId === activeId) return;
|
|
17646
|
+
if (!rememberToastId(messageId2)) return;
|
|
17647
|
+
const isGroup = !!(lastDM.isGroup || lastDM.groupName || lastDM.conversationType === "group");
|
|
17648
|
+
const title = isGroup ? lastDM.groupName || lastDM.name || "Group" : lastDM.sender?.name || "New message";
|
|
17649
|
+
const body = typeof lastDM.content === "string" ? lastDM.content : lastDM.message?.content || (lastDM.attachments?.length ? "Sent an attachment" : "");
|
|
17650
|
+
console.debug("[realtimex-push] socket \u2192 toast:", {
|
|
17651
|
+
title,
|
|
17652
|
+
conversationId,
|
|
17653
|
+
activeConversationId: activeId
|
|
17654
|
+
});
|
|
17655
|
+
emitToast(
|
|
17656
|
+
{
|
|
17657
|
+
title,
|
|
17658
|
+
body,
|
|
17659
|
+
data: { conversationId, messageId: messageId2 }
|
|
17660
|
+
},
|
|
17661
|
+
onPushRef.current
|
|
17662
|
+
);
|
|
17663
|
+
}, [lastDM]);
|
|
17596
17664
|
useEffect(() => {
|
|
17597
17665
|
let unsubscribe = null;
|
|
17598
17666
|
let retryTimer = null;
|
|
17599
17667
|
let cancelled = false;
|
|
17600
17668
|
const handlePayload = (payload) => {
|
|
17601
|
-
const incoming = payload.data
|
|
17602
|
-
const activeId =
|
|
17669
|
+
const incoming = resolveIncomingConversationId(payload.data);
|
|
17670
|
+
const activeId = String(
|
|
17671
|
+
useStore.getState().activeConversationId || ""
|
|
17672
|
+
);
|
|
17673
|
+
const messageId2 = String(
|
|
17674
|
+
payload.data?.messageId || payload.data?.message_id || payload.data?.messageID || ""
|
|
17675
|
+
);
|
|
17603
17676
|
if (incoming && activeId && incoming === activeId) {
|
|
17604
17677
|
console.debug(
|
|
17605
17678
|
"[realtimex-push] foreground push suppressed (conversation open):",
|
|
@@ -17607,14 +17680,13 @@ var ForegroundPushBridge = ({ onPush }) => {
|
|
|
17607
17680
|
);
|
|
17608
17681
|
return;
|
|
17609
17682
|
}
|
|
17683
|
+
if (!rememberToastId(messageId2)) return;
|
|
17610
17684
|
console.debug("[realtimex-push] foreground push \u2192 toast:", {
|
|
17611
17685
|
title: payload.title,
|
|
17612
17686
|
conversationId: incoming,
|
|
17613
17687
|
activeConversationId: activeId
|
|
17614
17688
|
});
|
|
17615
|
-
|
|
17616
|
-
const text = payload.title ? payload.body ? `${payload.title}: ${payload.body}` : payload.title : payload.body;
|
|
17617
|
-
if (text) showNotification(text, "info");
|
|
17689
|
+
emitToast(payload, onPushRef.current);
|
|
17618
17690
|
};
|
|
17619
17691
|
const start = async (attempt = 0) => {
|
|
17620
17692
|
if (cancelled || unsubscribe || !getStoredPushToken()) return;
|
|
@@ -17657,8 +17729,15 @@ var ForegroundPushBridge = ({ onPush }) => {
|
|
|
17657
17729
|
unsubscribe?.();
|
|
17658
17730
|
window.removeEventListener(PUSH_CHANGED_EVENT, onPushChanged);
|
|
17659
17731
|
};
|
|
17660
|
-
}, [
|
|
17661
|
-
return
|
|
17732
|
+
}, []);
|
|
17733
|
+
return /* @__PURE__ */ jsx(
|
|
17734
|
+
Toaster,
|
|
17735
|
+
{
|
|
17736
|
+
position: "top-right",
|
|
17737
|
+
toastOptions: { duration: 4e3 },
|
|
17738
|
+
containerStyle: { zIndex: 99999 }
|
|
17739
|
+
}
|
|
17740
|
+
);
|
|
17662
17741
|
};
|
|
17663
17742
|
var ChatMain = ({
|
|
17664
17743
|
clientId,
|