@dialtribe/chat-client 0.3.0 → 0.4.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/README.md CHANGED
@@ -107,6 +107,7 @@ function MessageButton({ user }: { user: { id: string; name: string } }) {
107
107
  | `contexts` | `[]` | Extra rail entries, e.g. live shows: `{ roomId, label, avatarUrl?, badge? }` |
108
108
  | `theme` | | `{ accent, background, surface, text, textMuted, border }` |
109
109
  | `labels` | English | Override any string (`MessagesLabels`) to localize |
110
+ | `confirm` | built-in dialog | `(options) => Promise<boolean>`: show the mute and archive confirmations in your own modal (`ConfirmOptions`: `title`, `body`, `confirmLabel`, `cancelLabel`) |
110
111
  | `panelWidth` | `380` | Desktop panel width in px |
111
112
  | `railDmLimit` | `5` | Recent DMs shown as rail icons |
112
113
  | `mobileBreakpoint` | `768` | Below this width the rail becomes the floating button |
@@ -151,7 +152,7 @@ const {
151
152
  requests, // incoming requests not yet answered
152
153
  totalUnread, // across unmuted, accepted DMs
153
154
  requestDM, acceptDM, ignoreDM, closeDM, reopenDM, hideDM,
154
- addParticipant, setMuted, markRead, setVisible, refresh,
155
+ addParticipant, setMuted, setArchived, markRead, setVisible, refresh,
155
156
  } = useChatRooms();
156
157
  ```
157
158
 
@@ -163,6 +164,13 @@ deleted and the other person sees no change; it comes back when a newer message
163
164
  arrives or when the user messages or reopens it. `closeDM` is different: it
164
165
  closes the conversation for everyone and makes it read-only.
165
166
 
167
+ `setArchived(roomId, true)` archives a conversation for this user only: it
168
+ leaves their rail, stays in their inbox under Archived (`isArchived` on each
169
+ room), and its unread still counts toward `totalUnread`. New messages don't
170
+ unarchive it. In `<DialtribeMessages>` each conversation's menu (the kebab
171
+ next to the close X) offers Mute notifications and Archive conversation, each
172
+ behind a confirmation.
173
+
166
174
  ### `useDialtribeChat({ roomId })`
167
175
 
168
176
  One room (a DM or a show room): `messages`, `config`, `typingUsers`, `status`,
package/dist/index.d.mts CHANGED
@@ -104,6 +104,11 @@ interface DmRoomSummary {
104
104
  /** "pending" means this is an incoming request the user hasn't answered. */
105
105
  myStatus: DmMemberStatus;
106
106
  isMuted: boolean;
107
+ /**
108
+ * Archived by the signed-in user: off their rail, kept in their inbox under
109
+ * Archived, unread still counted. Private to them. Absent on older servers.
110
+ */
111
+ isArchived?: boolean;
107
112
  /** Everyone except the signed-in user. */
108
113
  participants: DmParticipant[];
109
114
  lastMessageAt: string | null;
@@ -305,6 +310,11 @@ declare class InboxStore extends Store<InboxSnapshot> {
305
310
  */
306
311
  hideDM(roomId: string): Promise<void>;
307
312
  setMuted(roomId: string, muted: boolean): Promise<void>;
313
+ /**
314
+ * Archive or unarchive for the signed-in user only (optimistic). The room
315
+ * leaves the rail but stays in the inbox; new messages don't unarchive it.
316
+ */
317
+ setArchived(roomId: string, archived: boolean): Promise<void>;
308
318
  /** Mark a room read now (optimistic). */
309
319
  markRead(roomId: string): Promise<void>;
310
320
  /**
@@ -525,7 +535,7 @@ declare function ChatRoomProvider({ roomId, children }: ChatRoomProviderProps):
525
535
  /** The room from the nearest <ChatRoomProvider>. */
526
536
  declare function useChatRoomContext(): UseDialtribeChatReturn;
527
537
 
528
- type UseChatRoomsReturn = InboxSnapshot & Pick<InboxStore, "requestDM" | "acceptDM" | "ignoreDM" | "closeDM" | "reopenDM" | "hideDM" | "addParticipant" | "setMuted" | "markRead" | "setVisible" | "refresh">;
538
+ type UseChatRoomsReturn = InboxSnapshot & Pick<InboxStore, "requestDM" | "acceptDM" | "ignoreDM" | "closeDM" | "reopenDM" | "hideDM" | "addParticipant" | "setMuted" | "setArchived" | "markRead" | "setVisible" | "refresh">;
529
539
  /**
530
540
  * The signed-in user's DMs: inbox (newest first), incoming requests, unread
531
541
  * totals, and every DM action. Live via the personal channel; reconciled with
@@ -589,16 +599,42 @@ interface MessagesLabels {
589
599
  waitingForReply: string;
590
600
  conversationClosed: string;
591
601
  reopen: string;
602
+ /** @deprecated No longer shown. Conversations are archived instead of closed. */
592
603
  closeConversation: string;
593
604
  /** Inbox row X: remove from the inbox (comes back on a new message). */
594
605
  removeConversation: string;
606
+ /** Conversation menu: mute / unmute notifications. */
595
607
  mute: string;
596
608
  unmute: string;
609
+ /** Conversation menu: archive / unarchive (private to the user). */
610
+ archive: string;
611
+ unarchive: string;
612
+ /** Inbox section for archived conversations. */
613
+ archived: string;
614
+ /** Accessible name for the conversation's kebab menu button. */
615
+ moreOptions: string;
616
+ muteConfirmTitle: (name: string) => string;
617
+ muteConfirmBody: string;
618
+ muteConfirm: string;
619
+ archiveConfirmTitle: (name: string) => string;
620
+ archiveConfirmBody: string;
621
+ archiveConfirm: string;
622
+ cancel: string;
597
623
  messagePlaceholder: string;
598
624
  openMessages: string;
599
625
  }
600
626
  declare const DEFAULT_LABELS: MessagesLabels;
601
627
 
628
+ /** What a confirmation asks. Hosts render it in their own modal via the `confirm` prop. */
629
+ interface ConfirmOptions {
630
+ title: string;
631
+ body?: string;
632
+ confirmLabel: string;
633
+ cancelLabel: string;
634
+ }
635
+ /** Resolves true when the user confirms. */
636
+ type ConfirmFn = (options: ConfirmOptions) => Promise<boolean>;
637
+
602
638
  /** A host-provided rail entry (e.g. a live show the user is watching). */
603
639
  interface MessagesContext {
604
640
  roomId: string;
@@ -664,6 +700,11 @@ interface DialtribeMessagesProps {
664
700
  railDmLimit?: number;
665
701
  /** Below this width (px) the rail collapses to a floating button + drawer. */
666
702
  mobileBreakpoint?: number;
703
+ /**
704
+ * Show confirmations (mute, archive) in your app's own modal. Resolve true to
705
+ * proceed. Without it, a built-in dialog inside the panel is used.
706
+ */
707
+ confirm?: ConfirmFn;
667
708
  }
668
709
  /**
669
710
  * Drop-in messages rail: inbox, DM requests, conversations, and any host
@@ -680,7 +721,7 @@ interface DialtribeMessagesProps {
680
721
  * </DialtribeChatProvider>
681
722
  * ```
682
723
  */
683
- declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
724
+ declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, confirm: hostConfirm, }: DialtribeMessagesProps): react.JSX.Element;
684
725
 
