@dialtribe/chat-client 0.6.0 → 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/README.md CHANGED
@@ -200,6 +200,20 @@ button from `getProfileUrl`. Use `profileActions` to add your own buttons:
200
200
  (`{ status: "ok", profile } | { status: "not_supported" } | { status: "hidden" }`),
201
201
  memoized per user.
202
202
 
203
+ ### Start new (group messages)
204
+
205
+ The pencil button in the Messages header opens a composer. Before you type it
206
+ lists people you've talked with; typing two or more characters searches handles
207
+ (apps on Dialtribe identity; others see only the recent list). Pick one person
208
+ to open your 1:1, or several to start a group. Each person's DM settings apply:
209
+ if some can't be messaged, the composer names them and offers the conversation
210
+ with everyone else.
211
+
212
+ From code: `useDialtribeMessages().openCompose()`, or
213
+ `startConversation(userIds)` to start one directly. `useChatClient().searchPeople(q)`
214
+ and `inbox.createGroup(userIds)` (`{ roomId, added, refused }`) are the
215
+ building blocks.
216
+
203
217
  ## Hooks
204
218
 
205
219
  All hooks must be under `<DialtribeChatProvider>`, which owns one connection
@@ -245,7 +259,8 @@ one subscription.
245
259
  ### `useDialtribeMessages()`
246
260
 
247
261
  Drive the rail: `open`, `close`, `toggle`, `openInbox`, `openRoom(roomId)`, `openItem(itemId)`,
248
- `openNotifications()`, `openProfile(userId, hint?)`, `back()`, `messageUser(userId, hint?)`, `isOpen`, `view`.
262
+ `openNotifications()`, `openProfile(userId, hint?)`, `openCompose()`, `back()`, `messageUser(userId, hint?)`,
263
+ `startConversation(userIds)`, `isOpen`, `view`.
249
264
 
250
265
  ### `useDialtribeNotifications()`
251
266
 
@@ -267,7 +282,7 @@ described them.
267
282
  </ChatRoomProvider>
