@realtimexsco/live-chat 1.4.8 → 1.4.9

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,35 +1650,38 @@ interface ForegroundPushBridgeProps {
1650
1650
  }
1651
1651
  declare const ForegroundPushBridge: ({ onPush }: ForegroundPushBridgeProps) => React.JSX.Element;
1652
1652
 
1653
- /** CustomEvent name — detail: `{ conversationId: string }` */
1653
+ /** CustomEvent name — detail: `PushOpenRequest` */
1654
1654
  declare const OPEN_CONVERSATION_EVENT = "realtimex:open-conversation";
1655
- /** Service-worker → page postMessage type */
1655
+ /** Service-worker → page postMessage / BroadcastChannel type */
1656
1656
  declare const NOTIFICATION_CLICK_SW_TYPE = "realtimex:notification-click";
1657
+ /** Must match the channel name in firebase-messaging-sw.js */
1658
+ declare const PUSH_BROADCAST_CHANNEL = "realtimex-push";
1659
+ interface PushOpenRequest {
1660
+ conversationId: string;
1661
+ senderId?: string;
1662
+ kind?: string;
1663
+ messageId?: string;
1664
+ title?: string;
1665
+ }
1657
1666
  declare const resolveConversationIdFromPushData: (data?: Record<string, unknown> | null) => string;
1667
+ /** @deprecated use peekPendingOpenRequest */
1658
1668
  declare const peekPendingOpenConversation: () => string | null;
1669
+ declare const peekPendingOpenRequest: () => PushOpenRequest | null;
1670
+ /** @deprecated use consumePendingOpenRequest */
1659
1671
  declare const consumePendingOpenConversation: () => string | null;
1672
+ declare const consumePendingOpenRequest: () => PushOpenRequest | null;
1660
1673
  /**
1661
1674
  * 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`).
1675
+ * mounted yet — the request is kept in sessionStorage until the chat consumes it.
1665
1676
  */
1666
- declare const requestOpenConversation: (conversationId: string) => void;
1677
+ declare const requestOpenConversation: (conversationId: string, meta?: Record<string, unknown> | PushOpenRequest) => void;
1678
+ /** Open immediately when the chat store/controller is already mounted. */
1679
+ declare const buildChannelFromPushRequest: (request: PushOpenRequest, loggedUserId?: string, allUsers?: any[]) => IChannel;
1667
1680
  interface NotificationClickBridgeOptions {
1668
1681
  /** Host chat route, default `/chat` */
1669
1682
  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
1683
  onNavigate?: (conversationId: string, pathWithQuery: string) => void;
1676
1684
  }
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
1685
  declare const installNotificationClickBridge: (options?: NotificationClickBridgeOptions) => (() => void);
1683
1686
 
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 };
1687
+ 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_BROADCAST_CHANNEL, PUSH_CHANGED_EVENT, type PendingJump, type PermissionDrawerSlotProps, type PhoneCallButtonSlotProps, type PinnedMessagesDrawerSlotProps, type PushConfig, PushNotificationToggle, type PushNotificationToggleProps, type PushNotificationsState, type PushOpenRequest, type PushPreference, type StarredMessagesDrawerSlotProps, type UIConfig, type UsePushNotifications, type VideoCallButtonSlotProps, apiGetPushConfig, apiGetPushPreference, apiRegisterPushToken, apiRemovePushToken, apiUpdatePushPreference, buildChannelFromPushRequest, capitalizeFirst, clampJumpDate, consumePendingOpenConversation, consumePendingOpenRequest, 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, peekPendingOpenRequest, 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,35 +1650,38 @@ interface ForegroundPushBridgeProps {
1650
1650
  }
1651
1651
  declare const ForegroundPushBridge: ({ onPush }: ForegroundPushBridgeProps) => React.JSX.Element;
1652
1652
 
1653
- /** CustomEvent name — detail: `{ conversationId: string }` */
1653
+ /** CustomEvent name — detail: `PushOpenRequest` */
1654
1654
  declare const OPEN_CONVERSATION_EVENT = "realtimex:open-conversation";
1655
- /** Service-worker → page postMessage type */
1655
+ /** Service-worker → page postMessage / BroadcastChannel type */
1656
1656
  declare const NOTIFICATION_CLICK_SW_TYPE = "realtimex:notification-click";