685
726
  interface AvatarProps {
686
727
  name: string;
@@ -759,4 +800,4 @@ interface ChatInputProps {
759
800
  */
760
801
  declare function ChatInput({ onSendMessage, onSendTyping, replyTo, onClearReply, disabled, placeholder, maxLength, }: ChatInputProps): react.JSX.Element;
761
802
 
762
- export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type ParsedReactions, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages };
803
+ export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, type ConfirmFn, type ConfirmOptions, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type ParsedReactions, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages };
package/dist/index.d.ts CHANGED
@@ -104,6 +104,11 @@ interface DmRoomSummary {
104
104
  /** "pending" means this is an incoming request the user hasn't answered. */
105
105
  myStatus: DmMemberStatus;
106
106
  isMuted: boolean;
107
+ /**
108
+ * Archived by the signed-in user: off their rail, kept in their inbox under
109
+ * Archived, unread still counted. Private to them. Absent on older servers.
110
+ */
111
+ isArchived?: boolean;
107
112
  /** Everyone except the signed-in user. */
108
113
  participants: DmParticipant[];
109
114
  lastMessageAt: string | null;
@@ -305,6 +310,11 @@ declare class InboxStore extends Store<InboxSnapshot> {
305
310
  */
306
311
  hideDM(roomId: string): Promise<void>;
307
312
  setMuted(roomId: string, muted: boolean): Promise<void>;
313
+ /**
314
+ * Archive or unarchive for the signed-in user only (optimistic). The room
315
+ * leaves the rail but stays in the inbox; new messages don't unarchive it.
316
+ */
317
+ setArchived(roomId: string, archived: boolean): Promise<void>;
308
318
  /** Mark a room read now (optimistic). */
309
319
  markRead(roomId: string): Promise<void>;
310
320
  /**
@@ -525,7 +535,7 @@ declare function ChatRoomProvider({ roomId, children }: ChatRoomProviderProps):
525
535
  /** The room from the nearest <ChatRoomProvider>. */
526
536
  declare function useChatRoomContext(): UseDialtribeChatReturn;
527
537
 
528
- type UseChatRoomsReturn = InboxSnapshot & Pick<InboxStore, "requestDM" | "acceptDM" | "ignoreDM" | "closeDM" | "reopenDM" | "hideDM" | "addParticipant" | "setMuted" | "markRead" | "setVisible" | "refresh">;
538
+ type UseChatRoomsReturn = InboxSnapshot & Pick<InboxStore, "requestDM" | "acceptDM" | "ignoreDM" | "closeDM" | "reopenDM" | "hideDM" | "addParticipant" | "setMuted" | "setArchived" | "markRead" | "setVisible" | "refresh">;
529
539
  /**
530
540
  * The signed-in user's DMs: inbox (newest first), incoming requests, unread
531
541
  * totals, and every DM action. Live via the personal channel; reconciled with
@@ -589,16 +599,42 @@ interface MessagesLabels {
589
599
  waitingForReply: string;
590
600
  conversationClosed: string;
591
601
  reopen: string;
602
+ /** @deprecated No longer shown. Conversations are archived instead of closed. */
592
603
  closeConversation: string;
593
604
  /** Inbox row X: remove from the inbox (comes back on a new message). */
594
605
  removeConversation: string;
606
+ /** Conversation menu: mute / unmute notifications. */
595
607
  mute: string;
596
608
  unmute: string;
609
+ /** Conversation menu: archive / unarchive (private to the user). */
610
+ archive: string;
611
+ unarchive: string;
612
+ /** Inbox section for archived conversations. */
613
+ archived: string;
614
+ /** Accessible name for the conversation's kebab menu button. */
615
+ moreOptions: string;
616
+ muteConfirmTitle: (name: string) => string;
617
+ muteConfirmBody: string;
618
+ muteConfirm: string;
619
+ archiveConfirmTitle: (name: string) => string;
620
+ archiveConfirmBody: string;
621
+ archiveConfirm: string;
622
+ cancel: string;
597
623
  messagePlaceholder: string;
598
624
  openMessages: string;
599
625
  }
600
626
  declare const DEFAULT_LABELS: MessagesLabels;
601
627
 
628
+ /** What a confirmation asks. Hosts render it in their own modal via the `confirm` prop. */
629
+ interface ConfirmOptions {
630
+ title: string;
631
+ body?: string;
632
+ confirmLabel: string;
633
+ cancelLabel: string;
634
+ }
635
+ /** Resolves true when the user confirms. */
636
+ type ConfirmFn = (options: ConfirmOptions) => Promise<boolean>;
637
+
602
638
  /** A host-provided rail entry (e.g. a live show the user is watching). */
603
639
  interface MessagesContext {
604
640
  roomId: string;
@@ -664,6 +700,11 @@ interface DialtribeMessagesProps {
664
700
  railDmLimit?: number;
665
701
  /** Below this width (px) the rail collapses to a floating button + drawer. */
666
702
  mobileBreakpoint?: number;
703
+ /**
704
+ * Show confirmations (mute, archive) in your app's own modal. Resolve true to
705
+ * proceed. Without it, a built-in dialog inside the panel is used.
706
+ */
707
+ confirm?: ConfirmFn;
667
708
  }
668
709
  /**
669
710
  * Drop-in messages rail: inbox, DM requests, conversations, and any host
@@ -680,7 +721,7 @@ interface DialtribeMessagesProps {
680
721
  * </DialtribeChatProvider>
681
722
  * ```
682
723
  */
683
- declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
724
+ declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, confirm: hostConfirm, }: DialtribeMessagesProps): react.JSX.Element;
684
725
 
