@dialtribe/chat-client 0.5.1 → 0.7.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
@@ -298,6 +298,17 @@ var InboxStore = class extends Store {
298
298
  this.removed.delete(roomId);
299
299
  await this.refresh();
300
300
  }
301
+ /**
302
+ * Start a group with several people in one step. Each person's DM settings
303
+ * apply: those whose DMs are closed come back in `refused`. If only one
304
+ * person is left, `roomId` is your 1:1 with them.
305
+ */
306
+ async createGroup(targetUserIds) {
307
+ const result = await this.client.dm("chat-dm-create-group", { targetUserIds });
308
+ this.removed.delete(result.roomId);
309
+ await this.refresh();
310
+ return { roomId: result.roomId, added: result.added ?? [], refused: result.refused ?? [] };
311
+ }
301
312
  /** Add someone. Returns the room to show (a new group when added to a 1:1). */
302
313
  async addParticipant(roomId, targetUserId, hint) {
303
314
  const result = await this.client.dm("chat-dm-add-participant", {
@@ -636,6 +647,7 @@ var ChatClient = class {
636
647
  this.rooms = /* @__PURE__ */ new Map();
637
648
  this.inboxStore = null;
638
649
  this.notificationsStore = null;
650
+ this.profiles = /* @__PURE__ */ new Map();
639
651
  this.serverUrl = options.serverUrl.replace(/\/$/, "");
640
652
  this.apiUrl = (options.apiUrl ?? "https://dialtribe.com").replace(/\/$/, "");
641
653
  }
@@ -810,6 +822,40 @@ var ChatClient = class {
810
822
  api(path, init = {}) {
811
823
  return this.request(path, init, `${this.apiUrl}/api/public/v1`);
812
824
  }
825
+ /**
826
+ * A person's mini-profile from Dialtribe, memoized per user for the life of
827
+ * the client. Network failures aren't remembered, so the next call retries.
828
+ */
829
+ getProfile(userId) {
830
+ let lookup = this.profiles.get(userId);
831
+ if (!lookup) {
832
+ lookup = this.api(`/chat/profiles/${encodeURIComponent(userId)}`).then(
833
+ (profile) => ({ status: "ok", profile }),
834
+ (err) => {
835
+ if (err instanceof ChatRequestError && err.code === "not-found") {
836
+ return err.message === "not_supported" ? { status: "not_supported" } : { status: "hidden" };
837
+ }
838
+ this.profiles.delete(userId);
839
+ throw err;
840
+ }
841
+ );
842
+ this.profiles.set(userId, lookup);
843
+ }
844
+ return lookup;
845
+ }
846
+ /**
847
+ * People whose handle starts with `query` (2+ characters), among those you can
848
+ * reach through this app's organization. Empty for apps not on Dialtribe identity.
849
+ */
850
+ async searchPeople(query) {
851
+ try {
852
+ const { people } = await this.api(`/chat/people?q=${encodeURIComponent(query)}`);
853
+ return people;
854
+ } catch (err) {
855
+ if (err instanceof ChatRequestError && err.code === "not-found") return [];
856
+ throw err;
857
+ }
858
+ }
813
859
  /** A DM action on POST /dm (see DMS.md). */
814
860
  dm(action, fields = {}) {
815
861
  return this.request("/dm", { method: "POST", body: { action, ...fields } });
@@ -887,6 +933,24 @@ var MessagesUiStore = class extends Store {
887
933
  openItem(itemId) {
888
934
  this.update({ open: true, view: { kind: "item", itemId } });
889
935
  }
936
+ /** The view to return to from a profile or the composer (never another overlay). */
937
+ returnTo() {
938
+ const current = this.getSnapshot().view;
939
+ return current.kind === "profile" || current.kind === "compose" ? current.from : current;
940
+ }
941
+ /** Show a person's mini-profile, returning to the current view on back. */
942
+ openProfile(userId, hint) {
943
+ this.update({ open: true, view: { kind: "profile", userId, from: this.returnTo(), hint } });
944
+ }
945
+ /** Show the "Start new" composer, returning to the current view on back. */
946
+ openCompose() {
947
+ this.update({ open: true, view: { kind: "compose", from: this.returnTo() } });
948
+ }
949
+ /** From a mini-profile or the composer, return to where it was opened. */
950
+ back() {
951
+ const { view } = this.getSnapshot();
952
+ this.update({ view: view.kind === "profile" || view.kind === "compose" ? view.from : { kind: "inbox" } });
953
+ }
890
954
  };
891
955
  var ClientContext = createContext(null);
892
956
  var MessagesUiContext = createContext(null);
@@ -1001,6 +1065,19 @@ function useDialtribeMessages() {
1001
1065
  openRoom: (roomId) => ui.openRoom(roomId),
1002
1066
  openItem: (itemId) => ui.openItem(itemId),
1003
1067
  openNotifications: () => ui.openNotifications(),
1068
+ openProfile: (userId, hint) => ui.openProfile(userId, hint),
1069
+ back: () => ui.back(),
1070
+ openCompose: () => ui.openCompose(),
1071
+ startConversation: async (userIds) => {
1072
+ if (userIds.length === 1) {
1073
+ const { roomId } = await client.inbox.requestDM(userIds[0]);
1074
+ ui.openRoom(roomId);
1075
+ return { roomId, added: userIds, refused: [] };
1076
+ }
1077
+ const result = await client.inbox.createGroup(userIds);
1078
+ ui.openRoom(result.roomId);
1079
+ return result;
1080
+ },
1004
1081
  messageUser: async (userId, hint) => {
1005
1082
  const result = await client.inbox.requestDM(userId, hint);
1006
1083
  ui.openRoom(result.roomId);
@@ -1052,6 +1129,8 @@ function ChatMessageItem({
1052
1129
  message,
1053
1130
  config,
1054
1131
  showAvatar = false,
1132
+ onAuthorClick,
1133
+ authorLabel = (name) => `View profile of ${name}`,
1055
1134
  onReply,
1056
1135
  onReact,
1057
1136
  modActions
@@ -1079,7 +1158,7 @@ function ChatMessageItem({
1079
1158
  message.replyPreview.text
1080
1159
  ] }),
1081
1160
  /* @__PURE__ */ jsxs("div", { className: "dtc-message-row", children: [
1082
- showAvatar && /* @__PURE__ */ jsx(Avatar, { name: message.authorName, url: message.avatarUrl, size: 28, className: "dtc-message-avatar" }),
1161
+ showAvatar && (onAuthorClick ? /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-person-btn", onClick: onAuthorClick, "aria-label": authorLabel(message.authorName), children: /* @__PURE__ */ jsx(Avatar, { name: message.authorName, url: message.avatarUrl, size: 28, className: "dtc-message-avatar" }) }) : /* @__PURE__ */ jsx(Avatar, { name: message.authorName, url: message.avatarUrl, size: 28, className: "dtc-message-avatar" })),
1083
1162
  /* @__PURE__ */ jsxs("div", { className: "dtc-message-content", children: [
1084
1163
  message.isHost && /* @__PURE__ */ jsx("span", { className: "dtc-badge dtc-badge-host", children: "HOST" }),
1085
1164
  message.isModerator && !message.isHost && /* @__PURE__ */ jsx("span", { className: "dtc-badge dtc-badge-mod", children: "MOD" }),
@@ -1092,7 +1171,16 @@ function ChatMessageItem({
1092
1171
  children: flair.tag
1093
1172
  }
1094
1173
  ),
1095
- /* @__PURE__ */ jsx("span", { className: `dtc-author ${message.isHost ? "dtc-author-host" : message.isModerator ? "dtc-author-mod" : ""}`, children: message.authorName }),
1174
+ onAuthorClick ? /* @__PURE__ */ jsx(
1175
+ "button",
1176
+ {
1177
+ type: "button",
1178
+ className: `dtc-person-btn dtc-author ${message.isHost ? "dtc-author-host" : message.isModerator ? "dtc-author-mod" : ""}`,
1179
+ onClick: onAuthorClick,
1180
+ "aria-label": authorLabel(message.authorName),
1181
+ children: message.authorName
1182
+ }
1183
+ ) : /* @__PURE__ */ jsx("span", { className: `dtc-author ${message.isHost ? "dtc-author-host" : message.isModerator ? "dtc-author-mod" : ""}`, children: message.authorName }),
1096
1184
  /* @__PURE__ */ jsx("span", { className: "dtc-message-text", children: message.message })
1097
1185
  ] }),
1098
1186
  showActions && (onReply || onReact || modActions) && /* @__PURE__ */ jsxs("div", { className: "dtc-actions", children: [
@@ -1201,7 +1289,9 @@ function ChatPanel({
1201
1289
  showAvatars = false,
1202
1290
  canSend = true,
1203
1291
  emptyLabel = "No messages yet",
1204
- placeholder
1292
+ placeholder,
1293
+ onAuthorClick,
1294
+ authorLabel
1205
1295
  }) {
1206
1296
  const chat = useChatRoomContext();
1207
1297
  const { messages, config, pinnedMessages, typingUsers, hasMoreHistory } = chat;
@@ -1269,6 +1359,8 @@ function ChatPanel({
1269
1359
  message: msg,
1270
1360
  config,
1271
1361
  showAvatar: showAvatars,
1362
+ onAuthorClick: onAuthorClick && !msg.isBotMessage ? () => onAuthorClick({ userId: msg.authorId, name: msg.authorName, avatarUrl: msg.avatarUrl ?? null }) : void 0,
1363
+ authorLabel,
1272
1364
  onReply: () => setReplyTo(msg),
1273
1365
  onReact: (id, emoji) => void chat.addReaction(id, emoji).catch(() => {
1274
1366
  }),
@@ -1359,7 +1451,21 @@ var DEFAULT_LABELS = {
1359
1451
  if (s < 86400) return `${Math.floor(s / 3600)}h`;
1360
1452
  if (s < 604800) return `${Math.floor(s / 86400)}d`;
1361
1453
  return date.toLocaleDateString(void 0, { month: "short", day: "numeric" });
1362
- }
1454
+ },
1455
+ viewSiteProfile: (site) => site ? `View ${site} profile` : "View profile",
1456
+ alsoOn: "Also on",
1457
+ message: "Message",
1458
+ viewProfileOf: (name) => `View profile of ${name}`,
1459
+ members: "Members",
1460
+ newMessage: "New message",
1461
+ searchPeople: "Search by handle",
1462
+ recent: "Recent",
1463
+ noPeopleFound: "No one found",
1464
+ start: "Start",
1465
+ cantMessage: (names) => `${names} can't be messaged right now`,
1466
+ openConversation: "Open conversation",
1467
+ removePerson: (name) => `Remove ${name}`,
1468
+ startFailed: "Couldn't start the conversation. Try again."
1363
1469
  };
1364
1470
  function badgeText(count) {
1365
1471
  return count > 99 ? "99+" : String(count);
@@ -1511,10 +1617,12 @@ function KebabIcon() {
1511
1617
  /* @__PURE__ */ jsx("circle", { cx: "12", cy: "19", r: "1.8" })
1512
1618
  ] });
1513
1619
  }
1514
- function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
1620
+ function ConversationView({ roomId, labels, onBack, onClose, confirm, onOpenProfile }) {
1515
1621
  const inbox = useChatRooms();
1516
1622
  const room = inbox.rooms.find((r) => r.roomId === roomId);
1517
1623
  const { setVisible } = inbox;
1624
+ const [membersOpen, setMembersOpen] = useState(false);
1625
+ const other = room?.kind === "dm" ? room.participants[0] : void 0;
1518
1626
  useEffect(() => setVisible(roomId), [setVisible, roomId]);
1519
1627
  const isRequest = room?.myStatus === "pending";
1520
1628
  const isClosed = room?.state === "closed";
@@ -1557,13 +1665,53 @@ function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
1557
1665
  return /* @__PURE__ */ jsxs("div", { className: "dtc-conversation", children: [
1558
1666
  /* @__PURE__ */ jsxs("div", { className: "dtc-conversation-header", children: [
1559
1667
  /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsx(ChevronLeft, {}) }),
1560
- room && /* @__PURE__ */ jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 28 }),
1561
- /* @__PURE__ */ jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" }),
1668
+ other ? /* @__PURE__ */ jsxs(
1669
+ "button",
1670
+ {
1671
+ type: "button",
1672
+ className: "dtc-person-btn dtc-conversation-person",
1673
+ onClick: () => onOpenProfile(other.userId, { name: other.name, avatarUrl: other.avatarUrl }),
1674
+ "aria-label": labels.viewProfileOf(other.name),
1675
+ children: [
1676
+ /* @__PURE__ */ jsx(Avatar, { name: other.name, url: other.avatarUrl, size: 28 }),
1677
+ /* @__PURE__ */ jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" })
1678
+ ]
1679
+ }
1680
+ ) : room?.kind === "group" ? /* @__PURE__ */ jsxs(
1681
+ "button",
1682
+ {
1683
+ type: "button",
1684
+ className: "dtc-person-btn dtc-conversation-person",
1685
+ onClick: () => setMembersOpen((v) => !v),
1686
+ "aria-expanded": membersOpen,
1687
+ "aria-label": labels.members,
1688
+ children: [
1689
+ /* @__PURE__ */ jsx(Avatar, { name: room.name, size: 28 }),
1690
+ /* @__PURE__ */ jsx("span", { className: "dtc-conversation-title", children: room.name })
1691
+ ]
1692
+ }
1693
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
1694
+ room && /* @__PURE__ */ jsx(Avatar, { name: room.name, size: 28 }),
1695
+ /* @__PURE__ */ jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" })
1696
+ ] }),
1562
1697
  /* @__PURE__ */ jsxs("span", { className: "dtc-conversation-actions", children: [
1563
1698
  /* @__PURE__ */ jsx(ConversationMenu, { label: labels.moreOptions, items: menuItems }),
1564
1699
  /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon, {}) })
1565
1700
  ] })
1566
1701
  ] }),
1702
+ membersOpen && room?.kind === "group" && /* @__PURE__ */ jsx("ul", { className: "dtc-member-list", "aria-label": labels.members, children: room.participants.map((p) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
1703
+ "button",
1704
+ {
1705
+ type: "button",
1706
+ className: "dtc-member",
1707
+ onClick: () => onOpenProfile(p.userId, { name: p.name, avatarUrl: p.avatarUrl }),
1708
+ "aria-label": labels.viewProfileOf(p.name),
1709
+ children: [
1710
+ /* @__PURE__ */ jsx(Avatar, { name: p.name, url: p.avatarUrl, size: 24 }),
1711
+ /* @__PURE__ */ jsx("span", { className: "dtc-member-name", children: p.name })
1712
+ ]
1713
+ }
1714
+ ) }, p.userId)) }),
1567
1715
  isRequest && room && /* @__PURE__ */ jsxs("div", { className: "dtc-request-banner", role: "region", "aria-label": labels.requests, children: [
1568
1716
  /* @__PURE__ */ jsx("span", { children: labels.wantsToMessage(room.name) }),
1569
1717
  /* @__PURE__ */ jsxs("span", { className: "dtc-request-actions", children: [
@@ -1595,7 +1743,9 @@ function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
1595
1743
  showPinnedMessages: false,
1596
1744
  canSend: !isRequest && !isClosed,
1597
1745
  emptyLabel: labels.noMessages,
1598
- placeholder: labels.messagePlaceholder
1746
+ placeholder: labels.messagePlaceholder,
1747
+ onAuthorClick: (a) => onOpenProfile(a.userId, { name: a.name, avatarUrl: a.avatarUrl }),
1748
+ authorLabel: labels.viewProfileOf
1599
1749
  }
1600
1750
  ) })
1601
1751
  ] });
@@ -1699,6 +1849,238 @@ function NotificationsPanel({ labels, onClose, onOpen, onOpened }) {
1699
1849
  ] })
1700
1850
  ] });