268
283
  ```
269
284
 
270
- `ChatPanel`, `ChatMessageItem`, `ChatInput`, `Avatar` and `ProfileView` are exported.
285
+ `ChatPanel`, `ChatMessageItem`, `ChatInput`, `Avatar`, `ProfileView` and `ComposeView` are exported.
271
286
  `ChatPanel`'s `onAuthorClick` makes authors' names and avatars buttons. Outside
272
287
  React, `ChatClient` is the framework-agnostic core the hooks are built on.
273
288
 
package/dist/index.d.mts CHANGED
@@ -124,6 +124,19 @@ interface DialtribeProfile {
124
124
  /** Whether a new conversation would be allowed. */
125
125
  canMessage: boolean;
126
126
  }
127
+ /** Someone you can start a conversation with (people search, recent contacts). */
128
+ interface PersonSummary {
129
+ userId: string;
130
+ name: string;
131
+ handle: string | null;
132
+ avatarUrl: string | null;
133
+ }
134
+ /** Result of starting a group: who was added, and who couldn't be (their DMs are closed). */
135
+ interface GroupCreateResult {
136
+ roomId: string;
137
+ added: string[];
138
+ refused: string[];
139
+ }
127
140
  /** getProfile: "not_supported" when the app isn't on Dialtribe identity, "hidden" when the profile isn't visible. */
128
141
  type ProfileLookup = {
129
142
  status: "ok";
@@ -370,6 +383,12 @@ declare class InboxStore extends Store<InboxSnapshot> {
370
383
  ignoreDM(requestId: string): Promise<void>;
371
384
  closeDM(roomId: string): Promise<void>;
372
385
  reopenDM(roomId: string): Promise<void>;
386
+ /**
387
+ * Start a group with several people in one step. Each person's DM settings
388
+ * apply: those whose DMs are closed come back in `refused`. If only one
389
+ * person is left, `roomId` is your 1:1 with them.
390
+ */
391
+ createGroup(targetUserIds: string[]): Promise<GroupCreateResult>;
373
392
  /** Add someone. Returns the room to show (a new group when added to a 1:1). */
374
393
  addParticipant(roomId: string, targetUserId: string, hint?: {
375
394
  name?: string;
@@ -562,6 +581,11 @@ declare class ChatClient {
562
581
  * the client. Network failures aren't remembered, so the next call retries.
563
582
  */
564
583
  getProfile(userId: string): Promise<ProfileLookup>;
584
+ /**
585
+ * People whose handle starts with `query` (2+ characters), among those you can
586
+ * reach through this app's organization. Empty for apps not on Dialtribe identity.
587
+ */
588
+ searchPeople(query: string): Promise<PersonSummary[]>;
565
589
  /** A DM action on POST /dm (see DMS.md). */
566
590
  dm<T = Record<string, unknown>>(action: string, fields?: Record<string, unknown>): Promise<T>;
567
591
  /**
@@ -597,6 +621,11 @@ type MessagesView = {
597
621
  userId: string;
598
622
  from: MessagesView;
599
623
  hint?: ProfileHint;
624
+ }
625
+ /** "Start new": pick people to message. Back returns to `from`. */
626
+ | {
627
+ kind: "compose";
628
+ from: MessagesView;
600
629
  };
601
630
  interface ProfileHint {
602
631
  name?: string;
@@ -722,8 +751,15 @@ interface UseDialtribeMessagesReturn {
722
751
  openNotifications: () => void;
723
752
  /** Show a person's mini-profile in the rail; back returns to the current view. */
724
753
  openProfile: (userId: string, hint?: ProfileHint) => void;
725
- /** From a mini-profile, go back to where it was opened. */
754
+ /** From a mini-profile or the composer, go back to where it was opened. */
726
755
  back: () => void;
756
+ /** Open the "Start new" composer. */
757
+ openCompose: () => void;
758
+ /**
759
+ * Start a conversation with one person (their 1:1) or several (a new group)
760
+ * and show it. For a group, `refused` lists people whose DMs are closed.
761
+ */
762
+ startConversation: (userIds: string[]) => Promise<GroupCreateResult>;
727
763
  /**
728
764
  * Start (or reopen) a DM with one of your users and show it. `hint` is only a
729
765
  * display name for someone Dialtribe hasn't seen yet. Rejects with
@@ -815,6 +851,24 @@ interface MessagesLabels {
815
851
  viewProfileOf: (name: string) => string;
816
852
  /** aria-label of a group conversation's title, which lists its members. */
817
853
  members: string;
854
+ /** Messages header button and composer title. */
855
+ newMessage: string;
856
+ /** Composer search field placeholder. */
857
+ searchPeople: string;
858
+ /** Composer: people you've talked with, before you search. */
859
+ recent: string;
860
+ /** Composer: the search found nobody. */
861
+ noPeopleFound: string;
862
+ /** Composer: start the conversation. */
863
+ start: string;
864
+ /** Composer: some people couldn't be added ("Sam, Lee can't be messaged right now"). */
865
+ cantMessage: (names: string) => string;
866
+ /** Composer: go to the conversation after some people couldn't be added. */
867
+ openConversation: string;
868
+ /** aria-label for removing a picked person: "Remove {name}". */
869
+ removePerson: (name: string) => string;
870
+ /** Composer: starting failed for another reason (network). */
871
+ startFailed: string;
818
872
  }
819
873
  declare const DEFAULT_LABELS: MessagesLabels;
820
874
 
@@ -971,6 +1025,20 @@ interface ProfileViewProps {
971
1025
  */
972
1026
  declare function ProfileView({ userId, hint, labels, onBack, onClose, onNavigate, onMessage, hideMessage, getProfileUrl, profileActions, }: ProfileViewProps): react.JSX.Element;
973
1027
 
1028
+ interface ComposeViewProps {
1029
+ labels: MessagesLabels;
1030
+ onBack: () => void;
1031
+ onClose: () => void;
1032
+ /** Show the conversation that was started. */
1033
+ onOpenRoom: (roomId: string) => void;
1034
+ }
1035
+ /**
1036
+ * "Start new": pick one person (opens your 1:1) or several (starts a group).
1037
+ * Before you type, it lists people you've talked with; typing 2+ characters
1038
+ * searches handles.
1039
+ */
1040
+ declare function ComposeView({ labels, onBack, onClose, onOpenRoom }: ComposeViewProps): react.JSX.Element;
1041
+
974
1042
  interface AvatarProps {
975
1043
  name: string;
976
1044
  url?: string | null;
@@ -1060,4 +1128,4 @@ interface ChatInputProps {
1060
1128
  */
1061
1129
  declare function ChatInput({ onSendMessage, onSendTyping, replyTo, onClearReply, disabled, placeholder, maxLength, }: ChatInputProps): react.JSX.Element;
1062
1130
 
1063
- 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 DialtribeProfile, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type NotificationItem, NotificationsPanel, type NotificationsPanelProps, type NotificationsSnapshot, type ParsedReactions, type ProfileHint, type ProfileLookup, type ProfileSite, ProfileView, type ProfileViewProps, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UseDialtribeNotificationsReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
1131
+ 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, ComposeView, type ComposeViewProps, type ConfirmFn, type ConfirmOptions, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DialtribeProfile, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type GroupCreateResult, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type NotificationItem, NotificationsPanel, type NotificationsPanelProps, type NotificationsSnapshot, type ParsedReactions, type PersonSummary, type ProfileHint, type ProfileLookup, type ProfileSite, ProfileView, type ProfileViewProps, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UseDialtribeNotificationsReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
package/dist/index.d.ts CHANGED
@@ -124,6 +124,19 @@ interface DialtribeProfile {
124
124
  /** Whether a new conversation would be allowed. */
125
125
  canMessage: boolean;
126
126
  }
127
+ /** Someone you can start a conversation with (people search, recent contacts). */
128
+ interface PersonSummary {
129
+ userId: string;
130
+ name: string;
131
+ handle: string | null;
132
+ avatarUrl: string | null;
133
+ }
134
+ /** Result of starting a group: who was added, and who couldn't be (their DMs are closed). */
135
+ interface GroupCreateResult {
136
+ roomId: string;
137
+ added: string[];
138
+ refused: string[];
139
+ }
127
140
  /** getProfile: "not_supported" when the app isn't on Dialtribe identity, "hidden" when the profile isn't visible. */
128
141
  type ProfileLookup = {
129
142
  status: "ok";
@@ -370,6 +383,12 @@ declare class InboxStore extends Store<InboxSnapshot> {
370
383
  ignoreDM(requestId: string): Promise<void>;
371
384
  closeDM(roomId: string): Promise<void>;
372
385
  reopenDM(roomId: string): Promise<void>;
386
+ /**
387
+ * Start a group with several people in one step. Each person's DM settings
388
+ * apply: those whose DMs are closed come back in `refused`. If only one
389
+ * person is left, `roomId` is your 1:1 with them.
390
+ */
391
+ createGroup(targetUserIds: string[]): Promise<GroupCreateResult>;
373
392
  /** Add someone. Returns the room to show (a new group when added to a 1:1). */
374
393
  addParticipant(roomId: string, targetUserId: string, hint?: {
375
394
  name?: string;
@@ -562,6 +581,11 @@ declare class ChatClient {
562
581
  * the client. Network failures aren't remembered, so the next call retries.
563
582
  */
564
583
  getProfile(userId: string): Promise<ProfileLookup>;
584
+ /**
585
+ * People whose handle starts with `query` (2+ characters), among those you can
586
+ * reach through this app's organization. Empty for apps not on Dialtribe identity.
587
+ */
588
+ searchPeople(query: string): Promise<PersonSummary[]>;
565
589
  /** A DM action on POST /dm (see DMS.md). */
566
590
  dm<T = Record<string, unknown>>(action: string, fields?: Record<string, unknown>): Promise<T>;
567
591
  /**
@@ -597,6 +621,11 @@ type MessagesView = {
597
621
  userId: string;
598
622
  from: MessagesView;
599
623
  hint?: ProfileHint;
624
+ }
625
+ /** "Start new": pick people to message. Back returns to `from`. */
626
+ | {
627
+ kind: "compose";
628
+ from: MessagesView;
600
629
  };
601
630
  interface ProfileHint {
602
631
  name?: string;
@@ -722,8 +751,15 @@ interface UseDialtribeMessagesReturn {
722
751
  openNotifications: () => void;
723
752
  /** Show a person's mini-profile in the rail; back returns to the current view. */
724
753
  openProfile: (userId: string, hint?: ProfileHint) => void;
725
- /** From a mini-profile, go back to where it was opened. */
754
+ /** From a mini-profile or the composer, go back to where it was opened. */
726
755
  back: () => void;
756
+ /** Open the "Start new" composer. */
757
+ openCompose: () => void;
758
+ /**
759
+ * Start a conversation with one person (their 1:1) or several (a new group)
760
+ * and show it. For a group, `refused` lists people whose DMs are closed.
761
+ */
762
+ startConversation: (userIds: string[]) => Promise<GroupCreateResult>;
727
763
  /**
728
764
  * Start (or reopen) a DM with one of your users and show it. `hint` is only a
729
765
  * display name for someone Dialtribe hasn't seen yet. Rejects with
@@ -815,6 +851,24 @@ interface MessagesLabels {
815
851
  viewProfileOf: (name: string) => string;
816
852
  /** aria-label of a group conversation's title, which lists its members. */
817
853
  members: string;
854
+ /** Messages header button and composer title. */
855
+ newMessage: string;
856
+ /** Composer search field placeholder. */
857
+ searchPeople: string;
858
+ /** Composer: people you've talked with, before you search. */
859
+ recent: string;
860
+ /** Composer: the search found nobody. */
861
+ noPeopleFound: string;
862
+ /** Composer: start the conversation. */
863
+ start: string;
864
+ /** Composer: some people couldn't be added ("Sam, Lee can't be messaged right now"). */
865
+ cantMessage: (names: string) => string;
866
+ /** Composer: go to the conversation after some people couldn't be added. */
867
+ openConversation: string;
868
+ /** aria-label for removing a picked person: "Remove {name}". */
869
+ removePerson: (name: string) => string;
870
+ /** Composer: starting failed for another reason (network). */
871
+ startFailed: string;
818
872
  }
819
873
  declare const DEFAULT_LABELS: MessagesLabels;
820
874
 
@@ -971,6 +1025,20 @@ interface ProfileViewProps {
971
1025
  */
972
1026
  declare function ProfileView({ userId, hint, labels, onBack, onClose, onNavigate, onMessage, hideMessage, getProfileUrl, profileActions, }: ProfileViewProps): react.JSX.Element;
973
1027
 
1028
+ interface ComposeViewProps {
1029
+ labels: MessagesLabels;
1030
+ onBack: () => void;
1031
+ onClose: () => void;
1032
+ /** Show the conversation that was started. */
1033
+ onOpenRoom: (roomId: string) => void;
1034
+ }
1035
+ /**
1036
+ * "Start new": pick one person (opens your 1:1) or several (starts a group).
1037
+ * Before you type, it lists people you've talked with; typing 2+ characters
1038
+ * searches handles.
1039
+ */
1040
+ declare function ComposeView({ labels, onBack, onClose, onOpenRoom }: ComposeViewProps): react.JSX.Element;
1041
+
974
1042
  interface AvatarProps {
975
1043
  name: string;
976
1044
  url?: string | null;
@@ -1060,4 +1128,4 @@ interface ChatInputProps {
1060
1128
  */
1061
1129
  declare function ChatInput({ onSendMessage, onSendTyping, replyTo, onClearReply, disabled, placeholder, maxLength, }: ChatInputProps): react.JSX.Element;
1062
1130
 
1063
- 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 DialtribeProfile, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type NotificationItem, NotificationsPanel, type NotificationsPanelProps, type NotificationsSnapshot, type ParsedReactions, type ProfileHint, type ProfileLookup, type ProfileSite, ProfileView, type ProfileViewProps, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UseDialtribeNotificationsReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
1131
+ 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, ComposeView, type ComposeViewProps, type ConfirmFn, type ConfirmOptions, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DialtribeProfile, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type GroupCreateResult, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type NotificationItem, NotificationsPanel, type NotificationsPanelProps, type NotificationsSnapshot, type ParsedReactions, type PersonSummary, type ProfileHint, type ProfileLookup, type ProfileSite, ProfileView, type ProfileViewProps, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UseDialtribeNotificationsReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
package/dist/index.js CHANGED
@@ -300,6 +300,17 @@ var InboxStore = class extends Store {
300
300
  this.removed.delete(roomId);
301
301
  await this.refresh();
302
302
  }
303
+ /**
304
+ * Start a group with several people in one step. Each person's DM settings
305
+ * apply: those whose DMs are closed come back in `refused`. If only one
306
+ * person is left, `roomId` is your 1:1 with them.
307
+ */
308
+ async createGroup(targetUserIds) {
309
+ const result = await this.client.dm("chat-dm-create-group", { targetUserIds });
310
+ this.removed.delete(result.roomId);
311
+ await this.refresh();
312
+ return { roomId: result.roomId, added: result.added ?? [], refused: result.refused ?? [] };
313
+ }
303
314
  /** Add someone. Returns the room to show (a new group when added to a 1:1). */
304
315
  async addParticipant(roomId, targetUserId, hint) {
305
316
  const result = await this.client.dm("chat-dm-add-participant", {
@@ -834,6 +845,19 @@ var ChatClient = class {
834
845
  }
835
846
  return lookup;
836
847
  }
848
+ /**
849
+ * People whose handle starts with `query` (2+ characters), among those you can
850
+ * reach through this app's organization. Empty for apps not on Dialtribe identity.
851
+ */
852
+ async searchPeople(query) {
853
+ try {
854
+ const { people } = await this.api(`/chat/people?q=${encodeURIComponent(query)}`);
855
+ return people;
856
+ } catch (err) {
857
+ if (err instanceof ChatRequestError && err.code === "not-found") return [];
858
+ throw err;
859
+ }
860
+ }
837
861
  /** A DM action on POST /dm (see DMS.md). */
838
862
  dm(action, fields = {}) {
839
863
  return this.request("/dm", { method: "POST", body: { action, ...fields } });
@@ -911,16 +935,23 @@ var MessagesUiStore = class extends Store {
911
935
  openItem(itemId) {
912
936
  this.update({ open: true, view: { kind: "item", itemId } });
913
937
  }
938
+ /** The view to return to from a profile or the composer (never another overlay). */
939
+ returnTo() {
940
+ const current = this.getSnapshot().view;
941
+ return current.kind === "profile" || current.kind === "compose" ? current.from : current;
942
+ }
914
943
  /** Show a person's mini-profile, returning to the current view on back. */
915
944
  openProfile(userId, hint) {
916
- const current = this.getSnapshot().view;
917
- const from = current.kind === "profile" ? current.from : current;
918
- this.update({ open: true, view: { kind: "profile", userId, from, hint } });
945
+ this.update({ open: true, view: { kind: "profile", userId, from: this.returnTo(), hint } });
946
+ }
947
+ /** Show the "Start new" composer, returning to the current view on back. */
948
+ openCompose() {
949
+ this.update({ open: true, view: { kind: "compose", from: this.returnTo() } });
919
950
  }
920
- /** From a mini-profile, return to where it was opened. */
951
+ /** From a mini-profile or the composer, return to where it was opened. */
921
952
  back() {
922
953
  const { view } = this.getSnapshot();
923
- this.update({ view: view.kind === "profile" ? view.from : { kind: "inbox" } });
954
+ this.update({ view: view.kind === "profile" || view.kind === "compose" ? view.from : { kind: "inbox" } });
924
955
  }
925
956
  };
926
957
  var ClientContext = react.createContext(null);
@@ -1038,6 +1069,17 @@ function useDialtribeMessages() {
1038
1069
  openNotifications: () => ui.openNotifications(),
1039
1070
  openProfile: (userId, hint) => ui.openProfile(userId, hint),
1040
1071
  back: () => ui.back(),
1072
+ openCompose: () => ui.openCompose(),
1073
+ startConversation: async (userIds) => {
1074
+ if (userIds.length === 1) {
1075
+ const { roomId } = await client.inbox.requestDM(userIds[0]);
1076
+ ui.openRoom(roomId);
1077
+ return { roomId, added: userIds, refused: [] };
1078
+ }
1079
+ const result = await client.inbox.createGroup(userIds);
1080
+ ui.openRoom(result.roomId);
1081
+ return result;
1082
+ },
1041
1083
  messageUser: async (userId, hint) => {
1042
1084
  const result = await client.inbox.requestDM(userId, hint);
1043
1085
  ui.openRoom(result.roomId);
@@ -1416,7 +1458,16 @@ var DEFAULT_LABELS = {
1416
1458
  alsoOn: "Also on",
1417
1459
  message: "Message",
1418
1460
  viewProfileOf: (name) => `View profile of ${name}`,
1419
- members: "Members"
1461
+ members: "Members",
1462
+ newMessage: "New message",
1463
+ searchPeople: "Search by handle",
1464
+ recent: "Recent",
1465
+ noPeopleFound: "No one found",
1466
+ start: "Start",
1467
+ cantMessage: (names) => `${names} can't be messaged right now`,
1468
+ openConversation: "Open conversation",
1469
+ removePerson: (name) => `Remove ${name}`,
1470
+ startFailed: "Couldn't start the conversation. Try again."
1420
1471
  };