685
726
  interface AvatarProps {
686
727
  name: string;
@@ -759,4 +800,4 @@ interface ChatInputProps {
759
800
  */
760
801
  declare function ChatInput({ onSendMessage, onSendTyping, replyTo, onClearReply, disabled, placeholder, maxLength, }: ChatInputProps): react.JSX.Element;
761
802
 
762
- export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type ParsedReactions, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages };
803
+ export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, type ConfirmFn, type ConfirmOptions, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type ParsedReactions, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages };
package/dist/index.js CHANGED
@@ -330,6 +330,19 @@ var InboxStore = class extends Store {
330
330
  this.patchRoom(roomId, (room) => ({ ...room, isMuted: muted }));
331
331
  await this.client.dm("chat-dm-mute", { roomId, muted });
332
332
  }
333
+ /**
334
+ * Archive or unarchive for the signed-in user only (optimistic). The room
335
+ * leaves the rail but stays in the inbox; new messages don't unarchive it.
336
+ */
337
+ async setArchived(roomId, archived) {
338
+ this.patchRoom(roomId, (room) => ({ ...room, isArchived: archived }));
339
+ try {
340
+ await this.client.dm("chat-dm-archive", { roomId, archived });
341
+ } catch (err) {
342
+ this.patchRoom(roomId, (room) => ({ ...room, isArchived: !archived }));
343
+ throw err;
344
+ }
345
+ }
333
346
  /** Mark a room read now (optimistic). */