1701
1851
  }
1852
+ function fallbackProfile(userId, hint, canMessage) {
1853
+ return {
1854
+ userId,
1855
+ name: hint?.name || userId,
1856
+ handle: null,
1857
+ avatarUrl: hint?.avatarUrl ?? null,
1858
+ bio: null,
1859
+ current: null,
1860
+ apps: [],
1861
+ canMessage
1862
+ };
1863
+ }
1864
+ function ProfileView({
1865
+ userId,
1866
+ hint,
1867
+ labels,
1868
+ onBack,
1869
+ onClose,
1870
+ onNavigate,
1871
+ onMessage,
1872
+ hideMessage,
1873
+ getProfileUrl,
1874
+ profileActions
1875
+ }) {
1876
+ const client = useChatClient();
1877
+ const [lookup, setLookup] = useState(null);
1878
+ useEffect(() => {
1879
+ let live = true;
1880
+ setLookup(null);
1881
+ client.getProfile(userId).then(
1882
+ (result) => live && setLookup(result),
1883
+ () => live && setLookup({ status: "not_supported" })
1884
+ );
1885
+ return () => {
1886
+ live = false;
1887
+ };
1888
+ }, [client, userId]);
1889
+ const profile = lookup?.status === "ok" ? lookup.profile : fallbackProfile(userId, hint, lookup?.status !== "hidden");
1890
+ const fallbackUrl = lookup?.status === "not_supported" ? getProfileUrl?.(userId) ?? null : null;
1891
+ const primary = profile.current ? { url: profile.current.profileUrl, label: labels.viewSiteProfile(profile.current.siteName) } : fallbackUrl ? { url: fallbackUrl, label: labels.viewSiteProfile("") } : null;
1892
+ const showHandle = !!profile.handle && profile.handle.toLowerCase() !== profile.name.toLowerCase();
1893
+ const showMessage = !hideMessage && lookup !== null && profile.canMessage;
1894
+ return /* @__PURE__ */ jsxs("div", { className: "dtc-conversation", children: [
1895
+ /* @__PURE__ */ jsxs("div", { className: "dtc-conversation-header", children: [
1896
+ /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsx(ChevronLeft2, {}) }),
1897
+ /* @__PURE__ */ jsx("span", { className: "dtc-conversation-title" }),
1898
+ /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon2, {}) })
1899
+ ] }),
1900
+ /* @__PURE__ */ jsxs("div", { className: "dtc-profile", children: [
1901
+ /* @__PURE__ */ jsxs("div", { className: "dtc-profile-head", children: [
1902
+ /* @__PURE__ */ jsx(Avatar, { name: profile.name, url: profile.avatarUrl, size: 64 }),
1903
+ /* @__PURE__ */ jsxs("div", { className: "dtc-profile-names", children: [
1904
+ /* @__PURE__ */ jsx("span", { className: "dtc-profile-name", children: profile.name }),
1905
+ showHandle && /* @__PURE__ */ jsxs("span", { className: "dtc-profile-handle", children: [
1906
+ "@",
1907
+ profile.handle
1908
+ ] })
1909
+ ] })
1910
+ ] }),
1911
+ profile.bio && /* @__PURE__ */ jsx("p", { className: "dtc-profile-bio", children: profile.bio }),
1912
+ primary && /* @__PURE__ */ jsx("a", { className: "dtc-btn dtc-btn-primary dtc-profile-primary", href: primary.url, onClick: onNavigate, children: primary.label }),
1913
+ profile.apps.length > 0 && /* @__PURE__ */ jsxs("div", { className: "dtc-profile-sites", children: [
1914
+ /* @__PURE__ */ jsx("span", { className: "dtc-profile-sites-title", children: labels.alsoOn }),
1915
+ profile.apps.map((site) => {
1916
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [
1917
+ site.iconUrl ? /* @__PURE__ */ jsx("img", { className: "dtc-profile-site-icon", src: site.iconUrl, alt: "" }) : /* @__PURE__ */ jsx(Avatar, { name: site.siteName, size: 20, className: "dtc-profile-site-icon" }),
1918
+ /* @__PURE__ */ jsx("span", { className: "dtc-profile-site-name", children: site.siteName }),
1919
+ site.url && /* @__PURE__ */ jsx(ArrowIcon, {})
1920
+ ] });
1921
+ return site.url ? /* @__PURE__ */ jsx("a", { className: "dtc-profile-site", href: site.url, target: "_blank", rel: "noopener noreferrer", children: body }, site.appId) : /* @__PURE__ */ jsx("span", { className: "dtc-profile-site", children: body }, site.appId);
1922
+ })
1923
+ ] }),
1924
+ showMessage && /* @__PURE__ */ jsx(
1925
+ "button",
1926
+ {
1927
+ type: "button",
1928
+ className: "dtc-btn dtc-profile-message",
1929
+ onClick: () => onMessage(userId, { name: profile.name, avatarUrl: profile.avatarUrl }),
1930
+ children: labels.message
1931
+ }
1932
+ ),
1933
+ profileActions && lookup !== null && lookup.status !== "hidden" && /* @__PURE__ */ jsx("div", { className: "dtc-profile-actions", children: profileActions(profile) })
1934
+ ] })
1935
+ ] });
1936
+ }
1937
+ function ChevronLeft2() {
1938
+ 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" }) });
1939
+ }
1940
+ function CloseIcon2() {
1941
+ 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" }) });
1942
+ }
1943
+ function ArrowIcon() {
1944
+ return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M7 17L17 7M9 7h8v8" }) });
1945
+ }
1946
+ var SEARCH_MIN = 2;
1947
+ var SEARCH_DEBOUNCE_MS = 250;
1948
+ function ComposeView({ labels, onBack, onClose, onOpenRoom }) {
1949
+ const client = useChatClient();
1950
+ const inbox = useChatRooms();
1951
+ const [query, setQuery] = useState("");
1952
+ const [results, setResults] = useState(null);
1953
+ const [picked, setPicked] = useState([]);
1954
+ const [busy, setBusy] = useState(false);
1955
+ const [notice, setNotice] = useState(null);
1956
+ const inputRef = useRef(null);
1957
+ const selfId = client.self?.userId;
1958
+ useEffect(() => inputRef.current?.focus(), []);
1959
+ const recent = useMemo(() => {
1960
+ const seen = /* @__PURE__ */ new Set();
1961
+ const people = [];
1962
+ for (const room of inbox.rooms) {
1963
+ for (const p of room.participants) {
1964
+ if (p.userId === selfId || seen.has(p.userId)) continue;
1965
+ seen.add(p.userId);
1966
+ people.push({ userId: p.userId, name: p.name, handle: null, avatarUrl: p.avatarUrl });
1967
+ }
1968
+ }
1969
+ return people;
1970
+ }, [inbox.rooms, selfId]);
1971
+ const q = query.trim().replace(/^@/, "");
1972
+ useEffect(() => {
1973
+ if (q.length < SEARCH_MIN) {
1974
+ setResults(null);
1975
+ return;
1976
+ }
1977
+ let live = true;
1978
+ const timer = setTimeout(() => {
1979
+ client.searchPeople(q).then(
1980
+ (people) => live && setResults(people),
1981
+ () => live && setResults([])
1982
+ );
1983
+ }, SEARCH_DEBOUNCE_MS);
1984
+ return () => {
1985
+ live = false;
1986
+ clearTimeout(timer);
1987
+ };
1988
+ }, [client, q]);
1989
+ const searching = q.length >= SEARCH_MIN;
1990
+ const list = searching ? results ?? [] : recent;
1991
+ const pickedIds = new Set(picked.map((p) => p.userId));
1992
+ const toggle = (person) => {
1993
+ setNotice(null);
1994
+ setPicked(
1995
+ (current) => current.some((p) => p.userId === person.userId) ? current.filter((p) => p.userId !== person.userId) : [...current, person]
1996
+ );
1997
+ };
1998
+ const namesOf = (ids) => picked.filter((p) => ids.includes(p.userId)).map((p) => p.name).join(", ");
1999
+ const start = async () => {
2000
+ if (!picked.length || busy) return;
2001
+ setBusy(true);
2002
+ setNotice(null);
2003
+ try {
2004
+ if (picked.length === 1) {
2005
+ const { roomId } = await client.inbox.requestDM(picked[0].userId, {
2006
+ name: picked[0].name,
2007
+ avatarUrl: picked[0].avatarUrl ?? void 0
2008
+ });
2009
+ onOpenRoom(roomId);
2010
+ return;
2011
+ }
2012
+ const result = await client.inbox.createGroup(picked.map((p) => p.userId));
2013
+ if (result.refused.length) setNotice({ text: labels.cantMessage(namesOf(result.refused)), roomId: result.roomId });
2014
+ else onOpenRoom(result.roomId);
2015
+ } catch (err) {
2016
+ const refused = err instanceof ChatRequestError && err.code === "dm-not-allowed";
2017
+ setNotice({ text: refused ? labels.cantMessage(namesOf(picked.map((p) => p.userId))) : labels.startFailed, roomId: null });
2018
+ } finally {
2019
+ setBusy(false);
2020
+ }
2021
+ };
2022
+ return /* @__PURE__ */ jsxs("div", { className: "dtc-conversation", children: [
2023
+ /* @__PURE__ */ jsxs("div", { className: "dtc-conversation-header", children: [
2024
+ /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsx(ChevronLeft3, {}) }),
2025
+ /* @__PURE__ */ jsx("span", { className: "dtc-conversation-title", children: labels.newMessage }),
2026
+ /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon3, {}) })
2027
+ ] }),
2028
+ /* @__PURE__ */ jsxs("div", { className: "dtc-compose", children: [
2029
+ /* @__PURE__ */ jsxs("div", { className: "dtc-compose-field", children: [
2030
+ picked.map((p) => /* @__PURE__ */ jsxs("span", { className: "dtc-compose-chip", children: [
2031
+ p.name,
2032
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: () => toggle(p), "aria-label": labels.removePerson(p.name), children: /* @__PURE__ */ jsx(CloseIcon3, { size: 12 }) })
2033
+ ] }, p.userId)),
2034
+ /* @__PURE__ */ jsx(
2035
+ "input",
2036
+ {
2037
+ ref: inputRef,
2038
+ className: "dtc-compose-input",
2039
+ value: query,
2040
+ onChange: (e) => setQuery(e.target.value.slice(0, 50)),
2041
+ onKeyDown: (e) => {
2042
+ if (e.key === "Backspace" && !query && picked.length) setPicked(picked.slice(0, -1));
2043
+ },
2044
+ placeholder: picked.length ? "" : labels.searchPeople,
2045
+ "aria-label": labels.searchPeople
2046
+ }
2047
+ )
2048
+ ] }),
2049
+ !searching && recent.length > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-profile-sites-title", children: labels.recent }),
2050
+ /* @__PURE__ */ jsx("ul", { className: "dtc-compose-list", children: list.map((person) => {
2051
+ const on = pickedIds.has(person.userId);
2052
+ return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("button", { type: "button", className: "dtc-member", "aria-pressed": on, onClick: () => toggle(person), children: [
2053
+ /* @__PURE__ */ jsx(Avatar, { name: person.name, url: person.avatarUrl, size: 32 }),
2054
+ /* @__PURE__ */ jsxs("span", { className: "dtc-compose-names", children: [
2055
+ /* @__PURE__ */ jsx("span", { className: "dtc-member-name", children: person.name }),
2056
+ person.handle && person.handle.toLowerCase() !== person.name.toLowerCase() && /* @__PURE__ */ jsxs("span", { className: "dtc-profile-handle", children: [
2057
+ "@",
2058
+ person.handle
2059
+ ] })
2060
+ ] }),
2061
+ /* @__PURE__ */ jsx("span", { className: `dtc-compose-check ${on ? "dtc-compose-check-on" : ""}`, "aria-hidden": "true", children: on && /* @__PURE__ */ jsx(CheckIcon, {}) })
2062
+ ] }) }, person.userId);
2063
+ }) }),
2064
+ searching && results !== null && results.length === 0 && /* @__PURE__ */ jsx("div", { className: "dtc-empty", children: labels.noPeopleFound })
2065
+ ] }),
2066
+ /* @__PURE__ */ jsxs("div", { className: "dtc-compose-footer", children: [
2067
+ notice && /* @__PURE__ */ jsxs("div", { className: "dtc-conversation-note", children: [
2068
+ notice.text,
2069
+ notice.roomId && /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-text-btn", onClick: () => onOpenRoom(notice.roomId), children: labels.openConversation })
2070
+ ] }),
2071
+ /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-btn dtc-btn-primary dtc-compose-start", disabled: !picked.length || busy, onClick: () => void start(), children: labels.start })
2072
+ ] })
2073
+ ] });
2074
+ }
2075
+ function ChevronLeft3() {
2076
+ 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" }) });
2077
+ }
2078
+ function CloseIcon3({ size = 18 }) {
2079
+ return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: size, height: size, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" }) });
2080
+ }
2081
+ function CheckIcon() {
2082
+ return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: 3, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M5 12l5 5L20 7" }) });
2083
+ }
1702
2084
  var RAIL_WIDTH = 64;
