@dialtribe/chat-client 0.5.1 → 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 +120 -5
- package/dist/index.d.ts +120 -5
- package/dist/index.js +247 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +247 -16
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -636,6 +636,7 @@ var ChatClient = class {
|
|
|
636
636
|
this.rooms = /* @__PURE__ */ new Map();
|
|
637
637
|
this.inboxStore = null;
|
|
638
638
|
this.notificationsStore = null;
|
|
639
|
+
this.profiles = /* @__PURE__ */ new Map();
|
|
639
640
|
this.serverUrl = options.serverUrl.replace(/\/$/, "");
|
|
640
641
|
this.apiUrl = (options.apiUrl ?? "https://dialtribe.com").replace(/\/$/, "");
|
|
641
642
|
}
|
|
@@ -810,6 +811,27 @@ var ChatClient = class {
|
|
|
810
811
|
api(path, init = {}) {
|
|
811
812
|
return this.request(path, init, `${this.apiUrl}/api/public/v1`);
|
|
812
813
|
}
|
|
814
|
+
/**
|
|
815
|
+
* A person's mini-profile from Dialtribe, memoized per user for the life of
|
|
816
|
+
* the client. Network failures aren't remembered, so the next call retries.
|
|
817
|
+
*/
|
|
818
|
+
getProfile(userId) {
|
|
819
|
+
let lookup = this.profiles.get(userId);
|
|
820
|
+
if (!lookup) {
|
|
821
|
+
lookup = this.api(`/chat/profiles/${encodeURIComponent(userId)}`).then(
|
|
822
|
+
(profile) => ({ status: "ok", profile }),
|
|
823
|
+
(err) => {
|
|
824
|
+
if (err instanceof ChatRequestError && err.code === "not-found") {
|
|
825
|
+
return err.message === "not_supported" ? { status: "not_supported" } : { status: "hidden" };
|
|
826
|
+
}
|
|
827
|
+
this.profiles.delete(userId);
|
|
828
|
+
throw err;
|
|
829
|
+
}
|
|
830
|
+
);
|
|
831
|
+
this.profiles.set(userId, lookup);
|
|
832
|
+
}
|
|
833
|
+
return lookup;
|
|
834
|
+
}
|
|
813
835
|
/** A DM action on POST /dm (see DMS.md). */
|
|
814
836
|
dm(action, fields = {}) {
|
|
815
837
|
return this.request("/dm", { method: "POST", body: { action, ...fields } });
|
|
@@ -887,6 +909,17 @@ var MessagesUiStore = class extends Store {
|
|
|
887
909
|
openItem(itemId) {
|
|
888
910
|
this.update({ open: true, view: { kind: "item", itemId } });
|
|
889
911
|
}
|
|
912
|
+
/** Show a person's mini-profile, returning to the current view on back. */
|
|
913
|
+
openProfile(userId, hint) {
|
|
914
|
+
const current = this.getSnapshot().view;
|
|
915
|
+
const from = current.kind === "profile" ? current.from : current;
|
|
916
|
+
this.update({ open: true, view: { kind: "profile", userId, from, hint } });
|
|
917
|
+
}
|
|
918
|
+
/** From a mini-profile, return to where it was opened. */
|
|
919
|
+
back() {
|
|
920
|
+
const { view } = this.getSnapshot();
|
|
921
|
+
this.update({ view: view.kind === "profile" ? view.from : { kind: "inbox" } });
|
|
922
|
+
}
|
|
890
923
|
};
|
|
891
924
|
var ClientContext = createContext(null);
|
|
892
925
|
var MessagesUiContext = createContext(null);
|
|
@@ -1001,6 +1034,8 @@ function useDialtribeMessages() {
|
|
|
1001
1034
|
openRoom: (roomId) => ui.openRoom(roomId),
|
|
1002
1035
|
openItem: (itemId) => ui.openItem(itemId),
|
|
1003
1036
|
openNotifications: () => ui.openNotifications(),
|
|
1037
|
+
openProfile: (userId, hint) => ui.openProfile(userId, hint),
|
|
1038
|
+
back: () => ui.back(),
|
|
1004
1039
|
messageUser: async (userId, hint) => {
|
|
1005
1040
|
const result = await client.inbox.requestDM(userId, hint);
|
|
1006
1041
|
ui.openRoom(result.roomId);
|
|
@@ -1052,6 +1087,8 @@ function ChatMessageItem({
|
|
|
1052
1087
|
message,
|
|
1053
1088
|
config,
|
|
1054
1089
|
showAvatar = false,
|
|
1090
|
+
onAuthorClick,
|
|
1091
|
+
authorLabel = (name) => `View profile of ${name}`,
|
|
1055
1092
|
onReply,
|
|
1056
1093
|
onReact,
|
|
1057
1094
|
modActions
|
|
@@ -1079,7 +1116,7 @@ function ChatMessageItem({
|
|
|
1079
1116
|
message.replyPreview.text
|
|
1080
1117
|
] }),
|
|
1081
1118
|
/* @__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" }),
|
|
1119
|
+
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
1120
|
/* @__PURE__ */ jsxs("div", { className: "dtc-message-content", children: [
|
|
1084
1121
|
message.isHost && /* @__PURE__ */ jsx("span", { className: "dtc-badge dtc-badge-host", children: "HOST" }),
|
|
1085
1122
|
message.isModerator && !message.isHost && /* @__PURE__ */ jsx("span", { className: "dtc-badge dtc-badge-mod", children: "MOD" }),
|
|
@@ -1092,7 +1129,16 @@ function ChatMessageItem({
|
|
|
1092
1129
|
children: flair.tag
|
|
1093
1130
|
}
|
|
1094
1131
|
),
|
|
1095
|
-
/* @__PURE__ */ jsx(
|
|
1132
|
+
onAuthorClick ? /* @__PURE__ */ jsx(
|
|
1133
|
+
"button",
|
|
1134
|
+
{
|
|
1135
|
+
type: "button",
|
|
1136
|
+
className: `dtc-person-btn dtc-author ${message.isHost ? "dtc-author-host" : message.isModerator ? "dtc-author-mod" : ""}`,
|
|
1137
|
+
onClick: onAuthorClick,
|
|
1138
|
+
"aria-label": authorLabel(message.authorName),
|
|
1139
|
+
children: message.authorName
|
|
1140
|
+
}
|
|
1141
|
+
) : /* @__PURE__ */ jsx("span", { className: `dtc-author ${message.isHost ? "dtc-author-host" : message.isModerator ? "dtc-author-mod" : ""}`, children: message.authorName }),
|
|
1096
1142
|
/* @__PURE__ */ jsx("span", { className: "dtc-message-text", children: message.message })
|
|
1097
1143
|
] }),
|
|
1098
1144
|
showActions && (onReply || onReact || modActions) && /* @__PURE__ */ jsxs("div", { className: "dtc-actions", children: [
|
|
@@ -1201,7 +1247,9 @@ function ChatPanel({
|
|
|
1201
1247
|
showAvatars = false,
|
|
1202
1248
|
canSend = true,
|
|
1203
1249
|
emptyLabel = "No messages yet",
|
|
1204
|
-
placeholder
|
|
1250
|
+
placeholder,
|
|
1251
|
+
onAuthorClick,
|
|
1252
|
+
authorLabel
|
|
1205
1253
|
}) {
|
|
1206
1254
|
const chat = useChatRoomContext();
|
|
1207
1255
|
const { messages, config, pinnedMessages, typingUsers, hasMoreHistory } = chat;
|
|
@@ -1269,6 +1317,8 @@ function ChatPanel({
|
|
|
1269
1317
|
message: msg,
|
|
1270
1318
|
config,
|
|
1271
1319
|
showAvatar: showAvatars,
|
|
1320
|
+
onAuthorClick: onAuthorClick && !msg.isBotMessage ? () => onAuthorClick({ userId: msg.authorId, name: msg.authorName, avatarUrl: msg.avatarUrl ?? null }) : void 0,
|
|
1321
|
+
authorLabel,
|
|
1272
1322
|
onReply: () => setReplyTo(msg),
|
|
1273
1323
|
onReact: (id, emoji) => void chat.addReaction(id, emoji).catch(() => {
|
|
1274
1324
|
}),
|
|
@@ -1359,7 +1409,12 @@ var DEFAULT_LABELS = {
|
|
|
1359
1409
|
if (s < 86400) return `${Math.floor(s / 3600)}h`;
|
|
1360
1410
|
if (s < 604800) return `${Math.floor(s / 86400)}d`;
|
|
1361
1411
|
return date.toLocaleDateString(void 0, { month: "short", day: "numeric" });
|
|
1362
|
-
}
|
|
1412
|
+
},
|
|
1413
|
+
viewSiteProfile: (site) => site ? `View ${site} profile` : "View profile",
|
|
1414
|
+
alsoOn: "Also on",
|
|
1415
|
+
message: "Message",
|
|
1416
|
+
viewProfileOf: (name) => `View profile of ${name}`,
|
|
1417
|
+
members: "Members"
|
|
1363
1418
|
};
|
|
1364
1419
|
function badgeText(count) {
|
|
1365
1420
|
return count > 99 ? "99+" : String(count);
|
|
@@ -1511,10 +1566,12 @@ function KebabIcon() {
|
|
|
1511
1566
|
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "19", r: "1.8" })
|
|
1512
1567
|
] });
|
|
1513
1568
|
}
|
|
1514
|
-
function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
|
|
1569
|
+
function ConversationView({ roomId, labels, onBack, onClose, confirm, onOpenProfile }) {
|
|
1515
1570
|
const inbox = useChatRooms();
|
|
1516
1571
|
const room = inbox.rooms.find((r) => r.roomId === roomId);
|
|
1517
1572
|
const { setVisible } = inbox;
|
|
1573
|
+
const [membersOpen, setMembersOpen] = useState(false);
|
|
1574
|
+
const other = room?.kind === "dm" ? room.participants[0] : void 0;
|
|
1518
1575
|
useEffect(() => setVisible(roomId), [setVisible, roomId]);
|
|
1519
1576
|
const isRequest = room?.myStatus === "pending";
|
|
1520
1577
|
const isClosed = room?.state === "closed";
|
|
@@ -1557,13 +1614,53 @@ function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
|
|
|
1557
1614
|
return /* @__PURE__ */ jsxs("div", { className: "dtc-conversation", children: [
|
|
1558
1615
|
/* @__PURE__ */ jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1559
1616
|
/* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsx(ChevronLeft, {}) }),
|
|
1560
|
-
|
|
1561
|
-
|
|
1617
|
+
other ? /* @__PURE__ */ jsxs(
|
|
1618
|
+
"button",
|
|
1619
|
+
{
|
|
1620
|
+
type: "button",
|
|
1621
|
+
className: "dtc-person-btn dtc-conversation-person",
|
|
1622
|
+
onClick: () => onOpenProfile(other.userId, { name: other.name, avatarUrl: other.avatarUrl }),
|
|
1623
|
+
"aria-label": labels.viewProfileOf(other.name),
|
|
1624
|
+
children: [
|
|
1625
|
+
/* @__PURE__ */ jsx(Avatar, { name: other.name, url: other.avatarUrl, size: 28 }),
|
|
1626
|
+
/* @__PURE__ */ jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" })
|
|
1627
|
+
]
|
|
1628
|
+
}
|
|
1629
|
+
) : room?.kind === "group" ? /* @__PURE__ */ jsxs(
|
|
1630
|
+
"button",
|
|
1631
|
+
{
|
|
1632
|
+
type: "button",
|
|
1633
|
+
className: "dtc-person-btn dtc-conversation-person",
|
|
1634
|
+
onClick: () => setMembersOpen((v) => !v),
|
|
1635
|
+
"aria-expanded": membersOpen,
|
|
1636
|
+
"aria-label": labels.members,
|
|
1637
|
+
children: [
|
|
1638
|
+
/* @__PURE__ */ jsx(Avatar, { name: room.name, size: 28 }),
|
|
1639
|
+
/* @__PURE__ */ jsx("span", { className: "dtc-conversation-title", children: room.name })
|
|
1640
|
+
]
|
|
1641
|
+
}
|
|
1642
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1643
|
+
room && /* @__PURE__ */ jsx(Avatar, { name: room.name, size: 28 }),
|
|
1644
|
+
/* @__PURE__ */ jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" })
|
|
1645
|
+
] }),
|
|
1562
1646
|
/* @__PURE__ */ jsxs("span", { className: "dtc-conversation-actions", children: [
|
|
1563
1647
|
/* @__PURE__ */ jsx(ConversationMenu, { label: labels.moreOptions, items: menuItems }),
|
|
1564
1648
|
/* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon, {}) })
|
|
1565
1649
|
] })
|
|
1566
1650
|
] }),
|
|
1651
|
+
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(
|
|
1652
|
+
"button",
|
|
1653
|
+
{
|
|
1654
|
+
type: "button",
|
|
1655
|
+
className: "dtc-member",
|
|
1656
|
+
onClick: () => onOpenProfile(p.userId, { name: p.name, avatarUrl: p.avatarUrl }),
|
|
1657
|
+
"aria-label": labels.viewProfileOf(p.name),
|
|
1658
|
+
children: [
|
|
1659
|
+
/* @__PURE__ */ jsx(Avatar, { name: p.name, url: p.avatarUrl, size: 24 }),
|
|
1660
|
+
/* @__PURE__ */ jsx("span", { className: "dtc-member-name", children: p.name })
|
|
1661
|
+
]
|
|
1662
|
+
}
|
|
1663
|
+
) }, p.userId)) }),
|
|
1567
1664
|
isRequest && room && /* @__PURE__ */ jsxs("div", { className: "dtc-request-banner", role: "region", "aria-label": labels.requests, children: [
|
|
1568
1665
|
/* @__PURE__ */ jsx("span", { children: labels.wantsToMessage(room.name) }),
|
|
1569
1666
|
/* @__PURE__ */ jsxs("span", { className: "dtc-request-actions", children: [
|
|
@@ -1595,7 +1692,9 @@ function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
|
|
|
1595
1692
|
showPinnedMessages: false,
|
|
1596
1693
|
canSend: !isRequest && !isClosed,
|
|
1597
1694
|
emptyLabel: labels.noMessages,
|
|
1598
|
-
placeholder: labels.messagePlaceholder
|
|
1695
|
+
placeholder: labels.messagePlaceholder,
|
|
1696
|
+
onAuthorClick: (a) => onOpenProfile(a.userId, { name: a.name, avatarUrl: a.avatarUrl }),
|
|
1697
|
+
authorLabel: labels.viewProfileOf
|
|
1599
1698
|
}
|
|
1600
1699
|
) })
|
|
1601
1700
|
] });
|
|
@@ -1699,6 +1798,100 @@ function NotificationsPanel({ labels, onClose, onOpen, onOpened }) {
|
|
|
1699
1798
|
] })
|
|
1700
1799
|
] });
|
|
1701
1800
|
}
|
|
1801
|
+
function fallbackProfile(userId, hint, canMessage) {
|
|
1802
|
+
return {
|
|
1803
|
+
userId,
|
|
1804
|
+
name: hint?.name || userId,
|
|
1805
|
+
handle: null,
|
|
1806
|
+
avatarUrl: hint?.avatarUrl ?? null,
|
|
1807
|
+
bio: null,
|
|
1808
|
+
current: null,
|
|
1809
|
+
apps: [],
|
|
1810
|
+
canMessage
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
function ProfileView({
|
|
1814
|
+
userId,
|
|
1815
|
+
hint,
|
|
1816
|
+
labels,
|
|
1817
|
+
onBack,
|
|
1818
|
+
onClose,
|
|
1819
|
+
onNavigate,
|
|
1820
|
+
onMessage,
|
|
1821
|
+
hideMessage,
|
|
1822
|
+
getProfileUrl,
|
|
1823
|
+
profileActions
|
|
1824
|
+
}) {
|
|
1825
|
+
const client = useChatClient();
|
|
1826
|
+
const [lookup, setLookup] = useState(null);
|
|
1827
|
+
useEffect(() => {
|
|
1828
|
+
let live = true;
|
|
1829
|
+
setLookup(null);
|
|
1830
|
+
client.getProfile(userId).then(
|
|
1831
|
+
(result) => live && setLookup(result),
|
|
1832
|
+
() => live && setLookup({ status: "not_supported" })
|
|
1833
|
+
);
|
|
1834
|
+
return () => {
|
|
1835
|
+
live = false;
|
|
1836
|
+
};
|
|
1837
|
+
}, [client, userId]);
|
|
1838
|
+
const profile = lookup?.status === "ok" ? lookup.profile : fallbackProfile(userId, hint, lookup?.status !== "hidden");
|
|
1839
|
+
const fallbackUrl = lookup?.status === "not_supported" ? getProfileUrl?.(userId) ?? null : null;
|
|
1840
|
+
const primary = profile.current ? { url: profile.current.profileUrl, label: labels.viewSiteProfile(profile.current.siteName) } : fallbackUrl ? { url: fallbackUrl, label: labels.viewSiteProfile("") } : null;
|
|
1841
|
+
const showHandle = !!profile.handle && profile.handle.toLowerCase() !== profile.name.toLowerCase();
|
|
1842
|
+
const showMessage = !hideMessage && lookup !== null && profile.canMessage;
|
|
1843
|
+
return /* @__PURE__ */ jsxs("div", { className: "dtc-conversation", children: [
|
|
1844
|
+
/* @__PURE__ */ jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1845
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsx(ChevronLeft2, {}) }),
|
|
1846
|
+
/* @__PURE__ */ jsx("span", { className: "dtc-conversation-title" }),
|
|
1847
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon2, {}) })
|
|
1848
|
+
] }),
|
|
1849
|
+
/* @__PURE__ */ jsxs("div", { className: "dtc-profile", children: [
|
|
1850
|
+
/* @__PURE__ */ jsxs("div", { className: "dtc-profile-head", children: [
|
|
1851
|
+
/* @__PURE__ */ jsx(Avatar, { name: profile.name, url: profile.avatarUrl, size: 64 }),
|
|
1852
|
+
/* @__PURE__ */ jsxs("div", { className: "dtc-profile-names", children: [
|
|
1853
|
+
/* @__PURE__ */ jsx("span", { className: "dtc-profile-name", children: profile.name }),
|
|
1854
|
+
showHandle && /* @__PURE__ */ jsxs("span", { className: "dtc-profile-handle", children: [
|
|
1855
|
+
"@",
|
|
1856
|
+
profile.handle
|
|
1857
|
+
] })
|
|
1858
|
+
] })
|
|
1859
|
+
] }),
|
|
1860
|
+
profile.bio && /* @__PURE__ */ jsx("p", { className: "dtc-profile-bio", children: profile.bio }),
|
|
1861
|
+
primary && /* @__PURE__ */ jsx("a", { className: "dtc-btn dtc-btn-primary dtc-profile-primary", href: primary.url, onClick: onNavigate, children: primary.label }),
|
|
1862
|
+
profile.apps.length > 0 && /* @__PURE__ */ jsxs("div", { className: "dtc-profile-sites", children: [
|
|
1863
|
+
/* @__PURE__ */ jsx("span", { className: "dtc-profile-sites-title", children: labels.alsoOn }),
|
|
1864
|
+
profile.apps.map((site) => {
|
|
1865
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1866
|
+
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" }),
|
|
1867
|
+
/* @__PURE__ */ jsx("span", { className: "dtc-profile-site-name", children: site.siteName }),
|
|
1868
|
+
site.url && /* @__PURE__ */ jsx(ArrowIcon, {})
|
|
1869
|
+
] });
|
|
1870
|
+
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);
|
|
1871
|
+
})
|
|
1872
|
+
] }),
|
|
1873
|
+
showMessage && /* @__PURE__ */ jsx(
|
|
1874
|
+
"button",
|
|
1875
|
+
{
|
|
1876
|
+
type: "button",
|
|
1877
|
+
className: "dtc-btn dtc-profile-message",
|
|
1878
|
+
onClick: () => onMessage(userId, { name: profile.name, avatarUrl: profile.avatarUrl }),
|
|
1879
|
+
children: labels.message
|
|
1880
|
+
}
|
|
1881
|
+
),
|
|
1882
|
+
profileActions && lookup !== null && lookup.status !== "hidden" && /* @__PURE__ */ jsx("div", { className: "dtc-profile-actions", children: profileActions(profile) })
|
|
1883
|
+
] })
|
|
1884
|
+
] });
|
|
1885
|
+
}
|
|
1886
|
+
function ChevronLeft2() {
|
|
1887
|
+
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" }) });
|
|
1888
|
+
}
|
|
1889
|
+
function CloseIcon2() {
|
|
1890
|
+
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" }) });
|
|
1891
|
+
}
|
|
1892
|
+
function ArrowIcon() {
|
|
1893
|
+
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" }) });
|
|
1894
|
+
}
|
|
1702
1895
|
var RAIL_WIDTH = 64;
|
|
1703
1896
|
var EDGE_SWIPE_ZONE = 24;
|
|
1704
1897
|
var SWIPE_DISTANCE = 60;
|
|
@@ -1715,7 +1908,9 @@ function DialtribeMessages({
|
|
|
1715
1908
|
railDmLimit = 5,
|
|
1716
1909
|
mobileBreakpoint = 768,
|
|
1717
1910
|
confirm: hostConfirm,
|
|
1718
|
-
notifications = false
|
|
1911
|
+
notifications = false,
|
|
1912
|
+
getProfileUrl,
|
|
1913
|
+
profileActions
|
|
1719
1914
|
}) {
|
|
1720
1915
|
const labels = useMemo(() => ({ ...DEFAULT_LABELS, ...labelOverrides }), [labelOverrides]);
|
|
1721
1916
|
const inbox = useChatRooms();
|
|
@@ -1782,6 +1977,14 @@ function DialtribeMessages({
|
|
|
1782
1977
|
item.id
|
|
1783
1978
|
);
|
|
1784
1979
|
};
|
|
1980
|
+
const client = useChatClient();
|
|
1981
|
+
const openProfile = (userId, hint) => ui.openProfile(userId, hint);
|
|
1982
|
+
const hideMessageFor = (userId, from) => {
|
|
1983
|
+
if (client.self?.userId === userId) return true;
|
|
1984
|
+
if (from.kind !== "room") return false;
|
|
1985
|
+
const room = inbox.rooms.find((r) => r.roomId === from.roomId);
|
|
1986
|
+
return room?.kind === "dm" && room.participants[0]?.userId === userId;
|
|
1987
|
+
};
|
|
1785
1988
|
const style = { ...themeVars(theme), "--dtc-panel-width": `${panelWidth}px`, "--dtc-rail-width": `${RAIL_WIDTH}px` };
|
|
1786
1989
|
const showRail = !isMobile || isOpen;
|
|
1787
1990
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1796,7 +1999,25 @@ function DialtribeMessages({
|
|
|
1796
1999
|
rollup > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
|
|
1797
2000
|
] }),
|
|
1798
2001
|
isOpen && /* @__PURE__ */ jsxs("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: [
|
|
1799
|
-
view.kind === "
|
|
2002
|
+
view.kind === "profile" ? /* @__PURE__ */ jsx(
|
|
2003
|
+
ProfileView,
|
|
2004
|
+
{
|
|
2005
|
+
userId: view.userId,
|
|
2006
|
+
hint: view.hint,
|
|
2007
|
+
labels,
|
|
2008
|
+
onBack: ui.back,
|
|
2009
|
+
onClose: ui.close,
|
|
2010
|
+
onNavigate: () => {
|
|
2011
|
+
if (isMobile) ui.close();
|
|
2012
|
+
},
|
|
2013
|
+
onMessage: (userId, hint) => void ui.messageUser(userId, { name: hint.name, avatarUrl: hint.avatarUrl ?? void 0 }).catch(() => {
|
|
2014
|
+
}),
|
|
2015
|
+
hideMessage: hideMessageFor(view.userId, view.from),
|
|
2016
|
+
getProfileUrl,
|
|
2017
|
+
profileActions
|
|
2018
|
+
},
|
|
2019
|
+
view.userId
|
|
2020
|
+
) : view.kind === "notifications" && notifications !== false ? /* @__PURE__ */ jsx(
|
|
1800
2021
|
NotificationsPanel,
|
|
1801
2022
|
{
|
|
1802
2023
|
labels,
|
|
@@ -1809,7 +2030,7 @@ function DialtribeMessages({
|
|
|
1809
2030
|
) : 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
2031
|
/* @__PURE__ */ jsxs("div", { className: "dtc-panel-header", children: [
|
|
1811
2032
|
/* @__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(
|
|
2033
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon3, {}) })
|
|
1813
2034
|
] }),
|
|
1814
2035
|
/* @__PURE__ */ jsx(
|
|
1815
2036
|
MessagesInbox,
|
|
@@ -1826,9 +2047,18 @@ function DialtribeMessages({
|
|
|
1826
2047
|
/* @__PURE__ */ jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1827
2048
|
/* @__PURE__ */ jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
|
|
1828
2049
|
/* @__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(
|
|
2050
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon3, {}) })
|
|
1830
2051
|
] }),
|
|
1831
|
-
/* @__PURE__ */ jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsx(
|
|
2052
|
+
/* @__PURE__ */ jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsx(
|
|
2053
|
+
ChatPanel,
|
|
2054
|
+
{
|
|
2055
|
+
showHeader: false,
|
|
2056
|
+
emptyLabel: labels.noMessages,
|
|
2057
|
+
placeholder: labels.messagePlaceholder,
|
|
2058
|
+
onAuthorClick: (a) => openProfile(a.userId, { name: a.name, avatarUrl: a.avatarUrl }),
|
|
2059
|
+
authorLabel: labels.viewProfileOf
|
|
2060
|
+
}
|
|
2061
|
+
) })
|
|
1832
2062
|
] }) : /* @__PURE__ */ jsx(
|
|
1833
2063
|
ConversationView,
|
|
1834
2064
|
{
|
|
@@ -1836,7 +2066,8 @@ function DialtribeMessages({
|
|
|
1836
2066
|
labels,
|
|
1837
2067
|
onBack: ui.openInbox,
|
|
1838
2068
|
onClose: ui.close,
|
|
1839
|
-
confirm
|
|
2069
|
+
confirm,
|
|
2070
|
+
onOpenProfile: openProfile
|
|
1840
2071
|
},
|
|
1841
2072
|
view.roomId
|
|
1842
2073
|
),
|
|
@@ -2059,10 +2290,10 @@ function useNotificationsBadge(enabled) {
|
|
|
2059
2290
|
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
2060
2291
|
return enabled ? snapshot.unreadCount : 0;
|
|
2061
2292
|
}
|
|
2062
|
-
function
|
|
2293
|
+
function CloseIcon3() {
|
|
2063
2294
|
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
2295
|
}
|
|
2065
2296
|
|
|
2066
|
-
export { Avatar, ChatClient, ChatInput, ChatMessageItem, ChatPanel, ChatRequestError, ChatRoomProvider, DEFAULT_LABELS, DialtribeChatProvider, DialtribeMessages, NotificationsPanel, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
|
|
2297
|
+
export { Avatar, ChatClient, ChatInput, ChatMessageItem, ChatPanel, ChatRequestError, ChatRoomProvider, DEFAULT_LABELS, DialtribeChatProvider, DialtribeMessages, NotificationsPanel, ProfileView, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
|
|
2067
2298
|
//# sourceMappingURL=index.mjs.map
|
|
2068
2299
|
//# sourceMappingURL=index.mjs.map
|