334
347
  async markRead(roomId) {
335
348
  this.patchRoom(roomId, (room) => room.unreadCount === 0 ? room : { ...room, unreadCount: 0 });
@@ -797,6 +810,7 @@ function useChatRooms() {
797
810
  hideDM: inbox.hideDM.bind(inbox),
798
811
  addParticipant: inbox.addParticipant.bind(inbox),
799
812
  setMuted: inbox.setMuted.bind(inbox),
813
+ setArchived: inbox.setArchived.bind(inbox),
800
814
  markRead: inbox.markRead.bind(inbox),
801
815
  setVisible: inbox.setVisible.bind(inbox),
802
816
  refresh: inbox.refresh.bind(inbox)
@@ -1132,8 +1146,19 @@ var DEFAULT_LABELS = {
1132
1146
  reopen: "Reopen",
1133
1147
  closeConversation: "Close conversation",
1134
1148
  removeConversation: "Remove from inbox",
1135
- mute: "Mute",
1136
- unmute: "Unmute",
1149
+ mute: "Mute notifications",
1150
+ unmute: "Unmute notifications",
1151
+ archive: "Archive conversation",
1152
+ unarchive: "Unarchive conversation",
1153
+ archived: "Archived",
1154
+ moreOptions: "More options",
1155
+ muteConfirmTitle: (name) => `Mute notifications from ${name}?`,
1156
+ muteConfirmBody: "You won't get alerts or unread badges for this conversation. Messages still arrive.",
1157
+ muteConfirm: "Mute",
1158
+ archiveConfirmTitle: (name) => `Archive your conversation with ${name}?`,
1159
+ archiveConfirmBody: "It moves off your rail and into Archived in Messages. New messages still count toward your unread. Only you will see that it's archived.",
1160
+ archiveConfirm: "Archive",
1161
+ cancel: "Cancel",
1137
1162
  messagePlaceholder: "Message...",
1138
1163
  openMessages: "Open messages"
1139
1164
  };
@@ -1141,7 +1166,11 @@ function badgeText(count) {
1141
1166
  return count > 99 ? "99+" : String(count);
1142
1167
  }
1143
1168
  function MessagesInbox({ rooms, requests, labels, onOpenRoom, onRemoveRoom }) {
1144
- const conversations = rooms.filter((r) => r.myStatus === "accepted");
1169
+ const [showArchived, setShowArchived] = react.useState(false);
1170
+ const accepted = rooms.filter((r) => r.myStatus === "accepted");
1171
+ const conversations = accepted.filter((r) => !r.isArchived);
1172
+ const archived = accepted.filter((r) => r.isArchived);
1173
+ const archivedUnread = archived.reduce((sum, r) => sum + (r.isMuted ? 0 : r.unreadCount), 0);
1145
1174
  if (rooms.length === 0) return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: labels.noMessages });
1146
1175
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-inbox", children: [
1147
1176
  requests.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "dtc-inbox-section", children: [
@@ -1157,7 +1186,29 @@ function MessagesInbox({ rooms, requests, labels, onOpenRoom, onRemoveRoom }) {
1157
1186
  removeLabel: labels.removeConversation
1158
1187
  },
1159
1188
  room.roomId
1160
- )) })
1189
+ )) }),
1190
+ archived.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "dtc-inbox-section", children: [
1191
+ /* @__PURE__ */ jsxRuntime.jsxs(
1192
+ "button",
1193
+ {
1194
+ type: "button",
1195
+ className: "dtc-inbox-heading dtc-inbox-toggle",
1196
+ "aria-expanded": showArchived,
1197
+ onClick: () => setShowArchived((v) => !v),
1198
+ children: [
1199
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
1200
+ labels.archived,
1201
+ " (",
1202
+ archived.length,
1203
+ ")"
1204
+ ] }),
1205
+ !showArchived && archivedUnread > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count", children: badgeText(archivedUnread) }),
1206
+ /* @__PURE__ */ jsxRuntime.jsx("svg", { className: "dtc-inbox-toggle-icon", viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 9l6 6 6-6" }) })
1207
+ ]
1208
+ }
1209
+ ),
1210
+ showArchived && archived.map((room) => /* @__PURE__ */ jsxRuntime.jsx(InboxRow, { room, onOpen: onOpenRoom }, room.roomId))
1211
+ ] })
1161
1212
  ] });