1703
2085
  var EDGE_SWIPE_ZONE = 24;
1704
2086
  var SWIPE_DISTANCE = 60;
@@ -1715,7 +2097,9 @@ function DialtribeMessages({
1715
2097
  railDmLimit = 5,
1716
2098
  mobileBreakpoint = 768,
1717
2099
  confirm: hostConfirm,
1718
- notifications = false
2100
+ notifications = false,
2101
+ getProfileUrl,
2102
+ profileActions
1719
2103
  }) {
1720
2104
  const labels = useMemo(() => ({ ...DEFAULT_LABELS, ...labelOverrides }), [labelOverrides]);
1721
2105
  const inbox = useChatRooms();
@@ -1782,6 +2166,14 @@ function DialtribeMessages({
1782
2166
  item.id
1783
2167
  );
1784
2168
  };
2169
+ const client = useChatClient();
2170
+ const openProfile = (userId, hint) => ui.openProfile(userId, hint);
2171
+ const hideMessageFor = (userId, from) => {
2172
+ if (client.self?.userId === userId) return true;
2173
+ if (from.kind !== "room") return false;
2174
+ const room = inbox.rooms.find((r) => r.roomId === from.roomId);
2175
+ return room?.kind === "dm" && room.participants[0]?.userId === userId;
2176
+ };
1785
2177
  const style = { ...themeVars(theme), "--dtc-panel-width": `${panelWidth}px`, "--dtc-rail-width": `${RAIL_WIDTH}px` };
1786
2178
  const showRail = !isMobile || isOpen;
1787
2179
  return /* @__PURE__ */ jsxs(
@@ -1796,7 +2188,25 @@ function DialtribeMessages({
1796
2188
  rollup > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
1797
2189
  ] }),
1798
2190
  isOpen && /* @__PURE__ */ jsxs("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: [
1799
- view.kind === "notifications" && notifications !== false ? /* @__PURE__ */ jsx(
2191
+ view.kind === "compose" ? /* @__PURE__ */ jsx(ComposeView, { labels, onBack: ui.back, onClose: ui.close, onOpenRoom: ui.openRoom }) : view.kind === "profile" ? /* @__PURE__ */ jsx(
2192
+ ProfileView,
2193
+ {
2194
+ userId: view.userId,
2195
+ hint: view.hint,
2196
+ labels,
2197
+ onBack: ui.back,
2198
+ onClose: ui.close,
2199
+ onNavigate: () => {
2200
+ if (isMobile) ui.close();
2201
+ },
2202
+ onMessage: (userId, hint) => void ui.messageUser(userId, { name: hint.name, avatarUrl: hint.avatarUrl ?? void 0 }).catch(() => {
2203
+ }),
2204
+ hideMessage: hideMessageFor(view.userId, view.from),
2205
+ getProfileUrl,
2206
+ profileActions
2207
+ },
2208
+ view.userId
2209
+ ) : view.kind === "notifications" && notifications !== false ? /* @__PURE__ */ jsx(
1800
2210
  NotificationsPanel,
1801
2211
  {
1802
2212
  labels,
@@ -1809,7 +2219,8 @@ function DialtribeMessages({
1809
2219
  ) : 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: [
1810
2220
  /* @__PURE__ */ jsxs("div", { className: "dtc-panel-header", children: [
1811
2221
  /* @__PURE__ */ jsx("span", { className: "dtc-panel-title", children: labels.messages }),
1812
- /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon2, {}) })
2222
+ /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.openCompose, "aria-label": labels.newMessage, title: labels.newMessage, children: /* @__PURE__ */ jsx(ComposeIcon, {}) }),
2223
+ /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon4, {}) })
1813
2224
  ] }),
