@dialtribe/chat-client 0.4.0 → 0.5.1

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.js CHANGED
@@ -468,6 +468,156 @@ var InboxStore = class extends Store {
468
468
  }
469
469
  };
470
470
 
471
+ // src/client/NotificationsStore.ts
472
+ var NotificationsStore = class extends Store {
473
+ constructor(client) {
474
+ super({ status: "idle", items: [], unreadCount: 0, hasMore: false, loadingMore: false, error: null });
475
+ this.client = client;
476
+ this.refs = 0;
477
+ this.unlisten = [];
478
+ this.refreshTimer = null;
479
+ this.nextCursor = null;
480
+ }
481
+ acquire() {
482
+ this.refs += 1;
483
+ if (this.refs > 1) return;
484
+ this.unlisten = [
485
+ this.client.on("connected", () => this.scheduleRefresh(0)),
486
+ this.client.on("user", (event) => this.onUserEvent(event))
487
+ ];
488
+ void this.client.start();
489
+ this.scheduleRefresh(0);
490
+ }
491
+ release() {
492
+ this.refs = Math.max(0, this.refs - 1);
493
+ if (this.refs > 0) return;
494
+ for (const off of this.unlisten) off();
495
+ this.unlisten = [];
496
+ if (this.refreshTimer) clearTimeout(this.refreshTimer);
497
+ }
498
+ // ===========================================================================
499
+ // Actions
500
+ // ===========================================================================
501
+ /** Reload the first page and the unread count. */
502
+ async refresh() {
503
+ if (this.getSnapshot().status === "idle") this.update({ status: "loading" });
504
+ try {
505
+ const page = await this.client.api("/notifications/inbox?limit=30");
506
+ this.nextCursor = page.nextCursor;
507
+ this.update({
508
+ status: "ready",
509
+ items: page.items,
510
+ unreadCount: page.unreadCount,
511
+ hasMore: page.nextCursor !== null,
512
+ error: null
513
+ });
514
+ } catch (err) {
515
+ this.update({
516
+ status: "error",
517
+ error: err instanceof ChatRequestError ? err : new ChatRequestError("network", "Could not load notifications")
518
+ });
519
+ }
520
+ }
521
+ /** Append the next (older) page. */
522
+ async loadMore() {
523
+ const snap = this.getSnapshot();
524
+ if (!this.nextCursor || snap.loadingMore) return;
525
+ this.update({ loadingMore: true });
526
+ try {
527
+ const page = await this.client.api(
528
+ `/notifications/inbox?limit=30&cursor=${encodeURIComponent(this.nextCursor)}`
529
+ );
530
+ this.nextCursor = page.nextCursor;
531
+ const have = new Set(this.getSnapshot().items.map((i) => i.id));
532
+ this.update({
533
+ items: [...this.getSnapshot().items, ...page.items.filter((i) => !have.has(i.id))],
534
+ hasMore: page.nextCursor !== null,
535
+ unreadCount: page.unreadCount
536
+ });
537
+ } finally {
538
+ this.update({ loadingMore: false });
539
+ }
540
+ }
541
+ /** Mark items read (optimistic). */
542
+ async markRead(ids) {
543
+ const unread = ids.filter((id) => this.getSnapshot().items.some((i) => i.id === id && !i.readAt));
544
+ if (unread.length === 0) return;
545
+ this.applyRead(unread, Math.max(0, this.getSnapshot().unreadCount - unread.length));
546
+ const { unreadCount } = await this.client.api("/notifications/inbox", {
547
+ method: "POST",
548
+ body: { action: "read", ids: unread }
549
+ });
550
+ this.update({ unreadCount });
551
+ }
552
+ /** Mark everything read (optimistic). */
553
+ async markAllRead() {
554
+ this.applyRead(null, 0);
555
+ const { unreadCount } = await this.client.api("/notifications/inbox", {
556
+ method: "POST",
557
+ body: { action: "read-all" }
558
+ });
559
+ this.update({ unreadCount });
560
+ }
561
+ /** Record that the list was shown (for stats; doesn't change unread). */
562
+ async markSeen() {
563
+ const unseen = this.getSnapshot().items.filter((i) => !i.seenAt).map((i) => i.id);
564
+ if (unseen.length === 0) return;
565
+ const now = (/* @__PURE__ */ new Date()).toISOString();
566
+ const set = new Set(unseen);
567
+ this.update({ items: this.getSnapshot().items.map((i) => set.has(i.id) ? { ...i, seenAt: now } : i) });
568
+ await this.client.api("/notifications/inbox", { method: "POST", body: { action: "seen", ids: unseen } });
569
+ }
570
+ /** Record a click (also marks read). Pass every id in a grouped row. */
571
+ async click(ids) {
572
+ if (ids.length === 0) return;
573
+ const now = (/* @__PURE__ */ new Date()).toISOString();
574
+ const set = new Set(ids);
575
+ const newlyRead = this.getSnapshot().items.filter((i) => set.has(i.id) && !i.readAt).length;
576
+ this.update({
577
+ items: this.getSnapshot().items.map(
578
+ (i) => set.has(i.id) ? { ...i, clickedAt: i.clickedAt ?? now, readAt: i.readAt ?? now } : i
579
+ ),
580
+ unreadCount: Math.max(0, this.getSnapshot().unreadCount - newlyRead)
581
+ });
582
+ const { unreadCount } = await this.client.api("/notifications/inbox", {
583
+ method: "POST",
584
+ body: { action: "click", ids }
585
+ });
586
+ this.update({ unreadCount });
587
+ }
588
+ // ===========================================================================
589
+ // Live updates
590
+ // ===========================================================================
591
+ onUserEvent(event) {
592
+ if (event.type === "notification.created") {
593
+ const items = this.getSnapshot().items;
594
+ if (items.some((i) => i.id === event.notification.id)) return;
595
+ this.update({
596
+ items: [event.notification, ...items],
597
+ unreadCount: typeof event.unreadCount === "number" ? event.unreadCount : this.getSnapshot().unreadCount + (event.notification.readAt ? 0 : 1)
598
+ });
599
+ } else if (event.type === "notification.read") {
600
+ this.applyRead(event.ids, event.unreadCount);
601
+ }
602
+ }
603
+ applyRead(ids, unreadCount) {
604
+ const now = (/* @__PURE__ */ new Date()).toISOString();
605
+ const set = ids ? new Set(ids) : null;
606
+ this.update({
607
+ items: this.getSnapshot().items.map((i) => !i.readAt && (!set || set.has(i.id)) ? { ...i, readAt: now } : i),
608
+ unreadCount
609
+ });
610
+ }
611
+ scheduleRefresh(delayMs) {
612
+ if (this.refs === 0) return;
613
+ if (this.refreshTimer) clearTimeout(this.refreshTimer);
614
+ this.refreshTimer = setTimeout(() => {
615
+ this.refreshTimer = null;
616
+ void this.refresh();
617
+ }, delayMs);
618
+ }
619
+ };
620
+
471
621
  // src/client/ChatClient.ts