1162
1213
  }
1163
1214
  function InboxRow({
@@ -1190,7 +1241,78 @@ function InboxRow({
1190
1241
  )
1191
1242
  ] });
1192
1243
  }
1193
- function ConversationView({ roomId, labels, onBack }) {
1244
+ function ConversationMenu({ label, items }) {
1245
+ const [open, setOpen] = react.useState(false);
1246
+ const rootRef = react.useRef(null);
1247
+ const buttonRef = react.useRef(null);
1248
+ const menuRef = react.useRef(null);
1249
+ react.useEffect(() => {
1250
+ if (!open) return;
1251
+ menuRef.current?.querySelector("[role=menuitem]")?.focus();
1252
+ const onPointer = (e) => {
1253
+ if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
1254
+ };
1255
+ const onKey = (e) => {
1256
+ if (e.key !== "Escape") return;
1257
+ e.preventDefault();
1258
+ setOpen(false);
1259
+ buttonRef.current?.focus();
1260
+ };
1261
+ document.addEventListener("pointerdown", onPointer);
1262
+ window.addEventListener("keydown", onKey, true);
1263
+ return () => {
1264
+ document.removeEventListener("pointerdown", onPointer);
1265
+ window.removeEventListener("keydown", onKey, true);
1266
+ };
1267
+ }, [open]);
1268
+ const onMenuKey = (e) => {
1269
+ if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return;
1270
+ e.preventDefault();
1271
+ const buttons = Array.from(menuRef.current?.querySelectorAll("[role=menuitem]") ?? []);
1272
+ const i = buttons.indexOf(document.activeElement);
1273
+ const next = e.key === "ArrowDown" ? (i + 1) % buttons.length : (i - 1 + buttons.length) % buttons.length;
1274
+ buttons[next]?.focus();
1275
+ };
1276
+ if (items.length === 0) return null;
1277
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-menu-root", ref: rootRef, children: [
1278
+ /* @__PURE__ */ jsxRuntime.jsx(
1279
+ "button",
1280
+ {
1281
+ ref: buttonRef,
1282
+ type: "button",
1283
+ className: "dtc-icon-btn",
1284
+ "aria-label": label,
1285
+ title: label,
1286
+ "aria-haspopup": "menu",
1287
+ "aria-expanded": open,
1288
+ onClick: () => setOpen((v) => !v),
1289
+ children: /* @__PURE__ */ jsxRuntime.jsx(KebabIcon, {})
1290
+ }
1291
+ ),
1292
+ open && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-menu", role: "menu", ref: menuRef, onKeyDown: onMenuKey, children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
1293
+ "button",
1294
+ {
1295
+ type: "button",
1296
+ role: "menuitem",
1297
+ className: "dtc-menu-item",
1298
+ onClick: () => {
1299
+ setOpen(false);
1300
+ item.onSelect();
1301
+ },
1302
+ children: item.label
1303
+ },
1304
+ item.id
1305
+ )) })
1306
+ ] });
1307
+ }
1308
+ function KebabIcon() {
1309
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "currentColor", "aria-hidden": "true", children: [
1310
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "5", r: "1.8" }),
1311
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "1.8" }),
1312
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "19", r: "1.8" })
1313
+ ] });
1314
+ }
1315
+ function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
1194
1316
  const inbox = useChatRooms();