1657
+ /** Must match the channel name in firebase-messaging-sw.js */
1658
+ declare const PUSH_BROADCAST_CHANNEL = "realtimex-push";
1659
+ interface PushOpenRequest {
1660
+ conversationId: string;
1661
+ senderId?: string;
1662
+ kind?: string;
1663
+ messageId?: string;
1664
+ title?: string;
1665
+ }
1657
1666
  declare const resolveConversationIdFromPushData: (data?: Record<string, unknown> | null) => string;
1667
+ /** @deprecated use peekPendingOpenRequest */
1658
1668
  declare const peekPendingOpenConversation: () => string | null;
1669
+ declare const peekPendingOpenRequest: () => PushOpenRequest | null;
1670
+ /** @deprecated use consumePendingOpenRequest */
1659
1671
  declare const consumePendingOpenConversation: () => string | null;
1672
+ declare const consumePendingOpenRequest: () => PushOpenRequest | null;
1660
1673
  /**
1661
1674
  * 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`).
1675
+ * mounted yet — the request is kept in sessionStorage until the chat consumes it.
1665
1676
  */
1666
- declare const requestOpenConversation: (conversationId: string) => void;
1677
+ declare const requestOpenConversation: (conversationId: string, meta?: Record<string, unknown> | PushOpenRequest) => void;
1678
+ /** Open immediately when the chat store/controller is already mounted. */
1679
+ declare const buildChannelFromPushRequest: (request: PushOpenRequest, loggedUserId?: string, allUsers?: any[]) => IChannel;
1667
1680
  interface NotificationClickBridgeOptions {
1668
1681
  /** Host chat route, default `/chat` */
1669
1682
  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
1683
  onNavigate?: (conversationId: string, pathWithQuery: string) => void;
1676
1684
  }
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
1685
  declare const installNotificationClickBridge: (options?: NotificationClickBridgeOptions) => (() => void);
1683
1686
 
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 };
1687
+ 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_BROADCAST_CHANNEL, PUSH_CHANGED_EVENT, type PendingJump, type PermissionDrawerSlotProps, type PhoneCallButtonSlotProps, type PinnedMessagesDrawerSlotProps, type PushConfig, PushNotificationToggle, type PushNotificationToggleProps, type PushNotificationsState, type PushOpenRequest, type PushPreference, type StarredMessagesDrawerSlotProps, type UIConfig, type UsePushNotifications, type VideoCallButtonSlotProps, apiGetPushConfig, apiGetPushPreference, apiRegisterPushToken, apiRemovePushToken, apiUpdatePushPreference, buildChannelFromPushRequest, capitalizeFirst, clampJumpDate, consumePendingOpenConversation, consumePendingOpenRequest, 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, peekPendingOpenRequest, 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
@@ -4631,46 +4631,112 @@ init_store_helpers();
4631
4631
  init_store_helpers();
4632
4632
  var OPEN_CONVERSATION_EVENT = "realtimex:open-conversation";
4633
4633
  var NOTIFICATION_CLICK_SW_TYPE = "realtimex:notification-click";
4634
+ var PUSH_BROADCAST_CHANNEL = "realtimex-push";
4634
4635
  var PENDING_STORAGE_KEY = "realtimex:pending-open-conversation";
4635
4636
  var resolveConversationIdFromPushData = (data) => {
4636
4637
  if (!data || typeof data !== "object") return "";
4637
- const nested = data.FCM_MSG && typeof data.FCM_MSG === "object" ? data.FCM_MSG.data : void 0;
4638
+ let fcmMsg = data.FCM_MSG;
4639
+ if (typeof fcmMsg === "string") {
4640
+ try {
4641
+ fcmMsg = JSON.parse(fcmMsg);
4642
+ } catch {
4643
+ fcmMsg = void 0;
4644
+ }
4645
+ }
4646
+ const nested = fcmMsg && typeof fcmMsg === "object" ? fcmMsg.data : void 0;
4638
4647
  const source = { ...nested || {}, ...data };
4639
4648
  return String(
4640
4649
  source.conversationId || source.conversation_id || source.conversationID || ""
4641
- );
4650
+ ).trim();
4651
+ };
4652
+ var normalizePushMeta = (meta) => {
4653
+ if (!meta || typeof meta !== "object") return {};
4654
+ return {
4655
+ senderId: String(
4656
+ meta.senderId || meta.sender_id || ""
4657
+ ).trim() || void 0,
4658
+ kind: String(meta.kind || "").trim() || void 0,
4659
+ messageId: String(
4660
+ meta.messageId || meta.message_id || ""
4661
+ ).trim() || void 0,
4662
+ title: String(meta.title || "").trim() || void 0
4663
+ };
4664
+ };
4665
+ var parsePendingRaw = (raw) => {
4666
+ if (!raw) return null;
4667
+ try {
4668
+ const parsed = JSON.parse(raw);
4669
+ if (parsed?.conversationId) {
4670
+ return {
4671
+ conversationId: String(parsed.conversationId).trim(),
4672
+ ...normalizePushMeta(parsed)
4673
+ };
4674
+ }
4675
+ } catch {
4676
+ }
4677
+ const id = String(raw).trim();
4678
+ return id ? { conversationId: id } : null;
4642
4679
  };
