@realtimexsco/live-chat 1.4.7 → 1.4.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/dist/index.d.mts CHANGED
@@ -1650,4 +1650,35 @@ interface ForegroundPushBridgeProps {
1650
1650
  }
1651
1651
  declare const ForegroundPushBridge: ({ onPush }: ForegroundPushBridgeProps) => React.JSX.Element;
1652
1652
 
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 };
1653
+ /** CustomEvent name detail: `{ conversationId: string }` */
1654
+ declare const OPEN_CONVERSATION_EVENT = "realtimex:open-conversation";
1655
+ /** Service-worker → page postMessage type */
1656
+ declare const NOTIFICATION_CLICK_SW_TYPE = "realtimex:notification-click";
1657
+ declare const resolveConversationIdFromPushData: (data?: Record<string, unknown> | null) => string;
1658
+ declare const peekPendingOpenConversation: () => string | null;
1659
+ declare const consumePendingOpenConversation: () => string | null;
1660
+ /**
1661
+ * Ask the chat UI to open a conversation. Safe to call when ChatMain is not
1662
+ * mounted yet — the id is kept in sessionStorage until the chat consumes it.
1663
+ * Host apps should also navigate to their chat route (see
1664
+ * `installNotificationClickBridge`).
1665
+ */
1666
+ declare const requestOpenConversation: (conversationId: string) => void;
1667
+ interface NotificationClickBridgeOptions {
1668
+ /** Host chat route, default `/chat` */
1669
+ chatPath?: string;
1670
+ /**
1671
+ * Called when a notification click needs the host router to move onto
1672
+ * the chat page (or sync `?conversationId=`). Required for redirect when
1673
+ * the user is on another route.
1674
+ */
1675
+ onNavigate?: (conversationId: string, pathWithQuery: string) => void;
1676
+ }
1677
+ /**
1678
+ * Listens for OS notification clicks (service worker postMessage) and an
1679
+ * optional `?conversationId=` URL, then calls `requestOpenConversation` +
1680
+ * `onNavigate` so the host can route to the chat page.
1681
+ */
1682
+ declare const installNotificationClickBridge: (options?: NotificationClickBridgeOptions) => (() => void);
1683
+
1684
+ 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, NOTIFICATION_CLICK_SW_TYPE, type NotificationClickBridgeOptions, OPEN_CONVERSATION_EVENT, 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, consumePendingOpenConversation, ChatMain as default, defaultChatClassNames, defaultChatComponents, defaultChatFeatures, defaultChatLayoutConfig, disablePushOnThisDevice, downloadFile, enablePushOnThisDevice, getChatBaseUrl, getChatQueryParamApis, getChatQueryParams, getChatQueryParamsByApi, getChatSocketUrl, getFirstAndLastNameOneCharacter, getResponsiveWidth, getSocketConfig, getStoredPushToken, installNotificationClickBridge, isEmpty, isPushSupported, mergeChatCustomization, mergeChatLayoutConfig, onForegroundPush, packageDefaultComponents, peekPendingOpenConversation, requestOpenConversation, resolveApiUrl, resolveChatApiKey, resolveConversationIdFromPushData, 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
@@ -1650,4 +1650,35 @@ interface ForegroundPushBridgeProps {
1650
1650
  }
1651
1651
  declare const ForegroundPushBridge: ({ onPush }: ForegroundPushBridgeProps) => React.JSX.Element;