1195
1317
  const room = inbox.rooms.find((r) => r.roomId === roomId);
1196
1318
  const { setVisible } = inbox;
@@ -1198,16 +1320,49 @@ function ConversationView({ roomId, labels, onBack }) {
1198
1320
  const isRequest = room?.myStatus === "pending";
1199
1321
  const isClosed = room?.state === "closed";
1200
1322
  const waitingOnThem = !isRequest && !!room && room.participants.length > 0 && room.participants.every((p) => p.status === "pending");
1323
+ const menuItems = [];
1324
+ if (room && !isRequest) {
1325
+ menuItems.push({
1326
+ id: "mute",
1327
+ label: room.isMuted ? labels.unmute : labels.mute,
1328
+ onSelect: async () => {
1329
+ if (room.isMuted) return void inbox.setMuted(roomId, false).catch(() => {
1330
+ });
1331
+ const ok = await confirm({
1332
+ title: labels.muteConfirmTitle(room.name),
1333
+ body: labels.muteConfirmBody,
1334
+ confirmLabel: labels.muteConfirm,
1335
+ cancelLabel: labels.cancel
1336
+ });
1337
+ if (ok) void inbox.setMuted(roomId, true).catch(() => {
1338
+ });
1339
+ }
1340
+ });
1341
+ menuItems.push({
1342
+ id: "archive",
1343
+ label: room.isArchived ? labels.unarchive : labels.archive,
1344
+ onSelect: async () => {
1345
+ if (room.isArchived) return void inbox.setArchived(roomId, false).catch(() => {
1346
+ });
1347
+ const ok = await confirm({
1348
+ title: labels.archiveConfirmTitle(room.name),
1349
+ body: labels.archiveConfirmBody,
1350
+ confirmLabel: labels.archiveConfirm,
1351
+ cancelLabel: labels.cancel
1352
+ });
1353
+ if (ok) void inbox.setArchived(roomId, true).catch(() => {
1354
+ });
1355
+ }
1356
+ });
1357
+ }
1201
1358
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
1202
1359
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
1203
1360
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsxRuntime.jsx(ChevronLeft, {}) }),
1204
1361
  room && /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 28 }),