472
622
  var ConnectionStore = class extends Store {
473
623
  set(patch) {
@@ -487,7 +637,9 @@ var ChatClient = class {
487
637
  this.generation = 0;
488
638
  this.rooms = /* @__PURE__ */ new Map();
489
639
  this.inboxStore = null;
640
+ this.notificationsStore = null;
490
641
  this.serverUrl = options.serverUrl.replace(/\/$/, "");
642
+ this.apiUrl = (options.apiUrl ?? "https://dialtribe.com").replace(/\/$/, "");
491
643
  }
492
644
  // ===========================================================================
493
645
  // Lifecycle
@@ -529,6 +681,11 @@ var ChatClient = class {
529
681
  this.inboxStore ?? (this.inboxStore = new InboxStore(this));
530
682
  return this.inboxStore;
531
683
  }
684
+ /** The signed-in user's notifications (created on first use). */
685
+ get notifications() {
686
+ this.notificationsStore ?? (this.notificationsStore = new NotificationsStore(this));
687
+ return this.notificationsStore;
688
+ }
532
689
  get self() {
533
690
  return this.connection.getSnapshot().self;
534
691
  }
@@ -648,6 +805,13 @@ var ChatClient = class {
648
805
  users(roomId) {
649
806
  return this.request(`/rooms/${encodeURIComponent(roomId)}/users`);
650
807
  }
808
+ /**
809
+ * Authenticated JSON request to the Dialtribe API (apiUrl), with the same
810
+ * session token and 401 retry as chat-ws requests. `path` is under /api/public/v1.
811
+ */
812
+ api(path, init = {}) {
813
+ return this.request(path, init, `${this.apiUrl}/api/public/v1`);
814
+ }
651
815
  /** A DM action on POST /dm (see DMS.md). */
652
816
  dm(action, fields = {}) {
653
817
  return this.request("/dm", { method: "POST", body: { action, ...fields } });
@@ -657,8 +821,8 @@ var ChatClient = class {
657
821
  * token on 401. Throws ChatRequestError for transport failures and for
658
822
  * `{ ok: false, error }` bodies.
659
823
  */
660
- async request(path, init = {}) {
661
- const attempt = async (token) => fetch(this.serverUrl + path, {
824
+ async request(path, init = {}, base = this.serverUrl) {
825
+ const attempt = async (token) => fetch(base + path, {
662
826
  method: init.method ?? "GET",
663
827
  headers: {
664
828
  Authorization: `Bearer ${token}`,
@@ -719,17 +883,20 @@ var MessagesUiStore = class extends Store {
719
883
  openRoom(roomId) {
720
884
  this.update({ open: true, view: { kind: "room", roomId } });
721
885
  }
886
+ openNotifications() {
887
+ this.update({ open: true, view: { kind: "notifications" } });
888
+ }
722
889
  openItem(itemId) {
723
890
  this.update({ open: true, view: { kind: "item", itemId } });
724
891
  }
725
892
  };
726
893
  var ClientContext = react.createContext(null);
727
894
  var MessagesUiContext = react.createContext(null);
728
- function DialtribeChatProvider({ children, getSessionToken, serverUrl, websocketUrl, websocket }) {
895
+ function DialtribeChatProvider({ children, getSessionToken, serverUrl, apiUrl, websocketUrl, websocket }) {
729
896
  const tokenRef = react.useRef(getSessionToken);
730
897
  tokenRef.current = getSessionToken;
731
898
  const [client] = react.useState(
732
- () => new ChatClient({ serverUrl, websocketUrl, websocket, getSessionToken: () => tokenRef.current() })
899
+ () => new ChatClient({ serverUrl, apiUrl, websocketUrl, websocket, getSessionToken: () => tokenRef.current() })
733
900
  );
734
901
  const [messagesUi] = react.useState(() => new MessagesUiStore());
735
902
  react.useEffect(() => {
@@ -835,6 +1002,7 @@ function useDialtribeMessages() {
835
1002
  openInbox: () => ui.openInbox(),
836
1003
  openRoom: (roomId) => ui.openRoom(roomId),
837
1004
  openItem: (itemId) => ui.openItem(itemId),
1005
+ openNotifications: () => ui.openNotifications(),
838
1006
  messageUser: async (userId, hint) => {
839
1007
  const result = await client.inbox.requestDM(userId, hint);
840
1008
  ui.openRoom(result.roomId);
@@ -845,6 +1013,26 @@ function useDialtribeMessages() {
845
1013
  );
846
1014
  return react.useMemo(() => ({ isOpen: snapshot.open, view: snapshot.view, ...actions }), [snapshot, actions]);
847
1015
  }
1016
+ function useDialtribeNotifications() {
1017
+ const store = useChatClient().notifications;
1018
+ react.useEffect(() => {
1019
+ store.acquire();
1020
+ return () => store.release();
1021
+ }, [store]);
1022
+ const snapshot = react.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
1023
+ const actions = react.useMemo(
1024
+ () => ({
1025
+ refresh: store.refresh.bind(store),
1026
+ loadMore: store.loadMore.bind(store),
1027
+ markRead: store.markRead.bind(store),
1028
+ markAllRead: store.markAllRead.bind(store),
1029
+ markSeen: store.markSeen.bind(store),
1030
+ click: store.click.bind(store)
1031
+ }),
1032
+ [store]
1033
+ );
1034
+ return react.useMemo(() => ({ ...snapshot, ...actions }), [snapshot, actions]);
1035
+ }
848
1036
 
849
1037
  // src/types/index.ts
850
1038
  function parseReactions(reactionsJson) {
@@ -1160,7 +1348,20 @@ var DEFAULT_LABELS = {
1160
1348
  archiveConfirm: "Archive",
1161
1349
  cancel: "Cancel",
1162
1350
  messagePlaceholder: "Message...",
1163
- openMessages: "Open messages"
1351
+ openMessages: "Open messages",
1352
+ notifications: "Notifications",
1353
+ noNotifications: "No notifications yet",
1354
+ markAllRead: "Mark all read",
1355
+ loadMore: "Load more",
1356
+ groupMore: (count) => `and ${count} more`,
1357
+ timeAgo: (date) => {
1358
+ const s = Math.max(0, Math.floor((Date.now() - date.getTime()) / 1e3));
1359
+ if (s < 60) return "now";
1360
+ if (s < 3600) return `${Math.floor(s / 60)}m`;
1361
+ if (s < 86400) return `${Math.floor(s / 3600)}h`;
1362
+ if (s < 604800) return `${Math.floor(s / 86400)}d`;
1363
+ return date.toLocaleDateString(void 0, { month: "short", day: "numeric" });
1364
+ }
1164
1365
  };
1165
1366
  function badgeText(count) {
1166
1367
  return count > 99 ? "99+" : String(count);
@@ -1407,6 +1608,99 @@ function CloseIcon() {
1407
1608
  function ChevronLeft() {
1408
1609
  return /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx("path", { d: "M15 18l-6-6 6-6" }) });
1409
1610
  }
1611
+ function groupRows(items) {
1612
+ const rows = [];
1613
+ const byKey = /* @__PURE__ */ new Map();
1614
+ for (const item of items) {
1615
+ const existing = item.groupKey ? byKey.get(item.groupKey) : void 0;
1616
+ if (existing) {
1617
+ existing.ids.push(item.id);
1618
+ existing.more += 1;
1619
+ existing.unread || (existing.unread = !item.readAt);
1620
+ continue;
1621
+ }
1622
+ const row = { lead: item, ids: [item.id], more: 0, unread: !item.readAt };
1623
+ rows.push(row);
1624
+ if (item.groupKey) byKey.set(item.groupKey, row);
1625
+ }
1626
+ return rows;
1627
+ }
1628
+ function NotificationsPanel({ labels, onClose, onOpen, onOpened }) {
1629
+ const n = useDialtribeNotifications();
1630
+ const rows = react.useMemo(() => groupRows(n.items), [n.items]);
1631
+ const { status, markSeen } = n;
1632
+ react.useEffect(() => {
1633
+ if (status === "ready") void markSeen().catch(() => {
1634
+ });
1635
+ }, [status, markSeen]);
1636
+ const open = (row) => {
1637
+ if (!row.lead.url) {
1638
+ if (row.unread) void n.markRead(row.ids).catch(() => {
1639
+ });
1640
+ return;
1641
+ }
1642
+ void n.click(row.ids).catch(() => {
1643
+ });
1644
+ const handled = onOpen?.(row.lead);
1645
+ onOpened?.(row.lead);
1646
+ if (!handled) window.location.assign(row.lead.url);
1647
+ };
1648
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-notif", children: [
1649
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
1650
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-panel-title", children: [
1651
+ labels.notifications,
1652
+ n.unreadCount > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-notif-title-badge", children: badgeText(n.unreadCount) })
1653
+ ] }),
1654
+ n.unreadCount > 0 && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-notif-markall", onClick: () => void n.markAllRead().catch(() => {
1655
+ }), children: labels.markAllRead }),
1656
+ onClose && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6l12 12" }) }) })
1657
+ ] }),
1658
+ n.status !== "ready" && rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: n.status === "error" ? n.error?.message ?? "" : "" }) : rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: labels.noNotifications }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-notif-list", children: [
1659
+ rows.map((row) => /* @__PURE__ */ jsxRuntime.jsxs(
1660
+ "button",
1661
+ {
1662
+ type: "button",
1663
+ className: `dtc-notif-row ${row.unread ? "dtc-notif-row-unread" : ""} ${row.lead.url ? "" : "dtc-notif-row-static"}`,
1664
+ onClick: () => open(row),
1665
+ children: [
1666
+ /* @__PURE__ */ jsxRuntime.jsx(
1667
+ Avatar,
1668
+ {
1669
+ name: row.lead.actor?.name ?? row.lead.title,
1670
+ url: row.lead.actor?.avatarUrl ?? row.lead.imageUrl,
1671
+ size: 40
1672
+ }
1673
+ ),
1674
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-notif-text", children: [
1675
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-notif-title", children: row.lead.title }),
1676
+ row.lead.body && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-notif-body", children: row.lead.body }),
1677
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-notif-meta", children: [
1678
+ labels.timeAgo(new Date(row.lead.createdAt)),
1679
+ row.more > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1680
+ " \xB7 ",
1681
+ labels.groupMore(row.more)
1682
+ ] })
1683
+ ] })
1684
+ ] }),
1685
+ row.unread && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-notif-dot", "aria-hidden": "true" })
1686
+ ]
1687
+ },
1688
+ row.lead.id
1689
+ )),
1690
+ n.hasMore && /* @__PURE__ */ jsxRuntime.jsx(
1691
+ "button",
1692
+ {
1693
+ type: "button",
1694
+ className: "dtc-btn dtc-notif-more",
1695
+ disabled: n.loadingMore,
1696
+ onClick: () => void n.loadMore().catch(() => {
1697
+ }),
1698
+ children: labels.loadMore
1699
+ }
1700
+ )
1701
+ ] })
1702
+ ] });
1703
+ }
1410
1704
  var RAIL_WIDTH = 64;