1814
2225
  /* @__PURE__ */ jsx(
1815
2226
  MessagesInbox,
@@ -1826,9 +2237,18 @@ function DialtribeMessages({
1826
2237
  /* @__PURE__ */ jsxs("div", { className: "dtc-conversation-header", children: [
1827
2238
  /* @__PURE__ */ jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
1828
2239
  /* @__PURE__ */ jsx("span", { className: "dtc-conversation-title", children: activeContext.label }),
1829
- /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon2, {}) })
2240
+ /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon4, {}) })
1830
2241
  ] }),
1831
- /* @__PURE__ */ jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
2242
+ /* @__PURE__ */ jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsx(
2243
+ ChatPanel,
2244
+ {
2245
+ showHeader: false,
2246
+ emptyLabel: labels.noMessages,
2247
+ placeholder: labels.messagePlaceholder,
2248
+ onAuthorClick: (a) => openProfile(a.userId, { name: a.name, avatarUrl: a.avatarUrl }),
2249
+ authorLabel: labels.viewProfileOf
2250
+ }
2251
+ ) })
1832
2252
  ] }) : /* @__PURE__ */ jsx(
1833
2253
  ConversationView,
1834
2254
  {
@@ -1836,7 +2256,8 @@ function DialtribeMessages({
1836
2256
  labels,
1837
2257
  onBack: ui.openInbox,
1838
2258
  onClose: ui.close,
1839
- confirm
2259
+ confirm,
2260
+ onOpenProfile: openProfile
1840
2261
  },
1841
2262
  view.roomId
1842
2263
  ),
@@ -2059,10 +2480,16 @@ function useNotificationsBadge(enabled) {
2059
2480
  const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
2060
2481
  return enabled ? snapshot.unreadCount : 0;
2061
2482
  }
2062
- function CloseIcon2() {
2483
+ function ComposeIcon() {
2484
+ return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
2485
+ /* @__PURE__ */ jsx("path", { d: "M12 20h9" }),
2486
+ /* @__PURE__ */ jsx("path", { d: "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z" })
2487
+ ] });
2488
+ }
2489
+ function CloseIcon4() {
2063
2490
  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" }) });
2064
2491
  }
2065
2492
 
2066
- export { Avatar, ChatClient, ChatInput, ChatMessageItem, ChatPanel, ChatRequestError, ChatRoomProvider, DEFAULT_LABELS, DialtribeChatProvider, DialtribeMessages, NotificationsPanel, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
2493
+ export { Avatar, ChatClient, ChatInput, ChatMessageItem, ChatPanel, ChatRequestError, ChatRoomProvider, ComposeView, DEFAULT_LABELS, DialtribeChatProvider, DialtribeMessages, NotificationsPanel, ProfileView, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
2067
2494
  //# sourceMappingURL=index.mjs.map
2068
2495
  //# sourceMappingURL=index.mjs.map