@dialtribe/chat-client 0.4.0 → 0.5.0

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.mjs CHANGED
@@ -466,6 +466,156 @@ var InboxStore = class extends Store {
466
466
  }
467
467
  };
468
468
 
469
+ // src/client/NotificationsStore.ts
470
+ var NotificationsStore = class extends Store {
471
+ constructor(client) {
472
+ super({ status: "idle", items: [], unreadCount: 0, hasMore: false, loadingMore: false, error: null });
473
+ this.client = client;
474
+ this.refs = 0;
475
+ this.unlisten = [];
476
+ this.refreshTimer = null;
477
+ this.nextCursor = null;
478
+ }
479
+ acquire() {
480
+ this.refs += 1;
481
+ if (this.refs > 1) return;
482
+ this.unlisten = [
483
+ this.client.on("connected", () => this.scheduleRefresh(0)),
484
+ this.client.on("user", (event) => this.onUserEvent(event))
485
+ ];
486
+ void this.client.start();
487
+ this.scheduleRefresh(0);
488
+ }
489
+ release() {
490
+ this.refs = Math.max(0, this.refs - 1);
491
+ if (this.refs > 0) return;
492
+ for (const off of this.unlisten) off();
493
+ this.unlisten = [];
494
+ if (this.refreshTimer) clearTimeout(this.refreshTimer);
495
+ }
496
+ // ===========================================================================
497
+ // Actions
498
+ // ===========================================================================
499
+ /** Reload the first page and the unread count. */
500
+ async refresh() {
501
+ if (this.getSnapshot().status === "idle") this.update({ status: "loading" });
502
+ try {
503
+ const page = await this.client.api("/notifications/inbox?limit=30");
504
+ this.nextCursor = page.nextCursor;
505
+ this.update({
506
+ status: "ready",
507
+ items: page.items,
508
+ unreadCount: page.unreadCount,
509
+ hasMore: page.nextCursor !== null,
510
+ error: null
511
+ });
512
+ } catch (err) {
513
+ this.update({
514
+ status: "error",
515
+ error: err instanceof ChatRequestError ? err : new ChatRequestError("network", "Could not load notifications")
516
+ });
517
+ }
518
+ }
519
+ /** Append the next (older) page. */
520
+ async loadMore() {
521
+ const snap = this.getSnapshot();
522
+ if (!this.nextCursor || snap.loadingMore) return;
523
+ this.update({ loadingMore: true });
524
+ try {
525
+ const page = await this.client.api(
526
+ `/notifications/inbox?limit=30&cursor=${encodeURIComponent(this.nextCursor)}`
527
+ );
528
+ this.nextCursor = page.nextCursor;
529
+ const have = new Set(this.getSnapshot().items.map((i) => i.id));
530
+ this.update({
531
+ items: [...this.getSnapshot().items, ...page.items.filter((i) => !have.has(i.id))],
532
+ hasMore: page.nextCursor !== null,
533
+ unreadCount: page.unreadCount
534
+ });
535
+ } finally {
536
+ this.update({ loadingMore: false });
537
+ }
538
+ }
539
+ /** Mark items read (optimistic). */
540
+ async markRead(ids) {
541
+ const unread = ids.filter((id) => this.getSnapshot().items.some((i) => i.id === id && !i.readAt));
542
+ if (unread.length === 0) return;
543
+ this.applyRead(unread, Math.max(0, this.getSnapshot().unreadCount - unread.length));
544
+ const { unreadCount } = await this.client.api("/notifications/inbox", {
545
+ method: "POST",
546
+ body: { action: "read", ids: unread }
547
+ });
548
+ this.update({ unreadCount });
549
+ }
550
+ /** Mark everything read (optimistic). */
551
+ async markAllRead() {
552
+ this.applyRead(null, 0);
553
+ const { unreadCount } = await this.client.api("/notifications/inbox", {
554
+ method: "POST",
555
+ body: { action: "read-all" }
556
+ });
557
+ this.update({ unreadCount });
558
+ }
559
+ /** Record that the list was shown (for stats; doesn't change unread). */
560
+ async markSeen() {
561
+ const unseen = this.getSnapshot().items.filter((i) => !i.seenAt).map((i) => i.id);
562
+ if (unseen.length === 0) return;
563
+ const now = (/* @__PURE__ */ new Date()).toISOString();
564
+ const set = new Set(unseen);
565
+ this.update({ items: this.getSnapshot().items.map((i) => set.has(i.id) ? { ...i, seenAt: now } : i) });
566
+ await this.client.api("/notifications/inbox", { method: "POST", body: { action: "seen", ids: unseen } });
567
+ }
568
+ /** Record a click (also marks read). Pass every id in a grouped row. */
569
+ async click(ids) {
570
+ if (ids.length === 0) return;
571
+ const now = (/* @__PURE__ */ new Date()).toISOString();
572
+ const set = new Set(ids);
573
+ const newlyRead = this.getSnapshot().items.filter((i) => set.has(i.id) && !i.readAt).length;
574
+ this.update({
575
+ items: this.getSnapshot().items.map(
576
+ (i) => set.has(i.id) ? { ...i, clickedAt: i.clickedAt ?? now, readAt: i.readAt ?? now } : i
577
+ ),
578
+ unreadCount: Math.max(0, this.getSnapshot().unreadCount - newlyRead)
579
+ });
580
+ const { unreadCount } = await this.client.api("/notifications/inbox", {
581
+ method: "POST",
582
+ body: { action: "click", ids }
583
+ });
584
+ this.update({ unreadCount });
585
+ }
586
+ // ===========================================================================
587
+ // Live updates
588
+ // ===========================================================================
589
+ onUserEvent(event) {
590
+ if (event.type === "notification.created") {
591
+ const items = this.getSnapshot().items;
592
+ if (items.some((i) => i.id === event.notification.id)) return;
593
+ this.update({
594
+ items: [event.notification, ...items],
595
+ unreadCount: typeof event.unreadCount === "number" ? event.unreadCount : this.getSnapshot().unreadCount + (event.notification.readAt ? 0 : 1)
596
+ });
597
+ } else if (event.type === "notification.read") {
598
+ this.applyRead(event.ids, event.unreadCount);
599
+ }
600
+ }
601
+ applyRead(ids, unreadCount) {
602
+ const now = (/* @__PURE__ */ new Date()).toISOString();
603
+ const set = ids ? new Set(ids) : null;
604
+ this.update({
605
+ items: this.getSnapshot().items.map((i) => !i.readAt && (!set || set.has(i.id)) ? { ...i, readAt: now } : i),
606
+ unreadCount
607
+ });
608
+ }
609
+ scheduleRefresh(delayMs) {
610
+ if (this.refs === 0) return;
611
+ if (this.refreshTimer) clearTimeout(this.refreshTimer);
612
+ this.refreshTimer = setTimeout(() => {
613
+ this.refreshTimer = null;
614
+ void this.refresh();
615
+ }, delayMs);
616
+ }
617
+ };
618
+
469
619
  // src/client/ChatClient.ts