1205
1362
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" }),
1206
- room && !isRequest && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-conversation-actions", children: [
1207
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-text-btn", onClick: () => void inbox.setMuted(roomId, !room.isMuted).catch(() => {
1208
- }), children: room.isMuted ? labels.unmute : labels.mute }),
1209
- !isClosed && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-text-btn", onClick: () => void inbox.closeDM(roomId).catch(() => {
1210
- }), children: labels.closeConversation })
1363
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-conversation-actions", children: [
1364
+ /* @__PURE__ */ jsxRuntime.jsx(ConversationMenu, { label: labels.moreOptions, items: menuItems }),
1365
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
1211
1366
  ] })
1212
1367
  ] }),
1213
1368
  isRequest && room && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-request-banner", role: "region", "aria-label": labels.requests, children: [
@@ -1246,6 +1401,9 @@ function ConversationView({ roomId, labels, onBack }) {
1246
1401
  ) })
1247
1402
  ] });
1248
1403
  }
1404
+ function CloseIcon() {
1405
+ 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" }) });
1406
+ }
1249
1407
  function ChevronLeft() {
1250
1408
  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" }) });
1251
1409
  }
@@ -1263,7 +1421,8 @@ function DialtribeMessages({
1263
1421
  labels: labelOverrides,
1264
1422
  panelWidth = 380,
1265
1423
  railDmLimit = 5,
1266
- mobileBreakpoint = 768
1424
+ mobileBreakpoint = 768,
1425
+ confirm: hostConfirm
1267
1426
  }) {
1268
1427
  const labels = react.useMemo(() => ({ ...DEFAULT_LABELS, ...labelOverrides }), [labelOverrides]);
1269
1428
  const inbox = useChatRooms();
@@ -1272,7 +1431,21 @@ function DialtribeMessages({
1272
1431
  const { isOpen, view } = ui;
1273
1432
  const pendingCount = inbox.requests.length;
1274
1433
  const rollup = inbox.totalUnread + pendingCount;
1275
- const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted").slice(0, railDmLimit);
1434
+ const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted" && !r.isArchived).slice(0, railDmLimit);
1435
+ const [builtInConfirm, setBuiltInConfirm] = react.useState(null);
1436
+ const confirmOpen = react.useRef(false);
1437
+ const confirm = react.useMemo(
1438
+ () => async (options) => {
1439
+ confirmOpen.current = true;
1440
+ try {
1441
+ return hostConfirm ? await hostConfirm(options) : await new Promise((resolve) => setBuiltInConfirm({ options, resolve }));
1442
+ } finally {
1443
+ confirmOpen.current = false;
1444
+ setBuiltInConfirm(null);
1445
+ }
1446
+ },
1447
+ [hostConfirm]
1448
+ );
1276
1449
  const activeRoomId = isOpen && view.kind === "room" ? view.roomId : null;
1277
1450
  const activeContext = contexts.find((c) => c.roomId === activeRoomId);
1278
1451
  const activeItemId = isOpen && view.kind === "item" ? view.itemId : null;
@@ -1286,7 +1459,9 @@ function DialtribeMessages({
1286
1459
  useEdgeSwipe(isMobile, isOpen, ui.open, ui.close, side);
1287
1460
  react.useEffect(() => {
1288
1461
  if (!isOpen) return;
1289
- const onKey = (e) => e.key === "Escape" && ui.close();
1462
+ const onKey = (e) => {
1463
+ if (e.key === "Escape" && !e.defaultPrevented && !confirmOpen.current) ui.close();
1464
+ };
1290
1465
  window.addEventListener("keydown", onKey);
1291
1466
  return () => window.removeEventListener("keydown", onKey);
1292
1467
  }, [isOpen, ui]);
@@ -1324,30 +1499,49 @@ function DialtribeMessages({
1324
1499
  /* @__PURE__ */ jsxRuntime.jsx(ChatIcon, {}),
1325
1500
  rollup > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
1326
1501
  ] }),
1327
- isOpen && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: 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: [
1328
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
1329
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
1330
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
1331
- ] }),
1332
- /* @__PURE__ */ jsxRuntime.jsx(
1333
- MessagesInbox,
1502
+ 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: [
1504
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
1505
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
1506
+ /* @__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, {}) })
1507
+ ] }),
1508
+ /* @__PURE__ */ jsxRuntime.jsx(
1509
+ MessagesInbox,
1510
+ {
1511
+ rooms: inbox.rooms,
1512
+ requests: inbox.requests,
1513
+ labels,
1514
+ onOpenRoom: ui.openRoom,
1515
+ onRemoveRoom: inboxRowClose ? (roomId) => void inbox.hideDM(roomId).catch(() => {
1516
+ }) : void 0
1517
+ }
1518
+ )
1519
+ ] }) : activeContext ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
1520
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
1521
+ /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
1522
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: activeContext.label }),
1523
+ /* @__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, {}) })
1524
+ ] }),
1525
+ /* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
1526
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(
1527
+ ConversationView,
1334
1528
  {
1335
- rooms: inbox.rooms,
1336
- requests: inbox.requests,
1529
+ roomId: view.roomId,
1337
1530
  labels,
1338
- onOpenRoom: ui.openRoom,
1339
- onRemoveRoom: inboxRowClose ? (roomId) => void inbox.hideDM(roomId).catch(() => {
1340
- }) : void 0
1531
+ onBack: ui.openInbox,
1532
+ onClose: ui.close,
1533
+ confirm
1534
+ },
1535
+ view.roomId
1536
+ ),
1537
+ builtInConfirm && /* @__PURE__ */ jsxRuntime.jsx(
1538
+ ConfirmDialog,
1539
+ {
1540
+ options: builtInConfirm.options,
1541
+ onAnswer: builtInConfirm.resolve
1341
1542
  }
1342
1543
  )