1652
1652
 
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 };
1653
+ /** CustomEvent name detail: `{ conversationId: string }` */
1654
+ declare const OPEN_CONVERSATION_EVENT = "realtimex:open-conversation";
1655
+ /** Service-worker → page postMessage type */
1656
+ declare const NOTIFICATION_CLICK_SW_TYPE = "realtimex:notification-click";
1657
+ declare const resolveConversationIdFromPushData: (data?: Record<string, unknown> | null) => string;
1658
+ declare const peekPendingOpenConversation: () => string | null;
1659
+ declare const consumePendingOpenConversation: () => string | null;
1660
+ /**
1661
+ * Ask the chat UI to open a conversation. Safe to call when ChatMain is not
1662
+ * mounted yet — the id is kept in sessionStorage until the chat consumes it.
1663
+ * Host apps should also navigate to their chat route (see
1664
+ * `installNotificationClickBridge`).
1665
+ */
1666
+ declare const requestOpenConversation: (conversationId: string) => void;
1667
+ interface NotificationClickBridgeOptions {
1668
+ /** Host chat route, default `/chat` */
1669
+ chatPath?: string;
1670
+ /**
1671
+ * Called when a notification click needs the host router to move onto
1672
+ * the chat page (or sync `?conversationId=`). Required for redirect when
1673
+ * the user is on another route.
1674
+ */
1675
+ onNavigate?: (conversationId: string, pathWithQuery: string) => void;
1676
+ }
1677
+ /**
1678
+ * Listens for OS notification clicks (service worker postMessage) and an
1679
+ * optional `?conversationId=` URL, then calls `requestOpenConversation` +
1680
+ * `onNavigate` so the host can route to the chat page.
1681
+ */
1682
+ declare const installNotificationClickBridge: (options?: NotificationClickBridgeOptions) => (() => void);
1683
+
1684
+ 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, NOTIFICATION_CLICK_SW_TYPE, type NotificationClickBridgeOptions, OPEN_CONVERSATION_EVENT, 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, consumePendingOpenConversation, ChatMain as default, defaultChatClassNames, defaultChatComponents, defaultChatFeatures, defaultChatLayoutConfig, disablePushOnThisDevice, downloadFile, enablePushOnThisDevice, getChatBaseUrl, getChatQueryParamApis, getChatQueryParams, getChatQueryParamsByApi, getChatSocketUrl, getFirstAndLastNameOneCharacter, getResponsiveWidth, getSocketConfig, getStoredPushToken, installNotificationClickBridge, isEmpty, isPushSupported, mergeChatCustomization, mergeChatLayoutConfig, onForegroundPush, packageDefaultComponents, peekPendingOpenConversation, requestOpenConversation, resolveApiUrl, resolveChatApiKey, resolveConversationIdFromPushData, 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, Toaster } from 'react-hot-toast';
16
+ import toast2, { toast, Toaster } from 'react-hot-toast';
17
17
 
18
18
  var __defProp = Object.defineProperty;