470
620
  var ConnectionStore = class extends Store {
471
621
  set(patch) {
@@ -485,7 +635,9 @@ var ChatClient = class {
485
635
  this.generation = 0;
486
636
  this.rooms = /* @__PURE__ */ new Map();
487
637
  this.inboxStore = null;
638
+ this.notificationsStore = null;
488
639
  this.serverUrl = options.serverUrl.replace(/\/$/, "");
640
+ this.apiUrl = (options.apiUrl ?? "https://dialtribe.com").replace(/\/$/, "");
489
641
  }
490
642
  // ===========================================================================
491
643
  // Lifecycle
@@ -527,6 +679,11 @@ var ChatClient = class {
527
679
  this.inboxStore ?? (this.inboxStore = new InboxStore(this));
528
680
  return this.inboxStore;
529
681
  }
682
+ /** The signed-in user's notifications (created on first use). */
683
+ get notifications() {
684
+ this.notificationsStore ?? (this.notificationsStore = new NotificationsStore(this));
685
+ return this.notificationsStore;
686
+ }
530
687
  get self() {
531
688
  return this.connection.getSnapshot().self;
532
689
  }
@@ -646,6 +803,13 @@ var ChatClient = class {
646
803
  users(roomId) {
647
804
  return this.request(`/rooms/${encodeURIComponent(roomId)}/users`);
648
805
  }
806
+ /**
807
+ * Authenticated JSON request to the Dialtribe API (apiUrl), with the same
808
+ * session token and 401 retry as chat-ws requests. `path` is under /api/public/v1.
809
+ */
810
+ api(path, init = {}) {
811
+ return this.request(path, init, `${this.apiUrl}/api/public/v1`);
812
+ }
649
813
  /** A DM action on POST /dm (see DMS.md). */
650
814
  dm(action, fields = {}) {
651
815
  return this.request("/dm", { method: "POST", body: { action, ...fields } });
@@ -655,8 +819,8 @@ var ChatClient = class {
655
819
  * token on 401. Throws ChatRequestError for transport failures and for
656
820
  * `{ ok: false, error }` bodies.
657
821
  */
658
- async request(path, init = {}) {
659
- const attempt = async (token) => fetch(this.serverUrl + path, {
822
+ async request(path, init = {}, base = this.serverUrl) {
823
+ const attempt = async (token) => fetch(base + path, {
660
824
  method: init.method ?? "GET",
661
825
  headers: {
662
826
  Authorization: `Bearer ${token}`,
@@ -717,17 +881,20 @@ var MessagesUiStore = class extends Store {
717
881
  openRoom(roomId) {
718
882
  this.update({ open: true, view: { kind: "room", roomId } });
719
883
  }
884
+ openNotifications() {
885
+ this.update({ open: true, view: { kind: "notifications" } });
886
+ }
720
887
  openItem(itemId) {
721
888
  this.update({ open: true, view: { kind: "item", itemId } });
722
889
  }
723
890
  };
724
891
  var ClientContext = createContext(null);
725
892
  var MessagesUiContext = createContext(null);
726
- function DialtribeChatProvider({ children, getSessionToken, serverUrl, websocketUrl, websocket }) {
893
+ function DialtribeChatProvider({ children, getSessionToken, serverUrl, apiUrl, websocketUrl, websocket }) {
727
894
  const tokenRef = useRef(getSessionToken);
728
895
  tokenRef.current = getSessionToken;
729
896
  const [client] = useState(
730
- () => new ChatClient({ serverUrl, websocketUrl, websocket, getSessionToken: () => tokenRef.current() })
897
+ () => new ChatClient({ serverUrl, apiUrl, websocketUrl, websocket, getSessionToken: () => tokenRef.current() })
731
898
  );
732
899
  const [messagesUi] = useState(() => new MessagesUiStore());
733
900
  useEffect(() => {
@@ -833,6 +1000,7 @@ function useDialtribeMessages() {
833
1000
  openInbox: () => ui.openInbox(),
834
1001
  openRoom: (roomId) => ui.openRoom(roomId),
835
1002
  openItem: (itemId) => ui.openItem(itemId),
1003
+ openNotifications: () => ui.openNotifications(),
836
1004
  messageUser: async (userId, hint) => {
837
1005
  const result = await client.inbox.requestDM(userId, hint);
838
1006
  ui.openRoom(result.roomId);
@@ -843,6 +1011,26 @@ function useDialtribeMessages() {
843
1011
  );
844
1012
  return useMemo(() => ({ isOpen: snapshot.open, view: snapshot.view, ...actions }), [snapshot, actions]);
845
1013
  }
1014
+ function useDialtribeNotifications() {
1015
+ const store = useChatClient().notifications;
1016
+ useEffect(() => {
1017
+ store.acquire();
1018
+ return () => store.release();
1019
+ }, [store]);
1020
+ const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
1021
+ const actions = useMemo(
1022
+ () => ({
1023
+ refresh: store.refresh.bind(store),
1024
+ loadMore: store.loadMore.bind(store),
1025
+ markRead: store.markRead.bind(store),
1026
+ markAllRead: store.markAllRead.bind(store),
1027
+ markSeen: store.markSeen.bind(store),
1028
+ click: store.click.bind(store)
1029
+ }),
1030
+ [store]
1031
+ );
1032
+ return useMemo(() => ({ ...snapshot, ...actions }), [snapshot, actions]);
1033
+ }
846
1034
 
847
1035
  // src/types/index.ts
848
1036
  function parseReactions(reactionsJson) {
@@ -1158,7 +1346,20 @@ var DEFAULT_LABELS = {
1158
1346
  archiveConfirm: "Archive",
1159
1347
  cancel: "Cancel",
1160
1348
  messagePlaceholder: "Message...",
1161
- openMessages: "Open messages"
1349
+ openMessages: "Open messages",
1350
+ notifications: "Notifications",
1351
+ noNotifications: "No notifications yet",
1352
+ markAllRead: "Mark all read",
1353
+ loadMore: "Load more",
1354
+ groupMore: (count) => `and ${count} more`,
1355
+ timeAgo: (date) => {
1356
+ const s = Math.max(0, Math.floor((Date.now() - date.getTime()) / 1e3));
1357
+ if (s < 60) return "now";
1358
+ if (s < 3600) return `${Math.floor(s / 60)}m`;
1359
+ if (s < 86400) return `${Math.floor(s / 3600)}h`;
1360
+ if (s < 604800) return `${Math.floor(s / 86400)}d`;
1361
+ return date.toLocaleDateString(void 0, { month: "short", day: "numeric" });
1362
+ }
1162
1363
  };
1163
1364
  function badgeText(count) {
1164
1365
  return count > 99 ? "99+" : String(count);
@@ -1405,6 +1606,93 @@ function CloseIcon() {
1405
1606
  function ChevronLeft() {
1406
1607
  return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M15 18l-6-6 6-6" }) });
1407
1608
  }
1609
+ function groupRows(items) {
1610
+ const rows = [];
1611
+ const byKey = /* @__PURE__ */ new Map();
1612
+ for (const item of items) {
1613
+ const existing = item.groupKey ? byKey.get(item.groupKey) : void 0;
1614
+ if (existing) {
1615
+ existing.ids.push(item.id);
1616
+ existing.more += 1;
1617
+ existing.unread || (existing.unread = !item.readAt);
1618
+ continue;
1619
+ }
1620
+ const row = { lead: item, ids: [item.id], more: 0, unread: !item.readAt };
1621
+ rows.push(row);
1622
+ if (item.groupKey) byKey.set(item.groupKey, row);
1623
+ }
1624
+ return rows;
1625
+ }
1626
+ function NotificationsPanel({ labels, onClose, onOpen }) {
1627
+ const n = useDialtribeNotifications();
1628
+ const rows = useMemo(() => groupRows(n.items), [n.items]);
1629
+ const { status, markSeen } = n;
1630
+ useEffect(() => {
1631
+ if (status === "ready") void markSeen().catch(() => {
1632
+ });
1633
+ }, [status, markSeen]);
1634
+ const open = (row) => {
1635
+ void n.click(row.ids).catch(() => {
1636
+ });
1637
+ const handled = onOpen?.(row.lead);
1638
+ if (!handled && row.lead.url) window.location.assign(row.lead.url);
1639
+ };
1640
+ return /* @__PURE__ */ jsxs("div", { className: "dtc-notif", children: [
1641
+ /* @__PURE__ */ jsxs("div", { className: "dtc-panel-header", children: [
1642
+ /* @__PURE__ */ jsxs("span", { className: "dtc-panel-title", children: [
1643
+ labels.notifications,
1644
+ n.unreadCount > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-badge-count dtc-notif-title-badge", children: badgeText(n.unreadCount) })
1645
+ ] }),
1646
+ n.unreadCount > 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-notif-markall", onClick: () => void n.markAllRead().catch(() => {
1647
+ }), children: labels.markAllRead }),
1648
+ onClose && /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" }) }) })
1649
+ ] }),
1650
+ n.status !== "ready" && rows.length === 0 ? /* @__PURE__ */ jsx("div", { className: "dtc-empty", children: n.status === "error" ? n.error?.message ?? "" : "" }) : rows.length === 0 ? /* @__PURE__ */ jsx("div", { className: "dtc-empty", children: labels.noNotifications }) : /* @__PURE__ */ jsxs("div", { className: "dtc-notif-list", children: [
1651
+ rows.map((row) => /* @__PURE__ */ jsxs(
1652
+ "button",
1653
+ {
1654
+ type: "button",
1655
+ className: `dtc-notif-row ${row.unread ? "dtc-notif-row-unread" : ""}`,
1656
+ onClick: () => open(row),
1657
+ children: [
1658
+ /* @__PURE__ */ jsx(
1659
+ Avatar,
1660
+ {
1661
+ name: row.lead.actor?.name ?? row.lead.title,
1662
+ url: row.lead.actor?.avatarUrl ?? row.lead.imageUrl,
1663
+ size: 40
1664
+ }
1665
+ ),
1666
+ /* @__PURE__ */ jsxs("span", { className: "dtc-notif-text", children: [
1667
+ /* @__PURE__ */ jsx("span", { className: "dtc-notif-title", children: row.lead.title }),
1668
+ row.lead.body && /* @__PURE__ */ jsx("span", { className: "dtc-notif-body", children: row.lead.body }),
1669
+ /* @__PURE__ */ jsxs("span", { className: "dtc-notif-meta", children: [
1670
+ labels.timeAgo(new Date(row.lead.createdAt)),
1671
+ row.more > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
1672
+ " \xB7 ",
1673
+ labels.groupMore(row.more)
1674
+ ] })
1675
+ ] })
1676
+ ] }),
1677
+ row.unread && /* @__PURE__ */ jsx("span", { className: "dtc-notif-dot", "aria-hidden": "true" })
1678
+ ]
1679
+ },
1680
+ row.lead.id
1681
+ )),
1682
+ n.hasMore && /* @__PURE__ */ jsx(
1683
+ "button",
1684
+ {
1685
+ type: "button",
1686
+ className: "dtc-btn dtc-notif-more",
1687
+ disabled: n.loadingMore,
1688
+ onClick: () => void n.loadMore().catch(() => {
1689
+ }),
1690
+ children: labels.loadMore
1691
+ }
1692
+ )
1693
+ ] })
1694
+ ] });
1695
+ }
1408
1696
  var RAIL_WIDTH = 64;
1409
1697
  var EDGE_SWIPE_ZONE = 24;
1410
1698
  var SWIPE_DISTANCE = 60;
@@ -1420,7 +1708,8 @@ function DialtribeMessages({
1420
1708
  panelWidth = 380,
1421
1709
  railDmLimit = 5,
1422
1710
  mobileBreakpoint = 768,
1423
- confirm: hostConfirm
1711
+ confirm: hostConfirm,
1712
+ notifications = false
1424
1713
  }) {
1425
1714
  const labels = useMemo(() => ({ ...DEFAULT_LABELS, ...labelOverrides }), [labelOverrides]);
1426
1715
  const inbox = useChatRooms();
@@ -1428,7 +1717,9 @@ function DialtribeMessages({
1428
1717
  const isMobile = useMediaQuery(`(max-width: ${mobileBreakpoint - 1}px)`);
1429
1718
  const { isOpen, view } = ui;
1430
1719
  const pendingCount = inbox.requests.length;
1431
- const rollup = inbox.totalUnread + pendingCount;
1720
+ const notifUnread = useNotificationsBadge(notifications !== false);
1721
+ const rollup = inbox.totalUnread + pendingCount + notifUnread;
1722
+ const notifOnOpen = typeof notifications === "object" ? notifications.onOpen : void 0;
1432
1723
  const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted" && !r.isArchived).slice(0, railDmLimit);
1433
1724
  const [builtInConfirm, setBuiltInConfirm] = useState(null);
1434
1725
  const confirmOpen = useRef(false);
@@ -1464,10 +1755,11 @@ function DialtribeMessages({
1464
1755
  return () => window.removeEventListener("keydown", onKey);
1465
1756
  }, [isOpen, ui]);
1466
1757
  const select = (target) => {
1467
- const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : activeItemId === target.itemId);
1758
+ const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : target.kind === "notifications" ? view.kind === "notifications" : activeItemId === target.itemId);
1468
1759
  if (showing) ui.close();
1469
1760
  else if (target.kind === "inbox") ui.openInbox();
1470
1761
  else if (target.kind === "room") ui.openRoom(target.roomId);
1762
+ else if (target.kind === "notifications") ui.openNotifications();
1471
1763
  else ui.openItem(target.itemId);
1472
1764
  };
1473
1765
  const renderItemButton = (item) => {
@@ -1498,7 +1790,7 @@ function DialtribeMessages({
1498
1790
  rollup > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
1499
1791
  ] }),
1500
1792
  isOpen && /* @__PURE__ */ jsxs("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: [
1501
- activeItem ? /* @__PURE__ */ jsx("div", { className: "dtc-item-panel", children: typeof activeItem.panel === "function" ? activeItem.panel({ close: ui.close }) : activeItem.panel }) : view.kind !== "room" ? /* @__PURE__ */ jsxs(Fragment, { children: [
1793
+ view.kind === "notifications" && notifications !== false ? /* @__PURE__ */ jsx(NotificationsPanel, { labels, onClose: ui.close, onOpen: notifOnOpen }) : activeItem ? /* @__PURE__ */ jsx("div", { className: "dtc-item-panel", children: typeof activeItem.panel === "function" ? activeItem.panel({ close: ui.close }) : activeItem.panel }) : view.kind !== "room" ? /* @__PURE__ */ jsxs(Fragment, { children: [
1502
1794
  /* @__PURE__ */ jsxs("div", { className: "dtc-panel-header", children: [
1503
1795
  /* @__PURE__ */ jsx("span", { className: "dtc-panel-title", children: labels.messages }),
1504
1796
  /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon2, {}) })
@@ -1544,6 +1836,16 @@ function DialtribeMessages({
1544
1836
  /* @__PURE__ */ jsxs("div", { className: "dtc-rail-scroll", children: [
1545
1837
  topItems.map(renderItemButton),
1546
1838
  topItems.length > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-rail-divider" }),
1839
+ notifications !== false && /* @__PURE__ */ jsx(
1840
+ RailButton,
1841
+ {
1842
+ label: labels.notifications,
1843
+ active: isOpen && view.kind === "notifications",
1844
+ badge: notifUnread,
1845
+ onClick: () => select({ kind: "notifications" }),
1846
+ children: /* @__PURE__ */ jsx(BellIcon, {})
1847
+ }
1848
+ ),
1547
1849
  /* @__PURE__ */ jsx(
1548
1850
  RailButton,
1549
1851
  {
@@ -1725,10 +2027,26 @@ function themeVars(theme) {
1725
2027
  function ChatIcon() {
1726
2028
  return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
1727
2029
  }
2030
+ function BellIcon() {
2031
+ return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
2032
+ /* @__PURE__ */ jsx("path", { d: "M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9" }),
2033
+ /* @__PURE__ */ jsx("path", { d: "M13.73 21a2 2 0 0 1-3.46 0" })
2034
+ ] });
2035
+ }
2036
+ function useNotificationsBadge(enabled) {
2037
+ const store = useChatClient().notifications;
2038
+ useEffect(() => {
2039
+ if (!enabled) return;
2040
+ store.acquire();
2041
+ return () => store.release();
2042
+ }, [enabled, store]);
2043
+ const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
2044
+ return enabled ? snapshot.unreadCount : 0;
2045
+ }
1728
2046
  function CloseIcon2() {
1729
2047
  return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" }) });
1730
2048
  }
1731
2049
 
1732
- export { Avatar, ChatClient, ChatInput, ChatMessageItem, ChatPanel, ChatRequestError, ChatRoomProvider, DEFAULT_LABELS, DialtribeChatProvider, DialtribeMessages, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages };
2050
+ export { Avatar, ChatClient, ChatInput, ChatMessageItem, ChatPanel, ChatRequestError, ChatRoomProvider, DEFAULT_LABELS, DialtribeChatProvider, DialtribeMessages, NotificationsPanel, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
1733
2051
  //# sourceMappingURL=index.mjs.map
1734
2052
  //# sourceMappingURL=index.mjs.map