1421
1472
  function badgeText(count) {
1422
1473
  return count > 99 ? "99+" : String(count);
@@ -1894,6 +1945,144 @@ function CloseIcon2() {
1894
1945
  function ArrowIcon() {
1895
1946
  return /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx("path", { d: "M7 17L17 7M9 7h8v8" }) });
1896
1947
  }
1948
+ var SEARCH_MIN = 2;
1949
+ var SEARCH_DEBOUNCE_MS = 250;
1950
+ function ComposeView({ labels, onBack, onClose, onOpenRoom }) {
1951
+ const client = useChatClient();
1952
+ const inbox = useChatRooms();
1953
+ const [query, setQuery] = react.useState("");
1954
+ const [results, setResults] = react.useState(null);
1955
+ const [picked, setPicked] = react.useState([]);
1956
+ const [busy, setBusy] = react.useState(false);
1957
+ const [notice, setNotice] = react.useState(null);
1958
+ const inputRef = react.useRef(null);
1959
+ const selfId = client.self?.userId;
1960
+ react.useEffect(() => inputRef.current?.focus(), []);
1961
+ const recent = react.useMemo(() => {
1962
+ const seen = /* @__PURE__ */ new Set();
1963
+ const people = [];
1964
+ for (const room of inbox.rooms) {
1965
+ for (const p of room.participants) {
1966
+ if (p.userId === selfId || seen.has(p.userId)) continue;
1967
+ seen.add(p.userId);
1968
+ people.push({ userId: p.userId, name: p.name, handle: null, avatarUrl: p.avatarUrl });
1969
+ }
1970
+ }
1971
+ return people;
1972
+ }, [inbox.rooms, selfId]);
1973
+ const q = query.trim().replace(/^@/, "");
1974
+ react.useEffect(() => {
1975
+ if (q.length < SEARCH_MIN) {
1976
+ setResults(null);
1977
+ return;
1978
+ }
1979
+ let live = true;
1980
+ const timer = setTimeout(() => {
1981
+ client.searchPeople(q).then(
1982
+ (people) => live && setResults(people),
1983
+ () => live && setResults([])
1984
+ );
1985
+ }, SEARCH_DEBOUNCE_MS);
1986
+ return () => {
1987
+ live = false;
1988
+ clearTimeout(timer);
1989
+ };
1990
+ }, [client, q]);
1991
+ const searching = q.length >= SEARCH_MIN;
1992
+ const list = searching ? results ?? [] : recent;
1993
+ const pickedIds = new Set(picked.map((p) => p.userId));
1994
+ const toggle = (person) => {
1995
+ setNotice(null);
1996
+ setPicked(
1997
+ (current) => current.some((p) => p.userId === person.userId) ? current.filter((p) => p.userId !== person.userId) : [...current, person]
1998
+ );
1999
+ };
2000
+ const namesOf = (ids) => picked.filter((p) => ids.includes(p.userId)).map((p) => p.name).join(", ");
2001
+ const start = async () => {
2002
+ if (!picked.length || busy) return;
2003
+ setBusy(true);
2004
+ setNotice(null);
2005
+ try {
2006
+ if (picked.length === 1) {
2007
+ const { roomId } = await client.inbox.requestDM(picked[0].userId, {
2008
+ name: picked[0].name,
2009
+ avatarUrl: picked[0].avatarUrl ?? void 0
2010
+ });
2011
+ onOpenRoom(roomId);
2012
+ return;
2013
+ }
2014
+ const result = await client.inbox.createGroup(picked.map((p) => p.userId));
2015
+ if (result.refused.length) setNotice({ text: labels.cantMessage(namesOf(result.refused)), roomId: result.roomId });
2016
+ else onOpenRoom(result.roomId);
2017
+ } catch (err) {
2018
+ const refused = err instanceof ChatRequestError && err.code === "dm-not-allowed";
2019
+ setNotice({ text: refused ? labels.cantMessage(namesOf(picked.map((p) => p.userId))) : labels.startFailed, roomId: null });
2020
+ } finally {
2021
+ setBusy(false);
2022
+ }
2023
+ };
2024
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
2025
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
2026
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsxRuntime.jsx(ChevronLeft3, {}) }),
2027
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: labels.newMessage }),
2028
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon3, {}) })
2029
+ ] }),
2030
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-compose", children: [
2031
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-compose-field", children: [
2032
+ picked.map((p) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-compose-chip", children: [
2033
+ p.name,
2034
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => toggle(p), "aria-label": labels.removePerson(p.name), children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon3, { size: 12 }) })
2035
+ ] }, p.userId)),
2036
+ /* @__PURE__ */ jsxRuntime.jsx(
2037
+ "input",
2038
+ {
2039
+ ref: inputRef,
2040
+ className: "dtc-compose-input",
2041
+ value: query,
2042
+ onChange: (e) => setQuery(e.target.value.slice(0, 50)),
2043
+ onKeyDown: (e) => {
2044
+ if (e.key === "Backspace" && !query && picked.length) setPicked(picked.slice(0, -1));
2045
+ },
2046
+ placeholder: picked.length ? "" : labels.searchPeople,
2047
+ "aria-label": labels.searchPeople
2048
+ }
2049
+ )
2050
+ ] }),
2051
+ !searching && recent.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-profile-sites-title", children: labels.recent }),
2052
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "dtc-compose-list", children: list.map((person) => {
2053
+ const on = pickedIds.has(person.userId);
2054
+ return /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "dtc-member", "aria-pressed": on, onClick: () => toggle(person), children: [
2055
+ /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: person.name, url: person.avatarUrl, size: 32 }),
2056
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-compose-names", children: [
2057
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-member-name", children: person.name }),
2058
+ person.handle && person.handle.toLowerCase() !== person.name.toLowerCase() && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-profile-handle", children: [
2059
+ "@",
2060
+ person.handle
2061
+ ] })
2062
+ ] }),
2063
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: `dtc-compose-check ${on ? "dtc-compose-check-on" : ""}`, "aria-hidden": "true", children: on && /* @__PURE__ */ jsxRuntime.jsx(CheckIcon, {}) })
2064
+ ] }) }, person.userId);
2065
+ }) }),
2066
+ searching && results !== null && results.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: labels.noPeopleFound })
2067
+ ] }),
2068
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-compose-footer", children: [
2069
+ notice && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-note", children: [
2070
+ notice.text,
2071
+ notice.roomId && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-text-btn", onClick: () => onOpenRoom(notice.roomId), children: labels.openConversation })
2072
+ ] }),
2073
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-btn dtc-btn-primary dtc-compose-start", disabled: !picked.length || busy, onClick: () => void start(), children: labels.start })
2074
+ ] })
2075
+ ] });
2076
+ }
2077
+ function ChevronLeft3() {
2078
+ 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" }) });
2079
+ }
2080
+ function CloseIcon3({ size = 18 }) {
2081
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: size, height: size, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6l12 12" }) });
2082
+ }
2083
+ function CheckIcon() {
2084
+ return /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx("path", { d: "M5 12l5 5L20 7" }) });
2085
+ }
1897
2086
  var RAIL_WIDTH = 64;