4643
- var peekPendingOpenConversation = () => {
4680
+ var peekPendingOpenConversation = () => peekPendingOpenRequest()?.conversationId ?? null;
4681
+ var peekPendingOpenRequest = () => {
4644
4682
  try {
4645
- return sessionStorage.getItem(PENDING_STORAGE_KEY);
4683
+ return parsePendingRaw(sessionStorage.getItem(PENDING_STORAGE_KEY));
4646
4684
  } catch {
4647
4685
  return null;
4648
4686
  }
4649
4687
  };
4650
- var consumePendingOpenConversation = () => {
4651
- const id = peekPendingOpenConversation();
4688
+ var consumePendingOpenConversation = () => consumePendingOpenRequest()?.conversationId ?? null;
4689
+ var consumePendingOpenRequest = () => {
4690
+ const request = peekPendingOpenRequest();
4652
4691
  try {
4653
4692
  sessionStorage.removeItem(PENDING_STORAGE_KEY);
4654
4693
  } catch {
4655
4694
  }
4656
- return id;
4695
+ return request;
4657
4696
  };
4658
- var requestOpenConversation = (conversationId) => {
4697
+ var requestOpenConversation = (conversationId, meta) => {
4659
4698
  const id = String(conversationId || "").trim();
4660
4699
  if (!id) return;
4700
+ const request = {
4701
+ conversationId: id,
4702
+ ...normalizePushMeta(meta)
4703
+ };
4704
+ console.log("[realtimex-push] requestOpenConversation:", request);
4661
4705
  try {
4662
- sessionStorage.setItem(PENDING_STORAGE_KEY, id);
4706
+ sessionStorage.setItem(PENDING_STORAGE_KEY, JSON.stringify(request));
4663
4707
  } catch {
4664
4708
  }
4665
4709
  try {
4666
4710
  window.dispatchEvent(
4667
- new CustomEvent(OPEN_CONVERSATION_EVENT, {
4668
- detail: { conversationId: id }
4669
- })
4711
+ new CustomEvent(OPEN_CONVERSATION_EVENT, { detail: request })
4670
4712
  );
4671
4713
  } catch {
4672
4714
  }
4673
4715
  };
4716
+ var buildChannelFromPushRequest = (request, loggedUserId, allUsers) => {
4717
+ const conversationId = request.conversationId;
4718
+ const isGroup = request.kind === "group";
4719
+ const senderId = String(request.senderId || "").trim();
4720
+ if (isGroup) {
4721
+ const rawName2 = request.title || "Group Chat";
4722
+ return {
4723
+ id: conversationId,
4724
+ conversationId,
4725
+ name: rawName2.charAt(0).toUpperCase() + rawName2.slice(1),
4726
+ isGroup: true
4727
+ };
4728
+ }
4729
+ const senderUser = senderId ? (allUsers || []).find((user) => String(user._id) === senderId) : null;
4730
+ const rawName = senderUser?.name || request.title || "New message";
4731
+ return {
4732
+ id: senderId || conversationId,
4733
+ conversationId,
4734
+ name: rawName.charAt(0).toUpperCase() + rawName.slice(1),
4735
+ image: senderUser?.image || void 0,
4736
+ email: senderUser?.email,
4737
+ isGroup: false
4738
+ };
4739
+ };
4674
4740
  var mapConversationToChannel = (conversation, loggedUserId, allUsers) => {
4675
4741
  const conversationId = String(conversation?._id || conversation?.id || "");
4676
4742
  const isGroup = isGroupConversation(conversation);
@@ -4715,34 +4781,46 @@ var readConversationIdFromLocation = () => {
4715
4781
  }
4716
4782
  };
4717
4783
  var consumedUrlConversationIds = /* @__PURE__ */ new Set();
4784
+ var handleNotificationOpen = (conversationId, pushData, options) => {
4785
+ const id = String(conversationId || "").trim();
4786
+ if (!id) {
4787
+ console.warn("[realtimex-push] notification open ignored \u2014 no conversationId", pushData);
4788
+ return;
4789
+ }
4790
+ requestOpenConversation(id, pushData);
4791
+ const chatPath = options.chatPath || "/chat";
4792
+ const pathWithQuery = `${chatPath}?conversationId=${encodeURIComponent(id)}`;
4793
+ options.onNavigate?.(id, pathWithQuery);
4794
+ };
4718
4795
  var installNotificationClickBridge = (options = {}) => {
4719
4796
  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
4797
  const onSwMessage = (event) => {
4729
4798
  const data = event.data;
4730
4799
  console.log("[realtimex-push] SW \u2192 page message:", data);
4731
4800
  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 || ""));
4801
+ const pushData = data.data && typeof data.data === "object" ? data.data : void 0;
4802
+ const conversationId = String(data.conversationId || "") || resolveConversationIdFromPushData(pushData);
4803
+ console.log("[realtimex-push] notification click \u2192 open:", {
4804
+ conversationId,
4805
+ pushData
4806
+ });
4807
+ handleNotificationOpen(conversationId, pushData, options);
4737
4808
  };
4738
4809
  navigator.serviceWorker?.addEventListener("message", onSwMessage);
4810
+ let broadcast = null;
4811
+ try {
4812
+ broadcast = new BroadcastChannel(PUSH_BROADCAST_CHANNEL);
4813
+ broadcast.onmessage = onSwMessage;
4814
+ } catch {
4815
+ }
4739
4816
  const fromUrl = readConversationIdFromLocation();
4740
4817
  if (fromUrl && !consumedUrlConversationIds.has(fromUrl)) {
4741
4818
  consumedUrlConversationIds.add(fromUrl);
4742
- handleOpen(fromUrl);
4819
+ handleNotificationOpen(fromUrl, void 0, options);
4743
4820
  }
4744
4821
  return () => {
4745
4822
  navigator.serviceWorker?.removeEventListener("message", onSwMessage);
4823
+ broadcast?.close();
4746
4824
  };
4747
4825
  };
4748
4826
 
@@ -4822,7 +4900,7 @@ var useChatController = () => {
4822
4900
  const allUsers = useStore((s) => s.allUsers);
4823
4901
  const isFetchingConversations = useStore((s) => s.isFetchingConversations);
4824
4902
  const conversations = useStore((s) => s.conversations);
4825
- const [pendingOpenConversationId, setPendingOpenConversationId] = useState(() => peekPendingOpenConversation());
4903
+ const [pendingOpenRequest, setPendingOpenRequest] = useState(() => peekPendingOpenRequest());
4826
4904
  const conversationsLength = useStore(
4827
4905
  (s) => state.activeChannel?.conversationId ? 0 : s.conversations.length
4828
4906
  );
@@ -4853,32 +4931,42 @@ var useChatController = () => {
4853
4931
  });
4854
4932
  useEffect(() => {
4855
4933
  const onOpen = (event) => {
4856
- const id = String(
4857
- event.detail?.conversationId || ""
4858
- ).trim();
4859
- if (id) setPendingOpenConversationId(id);
4934
+ const detail = event.detail;
4935
+ if (detail?.conversationId) {
4936
+ console.log("[realtimex-push] OPEN_CONVERSATION_EVENT:", detail);
4937
+ setPendingOpenRequest({
4938
+ conversationId: String(detail.conversationId),
4939
+ senderId: detail.senderId,
4940
+ kind: detail.kind,
4941
+ messageId: detail.messageId,
4942
+ title: detail.title
4943
+ });
4944
+ }
4860
4945
  };
4861
4946
  window.addEventListener(OPEN_CONVERSATION_EVENT, onOpen);
4862
4947
  return () => window.removeEventListener(OPEN_CONVERSATION_EVENT, onOpen);
4863
4948
  }, []);
4864
4949
  useEffect(() => {
4865
- if (!pendingOpenConversationId || !loggedUserDetails) return;
4950
+ if (!pendingOpenRequest?.conversationId || !loggedUserDetails) return;
4866
4951
  let cancelled = false;
4867
4952
  const openPending = async () => {
4868
- const targetId = String(pendingOpenConversationId);
4953
+ const targetId = String(pendingOpenRequest.conversationId);
4954
+ console.log("[realtimex-push] opening conversation:", pendingOpenRequest);
4869
4955
  let conversation = conversations.find(
4870
4956
  (c) => String(c._id || c.id) === targetId
4871
4957
  ) || null;
4872
4958
  if (!conversation) {
4873
- const fromInfo = conversationInfos[targetId];
4874
- if (fromInfo) conversation = fromInfo;
4959
+ conversation = conversationInfos[targetId] || null;
4875
4960
  }
4876
4961
  if (!conversation) {
4877
- if (isFetchingConversations) return;
4962
+ if (isFetchingConversations) {
4963
+ console.log("[realtimex-push] waiting for conversations list\u2026");
4964
+ return;
4965
+ }
4878
4966
  try {
4879
4967
  await fetchConversationInfo2(targetId);
4880
- } catch {
4881
- return;
4968
+ } catch (error) {
4969
+ console.warn("[realtimex-push] fetchConversationInfo failed:", error);
4882
4970
  }
4883
4971
  if (cancelled) return;
4884
4972
  const stateNow = useStore.getState();
@@ -4886,12 +4974,17 @@ var useChatController = () => {
4886
4974
  (c) => String(c._id || c.id) === targetId
4887
4975
  ) || stateNow.conversationInfos[targetId] || null;
4888
4976
  }
4889
- if (!conversation || cancelled) return;
4890
- const channel = mapConversationToChannel(
4977
+ const channel = conversation ? mapConversationToChannel(
4891
4978
  conversation,
4892
4979
  loggedUserDetails._id,
4893
4980
  allUsers
4981
+ ) : buildChannelFromPushRequest(
4982
+ pendingOpenRequest,
4983
+ loggedUserDetails._id,
4984
+ allUsers
4894
4985
  );
4986
+ console.log("[realtimex-push] selected channel:", channel);
4987
+ if (cancelled) return;
4895
4988
  setState((prev) => {
4896
4989
  if (prev.activeChannel?.conversationId && String(prev.activeChannel.conversationId) === targetId) {
4897
4990
  return prev;
@@ -4902,15 +4995,16 @@ var useChatController = () => {
4902
4995
  activeConversationId: targetId
4903
4996
  };
4904
4997
  });
4905
- consumePendingOpenConversation();
4906
- setPendingOpenConversationId(null);
4998
+ useStore.getState().setActiveConversationId(targetId);
4999
+ consumePendingOpenRequest();
5000
+ setPendingOpenRequest(null);
4907
5001
  };
4908
5002
  void openPending();
4909
5003
  return () => {
4910
5004
  cancelled = true;
4911
5005
  };
4912
5006
  }, [
4913
- pendingOpenConversationId,
5007
+ pendingOpenRequest,
4914
5008
  loggedUserDetails,
4915
5009
  conversations,
4916
5010
  conversationInfos,
@@ -17817,7 +17911,7 @@ var emitToast = (payload, onPush) => {
17817
17911
  type: "button",
17818
17912
  onClick: () => {
17819
17913
  toast2.dismiss(t.id);
17820
- requestOpenConversation(conversationId);
17914
+ requestOpenConversation(conversationId, payload.data);
17821
17915
  },
17822
17916
  style: {
17823
17917
  display: "block",
@@ -18441,6 +18535,6 @@ var PushNotificationToggle = ({
18441
18535
  // src/index.ts
18442
18536
  var index_default = ChatMain_default;
18443
18537
 
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 };
18538
+ 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_BROADCAST_CHANNEL, PUSH_CHANGED_EVENT, PushNotificationToggle, apiGetPushConfig, apiGetPushPreference, apiRegisterPushToken, apiRemovePushToken, apiUpdatePushPreference, buildChannelFromPushRequest, capitalizeFirst, clampJumpDate, consumePendingOpenConversation, consumePendingOpenRequest, 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, peekPendingOpenRequest, 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 };
18445
18539
  //# sourceMappingURL=index.mjs.map
18446
18540
  //# sourceMappingURL=index.mjs.map