1411
1705
  var EDGE_SWIPE_ZONE = 24;
1412
1706
  var SWIPE_DISTANCE = 60;
@@ -1422,7 +1716,8 @@ function DialtribeMessages({
1422
1716
  panelWidth = 380,
1423
1717
  railDmLimit = 5,
1424
1718
  mobileBreakpoint = 768,
1425
- confirm: hostConfirm
1719
+ confirm: hostConfirm,
1720
+ notifications = false
1426
1721
  }) {
1427
1722
  const labels = react.useMemo(() => ({ ...DEFAULT_LABELS, ...labelOverrides }), [labelOverrides]);
1428
1723
  const inbox = useChatRooms();
@@ -1430,7 +1725,9 @@ function DialtribeMessages({
1430
1725
  const isMobile = useMediaQuery(`(max-width: ${mobileBreakpoint - 1}px)`);
1431
1726
  const { isOpen, view } = ui;
1432
1727
  const pendingCount = inbox.requests.length;
1433
- const rollup = inbox.totalUnread + pendingCount;
1728
+ const notifUnread = useNotificationsBadge(notifications !== false);
1729
+ const rollup = inbox.totalUnread + pendingCount + notifUnread;
1730
+ const notifOnOpen = typeof notifications === "object" ? notifications.onOpen : void 0;
1434
1731
  const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted" && !r.isArchived).slice(0, railDmLimit);
1435
1732
  const [builtInConfirm, setBuiltInConfirm] = react.useState(null);
1436
1733
  const confirmOpen = react.useRef(false);
@@ -1466,10 +1763,11 @@ function DialtribeMessages({
1466
1763
  return () => window.removeEventListener("keydown", onKey);
1467
1764
  }, [isOpen, ui]);
1468
1765
  const select = (target) => {
1469
- const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : activeItemId === target.itemId);
1766
+ const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : target.kind === "notifications" ? view.kind === "notifications" : activeItemId === target.itemId);
1470
1767
  if (showing) ui.close();
1471
1768
  else if (target.kind === "inbox") ui.openInbox();
1472
1769
  else if (target.kind === "room") ui.openRoom(target.roomId);
1770
+ else if (target.kind === "notifications") ui.openNotifications();
1473
1771
  else ui.openItem(target.itemId);
1474
1772
  };
1475
1773
  const renderItemButton = (item) => {
@@ -1500,7 +1798,17 @@ function DialtribeMessages({
1500
1798
  rollup > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
1501
1799
  ] }),
1502
1800
  isOpen && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: [
1503
- activeItem ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-item-panel", children: typeof activeItem.panel === "function" ? activeItem.panel({ close: ui.close }) : activeItem.panel }) : view.kind !== "room" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1801
+ view.kind === "notifications" && notifications !== false ? /* @__PURE__ */ jsxRuntime.jsx(
1802
+ NotificationsPanel,
1803
+ {
1804
+ labels,
1805
+ onClose: ui.close,
1806
+ onOpen: notifOnOpen,
1807
+ onOpened: () => {
1808
+ if (isMobile) ui.close();
1809
+ }
1810
+ }
1811
+ ) : activeItem ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-item-panel", children: typeof activeItem.panel === "function" ? activeItem.panel({ close: ui.close }) : activeItem.panel }) : view.kind !== "room" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1504
1812
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
1505
1813
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
1506
1814
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon2, {}) })
@@ -1546,6 +1854,16 @@ function DialtribeMessages({
1546
1854
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-rail-scroll", children: [
1547
1855
  topItems.map(renderItemButton),
1548
1856
  topItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
1857
+ notifications !== false && /* @__PURE__ */ jsxRuntime.jsx(
1858
+ RailButton,
1859
+ {
1860
+ label: labels.notifications,
1861
+ active: isOpen && view.kind === "notifications",
1862
+ badge: notifUnread,
1863
+ onClick: () => select({ kind: "notifications" }),
1864
+ children: /* @__PURE__ */ jsxRuntime.jsx(BellIcon, {})
1865
+ }
1866
+ ),
1549
1867
  /* @__PURE__ */ jsxRuntime.jsx(
1550
1868
  RailButton,
1551
1869
  {
@@ -1727,6 +2045,22 @@ function themeVars(theme) {
1727
2045
  function ChatIcon() {
1728
2046
  return /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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" }) });
1729
2047
  }
2048
+ function BellIcon() {
2049
+ return /* @__PURE__ */ jsxRuntime.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: [
2050
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9" }),
2051
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M13.73 21a2 2 0 0 1-3.46 0" })
2052
+ ] });
2053
+ }
2054
+ function useNotificationsBadge(enabled) {
2055
+ const store = useChatClient().notifications;
2056
+ react.useEffect(() => {
2057
+ if (!enabled) return;
2058
+ store.acquire();
2059
+ return () => store.release();
2060
+ }, [enabled, store]);
2061
+ const snapshot = react.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
2062
+ return enabled ? snapshot.unreadCount : 0;
2063
+ }
1730
2064
  function CloseIcon2() {
1731
2065
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6l12 12" }) });
1732
2066
  }
@@ -1741,6 +2075,7 @@ exports.ChatRoomProvider = ChatRoomProvider;
1741
2075
  exports.DEFAULT_LABELS = DEFAULT_LABELS;
1742
2076
  exports.DialtribeChatProvider = DialtribeChatProvider;
1743
2077
  exports.DialtribeMessages = DialtribeMessages;
2078
+ exports.NotificationsPanel = NotificationsPanel;
1744
2079
  exports.parseReactions = parseReactions;
1745
2080
  exports.useChatClient = useChatClient;
1746
2081
  exports.useChatConnection = useChatConnection;
@@ -1748,5 +2083,6 @@ exports.useChatRoomContext = useChatRoomContext;
1748
2083
  exports.useChatRooms = useChatRooms;
1749
2084
  exports.useDialtribeChat = useDialtribeChat;
1750
2085
  exports.useDialtribeMessages = useDialtribeMessages;
2086
+ exports.useDialtribeNotifications = useDialtribeNotifications;
1751
2087
  //# sourceMappingURL=index.js.map
1752
2088
  //# sourceMappingURL=index.js.map