@dialtribe/chat-client 0.5.0 → 0.6.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 +35 -3
- package/dist/index.d.mts +123 -6
- package/dist/index.d.ts +123 -6
- package/dist/index.js +266 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +266 -19
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,6 +112,8 @@ function MessageButton({ user }: { user: { id: string; name: string } }) {
|
|
|
112
112
|
| `railDmLimit` | `5` | Recent DMs shown as rail icons |
|
|
113
113
|
| `mobileBreakpoint` | `768` | Below this width the rail becomes the floating button |
|
|
114
114
|
| `notifications` | `false` | Show the Dialtribe Notifications inbox: a bell above Messages with an unread badge (see below). Pass `{ onOpen(item) }` to route clicks yourself; return `true` when you navigated |
|
|
115
|
+
| `getProfileUrl` | | Apps not on Dialtribe identity: `(userId) => string \| null`, your profile page for a user, shown as the mini-profile's primary button |
|
|
116
|
+
| `profileActions` | | `(profile) => ReactNode`: your own buttons on a mini-profile, under Message (e.g. Block, which you push to Dialtribe as `blockedUserIds`) |
|
|
115
117
|
|
|
116
118
|
### Your own rail items
|
|
117
119
|
|
|
@@ -167,7 +169,36 @@ await fetch("https://dialtribe.com/api/public/v1/notifications", {
|
|
|
167
169
|
```
|
|
168
170
|
|
|
169
171
|
The provider's `apiUrl` (default `https://dialtribe.com`) is where notifications
|
|
170
|
-
are read from.
|
|
172
|
+
and mini-profiles are read from.
|
|
173
|
+
|
|
174
|
+
### Mini-profiles
|
|
175
|
+
|
|
176
|
+
Clicking a person's name or avatar in the rail (a message author, the header of
|
|
177
|
+
a 1:1 conversation, or a member in a group's member list, opened from its title)
|
|
178
|
+
opens their mini-profile in the panel. Back returns to where you were.
|
|
179
|
+
|
|
180
|
+
For apps on Dialtribe identity it comes from Dialtribe: avatar, name, handle,
|
|
181
|
+
bio, a primary **View {site} profile** button when your site has profile pages
|
|
182
|
+
(set by Dialtribe staff as your app's profile URL template), **Also on** with
|
|
183
|
+
the other Dialtribe sites the person uses (opening in a new tab), and
|
|
184
|
+
**Message** when their DM settings allow it. Message is hidden on your own
|
|
185
|
+
profile and inside your 1:1 with that person. The current site's profile link
|
|
186
|
+
opens in the same tab and closes the rail on mobile.
|
|
187
|
+
|
|
188
|
+
Other apps get the name and avatar chat already has, Message, and the primary
|
|
189
|
+
button from `getProfileUrl`. Use `profileActions` to add your own buttons:
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
<DialtribeMessages
|
|
193
|
+
profileActions={(profile) => (
|
|
194
|
+
<button className="dtc-btn" onClick={() => blockUser(profile.userId)}>Block</button>
|
|
195
|
+
)}
|
|
196
|
+
/>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`useChatClient().getProfile(userId)` returns the same data
|
|
200
|
+
(`{ status: "ok", profile } | { status: "not_supported" } | { status: "hidden" }`),
|
|
201
|
+
memoized per user.
|
|
171
202
|
|
|
172
203
|
## Hooks
|
|
173
204
|
|
|
@@ -214,7 +245,7 @@ one subscription.
|
|
|
214
245
|
### `useDialtribeMessages()`
|
|
215
246
|
|
|
216
247
|
Drive the rail: `open`, `close`, `toggle`, `openInbox`, `openRoom(roomId)`, `openItem(itemId)`,
|
|
217
|
-
`openNotifications()`, `messageUser(userId, hint?)`, `isOpen`, `view`.
|
|
248
|
+
`openNotifications()`, `openProfile(userId, hint?)`, `back()`, `messageUser(userId, hint?)`, `isOpen`, `view`.
|
|
218
249
|
|
|
219
250
|
### `useDialtribeNotifications()`
|
|
220
251
|
|
|
@@ -236,7 +267,8 @@ described them.
|
|
|
236
267
|
</ChatRoomProvider>
|
|
237
268
|
```
|
|
238
269
|
|
|
239
|
-
`ChatPanel`, `ChatMessageItem`, `ChatInput` and `
|
|
270
|
+
`ChatPanel`, `ChatMessageItem`, `ChatInput`, `Avatar` and `ProfileView` are exported.
|
|
271
|
+
`ChatPanel`'s `onAuthorClick` makes authors' names and avatars buttons. Outside
|
|
240
272
|
React, `ChatClient` is the framework-agnostic core the hooks are built on.
|
|
241
273
|
|
|
242
274
|
## Theming
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Minimal observable store: an immutable snapshot plus change listeners. Shaped
|
|
@@ -94,6 +95,44 @@ interface DmParticipant {
|
|
|
94
95
|
avatarUrl: string | null;
|
|
95
96
|
status: DmMemberStatus;
|
|
96
97
|
}
|
|
98
|
+
/** Another Dialtribe-identity site a person uses (mini-profile "Also on"). */
|
|
99
|
+
interface ProfileSite {
|
|
100
|
+
appId: string;
|
|
101
|
+
siteName: string;
|
|
102
|
+
iconUrl: string | null;
|
|
103
|
+
/** Their profile there, else the site itself, else null. */
|
|
104
|
+
url: string | null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A person's mini-profile (GET /api/public/v1/chat/profiles/:userId), for apps
|
|
108
|
+
* on Dialtribe identity. In the fallback for other apps it is built from what
|
|
109
|
+
* chat already knows (name and avatar), with no handle, bio or sites.
|
|
110
|
+
*/
|
|
111
|
+
interface DialtribeProfile {
|
|
112
|
+
userId: string;
|
|
113
|
+
name: string;
|
|
114
|
+
handle: string | null;
|
|
115
|
+
avatarUrl: string | null;
|
|
116
|
+
bio: string | null;
|
|
117
|
+
/** This site's profile page, when it has one. */
|
|
118
|
+
current: {
|
|
119
|
+
appId: string;
|
|
120
|
+
siteName: string;
|
|
121
|
+
profileUrl: string;
|
|
122
|
+
} | null;
|
|
123
|
+
apps: ProfileSite[];
|
|
124
|
+
/** Whether a new conversation would be allowed. */
|
|
125
|
+
canMessage: boolean;
|
|
126
|
+
}
|
|
127
|
+
/** getProfile: "not_supported" when the app isn't on Dialtribe identity, "hidden" when the profile isn't visible. */
|
|
128
|
+
type ProfileLookup = {
|
|
129
|
+
status: "ok";
|
|
130
|
+
profile: DialtribeProfile;
|
|
131
|
+
} | {
|
|
132
|
+
status: "not_supported";
|
|
133
|
+
} | {
|
|
134
|
+
status: "hidden";
|
|
135
|
+
};
|
|
97
136
|
/** One row of the signed-in user's DM inbox, from their perspective. */
|
|
98
137
|
interface DmRoomSummary {
|
|
99
138
|
roomId: string;
|
|
@@ -411,7 +450,7 @@ interface ChatClientOptions {
|
|
|
411
450
|
/** chat-ws base URL, e.g. "https://chatws.dialtribe.com". */
|
|
412
451
|
serverUrl: string;
|
|
413
452
|
/**
|
|
414
|
-
* Dialtribe API base URL for services outside chat-ws (notifications).
|
|
453
|
+
* Dialtribe API base URL for services outside chat-ws (notifications, profiles).
|
|
415
454
|
* Defaults to "https://dialtribe.com". Uses the same session token.
|
|
416
455
|
*/
|
|
417
456
|
apiUrl?: string;
|
|
@@ -473,6 +512,7 @@ declare class ChatClient {
|
|
|
473
512
|
private rooms;
|
|
474
513
|
private inboxStore;
|
|
475
514
|
private notificationsStore;
|
|
515
|
+
private profiles;
|
|
476
516
|
constructor(options: ChatClientOptions);
|
|
477
517
|
/** Connect. Idempotent; resolves once the connection has been initiated. */
|
|
478
518
|
start(): Promise<void>;
|
|
@@ -517,6 +557,11 @@ declare class ChatClient {
|
|
|
517
557
|
method?: "GET" | "POST";
|
|
518
558
|
body?: unknown;
|
|
519
559
|
}): Promise<T>;
|
|
560
|
+
/**
|
|
561
|
+
* A person's mini-profile from Dialtribe, memoized per user for the life of
|
|
562
|
+
* the client. Network failures aren't remembered, so the next call retries.
|
|
563
|
+
*/
|
|
564
|
+
getProfile(userId: string): Promise<ProfileLookup>;
|
|
520
565
|
/** A DM action on POST /dm (see DMS.md). */
|
|
521
566
|
dm<T = Record<string, unknown>>(action: string, fields?: Record<string, unknown>): Promise<T>;
|
|
522
567
|
/**
|
|
@@ -542,7 +587,21 @@ type MessagesView = {
|
|
|
542
587
|
| {
|
|
543
588
|
kind: "item";
|
|
544
589
|
itemId: string;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* A person's mini-profile. Back returns to `from`. `hint` is what the click
|
|
593
|
+
* already knew (name, avatar), shown at once and as the fallback.
|
|
594
|
+
*/
|
|
595
|
+
| {
|
|
596
|
+
kind: "profile";
|
|
597
|
+
userId: string;
|
|
598
|
+
from: MessagesView;
|
|
599
|
+
hint?: ProfileHint;
|
|
545
600
|
};
|
|
601
|
+
interface ProfileHint {
|
|
602
|
+
name?: string;
|
|
603
|
+
avatarUrl?: string | null;
|
|
604
|
+
}
|
|
546
605
|
interface MessagesUiSnapshot {
|
|
547
606
|
open: boolean;
|
|
548
607
|
view: MessagesView;
|
|
@@ -661,6 +720,10 @@ interface UseDialtribeMessagesReturn {
|
|
|
661
720
|
openItem: (itemId: string) => void;
|
|
662
721
|
/** Open the notifications panel (when the rail shows notifications). */
|
|
663
722
|
openNotifications: () => void;
|
|
723
|
+
/** Show a person's mini-profile in the rail; back returns to the current view. */
|
|
724
|
+
openProfile: (userId: string, hint?: ProfileHint) => void;
|
|
725
|
+
/** From a mini-profile, go back to where it was opened. */
|
|
726
|
+
back: () => void;
|
|
664
727
|
/**
|
|
665
728
|
* Start (or reopen) a DM with one of your users and show it. `hint` is only a
|
|
666
729
|
* display name for someone Dialtribe hasn't seen yet. Rejects with
|
|
@@ -742,6 +805,16 @@ interface MessagesLabels {
|
|
|
742
805
|
groupMore: (count: number) => string;
|
|
743
806
|
/** Relative times: "now", "5m", "3h", "2d". */
|
|
744
807
|
timeAgo: (date: Date) => string;
|
|
808
|
+
/** Mini-profile primary button: "View Prankcast profile" ("View profile" without a site name). */
|
|
809
|
+
viewSiteProfile: (site: string) => string;
|
|
810
|
+
/** Mini-profile: the other sites the person uses. */
|
|
811
|
+
alsoOn: string;
|
|
812
|
+
/** Mini-profile: start a conversation. */
|
|
813
|
+
message: string;
|
|
814
|
+
/** aria-label of a person's name or avatar: "View profile of {name}". */
|
|
815
|
+
viewProfileOf: (name: string) => string;
|
|
816
|
+
/** aria-label of a group conversation's title, which lists its members. */
|
|
817
|
+
members: string;
|
|
745
818
|
}
|
|
746
819
|
declare const DEFAULT_LABELS: MessagesLabels;
|
|
747
820
|
|
|
@@ -833,6 +906,13 @@ interface DialtribeMessagesProps {
|
|
|
833
906
|
notifications?: boolean | {
|
|
834
907
|
onOpen?: (item: NotificationItem) => boolean | void;
|
|
835
908
|
};
|
|
909
|
+
/**
|
|
910
|
+
* Apps not on Dialtribe identity: your profile page for a user, shown as the
|
|
911
|
+
* mini-profile's primary button. Opted-in apps get theirs from Dialtribe.
|
|
912
|
+
*/
|
|
913
|
+
getProfileUrl?: (userId: string) => string | null;
|
|
914
|
+
/** Your own buttons on a mini-profile, under Message (e.g. Block, which you push to Dialtribe). */
|
|
915
|
+
profileActions?: (profile: DialtribeProfile) => React.ReactNode;
|
|
836
916
|
}
|
|
837
917
|
/**
|
|
838
918
|
* Drop-in messages rail: inbox, DM requests, conversations, and any host
|
|
@@ -849,7 +929,7 @@ interface DialtribeMessagesProps {
|
|
|
849
929
|
* </DialtribeChatProvider>
|
|
850
930
|
* ```
|
|
851
931
|
*/
|
|
852
|
-
declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, confirm: hostConfirm, notifications, }: DialtribeMessagesProps): react.JSX.Element;
|
|
932
|
+
declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, confirm: hostConfirm, notifications, getProfileUrl, profileActions, }: DialtribeMessagesProps): react.JSX.Element;
|
|
853
933
|
|
|
854
934
|
interface NotificationsPanelProps {
|
|
855
935
|
labels: MessagesLabels;
|
|
@@ -859,12 +939,37 @@ interface NotificationsPanelProps {
|
|
|
859
939
|
* navigation (e.g. client-side routing); otherwise the browser goes to its url.
|
|
860
940
|
*/
|
|
861
941
|
onOpen?: (item: NotificationItem) => boolean | void;
|
|
942
|
+
/** Called after a notification with a link was opened (the rail closes itself on mobile). */
|
|
943
|
+
onOpened?: (item: NotificationItem) => void;
|
|
862
944
|
}
|
|
863
945
|
/**
|
|
864
946
|
* The notifications list shown in the messages rail. Usable on its own too
|
|
865
947
|
* (any host panel) as long as it's under a <DialtribeChatProvider>.
|
|
866
948
|
*/
|
|
867
|
-
declare function NotificationsPanel({ labels, onClose, onOpen }: NotificationsPanelProps): react.JSX.Element;
|
|
949
|
+
declare function NotificationsPanel({ labels, onClose, onOpen, onOpened }: NotificationsPanelProps): react.JSX.Element;
|
|
950
|
+
|
|
951
|
+
interface ProfileViewProps {
|
|
952
|
+
userId: string;
|
|
953
|
+
hint?: ProfileHint;
|
|
954
|
+
labels: MessagesLabels;
|
|
955
|
+
onBack: () => void;
|
|
956
|
+
onClose: () => void;
|
|
957
|
+
/** The current site's profile link was followed (same tab). */
|
|
958
|
+
onNavigate: () => void;
|
|
959
|
+
/** Start or open a conversation with this person. */
|
|
960
|
+
onMessage: (userId: string, hint: ProfileHint) => void;
|
|
961
|
+
/** Hide Message (viewing yourself, or already in your 1:1 with them). */
|
|
962
|
+
hideMessage: boolean;
|
|
963
|
+
/** Apps not on Dialtribe identity: the host's own profile URL for this person. */
|
|
964
|
+
getProfileUrl?: (userId: string) => string | null;
|
|
965
|
+
/** Host-owned buttons under Message (e.g. Block). */
|
|
966
|
+
profileActions?: (profile: DialtribeProfile) => ReactNode;
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* A person's mini-profile in the rail: avatar, name, handle, bio, this site's
|
|
970
|
+
* profile (primary), the other Dialtribe sites they use, and Message.
|
|
971
|
+
*/
|
|
972
|
+
declare function ProfileView({ userId, hint, labels, onBack, onClose, onNavigate, onMessage, hideMessage, getProfileUrl, profileActions, }: ProfileViewProps): react.JSX.Element;
|
|
868
973
|
|
|
869
974
|
interface AvatarProps {
|
|
870
975
|
name: string;
|
|
@@ -894,6 +999,14 @@ interface ChatPanelProps {
|
|
|
894
999
|
emptyLabel?: string;
|
|
895
1000
|
/** Input placeholder. */
|
|
896
1001
|
placeholder?: string;
|
|
1002
|
+
/** Make authors' names and avatars buttons (e.g. to open a profile). */
|
|
1003
|
+
onAuthorClick?: (author: {
|
|
1004
|
+
userId: string;
|
|
1005
|
+
name: string;
|
|
1006
|
+
avatarUrl: string | null;
|
|
1007
|
+
}) => void;
|
|
1008
|
+
/** aria-label for an author button: "View profile of {name}". */
|
|
1009
|
+
authorLabel?: (name: string) => string;
|
|
897
1010
|
}
|
|
898
1011
|
/**
|
|
899
1012
|
* Full chat panel with messages, input, pinned messages, and typing indicators.
|
|
@@ -906,13 +1019,17 @@ interface ChatPanelProps {
|
|
|
906
1019
|
* </ChatRoomProvider>
|
|
907
1020
|
* ```
|
|
908
1021
|
*/
|
|
909
|
-
declare function ChatPanel({ className, showModActions, showTypingIndicators, showPinnedMessages, showHeader, showAvatars, canSend, emptyLabel, placeholder, }: ChatPanelProps): react.JSX.Element;
|
|
1022
|
+
declare function ChatPanel({ className, showModActions, showTypingIndicators, showPinnedMessages, showHeader, showAvatars, canSend, emptyLabel, placeholder, onAuthorClick, authorLabel, }: ChatPanelProps): react.JSX.Element;
|
|
910
1023
|
|
|
911
1024
|
interface ChatMessageItemProps {
|
|
912
1025
|
message: ChatMessage;
|
|
913
1026
|
config: ChatRoomConfig | null;
|
|
914
1027
|
/** Show the author's avatar beside the message (DM style). */
|
|
915
1028
|
showAvatar?: boolean;
|
|
1029
|
+
/** Render the author's name and avatar as buttons that call this. */
|
|
1030
|
+
onAuthorClick?: () => void;
|
|
1031
|
+
/** aria-label for those buttons (default "View profile of {name}"). */
|
|
1032
|
+
authorLabel?: (name: string) => string;
|
|
916
1033
|
onReply?: () => void;
|
|
917
1034
|
onReact?: (messageId: string, emoji: string) => void;
|
|
918
1035
|
/** Additional mod actions (feature, pin, delete, ban, kick) */
|
|
@@ -927,7 +1044,7 @@ interface ChatMessageItemProps {
|
|
|
927
1044
|
/**
|
|
928
1045
|
* Renders a single chat message with role badges, flair, reactions, and reply preview.
|
|
929
1046
|
*/
|
|
930
|
-
declare function ChatMessageItem({ message, config, showAvatar, onReply, onReact, modActions, }: ChatMessageItemProps): react.JSX.Element;
|
|
1047
|
+
declare function ChatMessageItem({ message, config, showAvatar, onAuthorClick, authorLabel, onReply, onReact, modActions, }: ChatMessageItemProps): react.JSX.Element;
|
|
931
1048
|
|
|
932
1049
|
interface ChatInputProps {
|
|
933
1050
|
onSendMessage: (text: string, replyToId?: string) => void;
|
|
@@ -943,4 +1060,4 @@ interface ChatInputProps {
|
|
|
943
1060
|
*/
|
|
944
1061
|
declare function ChatInput({ onSendMessage, onSendTyping, replyTo, onClearReply, disabled, placeholder, maxLength, }: ChatInputProps): react.JSX.Element;
|
|
945
1062
|
|
|
946
|
-
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 NotificationItem, NotificationsPanel, type NotificationsPanelProps, type NotificationsSnapshot, 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 UseDialtribeNotificationsReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Minimal observable store: an immutable snapshot plus change listeners. Shaped
|
|
@@ -94,6 +95,44 @@ interface DmParticipant {
|
|
|
94
95
|
avatarUrl: string | null;
|
|
95
96
|
status: DmMemberStatus;
|
|
96
97
|
}
|
|
98
|
+
/** Another Dialtribe-identity site a person uses (mini-profile "Also on"). */
|
|
99
|
+
interface ProfileSite {
|
|
100
|
+
appId: string;
|
|
101
|
+
siteName: string;
|
|
102
|
+
iconUrl: string | null;
|
|
103
|
+
/** Their profile there, else the site itself, else null. */
|
|
104
|
+
url: string | null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A person's mini-profile (GET /api/public/v1/chat/profiles/:userId), for apps
|
|
108
|
+
* on Dialtribe identity. In the fallback for other apps it is built from what
|
|
109
|
+
* chat already knows (name and avatar), with no handle, bio or sites.
|
|
110
|
+
*/
|
|
111
|
+
interface DialtribeProfile {
|
|
112
|
+
userId: string;
|
|
113
|
+
name: string;
|
|
114
|
+
handle: string | null;
|
|
115
|
+
avatarUrl: string | null;
|
|
116
|
+
bio: string | null;
|
|
117
|
+
/** This site's profile page, when it has one. */
|
|
118
|
+
current: {
|
|
119
|
+
appId: string;
|
|
120
|
+
siteName: string;
|
|
121
|
+
profileUrl: string;
|
|
122
|
+
} | null;
|
|
123
|
+
apps: ProfileSite[];
|
|
124
|
+
/** Whether a new conversation would be allowed. */
|
|
125
|
+
canMessage: boolean;
|
|
126
|
+
}
|
|
127
|
+
/** getProfile: "not_supported" when the app isn't on Dialtribe identity, "hidden" when the profile isn't visible. */
|
|
128
|
+
type ProfileLookup = {
|
|
129
|
+
status: "ok";
|
|
130
|
+
profile: DialtribeProfile;
|
|
131
|
+
} | {
|
|
132
|
+
status: "not_supported";
|
|
133
|
+
} | {
|
|
134
|
+
status: "hidden";
|
|
135
|
+
};
|
|
97
136
|
/** One row of the signed-in user's DM inbox, from their perspective. */
|
|
98
137
|
interface DmRoomSummary {
|
|
99
138
|
roomId: string;
|
|
@@ -411,7 +450,7 @@ interface ChatClientOptions {
|
|
|
411
450
|
/** chat-ws base URL, e.g. "https://chatws.dialtribe.com". */
|
|
412
451
|
serverUrl: string;
|
|
413
452
|
/**
|
|
414
|
-
* Dialtribe API base URL for services outside chat-ws (notifications).
|
|
453
|
+
* Dialtribe API base URL for services outside chat-ws (notifications, profiles).
|
|
415
454
|
* Defaults to "https://dialtribe.com". Uses the same session token.
|
|
416
455
|
*/
|
|
417
456
|
apiUrl?: string;
|
|
@@ -473,6 +512,7 @@ declare class ChatClient {
|
|
|
473
512
|
private rooms;
|
|
474
513
|
private inboxStore;
|
|
475
514
|
private notificationsStore;
|
|
515
|
+
private profiles;
|
|
476
516
|
constructor(options: ChatClientOptions);
|
|
477
517
|
/** Connect. Idempotent; resolves once the connection has been initiated. */
|
|
478
518
|
start(): Promise<void>;
|
|
@@ -517,6 +557,11 @@ declare class ChatClient {
|
|
|
517
557
|
method?: "GET" | "POST";
|
|
518
558
|
body?: unknown;
|
|
519
559
|
}): Promise<T>;
|
|
560
|
+
/**
|
|
561
|
+
* A person's mini-profile from Dialtribe, memoized per user for the life of
|
|
562
|
+
* the client. Network failures aren't remembered, so the next call retries.
|
|
563
|
+
*/
|
|
564
|
+
getProfile(userId: string): Promise<ProfileLookup>;
|
|
520
565
|
/** A DM action on POST /dm (see DMS.md). */
|
|
521
566
|
dm<T = Record<string, unknown>>(action: string, fields?: Record<string, unknown>): Promise<T>;
|
|
522
567
|
/**
|
|
@@ -542,7 +587,21 @@ type MessagesView = {
|
|
|
542
587
|
| {
|
|
543
588
|
kind: "item";
|
|
544
589
|
itemId: string;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* A person's mini-profile. Back returns to `from`. `hint` is what the click
|
|
593
|
+
* already knew (name, avatar), shown at once and as the fallback.
|
|
594
|
+
*/
|
|
595
|
+
| {
|
|
596
|
+
kind: "profile";
|
|
597
|
+
userId: string;
|
|
598
|
+
from: MessagesView;
|
|
599
|
+
hint?: ProfileHint;
|
|
545
600
|
};
|
|
601
|
+
interface ProfileHint {
|
|
602
|
+
name?: string;
|
|
603
|
+
avatarUrl?: string | null;
|
|
604
|
+
}
|
|
546
605
|
interface MessagesUiSnapshot {
|
|
547
606
|
open: boolean;
|
|
548
607
|
view: MessagesView;
|
|
@@ -661,6 +720,10 @@ interface UseDialtribeMessagesReturn {
|
|
|
661
720
|
openItem: (itemId: string) => void;
|
|
662
721
|
/** Open the notifications panel (when the rail shows notifications). */
|
|
663
722
|
openNotifications: () => void;
|
|
723
|
+
/** Show a person's mini-profile in the rail; back returns to the current view. */
|
|
724
|
+
openProfile: (userId: string, hint?: ProfileHint) => void;
|
|
725
|
+
/** From a mini-profile, go back to where it was opened. */
|
|
726
|
+
back: () => void;
|
|
664
727
|
/**
|
|
665
728
|
* Start (or reopen) a DM with one of your users and show it. `hint` is only a
|
|
666
729
|
* display name for someone Dialtribe hasn't seen yet. Rejects with
|
|
@@ -742,6 +805,16 @@ interface MessagesLabels {
|
|
|
742
805
|
groupMore: (count: number) => string;
|
|
743
806
|
/** Relative times: "now", "5m", "3h", "2d". */
|
|
744
807
|
timeAgo: (date: Date) => string;
|
|
808
|
+
/** Mini-profile primary button: "View Prankcast profile" ("View profile" without a site name). */
|
|
809
|
+
viewSiteProfile: (site: string) => string;
|
|
810
|
+
/** Mini-profile: the other sites the person uses. */
|
|
811
|
+
alsoOn: string;
|
|
812
|
+
/** Mini-profile: start a conversation. */
|
|
813
|
+
message: string;
|
|
814
|
+
/** aria-label of a person's name or avatar: "View profile of {name}". */
|
|
815
|
+
viewProfileOf: (name: string) => string;
|
|
816
|
+
/** aria-label of a group conversation's title, which lists its members. */
|
|
817
|
+
members: string;
|
|
745
818
|
}
|
|
746
819
|
declare const DEFAULT_LABELS: MessagesLabels;
|
|
747
820
|
|
|
@@ -833,6 +906,13 @@ interface DialtribeMessagesProps {
|
|
|
833
906
|
notifications?: boolean | {
|
|
834
907
|
onOpen?: (item: NotificationItem) => boolean | void;
|
|
835
908
|
};
|
|
909
|
+
/**
|
|
910
|
+
* Apps not on Dialtribe identity: your profile page for a user, shown as the
|
|
911
|
+
* mini-profile's primary button. Opted-in apps get theirs from Dialtribe.
|
|
912
|
+
*/
|
|
913
|
+
getProfileUrl?: (userId: string) => string | null;
|
|
914
|
+
/** Your own buttons on a mini-profile, under Message (e.g. Block, which you push to Dialtribe). */
|
|
915
|
+
profileActions?: (profile: DialtribeProfile) => React.ReactNode;
|
|
836
916
|
}
|
|
837
917
|
/**
|
|
838
918
|
* Drop-in messages rail: inbox, DM requests, conversations, and any host
|
|
@@ -849,7 +929,7 @@ interface DialtribeMessagesProps {
|
|
|
849
929
|
* </DialtribeChatProvider>
|
|
850
930
|
* ```
|
|
851
931
|
*/
|
|
852
|
-
declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, confirm: hostConfirm, notifications, }: DialtribeMessagesProps): react.JSX.Element;
|
|
932
|
+
declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, confirm: hostConfirm, notifications, getProfileUrl, profileActions, }: DialtribeMessagesProps): react.JSX.Element;
|
|
853
933
|
|
|
854
934
|
interface NotificationsPanelProps {
|
|
855
935
|
labels: MessagesLabels;
|
|
@@ -859,12 +939,37 @@ interface NotificationsPanelProps {
|
|
|
859
939
|
* navigation (e.g. client-side routing); otherwise the browser goes to its url.
|
|
860
940
|
*/
|
|
861
941
|
onOpen?: (item: NotificationItem) => boolean | void;
|
|
942
|
+
/** Called after a notification with a link was opened (the rail closes itself on mobile). */
|
|
943
|
+
onOpened?: (item: NotificationItem) => void;
|
|
862
944
|
}
|
|
863
945
|
/**
|
|
864
946
|
* The notifications list shown in the messages rail. Usable on its own too
|
|
865
947
|
* (any host panel) as long as it's under a <DialtribeChatProvider>.
|
|
866
948
|
*/
|
|
867
|
-
declare function NotificationsPanel({ labels, onClose, onOpen }: NotificationsPanelProps): react.JSX.Element;
|
|
949
|
+
declare function NotificationsPanel({ labels, onClose, onOpen, onOpened }: NotificationsPanelProps): react.JSX.Element;
|
|
950
|
+
|
|
951
|
+
interface ProfileViewProps {
|
|
952
|
+
userId: string;
|
|
953
|
+
hint?: ProfileHint;
|
|
954
|
+
labels: MessagesLabels;
|
|
955
|
+
onBack: () => void;
|
|
956
|
+
onClose: () => void;
|
|
957
|
+
/** The current site's profile link was followed (same tab). */
|
|
958
|
+
onNavigate: () => void;
|
|
959
|
+
/** Start or open a conversation with this person. */
|
|
960
|
+
onMessage: (userId: string, hint: ProfileHint) => void;
|
|
961
|
+
/** Hide Message (viewing yourself, or already in your 1:1 with them). */
|
|
962
|
+
hideMessage: boolean;
|
|
963
|
+
/** Apps not on Dialtribe identity: the host's own profile URL for this person. */
|
|
964
|
+
getProfileUrl?: (userId: string) => string | null;
|
|
965
|
+
/** Host-owned buttons under Message (e.g. Block). */
|
|
966
|
+
profileActions?: (profile: DialtribeProfile) => ReactNode;
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* A person's mini-profile in the rail: avatar, name, handle, bio, this site's
|
|
970
|
+
* profile (primary), the other Dialtribe sites they use, and Message.
|
|
971
|
+
*/
|
|
972
|
+
declare function ProfileView({ userId, hint, labels, onBack, onClose, onNavigate, onMessage, hideMessage, getProfileUrl, profileActions, }: ProfileViewProps): react.JSX.Element;
|
|
868
973
|
|
|
869
974
|
interface AvatarProps {
|
|
870
975
|
name: string;
|
|
@@ -894,6 +999,14 @@ interface ChatPanelProps {
|
|
|
894
999
|
emptyLabel?: string;
|
|
895
1000
|
/** Input placeholder. */
|
|
896
1001
|
placeholder?: string;
|
|
1002
|
+
/** Make authors' names and avatars buttons (e.g. to open a profile). */
|
|
1003
|
+
onAuthorClick?: (author: {
|
|
1004
|
+
userId: string;
|
|
1005
|
+
name: string;
|
|
1006
|
+
avatarUrl: string | null;
|
|
1007
|
+
}) => void;
|
|
1008
|
+
/** aria-label for an author button: "View profile of {name}". */
|
|
1009
|
+
authorLabel?: (name: string) => string;
|
|
897
1010
|
}
|
|
898
1011
|
/**
|
|
899
1012
|
* Full chat panel with messages, input, pinned messages, and typing indicators.
|
|
@@ -906,13 +1019,17 @@ interface ChatPanelProps {
|
|
|
906
1019
|
* </ChatRoomProvider>
|
|
907
1020
|
* ```
|
|
908
1021
|
*/
|
|
909
|
-
declare function ChatPanel({ className, showModActions, showTypingIndicators, showPinnedMessages, showHeader, showAvatars, canSend, emptyLabel, placeholder, }: ChatPanelProps): react.JSX.Element;
|
|
1022
|
+
declare function ChatPanel({ className, showModActions, showTypingIndicators, showPinnedMessages, showHeader, showAvatars, canSend, emptyLabel, placeholder, onAuthorClick, authorLabel, }: ChatPanelProps): react.JSX.Element;
|
|
910
1023
|
|
|
911
1024
|
interface ChatMessageItemProps {
|
|
912
1025
|
message: ChatMessage;
|
|
913
1026
|
config: ChatRoomConfig | null;
|
|
914
1027
|
/** Show the author's avatar beside the message (DM style). */
|
|
915
1028
|
showAvatar?: boolean;
|
|
1029
|
+
/** Render the author's name and avatar as buttons that call this. */
|
|
1030
|
+
onAuthorClick?: () => void;
|
|
1031
|
+
/** aria-label for those buttons (default "View profile of {name}"). */
|
|
1032
|
+
authorLabel?: (name: string) => string;
|
|
916
1033
|
onReply?: () => void;
|
|
917
1034
|
onReact?: (messageId: string, emoji: string) => void;
|
|
918
1035
|
/** Additional mod actions (feature, pin, delete, ban, kick) */
|
|
@@ -927,7 +1044,7 @@ interface ChatMessageItemProps {
|
|
|
927
1044
|
/**
|
|
928
1045
|
* Renders a single chat message with role badges, flair, reactions, and reply preview.
|
|
929
1046
|
*/
|
|
930
|
-
declare function ChatMessageItem({ message, config, showAvatar, onReply, onReact, modActions, }: ChatMessageItemProps): react.JSX.Element;
|
|
1047
|
+
declare function ChatMessageItem({ message, config, showAvatar, onAuthorClick, authorLabel, onReply, onReact, modActions, }: ChatMessageItemProps): react.JSX.Element;
|
|
931
1048
|
|
|
932
1049
|
interface ChatInputProps {
|
|
933
1050
|
onSendMessage: (text: string, replyToId?: string) => void;
|
|
@@ -943,4 +1060,4 @@ interface ChatInputProps {
|
|
|
943
1060
|
*/
|
|
944
1061
|
declare function ChatInput({ onSendMessage, onSendTyping, replyTo, onClearReply, disabled, placeholder, maxLength, }: ChatInputProps): react.JSX.Element;
|
|
945
1062
|
|
|
946
|
-
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 NotificationItem, NotificationsPanel, type NotificationsPanelProps, type NotificationsSnapshot, 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 UseDialtribeNotificationsReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
|
|
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 };
|