@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/dist/index.js
CHANGED
|
@@ -638,6 +638,7 @@ var ChatClient = class {
|
|
|
638
638
|
this.rooms = /* @__PURE__ */ new Map();
|
|
639
639
|
this.inboxStore = null;
|
|
640
640
|
this.notificationsStore = null;
|
|
641
|
+
this.profiles = /* @__PURE__ */ new Map();
|
|
641
642
|
this.serverUrl = options.serverUrl.replace(/\/$/, "");
|
|
642
643
|
this.apiUrl = (options.apiUrl ?? "https://dialtribe.com").replace(/\/$/, "");
|
|
643
644
|
}
|
|
@@ -812,6 +813,27 @@ var ChatClient = class {
|
|
|
812
813
|
api(path, init = {}) {
|
|
813
814
|
return this.request(path, init, `${this.apiUrl}/api/public/v1`);
|
|
814
815
|
}
|
|
816
|
+
/**
|
|
817
|
+
* A person's mini-profile from Dialtribe, memoized per user for the life of
|
|
818
|
+
* the client. Network failures aren't remembered, so the next call retries.
|
|
819
|
+
*/
|
|
820
|
+
getProfile(userId) {
|
|
821
|
+
let lookup = this.profiles.get(userId);
|
|
822
|
+
if (!lookup) {
|
|
823
|
+
lookup = this.api(`/chat/profiles/${encodeURIComponent(userId)}`).then(
|
|
824
|
+
(profile) => ({ status: "ok", profile }),
|
|
825
|
+
(err) => {
|
|
826
|
+
if (err instanceof ChatRequestError && err.code === "not-found") {
|
|
827
|
+
return err.message === "not_supported" ? { status: "not_supported" } : { status: "hidden" };
|
|
828
|
+
}
|
|
829
|
+
this.profiles.delete(userId);
|
|
830
|
+
throw err;
|
|
831
|
+
}
|
|
832
|
+
);
|
|
833
|
+
this.profiles.set(userId, lookup);
|
|
834
|
+
}
|
|
835
|
+
return lookup;
|
|
836
|
+
}
|
|
815
837
|
/** A DM action on POST /dm (see DMS.md). */
|
|
816
838
|
dm(action, fields = {}) {
|
|
817
839
|
return this.request("/dm", { method: "POST", body: { action, ...fields } });
|
|
@@ -889,6 +911,17 @@ var MessagesUiStore = class extends Store {
|
|
|
889
911
|
openItem(itemId) {
|
|
890
912
|
this.update({ open: true, view: { kind: "item", itemId } });
|
|
891
913
|
}
|
|
914
|
+
/** Show a person's mini-profile, returning to the current view on back. */
|
|
915
|
+
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 } });
|
|
919
|
+
}
|
|
920
|
+
/** From a mini-profile, return to where it was opened. */
|
|
921
|
+
back() {
|
|
922
|
+
const { view } = this.getSnapshot();
|
|
923
|
+
this.update({ view: view.kind === "profile" ? view.from : { kind: "inbox" } });
|
|
924
|
+
}
|
|
892
925
|
};
|
|
893
926
|
var ClientContext = react.createContext(null);
|
|
894
927
|
var MessagesUiContext = react.createContext(null);
|
|
@@ -1003,6 +1036,8 @@ function useDialtribeMessages() {
|
|
|
1003
1036
|
openRoom: (roomId) => ui.openRoom(roomId),
|
|
1004
1037
|
openItem: (itemId) => ui.openItem(itemId),
|
|
1005
1038
|
openNotifications: () => ui.openNotifications(),
|
|
1039
|
+
openProfile: (userId, hint) => ui.openProfile(userId, hint),
|
|
1040
|
+
back: () => ui.back(),
|
|
1006
1041
|
messageUser: async (userId, hint) => {
|
|
1007
1042
|
const result = await client.inbox.requestDM(userId, hint);
|
|
1008
1043
|
ui.openRoom(result.roomId);
|
|
@@ -1054,6 +1089,8 @@ function ChatMessageItem({
|
|
|
1054
1089
|
message,
|
|
1055
1090
|
config,
|
|
1056
1091
|
showAvatar = false,
|
|
1092
|
+
onAuthorClick,
|
|
1093
|
+
authorLabel = (name) => `View profile of ${name}`,
|
|
1057
1094
|
onReply,
|
|
1058
1095
|
onReact,
|
|
1059
1096
|
modActions
|
|
@@ -1081,7 +1118,7 @@ function ChatMessageItem({
|
|
|
1081
1118
|
message.replyPreview.text
|
|
1082
1119
|
] }),
|
|
1083
1120
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-message-row", children: [
|
|
1084
|
-
showAvatar && /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: message.authorName, url: message.avatarUrl, size: 28, className: "dtc-message-avatar" }),
|
|
1121
|
+
showAvatar && (onAuthorClick ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-person-btn", onClick: onAuthorClick, "aria-label": authorLabel(message.authorName), children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: message.authorName, url: message.avatarUrl, size: 28, className: "dtc-message-avatar" }) }) : /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: message.authorName, url: message.avatarUrl, size: 28, className: "dtc-message-avatar" })),
|
|
1085
1122
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-message-content", children: [
|
|
1086
1123
|
message.isHost && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge dtc-badge-host", children: "HOST" }),
|
|
1087
1124
|
message.isModerator && !message.isHost && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge dtc-badge-mod", children: "MOD" }),
|
|
@@ -1094,7 +1131,16 @@ function ChatMessageItem({
|
|
|
1094
1131
|
children: flair.tag
|
|
1095
1132
|
}
|
|
1096
1133
|
),
|
|
1097
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1134
|
+
onAuthorClick ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1135
|
+
"button",
|
|
1136
|
+
{
|
|
1137
|
+
type: "button",
|
|
1138
|
+
className: `dtc-person-btn dtc-author ${message.isHost ? "dtc-author-host" : message.isModerator ? "dtc-author-mod" : ""}`,
|
|
1139
|
+
onClick: onAuthorClick,
|
|
1140
|
+
"aria-label": authorLabel(message.authorName),
|
|
1141
|
+
children: message.authorName
|
|
1142
|
+
}
|
|
1143
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: `dtc-author ${message.isHost ? "dtc-author-host" : message.isModerator ? "dtc-author-mod" : ""}`, children: message.authorName }),
|
|
1098
1144
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-message-text", children: message.message })
|
|
1099
1145
|
] }),
|
|
1100
1146
|
showActions && (onReply || onReact || modActions) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-actions", children: [
|
|
@@ -1203,7 +1249,9 @@ function ChatPanel({
|
|
|
1203
1249
|
showAvatars = false,
|
|
1204
1250
|
canSend = true,
|
|
1205
1251
|
emptyLabel = "No messages yet",
|
|
1206
|
-
placeholder
|
|
1252
|
+
placeholder,
|
|
1253
|
+
onAuthorClick,
|
|
1254
|
+
authorLabel
|
|
1207
1255
|
}) {
|
|
1208
1256
|
const chat = useChatRoomContext();
|
|
1209
1257
|
const { messages, config, pinnedMessages, typingUsers, hasMoreHistory } = chat;
|
|
@@ -1271,6 +1319,8 @@ function ChatPanel({
|
|
|
1271
1319
|
message: msg,
|
|
1272
1320
|
config,
|
|
1273
1321
|
showAvatar: showAvatars,
|
|
1322
|
+
onAuthorClick: onAuthorClick && !msg.isBotMessage ? () => onAuthorClick({ userId: msg.authorId, name: msg.authorName, avatarUrl: msg.avatarUrl ?? null }) : void 0,
|
|
1323
|
+
authorLabel,
|
|
1274
1324
|
onReply: () => setReplyTo(msg),
|
|
1275
1325
|
onReact: (id, emoji) => void chat.addReaction(id, emoji).catch(() => {
|
|
1276
1326
|
}),
|
|
@@ -1361,7 +1411,12 @@ var DEFAULT_LABELS = {
|
|
|
1361
1411
|
if (s < 86400) return `${Math.floor(s / 3600)}h`;
|
|
1362
1412
|
if (s < 604800) return `${Math.floor(s / 86400)}d`;
|
|
1363
1413
|
return date.toLocaleDateString(void 0, { month: "short", day: "numeric" });
|
|
1364
|
-
}
|
|
1414
|
+
},
|
|
1415
|
+
viewSiteProfile: (site) => site ? `View ${site} profile` : "View profile",
|
|
1416
|
+
alsoOn: "Also on",
|
|
1417
|
+
message: "Message",
|
|
1418
|
+
viewProfileOf: (name) => `View profile of ${name}`,
|
|
1419
|
+
members: "Members"
|
|
1365
1420
|
};
|
|
1366
1421
|
function badgeText(count) {
|
|
1367
1422
|
return count > 99 ? "99+" : String(count);
|
|
@@ -1513,10 +1568,12 @@ function KebabIcon() {
|
|
|
1513
1568
|
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "19", r: "1.8" })
|
|
1514
1569
|
] });
|
|
1515
1570
|
}
|
|
1516
|
-
function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
|
|
1571
|
+
function ConversationView({ roomId, labels, onBack, onClose, confirm, onOpenProfile }) {
|
|
1517
1572
|
const inbox = useChatRooms();
|
|
1518
1573
|
const room = inbox.rooms.find((r) => r.roomId === roomId);
|
|
1519
1574
|
const { setVisible } = inbox;
|
|
1575
|
+
const [membersOpen, setMembersOpen] = react.useState(false);
|
|
1576
|
+
const other = room?.kind === "dm" ? room.participants[0] : void 0;
|
|
1520
1577
|
react.useEffect(() => setVisible(roomId), [setVisible, roomId]);
|
|
1521
1578
|
const isRequest = room?.myStatus === "pending";
|
|
1522
1579
|
const isClosed = room?.state === "closed";
|
|
@@ -1559,13 +1616,53 @@ function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
|
|
|
1559
1616
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
|
|
1560
1617
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1561
1618
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsxRuntime.jsx(ChevronLeft, {}) }),
|
|
1562
|
-
|
|
1563
|
-
|
|
1619
|
+
other ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1620
|
+
"button",
|
|
1621
|
+
{
|
|
1622
|
+
type: "button",
|
|
1623
|
+
className: "dtc-person-btn dtc-conversation-person",
|
|
1624
|
+
onClick: () => onOpenProfile(other.userId, { name: other.name, avatarUrl: other.avatarUrl }),
|
|
1625
|
+
"aria-label": labels.viewProfileOf(other.name),
|
|
1626
|
+
children: [
|
|
1627
|
+
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: other.name, url: other.avatarUrl, size: 28 }),
|
|
1628
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" })
|
|
1629
|
+
]
|
|
1630
|
+
}
|
|
1631
|
+
) : room?.kind === "group" ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1632
|
+
"button",
|
|
1633
|
+
{
|
|
1634
|
+
type: "button",
|
|
1635
|
+
className: "dtc-person-btn dtc-conversation-person",
|
|
1636
|
+
onClick: () => setMembersOpen((v) => !v),
|
|
1637
|
+
"aria-expanded": membersOpen,
|
|
1638
|
+
"aria-label": labels.members,
|
|
1639
|
+
children: [
|
|
1640
|
+
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, size: 28 }),
|
|
1641
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: room.name })
|
|
1642
|
+
]
|
|
1643
|
+
}
|
|
1644
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1645
|
+
room && /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, size: 28 }),
|
|
1646
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" })
|
|
1647
|
+
] }),
|
|
1564
1648
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-conversation-actions", children: [
|
|
1565
1649
|
/* @__PURE__ */ jsxRuntime.jsx(ConversationMenu, { label: labels.moreOptions, items: menuItems }),
|
|
1566
1650
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
|
|
1567
1651
|
] })
|
|
1568
1652
|
] }),
|
|
1653
|
+
membersOpen && room?.kind === "group" && /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "dtc-member-list", "aria-label": labels.members, children: room.participants.map((p) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1654
|
+
"button",
|
|
1655
|
+
{
|
|
1656
|
+
type: "button",
|
|
1657
|
+
className: "dtc-member",
|
|
1658
|
+
onClick: () => onOpenProfile(p.userId, { name: p.name, avatarUrl: p.avatarUrl }),
|
|
1659
|
+
"aria-label": labels.viewProfileOf(p.name),
|
|
1660
|
+
children: [
|
|
1661
|
+
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: p.name, url: p.avatarUrl, size: 24 }),
|
|
1662
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-member-name", children: p.name })
|
|
1663
|
+
]
|
|
1664
|
+
}
|
|
1665
|
+
) }, p.userId)) }),
|
|
1569
1666
|
isRequest && room && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-request-banner", role: "region", "aria-label": labels.requests, children: [
|
|
1570
1667
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: labels.wantsToMessage(room.name) }),
|
|
1571
1668
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-request-actions", children: [
|
|
@@ -1597,7 +1694,9 @@ function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
|
|
|
1597
1694
|
showPinnedMessages: false,
|
|
1598
1695
|
canSend: !isRequest && !isClosed,
|
|
1599
1696
|
emptyLabel: labels.noMessages,
|
|
1600
|
-
placeholder: labels.messagePlaceholder
|
|
1697
|
+
placeholder: labels.messagePlaceholder,
|
|
1698
|
+
onAuthorClick: (a) => onOpenProfile(a.userId, { name: a.name, avatarUrl: a.avatarUrl }),
|
|
1699
|
+
authorLabel: labels.viewProfileOf
|
|
1601
1700
|
}
|
|
1602
1701
|
) })
|
|
1603
1702
|
] });
|
|
@@ -1625,7 +1724,7 @@ function groupRows(items) {
|
|
|
1625
1724
|
}
|
|
1626
1725
|
return rows;
|
|
1627
1726
|
}
|
|
1628
|
-
function NotificationsPanel({ labels, onClose, onOpen }) {
|
|
1727
|
+
function NotificationsPanel({ labels, onClose, onOpen, onOpened }) {
|
|
1629
1728
|
const n = useDialtribeNotifications();
|
|
1630
1729
|
const rows = react.useMemo(() => groupRows(n.items), [n.items]);
|
|
1631
1730
|
const { status, markSeen } = n;
|
|
@@ -1634,10 +1733,16 @@ function NotificationsPanel({ labels, onClose, onOpen }) {
|
|
|
1634
1733
|
});
|
|
1635
1734
|
}, [status, markSeen]);
|
|
1636
1735
|
const open = (row) => {
|
|
1736
|
+
if (!row.lead.url) {
|
|
1737
|
+
if (row.unread) void n.markRead(row.ids).catch(() => {
|
|
1738
|
+
});
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1637
1741
|
void n.click(row.ids).catch(() => {
|
|
1638
1742
|
});
|
|
1639
1743
|
const handled = onOpen?.(row.lead);
|
|
1640
|
-
|
|
1744
|
+
onOpened?.(row.lead);
|
|
1745
|
+
if (!handled) window.location.assign(row.lead.url);
|
|
1641
1746
|
};
|
|
1642
1747
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-notif", children: [
|
|
1643
1748
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
|
|
@@ -1654,7 +1759,7 @@ function NotificationsPanel({ labels, onClose, onOpen }) {
|
|
|
1654
1759
|
"button",
|
|
1655
1760
|
{
|
|
1656
1761
|
type: "button",
|
|
1657
|
-
className: `dtc-notif-row ${row.unread ? "dtc-notif-row-unread" : ""}`,
|
|
1762
|
+
className: `dtc-notif-row ${row.unread ? "dtc-notif-row-unread" : ""} ${row.lead.url ? "" : "dtc-notif-row-static"}`,
|
|
1658
1763
|
onClick: () => open(row),
|
|
1659
1764
|
children: [
|
|
1660
1765
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1695,6 +1800,100 @@ function NotificationsPanel({ labels, onClose, onOpen }) {
|
|
|
1695
1800
|
] })
|
|
1696
1801
|
] });
|
|
1697
1802
|
}
|
|
1803
|
+
function fallbackProfile(userId, hint, canMessage) {
|
|
1804
|
+
return {
|
|
1805
|
+
userId,
|
|
1806
|
+
name: hint?.name || userId,
|
|
1807
|
+
handle: null,
|
|
1808
|
+
avatarUrl: hint?.avatarUrl ?? null,
|
|
1809
|
+
bio: null,
|
|
1810
|
+
current: null,
|
|
1811
|
+
apps: [],
|
|
1812
|
+
canMessage
|
|
1813
|
+
};
|
|
1814
|
+
}
|
|
1815
|
+
function ProfileView({
|
|
1816
|
+
userId,
|
|
1817
|
+
hint,
|
|
1818
|
+
labels,
|
|
1819
|
+
onBack,
|
|
1820
|
+
onClose,
|
|
1821
|
+
onNavigate,
|
|
1822
|
+
onMessage,
|
|
1823
|
+
hideMessage,
|
|
1824
|
+
getProfileUrl,
|
|
1825
|
+
profileActions
|
|
1826
|
+
}) {
|
|
1827
|
+
const client = useChatClient();
|
|
1828
|
+
const [lookup, setLookup] = react.useState(null);
|
|
1829
|
+
react.useEffect(() => {
|
|
1830
|
+
let live = true;
|
|
1831
|
+
setLookup(null);
|
|
1832
|
+
client.getProfile(userId).then(
|
|
1833
|
+
(result) => live && setLookup(result),
|
|
1834
|
+
() => live && setLookup({ status: "not_supported" })
|
|
1835
|
+
);
|
|
1836
|
+
return () => {
|
|
1837
|
+
live = false;
|
|
1838
|
+
};
|
|
1839
|
+
}, [client, userId]);
|
|
1840
|
+
const profile = lookup?.status === "ok" ? lookup.profile : fallbackProfile(userId, hint, lookup?.status !== "hidden");
|
|
1841
|
+
const fallbackUrl = lookup?.status === "not_supported" ? getProfileUrl?.(userId) ?? null : null;
|
|
1842
|
+
const primary = profile.current ? { url: profile.current.profileUrl, label: labels.viewSiteProfile(profile.current.siteName) } : fallbackUrl ? { url: fallbackUrl, label: labels.viewSiteProfile("") } : null;
|
|
1843
|
+
const showHandle = !!profile.handle && profile.handle.toLowerCase() !== profile.name.toLowerCase();
|
|
1844
|
+
const showMessage = !hideMessage && lookup !== null && profile.canMessage;
|
|
1845
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
|
|
1846
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1847
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsxRuntime.jsx(ChevronLeft2, {}) }),
|
|
1848
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title" }),
|
|
1849
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon2, {}) })
|
|
1850
|
+
] }),
|
|
1851
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-profile", children: [
|
|
1852
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-profile-head", children: [
|
|
1853
|
+
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: profile.name, url: profile.avatarUrl, size: 64 }),
|
|
1854
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-profile-names", children: [
|
|
1855
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-profile-name", children: profile.name }),
|
|
1856
|
+
showHandle && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-profile-handle", children: [
|
|
1857
|
+
"@",
|
|
1858
|
+
profile.handle
|
|
1859
|
+
] })
|
|
1860
|
+
] })
|
|
1861
|
+
] }),
|
|
1862
|
+
profile.bio && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "dtc-profile-bio", children: profile.bio }),
|
|
1863
|
+
primary && /* @__PURE__ */ jsxRuntime.jsx("a", { className: "dtc-btn dtc-btn-primary dtc-profile-primary", href: primary.url, onClick: onNavigate, children: primary.label }),
|
|
1864
|
+
profile.apps.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-profile-sites", children: [
|
|
1865
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-profile-sites-title", children: labels.alsoOn }),
|
|
1866
|
+
profile.apps.map((site) => {
|
|
1867
|
+
const body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1868
|
+
site.iconUrl ? /* @__PURE__ */ jsxRuntime.jsx("img", { className: "dtc-profile-site-icon", src: site.iconUrl, alt: "" }) : /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: site.siteName, size: 20, className: "dtc-profile-site-icon" }),
|
|
1869
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-profile-site-name", children: site.siteName }),
|
|
1870
|
+
site.url && /* @__PURE__ */ jsxRuntime.jsx(ArrowIcon, {})
|
|
1871
|
+
] });
|
|
1872
|
+
return site.url ? /* @__PURE__ */ jsxRuntime.jsx("a", { className: "dtc-profile-site", href: site.url, target: "_blank", rel: "noopener noreferrer", children: body }, site.appId) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-profile-site", children: body }, site.appId);
|
|
1873
|
+
})
|
|
1874
|
+
] }),
|
|
1875
|
+
showMessage && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1876
|
+
"button",
|
|
1877
|
+
{
|
|
1878
|
+
type: "button",
|
|
1879
|
+
className: "dtc-btn dtc-profile-message",
|
|
1880
|
+
onClick: () => onMessage(userId, { name: profile.name, avatarUrl: profile.avatarUrl }),
|
|
1881
|
+
children: labels.message
|
|
1882
|
+
}
|
|
1883
|
+
),
|
|
1884
|
+
profileActions && lookup !== null && lookup.status !== "hidden" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-profile-actions", children: profileActions(profile) })
|
|
1885
|
+
] })
|
|
1886
|
+
] });
|
|
1887
|
+
}
|
|
1888
|
+
function ChevronLeft2() {
|
|
1889
|
+
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" }) });
|
|
1890
|
+
}
|
|
1891
|
+
function CloseIcon2() {
|
|
1892
|
+
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" }) });
|
|
1893
|
+
}
|
|
1894
|
+
function ArrowIcon() {
|
|
1895
|
+
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
|
+
}
|
|
1698
1897
|
var RAIL_WIDTH = 64;
|
|
1699
1898
|
var EDGE_SWIPE_ZONE = 24;
|
|
1700
1899
|
var SWIPE_DISTANCE = 60;
|
|
@@ -1711,7 +1910,9 @@ function DialtribeMessages({
|
|
|
1711
1910
|
railDmLimit = 5,
|
|
1712
1911
|
mobileBreakpoint = 768,
|
|
1713
1912
|
confirm: hostConfirm,
|
|
1714
|
-
notifications = false
|
|
1913
|
+
notifications = false,
|
|
1914
|
+
getProfileUrl,
|
|
1915
|
+
profileActions
|
|
1715
1916
|
}) {
|
|
1716
1917
|
const labels = react.useMemo(() => ({ ...DEFAULT_LABELS, ...labelOverrides }), [labelOverrides]);
|
|
1717
1918
|
const inbox = useChatRooms();
|
|
@@ -1778,6 +1979,14 @@ function DialtribeMessages({
|
|
|
1778
1979
|
item.id
|
|
1779
1980
|
);
|
|
1780
1981
|
};
|
|
1982
|
+
const client = useChatClient();
|
|
1983
|
+
const openProfile = (userId, hint) => ui.openProfile(userId, hint);
|
|
1984
|
+
const hideMessageFor = (userId, from) => {
|
|
1985
|
+
if (client.self?.userId === userId) return true;
|
|
1986
|
+
if (from.kind !== "room") return false;
|
|
1987
|
+
const room = inbox.rooms.find((r) => r.roomId === from.roomId);
|
|
1988
|
+
return room?.kind === "dm" && room.participants[0]?.userId === userId;
|
|
1989
|
+
};
|
|
1781
1990
|
const style = { ...themeVars(theme), "--dtc-panel-width": `${panelWidth}px`, "--dtc-rail-width": `${RAIL_WIDTH}px` };
|
|
1782
1991
|
const showRail = !isMobile || isOpen;
|
|
1783
1992
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -1792,10 +2001,38 @@ function DialtribeMessages({
|
|
|
1792
2001
|
rollup > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
|
|
1793
2002
|
] }),
|
|
1794
2003
|
isOpen && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: [
|
|
1795
|
-
view.kind === "
|
|
2004
|
+
view.kind === "profile" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2005
|
+
ProfileView,
|
|
2006
|
+
{
|
|
2007
|
+
userId: view.userId,
|
|
2008
|
+
hint: view.hint,
|
|
2009
|
+
labels,
|
|
2010
|
+
onBack: ui.back,
|
|
2011
|
+
onClose: ui.close,
|
|
2012
|
+
onNavigate: () => {
|
|
2013
|
+
if (isMobile) ui.close();
|
|
2014
|
+
},
|
|
2015
|
+
onMessage: (userId, hint) => void ui.messageUser(userId, { name: hint.name, avatarUrl: hint.avatarUrl ?? void 0 }).catch(() => {
|
|
2016
|
+
}),
|
|
2017
|
+
hideMessage: hideMessageFor(view.userId, view.from),
|
|
2018
|
+
getProfileUrl,
|
|
2019
|
+
profileActions
|
|
2020
|
+
},
|
|
2021
|
+
view.userId
|
|
2022
|
+
) : view.kind === "notifications" && notifications !== false ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2023
|
+
NotificationsPanel,
|
|
2024
|
+
{
|
|
2025
|
+
labels,
|
|
2026
|
+
onClose: ui.close,
|
|
2027
|
+
onOpen: notifOnOpen,
|
|
2028
|
+
onOpened: () => {
|
|
2029
|
+
if (isMobile) ui.close();
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
) : 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: [
|
|
1796
2033
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
|
|
1797
2034
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
|
|
1798
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
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, {}) })
|
|
1799
2036
|
] }),
|
|
1800
2037
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1801
2038
|
MessagesInbox,
|
|
@@ -1812,9 +2049,18 @@ function DialtribeMessages({
|
|
|
1812
2049
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1813
2050
|
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
|
|
1814
2051
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: activeContext.label }),
|
|
1815
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
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, {}) })
|
|
1816
2053
|
] }),
|
|
1817
|
-
/* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2054
|
+
/* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2055
|
+
ChatPanel,
|
|
2056
|
+
{
|
|
2057
|
+
showHeader: false,
|
|
2058
|
+
emptyLabel: labels.noMessages,
|
|
2059
|
+
placeholder: labels.messagePlaceholder,
|
|
2060
|
+
onAuthorClick: (a) => openProfile(a.userId, { name: a.name, avatarUrl: a.avatarUrl }),
|
|
2061
|
+
authorLabel: labels.viewProfileOf
|
|
2062
|
+
}
|
|
2063
|
+
) })
|
|
1818
2064
|
] }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1819
2065
|
ConversationView,
|
|
1820
2066
|
{
|
|
@@ -1822,7 +2068,8 @@ function DialtribeMessages({
|
|
|
1822
2068
|
labels,
|
|
1823
2069
|
onBack: ui.openInbox,
|
|
1824
2070
|
onClose: ui.close,
|
|
1825
|
-
confirm
|
|
2071
|
+
confirm,
|
|
2072
|
+
onOpenProfile: openProfile
|
|
1826
2073
|
},
|
|
1827
2074
|
view.roomId
|
|
1828
2075
|
),
|
|
@@ -2045,7 +2292,7 @@ function useNotificationsBadge(enabled) {
|
|
|
2045
2292
|
const snapshot = react.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
2046
2293
|
return enabled ? snapshot.unreadCount : 0;
|
|
2047
2294
|
}
|
|
2048
|
-
function
|
|
2295
|
+
function CloseIcon3() {
|
|
2049
2296
|
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" }) });
|
|
2050
2297
|
}
|
|
2051
2298
|
|
|
@@ -2060,6 +2307,7 @@ exports.DEFAULT_LABELS = DEFAULT_LABELS;
|
|
|
2060
2307
|
exports.DialtribeChatProvider = DialtribeChatProvider;
|
|
2061
2308
|
exports.DialtribeMessages = DialtribeMessages;
|
|
2062
2309
|
exports.NotificationsPanel = NotificationsPanel;
|
|
2310
|
+
exports.ProfileView = ProfileView;
|
|
2063
2311
|
exports.parseReactions = parseReactions;
|
|
2064
2312
|
exports.useChatClient = useChatClient;
|
|
2065
2313
|
exports.useChatConnection = useChatConnection;
|