1343
- ] }) : activeContext ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
1344
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
1345
- /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
1346
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: activeContext.label }),
1347
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
1348
- ] }),
1349
- /* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
1350
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(ConversationView, { roomId: view.roomId, labels, onBack: ui.openInbox }, view.roomId) }),
1544
+ ] }),
1351
1545
  showRail && /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "dtc-rail", "aria-label": labels.messages, children: [
1352
1546
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-rail-scroll", children: [
1353
1547
  topItems.map(renderItemButton),
@@ -1395,6 +1589,37 @@ function DialtribeMessages({
1395
1589
  }
1396
1590
  );
1397
1591
  }
1592
+ function ConfirmDialog({ options, onAnswer }) {
1593
+ const confirmRef = react.useRef(null);
1594
+ react.useEffect(() => {
1595
+ confirmRef.current?.focus();
1596
+ const onKey = (e) => {
1597
+ if (e.key !== "Escape") return;
1598
+ e.preventDefault();
1599
+ onAnswer(false);
1600
+ };
1601
+ window.addEventListener("keydown", onKey, true);
1602
+ return () => window.removeEventListener("keydown", onKey, true);
1603
+ }, [onAnswer]);
1604
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-confirm-backdrop", onClick: () => onAnswer(false), children: /* @__PURE__ */ jsxRuntime.jsxs(
1605
+ "div",
1606
+ {
1607
+ className: "dtc-confirm",
1608
+ role: "alertdialog",
1609
+ "aria-modal": "true",
1610
+ "aria-labelledby": "dtc-confirm-title",
1611
+ onClick: (e) => e.stopPropagation(),
1612
+ children: [
1613
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { id: "dtc-confirm-title", className: "dtc-confirm-title", children: options.title }),
1614
+ options.body && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "dtc-confirm-body", children: options.body }),
1615
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-confirm-actions", children: [
1616
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-btn", onClick: () => onAnswer(false), children: options.cancelLabel }),
1617
+ /* @__PURE__ */ jsxRuntime.jsx("button", { ref: confirmRef, type: "button", className: "dtc-btn dtc-btn-primary", onClick: () => onAnswer(true), children: options.confirmLabel })
1618
+ ] })
1619
+ ]
1620
+ }
1621
+ ) });
1622
+ }
1398
1623
  function RailButton({
1399
1624
  label,
1400
1625
  active,
@@ -1502,7 +1727,7 @@ function themeVars(theme) {
1502
1727
  function ChatIcon() {
1503
1728
  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" }) });
1504
1729
  }
1505
- function CloseIcon() {
1730
+ function CloseIcon2() {
1506
1731
  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" }) });
1507
1732
  }
1508
1733