1898
2087
  var EDGE_SWIPE_ZONE = 24;
1899
2088
  var SWIPE_DISTANCE = 60;
@@ -2001,7 +2190,7 @@ function DialtribeMessages({
2001
2190
  rollup > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
2002
2191
  ] }),
2003
2192
  isOpen && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: [
2004
- view.kind === "profile" ? /* @__PURE__ */ jsxRuntime.jsx(
2193
+ view.kind === "compose" ? /* @__PURE__ */ jsxRuntime.jsx(ComposeView, { labels, onBack: ui.back, onClose: ui.close, onOpenRoom: ui.openRoom }) : view.kind === "profile" ? /* @__PURE__ */ jsxRuntime.jsx(
2005
2194
  ProfileView,
2006
2195
  {
2007
2196
  userId: view.userId,
@@ -2032,7 +2221,8 @@ function DialtribeMessages({
2032
2221
  ) : 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: [
2033
2222
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
2034
2223
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
2035
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon3, {}) })
2224
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.openCompose, "aria-label": labels.newMessage, title: labels.newMessage, children: /* @__PURE__ */ jsxRuntime.jsx(ComposeIcon, {}) }),
2225
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon4, {}) })
2036
2226
  ] }),
2037
2227
  /* @__PURE__ */ jsxRuntime.jsx(
2038
2228
  MessagesInbox,
@@ -2049,7 +2239,7 @@ function DialtribeMessages({
2049
2239
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
2050
2240
  /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
2051
2241
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: activeContext.label }),
2052
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon3, {}) })
2242
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon4, {}) })
2053
2243
  ] }),
2054
2244
  /* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(
2055
2245
  ChatPanel,
@@ -2292,7 +2482,13 @@ function useNotificationsBadge(enabled) {
2292
2482
  const snapshot = react.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
2293
2483
  return enabled ? snapshot.unreadCount : 0;
2294
2484
  }
2295
- function CloseIcon3() {
2485
+ function ComposeIcon() {
2486
+ return /* @__PURE__ */ jsxRuntime.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: [
2487
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 20h9" }),
2488
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z" })
2489
+ ] });
2490
+ }
2491
+ function CloseIcon4() {
2296
2492
  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" }) });
2297
2493
  }
2298
2494
 
@@ -2303,6 +2499,7 @@ exports.ChatMessageItem = ChatMessageItem;
2303
2499
  exports.ChatPanel = ChatPanel;
2304
2500
  exports.ChatRequestError = ChatRequestError;
2305
2501
  exports.ChatRoomProvider = ChatRoomProvider;
2502
+ exports.ComposeView = ComposeView;
2306
2503
  exports.DEFAULT_LABELS = DEFAULT_LABELS;
2307
2504
  exports.DialtribeChatProvider = DialtribeChatProvider;
2308
2505
  exports.DialtribeMessages = DialtribeMessages;