19
19
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -4626,6 +4626,127 @@ var Chat = ({
4626
4626
  // src/hooks/useChatController.ts
4627
4627
  init_useStore();
4628
4628
  init_store_helpers();
4629
+
4630
+ // src/notifications/open-conversation.ts
4631
+ init_store_helpers();
4632
+ var OPEN_CONVERSATION_EVENT = "realtimex:open-conversation";
4633
+ var NOTIFICATION_CLICK_SW_TYPE = "realtimex:notification-click";
4634
+ var PENDING_STORAGE_KEY = "realtimex:pending-open-conversation";
4635
+ var resolveConversationIdFromPushData = (data) => {
4636
+ if (!data || typeof data !== "object") return "";
4637
+ const nested = data.FCM_MSG && typeof data.FCM_MSG === "object" ? data.FCM_MSG.data : void 0;
4638
+ const source = { ...nested || {}, ...data };
4639
+ return String(
4640
+ source.conversationId || source.conversation_id || source.conversationID || ""
4641
+ );
4642
+ };
4643
+ var peekPendingOpenConversation = () => {
4644
+ try {
4645
+ return sessionStorage.getItem(PENDING_STORAGE_KEY);
4646
+ } catch {
4647
+ return null;
4648
+ }
4649
+ };
4650
+ var consumePendingOpenConversation = () => {
4651
+ const id = peekPendingOpenConversation();
4652
+ try {
4653
+ sessionStorage.removeItem(PENDING_STORAGE_KEY);
4654
+ } catch {
4655
+ }
4656
+ return id;
4657
+ };
4658
+ var requestOpenConversation = (conversationId) => {
4659
+ const id = String(conversationId || "").trim();
4660
+ if (!id) return;
4661
+ try {
4662
+ sessionStorage.setItem(PENDING_STORAGE_KEY, id);
4663
+ } catch {
4664
+ }
4665
+ try {
4666
+ window.dispatchEvent(
4667
+ new CustomEvent(OPEN_CONVERSATION_EVENT, {
4668
+ detail: { conversationId: id }
4669
+ })
4670
+ );
4671
+ } catch {
4672
+ }
4673
+ };
4674
+ var mapConversationToChannel = (conversation, loggedUserId, allUsers) => {
4675
+ const conversationId = String(conversation?._id || conversation?.id || "");
4676
+ const isGroup = isGroupConversation(conversation);
4677
+ if (isGroup) {
4678
+ const rawName2 = conversation.groupName || conversation.name || "Group Chat";
4679
+ return {
4680
+ id: conversationId,
4681
+ conversationId,
4682
+ name: rawName2.charAt(0).toUpperCase() + rawName2.slice(1),
4683
+ image: resolveGroupImage(conversation),
4684
+ isGroup: true,
4685
+ isLeft: !!conversation.isLeft,
4686
+ isBlocked: !!conversation.isBlocked,
4687
+ pinnedCount: conversation.pinnedCount,
4688
+ starredCount: conversation.starredCount
4689
+ };
4690
+ }
4691
+ const { id: otherId, user } = resolveOtherParticipant(
4692
+ conversation,
4693
+ loggedUserId,
4694
+ allUsers
4695
+ );
4696
+ const rawName = user?.name || "Unknown User";
4697
+ return {
4698
+ id: otherId || conversationId,
4699
+ conversationId,
4700
+ name: rawName.charAt(0).toUpperCase() + rawName.slice(1),
4701
+ image: user?.image || void 0,
4702
+ email: user?.email,
4703
+ isGroup: false,
4704
+ isLeft: !!conversation.isLeft,
4705
+ isBlocked: !!conversation.isBlocked,
4706
+ pinnedCount: conversation.pinnedCount,
4707
+ starredCount: conversation.starredCount
4708
+ };
4709
+ };
4710
+ var readConversationIdFromLocation = () => {
4711
+ try {
4712
+ return new URLSearchParams(window.location.search).get("conversationId") || "";
4713
+ } catch {
4714
+ return "";
4715
+ }
4716
+ };
4717
+ var consumedUrlConversationIds = /* @__PURE__ */ new Set();
4718
+ var installNotificationClickBridge = (options = {}) => {
4719
+ if (typeof window === "undefined") return () => void 0;
4720
+ const chatPath = options.chatPath || "/chat";
4721
+ const handleOpen = (conversationId) => {
4722
+ const id = String(conversationId || "").trim();
4723
+ if (!id) return;
4724
+ requestOpenConversation(id);
4725
+ const pathWithQuery = `${chatPath}?conversationId=${encodeURIComponent(id)}`;
4726
+ options.onNavigate?.(id, pathWithQuery);
4727
+ };
4728
+ const onSwMessage = (event) => {
4729
+ const data = event.data;
4730
+ console.log("[realtimex-push] SW \u2192 page message:", data);
4731
+ if (!data || data.type !== NOTIFICATION_CLICK_SW_TYPE) return;
4732
+ console.log(
4733
+ "[realtimex-push] notification click conversationId:",
4734
+ data.conversationId
4735
+ );
4736
+ handleOpen(String(data.conversationId || ""));
4737
+ };
4738
+ navigator.serviceWorker?.addEventListener("message", onSwMessage);
4739
+ const fromUrl = readConversationIdFromLocation();
4740
+ if (fromUrl && !consumedUrlConversationIds.has(fromUrl)) {
4741
+ consumedUrlConversationIds.add(fromUrl);
4742
+ handleOpen(fromUrl);
4743
+ }
4744
+ return () => {
4745
+ navigator.serviceWorker?.removeEventListener("message", onSwMessage);
4746
+ };
4747
+ };
4748
+
4749
+ // src/hooks/useChatController.ts
4629
4750
  function resolveMessageType(content, attachments) {
4630
4751
  if (attachments.length === 0) return "text";
4631
4752
  if (!content.trim() && attachments.length === 1) {
@@ -4698,6 +4819,10 @@ var useChatController = () => {
4698
4819
  const lastDM = useStore((s) => s.lastDM);
4699
4820
  const loggedUserDetails = useStore((s) => s.loggedUserDetails);
4700
4821
  const rateLimitResetAt2 = useStore((s) => s.rateLimitResetAt);
4822
+ const allUsers = useStore((s) => s.allUsers);
4823
+ const isFetchingConversations = useStore((s) => s.isFetchingConversations);
4824
+ const conversations = useStore((s) => s.conversations);
4825
+ const [pendingOpenConversationId, setPendingOpenConversationId] = useState(() => peekPendingOpenConversation());
4701
4826
  const conversationsLength = useStore(
4702
4827
  (s) => state.activeChannel?.conversationId ? 0 : s.conversations.length
4703
4828
  );
@@ -4726,6 +4851,73 @@ var useChatController = () => {
4726
4851
  isGroupConversation(latestInfo)
4727
4852
  ].join("|");
4728
4853
  });
4854
+ useEffect(() => {
4855
+ const onOpen = (event) => {
4856
+ const id = String(
4857
+ event.detail?.conversationId || ""
4858
+ ).trim();
4859
+ if (id) setPendingOpenConversationId(id);
4860
+ };
4861
+ window.addEventListener(OPEN_CONVERSATION_EVENT, onOpen);
4862
+ return () => window.removeEventListener(OPEN_CONVERSATION_EVENT, onOpen);
4863
+ }, []);
4864
+ useEffect(() => {
4865
+ if (!pendingOpenConversationId || !loggedUserDetails) return;
4866
+ let cancelled = false;
4867
+ const openPending = async () => {
4868
+ const targetId = String(pendingOpenConversationId);
4869
+ let conversation = conversations.find(
4870
+ (c) => String(c._id || c.id) === targetId
4871
+ ) || null;
4872
+ if (!conversation) {
4873
+ const fromInfo = conversationInfos[targetId];
4874
+ if (fromInfo) conversation = fromInfo;
4875
+ }
4876
+ if (!conversation) {
4877
+ if (isFetchingConversations) return;
4878
+ try {
4879
+ await fetchConversationInfo2(targetId);
4880
+ } catch {
4881
+ return;
4882
+ }
4883
+ if (cancelled) return;
4884
+ const stateNow = useStore.getState();
4885
+ conversation = stateNow.conversations.find(
4886
+ (c) => String(c._id || c.id) === targetId
4887
+ ) || stateNow.conversationInfos[targetId] || null;
4888
+ }
4889
+ if (!conversation || cancelled) return;
4890
+ const channel = mapConversationToChannel(
4891
+ conversation,
4892
+ loggedUserDetails._id,
4893
+ allUsers
4894
+ );
4895
+ setState((prev) => {
4896
+ if (prev.activeChannel?.conversationId && String(prev.activeChannel.conversationId) === targetId) {
4897
+ return prev;
4898
+ }
4899
+ return {
4900
+ ...prev,
4901
+ activeChannel: channel,
4902
+ activeConversationId: targetId
4903
+ };
4904
+ });
4905
+ consumePendingOpenConversation();
4906
+ setPendingOpenConversationId(null);
4907
+ };
4908
+ void openPending();
4909
+ return () => {
4910
+ cancelled = true;
4911
+ };
4912
+ }, [
4913
+ pendingOpenConversationId,
4914
+ loggedUserDetails,
4915
+ conversations,
4916
+ conversationInfos,
4917
+ isFetchingConversations,
4918
+ allUsers,
4919
+ fetchConversationInfo2
4920
+ ]);
4729
4921
  useEffect(() => {
4730
4922
  const handler = setTimeout(() => {
4731
4923
  updateState({ debouncedSearch: state.searchQuery });
@@ -17583,6 +17775,9 @@ var onForegroundPush = async (callback) => {
17583
17775
  }
17584
17776
  const { fb, messaging } = await getFirebaseMessaging(config.firebaseConfig);
17585
17777
  return fb.onMessage(messaging, (payload) => {
17778
+ console.log("[realtimex-push] FCM foreground payload (raw):", payload);
17779
+ console.log("[realtimex-push] FCM foreground data:", payload?.data);
17780
+ console.log("[realtimex-push] FCM foreground notification:", payload?.notification);
17586
17781
  callback({
17587
17782
  title: payload?.notification?.title,
17588
17783
  body: payload?.notification?.body,
@@ -17603,9 +17798,6 @@ var rememberToastId = (id) => {
17603
17798
  }
17604
17799
  return true;
17605
17800
  };
17606
- var resolveIncomingConversationId = (data) => String(
17607
- data?.conversationId || data?.conversation_id || data?.conversationID || ""
17608
- );
17609
17801
  var resolveToastText = (title, body) => {
17610
17802
  if (title && body) return `${title}: ${body}`;
17611
17803
  return title || body || "";
@@ -17615,7 +17807,39 @@ var emitToast = (payload, onPush) => {
17615
17807
  const title = payload.title || payload.data?.title;
17616
17808
  const body = payload.body || payload.data?.body || payload.data?.message;
17617
17809
  const text = resolveToastText(title, body);
17618
- if (text) showNotification(text, "info");
17810
+ const conversationId = resolveConversationIdFromPushData(payload.data);
17811
+ if (!text) return;
17812
+ if (conversationId) {
17813
+ toast2.custom(
17814
+ (t) => /* @__PURE__ */ jsx(
17815
+ "button",
17816
+ {
17817
+ type: "button",
17818
+ onClick: () => {
17819
+ toast2.dismiss(t.id);
17820
+ requestOpenConversation(conversationId);
17821
+ },
17822
+ style: {
17823
+ display: "block",
17824
+ width: "100%",
17825
+ textAlign: "left",
17826
+ cursor: "pointer",
17827
+ background: "var(--background, #fff)",
17828
+ color: "var(--foreground, #111)",
17829
+ border: "1px solid rgba(0,0,0,0.08)",
17830
+ borderRadius: 8,
17831
+ padding: "10px 14px",
17832
+ boxShadow: "0 4px 12px rgba(0,0,0,0.12)",
17833
+ font: "inherit"
17834
+ },
17835
+ children: text
17836
+ }
17837
+ ),
17838
+ { duration: 5e3 }
17839
+ );
17840
+ return;
17841
+ }
17842
+ showNotification(text, "info");
17619
17843
  };
17620
17844
  var ForegroundPushBridge = ({ onPush }) => {
17621
17845
  const lastDM = useStore((s) => s.lastDM);
@@ -17666,22 +17890,29 @@ var ForegroundPushBridge = ({ onPush }) => {
17666
17890
  let retryTimer = null;
17667
17891
  let cancelled = false;
17668
17892
  const handlePayload = (payload) => {
17669
- const incoming = resolveIncomingConversationId(payload.data);
17893
+ console.log("[realtimex-push] ForegroundPushBridge payload:", payload);
17894
+ console.log("[realtimex-push] ForegroundPushBridge data keys:", payload.data);
17895
+ const incoming = resolveConversationIdFromPushData(payload.data);
17670
17896
  const activeId = String(
17671
17897
  useStore.getState().activeConversationId || ""
17672
17898
  );
17673
17899
  const messageId2 = String(
17674
17900
  payload.data?.messageId || payload.data?.message_id || payload.data?.messageID || ""
17675
17901
  );
17902
+ console.log("[realtimex-push] resolved from backend data:", {
17903
+ conversationId: incoming,
17904
+ messageId: messageId2,
17905
+ activeConversationId: activeId
17906
+ });
17676
17907
  if (incoming && activeId && incoming === activeId) {
17677
- console.debug(
17908
+ console.log(
17678
17909
  "[realtimex-push] foreground push suppressed (conversation open):",
17679
17910
  incoming
17680
17911
  );
17681
17912
  return;
17682
17913
  }
17683
17914
  if (!rememberToastId(messageId2)) return;
17684
- console.debug("[realtimex-push] foreground push \u2192 toast:", {
17915
+ console.log("[realtimex-push] foreground push \u2192 toast:", {
17685
17916
  title: payload.title,
17686
17917
  conversationId: incoming,
17687
17918
  activeConversationId: activeId
@@ -17730,6 +17961,18 @@ var ForegroundPushBridge = ({ onPush }) => {
17730
17961
  window.removeEventListener(PUSH_CHANGED_EVENT, onPushChanged);
17731
17962
  };
17732
17963
  }, []);
17964
+ useEffect(() => {
17965
+ const onOpen = (event) => {
17966
+ const id = String(
17967
+ event.detail?.conversationId || ""
17968
+ );
17969
+ if (id) {
17970
+ console.debug("[realtimex-push] open-conversation event:", id);
17971
+ }
17972
+ };
17973
+ window.addEventListener(OPEN_CONVERSATION_EVENT, onOpen);
17974
+ return () => window.removeEventListener(OPEN_CONVERSATION_EVENT, onOpen);
17975
+ }, []);
17733
17976
  return /* @__PURE__ */ jsx(
17734
17977
  Toaster,
17735
17978
  {
@@ -18198,6 +18441,6 @@ var PushNotificationToggle = ({
18198
18441
  // src/index.ts
18199
18442
  var index_default = ChatMain_default;
18200
18443
 
18201
- export { CHAT_API_KEYS, CHAT_GET_API_KEYS, Calendar, CalendarDayButton, Channel, ChannelHeaderView_default as ChannelHeader, ChannelListView_default as ChannelList, ChannelListItem_default as ChannelListItem, Chat, ChatAlertsProvider, ChatAvatar_default as ChatAvatar, ChatCustomizationProvider, ChatDateJumpMenu, ChatLayout_default as ChatLayout, ChatLocaleProvider, ChatMain_default as ChatMain, ChatThemeProvider, ChatViewport, DefaultChannelListItem, DefaultChatAvatar, DefaultChatLayout_default as DefaultChatLayout, ForegroundPushBridge, ForwardModalView as ForwardModal, HeaderCallActions_default as HeaderCallActions, LoggedUserDetails_default as LoggedUserDetails, ChannelMessageBoxView_default as MessageInput, MessageItemView as MessageItem, ActiveChannelMessagesView_default as MessageList, PUSH_CHANGED_EVENT, PushNotificationToggle, apiGetPushConfig, apiGetPushPreference, apiRegisterPushToken, apiRemovePushToken, apiUpdatePushPreference, capitalizeFirst, clampJumpDate, index_default 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, socket_service_default as socketService, startOfLocalDay, toDateInputValue, uniqueList, useChatAlerts, useChatContext, useChatController, useChatCustomization, useChatCustomizationOptional, useChatFeatures, useChatFeaturesOptional, useChatLocale, useStore as useChatStore, useChatTheme, usePushNotifications };
18444
+ export { CHAT_API_KEYS, CHAT_GET_API_KEYS, Calendar, CalendarDayButton, Channel, ChannelHeaderView_default as ChannelHeader, ChannelListView_default as ChannelList, ChannelListItem_default as ChannelListItem, Chat, ChatAlertsProvider, ChatAvatar_default as ChatAvatar, ChatCustomizationProvider, ChatDateJumpMenu, ChatLayout_default as ChatLayout, ChatLocaleProvider, ChatMain_default as ChatMain, ChatThemeProvider, ChatViewport, DefaultChannelListItem, DefaultChatAvatar, DefaultChatLayout_default as DefaultChatLayout, ForegroundPushBridge, ForwardModalView as ForwardModal, HeaderCallActions_default as HeaderCallActions, LoggedUserDetails_default as LoggedUserDetails, ChannelMessageBoxView_default as MessageInput, MessageItemView as MessageItem, ActiveChannelMessagesView_default as MessageList, NOTIFICATION_CLICK_SW_TYPE, OPEN_CONVERSATION_EVENT, PUSH_CHANGED_EVENT, PushNotificationToggle, apiGetPushConfig, apiGetPushPreference, apiRegisterPushToken, apiRemovePushToken, apiUpdatePushPreference, capitalizeFirst, clampJumpDate, consumePendingOpenConversation, index_default as default, defaultChatClassNames, defaultChatComponents, defaultChatFeatures, defaultChatLayoutConfig, disablePushOnThisDevice, downloadFile, enablePushOnThisDevice, getChatBaseUrl, getChatQueryParamApis, getChatQueryParams, getChatQueryParamsByApi, getChatSocketUrl, getFirstAndLastNameOneCharacter, getResponsiveWidth, getSocketConfig, getStoredPushToken, installNotificationClickBridge, isEmpty, isPushSupported, mergeChatCustomization, mergeChatLayoutConfig, onForegroundPush, packageDefaultComponents, peekPendingOpenConversation, requestOpenConversation, resolveApiUrl, resolveChatApiKey, resolveConversationIdFromPushData, resolveJumpDateBounds, resolveJumpPreset, resolveJumpStep, resolveSocketUrl, setChatAccessToken, setChatBaseURL, setChatClientId, setChatQueryParamApis, setChatQueryParams, setChatQueryParamsByApi, setChatSocketUrl, showNotification, smoothScrollToMessage, socket_service_default as socketService, startOfLocalDay, toDateInputValue, uniqueList, useChatAlerts, useChatContext, useChatController, useChatCustomization, useChatCustomizationOptional, useChatFeatures, useChatFeaturesOptional, useChatLocale, useStore as useChatStore, useChatTheme, usePushNotifications };
18202
18445
  //# sourceMappingURL=index.mjs.map
18203
18446
  //# sourceMappingURL=index.mjs.map