@dialtribe/chat-client 0.3.0 → 0.5.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 +49 -2
- package/dist/index.d.mts +188 -4
- package/dist/index.d.ts +188 -4
- package/dist/index.js +586 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +585 -42
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -330,6 +330,19 @@ var InboxStore = class extends Store {
|
|
|
330
330
|
this.patchRoom(roomId, (room) => ({ ...room, isMuted: muted }));
|
|
331
331
|
await this.client.dm("chat-dm-mute", { roomId, muted });
|
|
332
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Archive or unarchive for the signed-in user only (optimistic). The room
|
|
335
|
+
* leaves the rail but stays in the inbox; new messages don't unarchive it.
|
|
336
|
+
*/
|
|
337
|
+
async setArchived(roomId, archived) {
|
|
338
|
+
this.patchRoom(roomId, (room) => ({ ...room, isArchived: archived }));
|
|
339
|
+
try {
|
|
340
|
+
await this.client.dm("chat-dm-archive", { roomId, archived });
|
|
341
|
+
} catch (err) {
|
|
342
|
+
this.patchRoom(roomId, (room) => ({ ...room, isArchived: !archived }));
|
|
343
|
+
throw err;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
333
346
|
/** Mark a room read now (optimistic). */
|
|
334
347
|
async markRead(roomId) {
|
|
335
348
|
this.patchRoom(roomId, (room) => room.unreadCount === 0 ? room : { ...room, unreadCount: 0 });
|
|
@@ -455,6 +468,156 @@ var InboxStore = class extends Store {
|
|
|
455
468
|
}
|
|
456
469
|
};
|
|
457
470
|
|
|
471
|
+
// src/client/NotificationsStore.ts
|
|
472
|
+
var NotificationsStore = class extends Store {
|
|
473
|
+
constructor(client) {
|
|
474
|
+
super({ status: "idle", items: [], unreadCount: 0, hasMore: false, loadingMore: false, error: null });
|
|
475
|
+
this.client = client;
|
|
476
|
+
this.refs = 0;
|
|
477
|
+
this.unlisten = [];
|
|
478
|
+
this.refreshTimer = null;
|
|
479
|
+
this.nextCursor = null;
|
|
480
|
+
}
|
|
481
|
+
acquire() {
|
|
482
|
+
this.refs += 1;
|
|
483
|
+
if (this.refs > 1) return;
|
|
484
|
+
this.unlisten = [
|
|
485
|
+
this.client.on("connected", () => this.scheduleRefresh(0)),
|
|
486
|
+
this.client.on("user", (event) => this.onUserEvent(event))
|
|
487
|
+
];
|
|
488
|
+
void this.client.start();
|
|
489
|
+
this.scheduleRefresh(0);
|
|
490
|
+
}
|
|
491
|
+
release() {
|
|
492
|
+
this.refs = Math.max(0, this.refs - 1);
|
|
493
|
+
if (this.refs > 0) return;
|
|
494
|
+
for (const off of this.unlisten) off();
|
|
495
|
+
this.unlisten = [];
|
|
496
|
+
if (this.refreshTimer) clearTimeout(this.refreshTimer);
|
|
497
|
+
}
|
|
498
|
+
// ===========================================================================
|
|
499
|
+
// Actions
|
|
500
|
+
// ===========================================================================
|
|
501
|
+
/** Reload the first page and the unread count. */
|
|
502
|
+
async refresh() {
|
|
503
|
+
if (this.getSnapshot().status === "idle") this.update({ status: "loading" });
|
|
504
|
+
try {
|
|
505
|
+
const page = await this.client.api("/notifications/inbox?limit=30");
|
|
506
|
+
this.nextCursor = page.nextCursor;
|
|
507
|
+
this.update({
|
|
508
|
+
status: "ready",
|
|
509
|
+
items: page.items,
|
|
510
|
+
unreadCount: page.unreadCount,
|
|
511
|
+
hasMore: page.nextCursor !== null,
|
|
512
|
+
error: null
|
|
513
|
+
});
|
|
514
|
+
} catch (err) {
|
|
515
|
+
this.update({
|
|
516
|
+
status: "error",
|
|
517
|
+
error: err instanceof ChatRequestError ? err : new ChatRequestError("network", "Could not load notifications")
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
/** Append the next (older) page. */
|
|
522
|
+
async loadMore() {
|
|
523
|
+
const snap = this.getSnapshot();
|
|
524
|
+
if (!this.nextCursor || snap.loadingMore) return;
|
|
525
|
+
this.update({ loadingMore: true });
|
|
526
|
+
try {
|
|
527
|
+
const page = await this.client.api(
|
|
528
|
+
`/notifications/inbox?limit=30&cursor=${encodeURIComponent(this.nextCursor)}`
|
|
529
|
+
);
|
|
530
|
+
this.nextCursor = page.nextCursor;
|
|
531
|
+
const have = new Set(this.getSnapshot().items.map((i) => i.id));
|
|
532
|
+
this.update({
|
|
533
|
+
items: [...this.getSnapshot().items, ...page.items.filter((i) => !have.has(i.id))],
|
|
534
|
+
hasMore: page.nextCursor !== null,
|
|
535
|
+
unreadCount: page.unreadCount
|
|
536
|
+
});
|
|
537
|
+
} finally {
|
|
538
|
+
this.update({ loadingMore: false });
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/** Mark items read (optimistic). */
|
|
542
|
+
async markRead(ids) {
|
|
543
|
+
const unread = ids.filter((id) => this.getSnapshot().items.some((i) => i.id === id && !i.readAt));
|
|
544
|
+
if (unread.length === 0) return;
|
|
545
|
+
this.applyRead(unread, Math.max(0, this.getSnapshot().unreadCount - unread.length));
|
|
546
|
+
const { unreadCount } = await this.client.api("/notifications/inbox", {
|
|
547
|
+
method: "POST",
|
|
548
|
+
body: { action: "read", ids: unread }
|
|
549
|
+
});
|
|
550
|
+
this.update({ unreadCount });
|
|
551
|
+
}
|
|
552
|
+
/** Mark everything read (optimistic). */
|
|
553
|
+
async markAllRead() {
|
|
554
|
+
this.applyRead(null, 0);
|
|
555
|
+
const { unreadCount } = await this.client.api("/notifications/inbox", {
|
|
556
|
+
method: "POST",
|
|
557
|
+
body: { action: "read-all" }
|
|
558
|
+
});
|
|
559
|
+
this.update({ unreadCount });
|
|
560
|
+
}
|
|
561
|
+
/** Record that the list was shown (for stats; doesn't change unread). */
|
|
562
|
+
async markSeen() {
|
|
563
|
+
const unseen = this.getSnapshot().items.filter((i) => !i.seenAt).map((i) => i.id);
|
|
564
|
+
if (unseen.length === 0) return;
|
|
565
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
566
|
+
const set = new Set(unseen);
|
|
567
|
+
this.update({ items: this.getSnapshot().items.map((i) => set.has(i.id) ? { ...i, seenAt: now } : i) });
|
|
568
|
+
await this.client.api("/notifications/inbox", { method: "POST", body: { action: "seen", ids: unseen } });
|
|
569
|
+
}
|
|
570
|
+
/** Record a click (also marks read). Pass every id in a grouped row. */
|
|
571
|
+
async click(ids) {
|
|
572
|
+
if (ids.length === 0) return;
|
|
573
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
574
|
+
const set = new Set(ids);
|
|
575
|
+
const newlyRead = this.getSnapshot().items.filter((i) => set.has(i.id) && !i.readAt).length;
|
|
576
|
+
this.update({
|
|
577
|
+
items: this.getSnapshot().items.map(
|
|
578
|
+
(i) => set.has(i.id) ? { ...i, clickedAt: i.clickedAt ?? now, readAt: i.readAt ?? now } : i
|
|
579
|
+
),
|
|
580
|
+
unreadCount: Math.max(0, this.getSnapshot().unreadCount - newlyRead)
|
|
581
|
+
});
|
|
582
|
+
const { unreadCount } = await this.client.api("/notifications/inbox", {
|
|
583
|
+
method: "POST",
|
|
584
|
+
body: { action: "click", ids }
|
|
585
|
+
});
|
|
586
|
+
this.update({ unreadCount });
|
|
587
|
+
}
|
|
588
|
+
// ===========================================================================
|
|
589
|
+
// Live updates
|
|
590
|
+
// ===========================================================================
|
|
591
|
+
onUserEvent(event) {
|
|
592
|
+
if (event.type === "notification.created") {
|
|
593
|
+
const items = this.getSnapshot().items;
|
|
594
|
+
if (items.some((i) => i.id === event.notification.id)) return;
|
|
595
|
+
this.update({
|
|
596
|
+
items: [event.notification, ...items],
|
|
597
|
+
unreadCount: typeof event.unreadCount === "number" ? event.unreadCount : this.getSnapshot().unreadCount + (event.notification.readAt ? 0 : 1)
|
|
598
|
+
});
|
|
599
|
+
} else if (event.type === "notification.read") {
|
|
600
|
+
this.applyRead(event.ids, event.unreadCount);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
applyRead(ids, unreadCount) {
|
|
604
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
605
|
+
const set = ids ? new Set(ids) : null;
|
|
606
|
+
this.update({
|
|
607
|
+
items: this.getSnapshot().items.map((i) => !i.readAt && (!set || set.has(i.id)) ? { ...i, readAt: now } : i),
|
|
608
|
+
unreadCount
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
scheduleRefresh(delayMs) {
|
|
612
|
+
if (this.refs === 0) return;
|
|
613
|
+
if (this.refreshTimer) clearTimeout(this.refreshTimer);
|
|
614
|
+
this.refreshTimer = setTimeout(() => {
|
|
615
|
+
this.refreshTimer = null;
|
|
616
|
+
void this.refresh();
|
|
617
|
+
}, delayMs);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
|
|
458
621
|
// src/client/ChatClient.ts
|
|
459
622
|
var ConnectionStore = class extends Store {
|
|
460
623
|
set(patch) {
|
|
@@ -474,7 +637,9 @@ var ChatClient = class {
|
|
|
474
637
|
this.generation = 0;
|
|
475
638
|
this.rooms = /* @__PURE__ */ new Map();
|
|
476
639
|
this.inboxStore = null;
|
|
640
|
+
this.notificationsStore = null;
|
|
477
641
|
this.serverUrl = options.serverUrl.replace(/\/$/, "");
|
|
642
|
+
this.apiUrl = (options.apiUrl ?? "https://dialtribe.com").replace(/\/$/, "");
|
|
478
643
|
}
|
|
479
644
|
// ===========================================================================
|
|
480
645
|
// Lifecycle
|
|
@@ -516,6 +681,11 @@ var ChatClient = class {
|
|
|
516
681
|
this.inboxStore ?? (this.inboxStore = new InboxStore(this));
|
|
517
682
|
return this.inboxStore;
|
|
518
683
|
}
|
|
684
|
+
/** The signed-in user's notifications (created on first use). */
|
|
685
|
+
get notifications() {
|
|
686
|
+
this.notificationsStore ?? (this.notificationsStore = new NotificationsStore(this));
|
|
687
|
+
return this.notificationsStore;
|
|
688
|
+
}
|
|
519
689
|
get self() {
|
|
520
690
|
return this.connection.getSnapshot().self;
|
|
521
691
|
}
|
|
@@ -635,6 +805,13 @@ var ChatClient = class {
|
|
|
635
805
|
users(roomId) {
|
|
636
806
|
return this.request(`/rooms/${encodeURIComponent(roomId)}/users`);
|
|
637
807
|
}
|
|
808
|
+
/**
|
|
809
|
+
* Authenticated JSON request to the Dialtribe API (apiUrl), with the same
|
|
810
|
+
* session token and 401 retry as chat-ws requests. `path` is under /api/public/v1.
|
|
811
|
+
*/
|
|
812
|
+
api(path, init = {}) {
|
|
813
|
+
return this.request(path, init, `${this.apiUrl}/api/public/v1`);
|
|
814
|
+
}
|
|
638
815
|
/** A DM action on POST /dm (see DMS.md). */
|
|
639
816
|
dm(action, fields = {}) {
|
|
640
817
|
return this.request("/dm", { method: "POST", body: { action, ...fields } });
|
|
@@ -644,8 +821,8 @@ var ChatClient = class {
|
|
|
644
821
|
* token on 401. Throws ChatRequestError for transport failures and for
|
|
645
822
|
* `{ ok: false, error }` bodies.
|
|
646
823
|
*/
|
|
647
|
-
async request(path, init = {}) {
|
|
648
|
-
const attempt = async (token) => fetch(
|
|
824
|
+
async request(path, init = {}, base = this.serverUrl) {
|
|
825
|
+
const attempt = async (token) => fetch(base + path, {
|
|
649
826
|
method: init.method ?? "GET",
|
|
650
827
|
headers: {
|
|
651
828
|
Authorization: `Bearer ${token}`,
|
|
@@ -706,17 +883,20 @@ var MessagesUiStore = class extends Store {
|
|
|
706
883
|
openRoom(roomId) {
|
|
707
884
|
this.update({ open: true, view: { kind: "room", roomId } });
|
|
708
885
|
}
|
|
886
|
+
openNotifications() {
|
|
887
|
+
this.update({ open: true, view: { kind: "notifications" } });
|
|
888
|
+
}
|
|
709
889
|
openItem(itemId) {
|
|
710
890
|
this.update({ open: true, view: { kind: "item", itemId } });
|
|
711
891
|
}
|
|
712
892
|
};
|
|
713
893
|
var ClientContext = react.createContext(null);
|
|
714
894
|
var MessagesUiContext = react.createContext(null);
|
|
715
|
-
function DialtribeChatProvider({ children, getSessionToken, serverUrl, websocketUrl, websocket }) {
|
|
895
|
+
function DialtribeChatProvider({ children, getSessionToken, serverUrl, apiUrl, websocketUrl, websocket }) {
|
|
716
896
|
const tokenRef = react.useRef(getSessionToken);
|
|
717
897
|
tokenRef.current = getSessionToken;
|
|
718
898
|
const [client] = react.useState(
|
|
719
|
-
() => new ChatClient({ serverUrl, websocketUrl, websocket, getSessionToken: () => tokenRef.current() })
|
|
899
|
+
() => new ChatClient({ serverUrl, apiUrl, websocketUrl, websocket, getSessionToken: () => tokenRef.current() })
|
|
720
900
|
);
|
|
721
901
|
const [messagesUi] = react.useState(() => new MessagesUiStore());
|
|
722
902
|
react.useEffect(() => {
|
|
@@ -797,6 +977,7 @@ function useChatRooms() {
|
|
|
797
977
|
hideDM: inbox.hideDM.bind(inbox),
|
|
798
978
|
addParticipant: inbox.addParticipant.bind(inbox),
|
|
799
979
|
setMuted: inbox.setMuted.bind(inbox),
|
|
980
|
+
setArchived: inbox.setArchived.bind(inbox),
|
|
800
981
|
markRead: inbox.markRead.bind(inbox),
|
|
801
982
|
setVisible: inbox.setVisible.bind(inbox),
|
|
802
983
|
refresh: inbox.refresh.bind(inbox)
|
|
@@ -821,6 +1002,7 @@ function useDialtribeMessages() {
|
|
|
821
1002
|
openInbox: () => ui.openInbox(),
|
|
822
1003
|
openRoom: (roomId) => ui.openRoom(roomId),
|
|
823
1004
|
openItem: (itemId) => ui.openItem(itemId),
|
|
1005
|
+
openNotifications: () => ui.openNotifications(),
|
|
824
1006
|
messageUser: async (userId, hint) => {
|
|
825
1007
|
const result = await client.inbox.requestDM(userId, hint);
|
|
826
1008
|
ui.openRoom(result.roomId);
|
|
@@ -831,6 +1013,26 @@ function useDialtribeMessages() {
|
|
|
831
1013
|
);
|
|
832
1014
|
return react.useMemo(() => ({ isOpen: snapshot.open, view: snapshot.view, ...actions }), [snapshot, actions]);
|
|
833
1015
|
}
|
|
1016
|
+
function useDialtribeNotifications() {
|
|
1017
|
+
const store = useChatClient().notifications;
|
|
1018
|
+
react.useEffect(() => {
|
|
1019
|
+
store.acquire();
|
|
1020
|
+
return () => store.release();
|
|
1021
|
+
}, [store]);
|
|
1022
|
+
const snapshot = react.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
1023
|
+
const actions = react.useMemo(
|
|
1024
|
+
() => ({
|
|
1025
|
+
refresh: store.refresh.bind(store),
|
|
1026
|
+
loadMore: store.loadMore.bind(store),
|
|
1027
|
+
markRead: store.markRead.bind(store),
|
|
1028
|
+
markAllRead: store.markAllRead.bind(store),
|
|
1029
|
+
markSeen: store.markSeen.bind(store),
|
|
1030
|
+
click: store.click.bind(store)
|
|
1031
|
+
}),
|
|
1032
|
+
[store]
|
|
1033
|
+
);
|
|
1034
|
+
return react.useMemo(() => ({ ...snapshot, ...actions }), [snapshot, actions]);
|
|
1035
|
+
}
|
|
834
1036
|
|
|
835
1037
|
// src/types/index.ts
|
|
836
1038
|
function parseReactions(reactionsJson) {
|
|
@@ -1132,16 +1334,44 @@ var DEFAULT_LABELS = {
|
|
|
1132
1334
|
reopen: "Reopen",
|
|
1133
1335
|
closeConversation: "Close conversation",
|
|
1134
1336
|
removeConversation: "Remove from inbox",
|
|
1135
|
-
mute: "Mute",
|
|
1136
|
-
unmute: "Unmute",
|
|
1337
|
+
mute: "Mute notifications",
|
|
1338
|
+
unmute: "Unmute notifications",
|
|
1339
|
+
archive: "Archive conversation",
|
|
1340
|
+
unarchive: "Unarchive conversation",
|
|
1341
|
+
archived: "Archived",
|
|
1342
|
+
moreOptions: "More options",
|
|
1343
|
+
muteConfirmTitle: (name) => `Mute notifications from ${name}?`,
|
|
1344
|
+
muteConfirmBody: "You won't get alerts or unread badges for this conversation. Messages still arrive.",
|
|
1345
|
+
muteConfirm: "Mute",
|
|
1346
|
+
archiveConfirmTitle: (name) => `Archive your conversation with ${name}?`,
|
|
1347
|
+
archiveConfirmBody: "It moves off your rail and into Archived in Messages. New messages still count toward your unread. Only you will see that it's archived.",
|
|
1348
|
+
archiveConfirm: "Archive",
|
|
1349
|
+
cancel: "Cancel",
|
|
1137
1350
|
messagePlaceholder: "Message...",
|
|
1138
|
-
openMessages: "Open messages"
|
|
1351
|
+
openMessages: "Open messages",
|
|
1352
|
+
notifications: "Notifications",
|
|
1353
|
+
noNotifications: "No notifications yet",
|
|
1354
|
+
markAllRead: "Mark all read",
|
|
1355
|
+
loadMore: "Load more",
|
|
1356
|
+
groupMore: (count) => `and ${count} more`,
|
|
1357
|
+
timeAgo: (date) => {
|
|
1358
|
+
const s = Math.max(0, Math.floor((Date.now() - date.getTime()) / 1e3));
|
|
1359
|
+
if (s < 60) return "now";
|
|
1360
|
+
if (s < 3600) return `${Math.floor(s / 60)}m`;
|
|
1361
|
+
if (s < 86400) return `${Math.floor(s / 3600)}h`;
|
|
1362
|
+
if (s < 604800) return `${Math.floor(s / 86400)}d`;
|
|
1363
|
+
return date.toLocaleDateString(void 0, { month: "short", day: "numeric" });
|
|
1364
|
+
}
|
|
1139
1365
|
};
|
|
1140
1366
|
function badgeText(count) {
|
|
1141
1367
|
return count > 99 ? "99+" : String(count);
|
|
1142
1368
|
}
|
|
1143
1369
|
function MessagesInbox({ rooms, requests, labels, onOpenRoom, onRemoveRoom }) {
|
|
1144
|
-
const
|
|
1370
|
+
const [showArchived, setShowArchived] = react.useState(false);
|
|
1371
|
+
const accepted = rooms.filter((r) => r.myStatus === "accepted");
|
|
1372
|
+
const conversations = accepted.filter((r) => !r.isArchived);
|
|
1373
|
+
const archived = accepted.filter((r) => r.isArchived);
|
|
1374
|
+
const archivedUnread = archived.reduce((sum, r) => sum + (r.isMuted ? 0 : r.unreadCount), 0);
|
|
1145
1375
|
if (rooms.length === 0) return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: labels.noMessages });
|
|
1146
1376
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-inbox", children: [
|
|
1147
1377
|
requests.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "dtc-inbox-section", children: [
|
|
@@ -1157,7 +1387,29 @@ function MessagesInbox({ rooms, requests, labels, onOpenRoom, onRemoveRoom }) {
|
|
|
1157
1387
|
removeLabel: labels.removeConversation
|
|
1158
1388
|
},
|
|
1159
1389
|
room.roomId
|
|
1160
|
-
)) })
|
|
1390
|
+
)) }),
|
|
1391
|
+
archived.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "dtc-inbox-section", children: [
|
|
1392
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1393
|
+
"button",
|
|
1394
|
+
{
|
|
1395
|
+
type: "button",
|
|
1396
|
+
className: "dtc-inbox-heading dtc-inbox-toggle",
|
|
1397
|
+
"aria-expanded": showArchived,
|
|
1398
|
+
onClick: () => setShowArchived((v) => !v),
|
|
1399
|
+
children: [
|
|
1400
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
1401
|
+
labels.archived,
|
|
1402
|
+
" (",
|
|
1403
|
+
archived.length,
|
|
1404
|
+
")"
|
|
1405
|
+
] }),
|
|
1406
|
+
!showArchived && archivedUnread > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count", children: badgeText(archivedUnread) }),
|
|
1407
|
+
/* @__PURE__ */ jsxRuntime.jsx("svg", { className: "dtc-inbox-toggle-icon", 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: "M6 9l6 6 6-6" }) })
|
|
1408
|
+
]
|
|
1409
|
+
}
|
|
1410
|
+
),
|
|
1411
|
+
showArchived && archived.map((room) => /* @__PURE__ */ jsxRuntime.jsx(InboxRow, { room, onOpen: onOpenRoom }, room.roomId))
|
|
1412
|
+
] })
|
|
1161
1413
|
] });
|
|
1162
1414
|
}
|
|
1163
1415
|
function InboxRow({
|
|
@@ -1190,7 +1442,78 @@ function InboxRow({
|
|
|
1190
1442
|
)
|
|
1191
1443
|
] });
|
|
1192
1444
|
}
|
|
1193
|
-
function
|
|
1445
|
+
function ConversationMenu({ label, items }) {
|
|
1446
|
+
const [open, setOpen] = react.useState(false);
|
|
1447
|
+
const rootRef = react.useRef(null);
|
|
1448
|
+
const buttonRef = react.useRef(null);
|
|
1449
|
+
const menuRef = react.useRef(null);
|
|
1450
|
+
react.useEffect(() => {
|
|
1451
|
+
if (!open) return;
|
|
1452
|
+
menuRef.current?.querySelector("[role=menuitem]")?.focus();
|
|
1453
|
+
const onPointer = (e) => {
|
|
1454
|
+
if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
|
|
1455
|
+
};
|
|
1456
|
+
const onKey = (e) => {
|
|
1457
|
+
if (e.key !== "Escape") return;
|
|
1458
|
+
e.preventDefault();
|
|
1459
|
+
setOpen(false);
|
|
1460
|
+
buttonRef.current?.focus();
|
|
1461
|
+
};
|
|
1462
|
+
document.addEventListener("pointerdown", onPointer);
|
|
1463
|
+
window.addEventListener("keydown", onKey, true);
|
|
1464
|
+
return () => {
|
|
1465
|
+
document.removeEventListener("pointerdown", onPointer);
|
|
1466
|
+
window.removeEventListener("keydown", onKey, true);
|
|
1467
|
+
};
|
|
1468
|
+
}, [open]);
|
|
1469
|
+
const onMenuKey = (e) => {
|
|
1470
|
+
if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return;
|
|
1471
|
+
e.preventDefault();
|
|
1472
|
+
const buttons = Array.from(menuRef.current?.querySelectorAll("[role=menuitem]") ?? []);
|
|
1473
|
+
const i = buttons.indexOf(document.activeElement);
|
|
1474
|
+
const next = e.key === "ArrowDown" ? (i + 1) % buttons.length : (i - 1 + buttons.length) % buttons.length;
|
|
1475
|
+
buttons[next]?.focus();
|
|
1476
|
+
};
|
|
1477
|
+
if (items.length === 0) return null;
|
|
1478
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-menu-root", ref: rootRef, children: [
|
|
1479
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1480
|
+
"button",
|
|
1481
|
+
{
|
|
1482
|
+
ref: buttonRef,
|
|
1483
|
+
type: "button",
|
|
1484
|
+
className: "dtc-icon-btn",
|
|
1485
|
+
"aria-label": label,
|
|
1486
|
+
title: label,
|
|
1487
|
+
"aria-haspopup": "menu",
|
|
1488
|
+
"aria-expanded": open,
|
|
1489
|
+
onClick: () => setOpen((v) => !v),
|
|
1490
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(KebabIcon, {})
|
|
1491
|
+
}
|
|
1492
|
+
),
|
|
1493
|
+
open && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-menu", role: "menu", ref: menuRef, onKeyDown: onMenuKey, children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1494
|
+
"button",
|
|
1495
|
+
{
|
|
1496
|
+
type: "button",
|
|
1497
|
+
role: "menuitem",
|
|
1498
|
+
className: "dtc-menu-item",
|
|
1499
|
+
onClick: () => {
|
|
1500
|
+
setOpen(false);
|
|
1501
|
+
item.onSelect();
|
|
1502
|
+
},
|
|
1503
|
+
children: item.label
|
|
1504
|
+
},
|
|
1505
|
+
item.id
|
|
1506
|
+
)) })
|
|
1507
|
+
] });
|
|
1508
|
+
}
|
|
1509
|
+
function KebabIcon() {
|
|
1510
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "currentColor", "aria-hidden": "true", children: [
|
|
1511
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "5", r: "1.8" }),
|
|
1512
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "1.8" }),
|
|
1513
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "19", r: "1.8" })
|
|
1514
|
+
] });
|
|
1515
|
+
}
|
|
1516
|
+
function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
|
|
1194
1517
|
const inbox = useChatRooms();
|
|
1195
1518
|
const room = inbox.rooms.find((r) => r.roomId === roomId);
|
|
1196
1519
|
const { setVisible } = inbox;
|
|
@@ -1198,16 +1521,49 @@ function ConversationView({ roomId, labels, onBack }) {
|
|
|
1198
1521
|
const isRequest = room?.myStatus === "pending";
|
|
1199
1522
|
const isClosed = room?.state === "closed";
|
|
1200
1523
|
const waitingOnThem = !isRequest && !!room && room.participants.length > 0 && room.participants.every((p) => p.status === "pending");
|
|
1524
|
+
const menuItems = [];
|
|
1525
|
+
if (room && !isRequest) {
|
|
1526
|
+
menuItems.push({
|
|
1527
|
+
id: "mute",
|
|
1528
|
+
label: room.isMuted ? labels.unmute : labels.mute,
|
|
1529
|
+
onSelect: async () => {
|
|
1530
|
+
if (room.isMuted) return void inbox.setMuted(roomId, false).catch(() => {
|
|
1531
|
+
});
|
|
1532
|
+
const ok = await confirm({
|
|
1533
|
+
title: labels.muteConfirmTitle(room.name),
|
|
1534
|
+
body: labels.muteConfirmBody,
|
|
1535
|
+
confirmLabel: labels.muteConfirm,
|
|
1536
|
+
cancelLabel: labels.cancel
|
|
1537
|
+
});
|
|
1538
|
+
if (ok) void inbox.setMuted(roomId, true).catch(() => {
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1542
|
+
menuItems.push({
|
|
1543
|
+
id: "archive",
|
|
1544
|
+
label: room.isArchived ? labels.unarchive : labels.archive,
|
|
1545
|
+
onSelect: async () => {
|
|
1546
|
+
if (room.isArchived) return void inbox.setArchived(roomId, false).catch(() => {
|
|
1547
|
+
});
|
|
1548
|
+
const ok = await confirm({
|
|
1549
|
+
title: labels.archiveConfirmTitle(room.name),
|
|
1550
|
+
body: labels.archiveConfirmBody,
|
|
1551
|
+
confirmLabel: labels.archiveConfirm,
|
|
1552
|
+
cancelLabel: labels.cancel
|
|
1553
|
+
});
|
|
1554
|
+
if (ok) void inbox.setArchived(roomId, true).catch(() => {
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1201
1559
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
|
|
1202
1560
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1203
1561
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsxRuntime.jsx(ChevronLeft, {}) }),
|
|
1204
1562
|
room && /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 28 }),
|
|
1205
1563
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" }),
|
|
1206
|
-
|
|
1207
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1208
|
-
|
|
1209
|
-
!isClosed && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-text-btn", onClick: () => void inbox.closeDM(roomId).catch(() => {
|
|
1210
|
-
}), children: labels.closeConversation })
|
|
1564
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-conversation-actions", children: [
|
|
1565
|
+
/* @__PURE__ */ jsxRuntime.jsx(ConversationMenu, { label: labels.moreOptions, items: menuItems }),
|
|
1566
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
|
|
1211
1567
|
] })
|
|
1212
1568
|
] }),
|
|
1213
1569
|
isRequest && room && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-request-banner", role: "region", "aria-label": labels.requests, children: [
|
|
@@ -1246,9 +1602,99 @@ function ConversationView({ roomId, labels, onBack }) {
|
|
|
1246
1602
|
) })
|
|
1247
1603
|
] });
|
|
1248
1604
|
}
|
|
1605
|
+
function CloseIcon() {
|
|
1606
|
+
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" }) });
|
|
1607
|
+
}
|
|
1249
1608
|
function ChevronLeft() {
|
|
1250
1609
|
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" }) });
|
|
1251
1610
|
}
|
|
1611
|
+
function groupRows(items) {
|
|
1612
|
+
const rows = [];
|
|
1613
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
1614
|
+
for (const item of items) {
|
|
1615
|
+
const existing = item.groupKey ? byKey.get(item.groupKey) : void 0;
|
|
1616
|
+
if (existing) {
|
|
1617
|
+
existing.ids.push(item.id);
|
|
1618
|
+
existing.more += 1;
|
|
1619
|
+
existing.unread || (existing.unread = !item.readAt);
|
|
1620
|
+
continue;
|
|
1621
|
+
}
|
|
1622
|
+
const row = { lead: item, ids: [item.id], more: 0, unread: !item.readAt };
|
|
1623
|
+
rows.push(row);
|
|
1624
|
+
if (item.groupKey) byKey.set(item.groupKey, row);
|
|
1625
|
+
}
|
|
1626
|
+
return rows;
|
|
1627
|
+
}
|
|
1628
|
+
function NotificationsPanel({ labels, onClose, onOpen }) {
|
|
1629
|
+
const n = useDialtribeNotifications();
|
|
1630
|
+
const rows = react.useMemo(() => groupRows(n.items), [n.items]);
|
|
1631
|
+
const { status, markSeen } = n;
|
|
1632
|
+
react.useEffect(() => {
|
|
1633
|
+
if (status === "ready") void markSeen().catch(() => {
|
|
1634
|
+
});
|
|
1635
|
+
}, [status, markSeen]);
|
|
1636
|
+
const open = (row) => {
|
|
1637
|
+
void n.click(row.ids).catch(() => {
|
|
1638
|
+
});
|
|
1639
|
+
const handled = onOpen?.(row.lead);
|
|
1640
|
+
if (!handled && row.lead.url) window.location.assign(row.lead.url);
|
|
1641
|
+
};
|
|
1642
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-notif", children: [
|
|
1643
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
|
|
1644
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-panel-title", children: [
|
|
1645
|
+
labels.notifications,
|
|
1646
|
+
n.unreadCount > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-notif-title-badge", children: badgeText(n.unreadCount) })
|
|
1647
|
+
] }),
|
|
1648
|
+
n.unreadCount > 0 && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-notif-markall", onClick: () => void n.markAllRead().catch(() => {
|
|
1649
|
+
}), children: labels.markAllRead }),
|
|
1650
|
+
onClose && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__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" }) }) })
|
|
1651
|
+
] }),
|
|
1652
|
+
n.status !== "ready" && rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: n.status === "error" ? n.error?.message ?? "" : "" }) : rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: labels.noNotifications }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-notif-list", children: [
|
|
1653
|
+
rows.map((row) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1654
|
+
"button",
|
|
1655
|
+
{
|
|
1656
|
+
type: "button",
|
|
1657
|
+
className: `dtc-notif-row ${row.unread ? "dtc-notif-row-unread" : ""}`,
|
|
1658
|
+
onClick: () => open(row),
|
|
1659
|
+
children: [
|
|
1660
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1661
|
+
Avatar,
|
|
1662
|
+
{
|
|
1663
|
+
name: row.lead.actor?.name ?? row.lead.title,
|
|
1664
|
+
url: row.lead.actor?.avatarUrl ?? row.lead.imageUrl,
|
|
1665
|
+
size: 40
|
|
1666
|
+
}
|
|
1667
|
+
),
|
|
1668
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-notif-text", children: [
|
|
1669
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-notif-title", children: row.lead.title }),
|
|
1670
|
+
row.lead.body && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-notif-body", children: row.lead.body }),
|
|
1671
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-notif-meta", children: [
|
|
1672
|
+
labels.timeAgo(new Date(row.lead.createdAt)),
|
|
1673
|
+
row.more > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1674
|
+
" \xB7 ",
|
|
1675
|
+
labels.groupMore(row.more)
|
|
1676
|
+
] })
|
|
1677
|
+
] })
|
|
1678
|
+
] }),
|
|
1679
|
+
row.unread && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-notif-dot", "aria-hidden": "true" })
|
|
1680
|
+
]
|
|
1681
|
+
},
|
|
1682
|
+
row.lead.id
|
|
1683
|
+
)),
|
|
1684
|
+
n.hasMore && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1685
|
+
"button",
|
|
1686
|
+
{
|
|
1687
|
+
type: "button",
|
|
1688
|
+
className: "dtc-btn dtc-notif-more",
|
|
1689
|
+
disabled: n.loadingMore,
|
|
1690
|
+
onClick: () => void n.loadMore().catch(() => {
|
|
1691
|
+
}),
|
|
1692
|
+
children: labels.loadMore
|
|
1693
|
+
}
|
|
1694
|
+
)
|
|
1695
|
+
] })
|
|
1696
|
+
] });
|
|
1697
|
+
}
|
|
1252
1698
|
var RAIL_WIDTH = 64;
|
|
1253
1699
|
var EDGE_SWIPE_ZONE = 24;
|
|
1254
1700
|
var SWIPE_DISTANCE = 60;
|
|
@@ -1263,7 +1709,9 @@ function DialtribeMessages({
|
|
|
1263
1709
|
labels: labelOverrides,
|
|
1264
1710
|
panelWidth = 380,
|
|
1265
1711
|
railDmLimit = 5,
|
|
1266
|
-
mobileBreakpoint = 768
|
|
1712
|
+
mobileBreakpoint = 768,
|
|
1713
|
+
confirm: hostConfirm,
|
|
1714
|
+
notifications = false
|
|
1267
1715
|
}) {
|
|
1268
1716
|
const labels = react.useMemo(() => ({ ...DEFAULT_LABELS, ...labelOverrides }), [labelOverrides]);
|
|
1269
1717
|
const inbox = useChatRooms();
|
|
@@ -1271,8 +1719,24 @@ function DialtribeMessages({
|
|
|
1271
1719
|
const isMobile = useMediaQuery(`(max-width: ${mobileBreakpoint - 1}px)`);
|
|
1272
1720
|
const { isOpen, view } = ui;
|
|
1273
1721
|
const pendingCount = inbox.requests.length;
|
|
1274
|
-
const
|
|
1275
|
-
const
|
|
1722
|
+
const notifUnread = useNotificationsBadge(notifications !== false);
|
|
1723
|
+
const rollup = inbox.totalUnread + pendingCount + notifUnread;
|
|
1724
|
+
const notifOnOpen = typeof notifications === "object" ? notifications.onOpen : void 0;
|
|
1725
|
+
const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted" && !r.isArchived).slice(0, railDmLimit);
|
|
1726
|
+
const [builtInConfirm, setBuiltInConfirm] = react.useState(null);
|
|
1727
|
+
const confirmOpen = react.useRef(false);
|
|
1728
|
+
const confirm = react.useMemo(
|
|
1729
|
+
() => async (options) => {
|
|
1730
|
+
confirmOpen.current = true;
|
|
1731
|
+
try {
|
|
1732
|
+
return hostConfirm ? await hostConfirm(options) : await new Promise((resolve) => setBuiltInConfirm({ options, resolve }));
|
|
1733
|
+
} finally {
|
|
1734
|
+
confirmOpen.current = false;
|
|
1735
|
+
setBuiltInConfirm(null);
|
|
1736
|
+
}
|
|
1737
|
+
},
|
|
1738
|
+
[hostConfirm]
|
|
1739
|
+
);
|
|
1276
1740
|
const activeRoomId = isOpen && view.kind === "room" ? view.roomId : null;
|
|
1277
1741
|
const activeContext = contexts.find((c) => c.roomId === activeRoomId);
|
|
1278
1742
|
const activeItemId = isOpen && view.kind === "item" ? view.itemId : null;
|
|
@@ -1286,15 +1750,18 @@ function DialtribeMessages({
|
|
|
1286
1750
|
useEdgeSwipe(isMobile, isOpen, ui.open, ui.close, side);
|
|
1287
1751
|
react.useEffect(() => {
|
|
1288
1752
|
if (!isOpen) return;
|
|
1289
|
-
const onKey = (e) =>
|
|
1753
|
+
const onKey = (e) => {
|
|
1754
|
+
if (e.key === "Escape" && !e.defaultPrevented && !confirmOpen.current) ui.close();
|
|
1755
|
+
};
|
|
1290
1756
|
window.addEventListener("keydown", onKey);
|
|
1291
1757
|
return () => window.removeEventListener("keydown", onKey);
|
|
1292
1758
|
}, [isOpen, ui]);
|
|
1293
1759
|
const select = (target) => {
|
|
1294
|
-
const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : activeItemId === target.itemId);
|
|
1760
|
+
const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : target.kind === "notifications" ? view.kind === "notifications" : activeItemId === target.itemId);
|
|
1295
1761
|
if (showing) ui.close();
|
|
1296
1762
|
else if (target.kind === "inbox") ui.openInbox();
|
|
1297
1763
|
else if (target.kind === "room") ui.openRoom(target.roomId);
|
|
1764
|
+
else if (target.kind === "notifications") ui.openNotifications();
|
|
1298
1765
|
else ui.openItem(target.itemId);
|
|
1299
1766
|
};
|
|
1300
1767
|
const renderItemButton = (item) => {
|
|
@@ -1324,34 +1791,63 @@ function DialtribeMessages({
|
|
|
1324
1791
|
/* @__PURE__ */ jsxRuntime.jsx(ChatIcon, {}),
|
|
1325
1792
|
rollup > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
|
|
1326
1793
|
] }),
|
|
1327
|
-
isOpen && /* @__PURE__ */ jsxRuntime.
|
|
1328
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1329
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1794
|
+
isOpen && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: [
|
|
1795
|
+
view.kind === "notifications" && notifications !== false ? /* @__PURE__ */ jsxRuntime.jsx(NotificationsPanel, { labels, onClose: ui.close, onOpen: notifOnOpen }) : 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
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
|
|
1797
|
+
/* @__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(CloseIcon2, {}) })
|
|
1799
|
+
] }),
|
|
1800
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1801
|
+
MessagesInbox,
|
|
1802
|
+
{
|
|
1803
|
+
rooms: inbox.rooms,
|
|
1804
|
+
requests: inbox.requests,
|
|
1805
|
+
labels,
|
|
1806
|
+
onOpenRoom: ui.openRoom,
|
|
1807
|
+
onRemoveRoom: inboxRowClose ? (roomId) => void inbox.hideDM(roomId).catch(() => {
|
|
1808
|
+
}) : void 0
|
|
1809
|
+
}
|
|
1810
|
+
)
|
|
1811
|
+
] }) : activeContext ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
|
|
1812
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1813
|
+
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
|
|
1814
|
+
/* @__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(CloseIcon2, {}) })
|
|
1816
|
+
] }),
|
|
1817
|
+
/* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
|
|
1818
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1819
|
+
ConversationView,
|
|
1334
1820
|
{
|
|
1335
|
-
|
|
1336
|
-
requests: inbox.requests,
|
|
1821
|
+
roomId: view.roomId,
|
|
1337
1822
|
labels,
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1823
|
+
onBack: ui.openInbox,
|
|
1824
|
+
onClose: ui.close,
|
|
1825
|
+
confirm
|
|
1826
|
+
},
|
|
1827
|
+
view.roomId
|
|
1828
|
+
),
|
|
1829
|
+
builtInConfirm && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1830
|
+
ConfirmDialog,
|
|
1831
|
+
{
|
|
1832
|
+
options: builtInConfirm.options,
|
|
1833
|
+
onAnswer: builtInConfirm.resolve
|
|
1341
1834
|
}
|
|
1342
1835
|
)
|
|
1343
|
-
] })
|
|
1344
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1345
|
-
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
|
|
1346
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: activeContext.label }),
|
|
1347
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
|
|
1348
|
-
] }),
|
|
1349
|
-
/* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
|
|
1350
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsx(ConversationView, { roomId: view.roomId, labels, onBack: ui.openInbox }, view.roomId) }),
|
|
1836
|
+
] }),
|
|
1351
1837
|
showRail && /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "dtc-rail", "aria-label": labels.messages, children: [
|
|
1352
1838
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-rail-scroll", children: [
|
|
1353
1839
|
topItems.map(renderItemButton),
|
|
1354
1840
|
topItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
|
|
1841
|
+
notifications !== false && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1842
|
+
RailButton,
|
|
1843
|
+
{
|
|
1844
|
+
label: labels.notifications,
|
|
1845
|
+
active: isOpen && view.kind === "notifications",
|
|
1846
|
+
badge: notifUnread,
|
|
1847
|
+
onClick: () => select({ kind: "notifications" }),
|
|
1848
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(BellIcon, {})
|
|
1849
|
+
}
|
|
1850
|
+
),
|
|
1355
1851
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1356
1852
|
RailButton,
|
|
1357
1853
|
{
|
|
@@ -1395,6 +1891,37 @@ function DialtribeMessages({
|
|
|
1395
1891
|
}
|
|
1396
1892
|
);
|
|
1397
1893
|
}
|
|
1894
|
+
function ConfirmDialog({ options, onAnswer }) {
|
|
1895
|
+
const confirmRef = react.useRef(null);
|
|
1896
|
+
react.useEffect(() => {
|
|
1897
|
+
confirmRef.current?.focus();
|
|
1898
|
+
const onKey = (e) => {
|
|
1899
|
+
if (e.key !== "Escape") return;
|
|
1900
|
+
e.preventDefault();
|
|
1901
|
+
onAnswer(false);
|
|
1902
|
+
};
|
|
1903
|
+
window.addEventListener("keydown", onKey, true);
|
|
1904
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
1905
|
+
}, [onAnswer]);
|
|
1906
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-confirm-backdrop", onClick: () => onAnswer(false), children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1907
|
+
"div",
|
|
1908
|
+
{
|
|
1909
|
+
className: "dtc-confirm",
|
|
1910
|
+
role: "alertdialog",
|
|
1911
|
+
"aria-modal": "true",
|
|
1912
|
+
"aria-labelledby": "dtc-confirm-title",
|
|
1913
|
+
onClick: (e) => e.stopPropagation(),
|
|
1914
|
+
children: [
|
|
1915
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { id: "dtc-confirm-title", className: "dtc-confirm-title", children: options.title }),
|
|
1916
|
+
options.body && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "dtc-confirm-body", children: options.body }),
|
|
1917
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-confirm-actions", children: [
|
|
1918
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-btn", onClick: () => onAnswer(false), children: options.cancelLabel }),
|
|
1919
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { ref: confirmRef, type: "button", className: "dtc-btn dtc-btn-primary", onClick: () => onAnswer(true), children: options.confirmLabel })
|
|
1920
|
+
] })
|
|
1921
|
+
]
|
|
1922
|
+
}
|
|
1923
|
+
) });
|
|
1924
|
+
}
|
|
1398
1925
|
function RailButton({
|
|
1399
1926
|
label,
|
|
1400
1927
|
active,
|
|
@@ -1502,7 +2029,23 @@ function themeVars(theme) {
|
|
|
1502
2029
|
function ChatIcon() {
|
|
1503
2030
|
return /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
|
|
1504
2031
|
}
|
|
1505
|
-
function
|
|
2032
|
+
function BellIcon() {
|
|
2033
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
2034
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9" }),
|
|
2035
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M13.73 21a2 2 0 0 1-3.46 0" })
|
|
2036
|
+
] });
|
|
2037
|
+
}
|
|
2038
|
+
function useNotificationsBadge(enabled) {
|
|
2039
|
+
const store = useChatClient().notifications;
|
|
2040
|
+
react.useEffect(() => {
|
|
2041
|
+
if (!enabled) return;
|
|
2042
|
+
store.acquire();
|
|
2043
|
+
return () => store.release();
|
|
2044
|
+
}, [enabled, store]);
|
|
2045
|
+
const snapshot = react.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
2046
|
+
return enabled ? snapshot.unreadCount : 0;
|
|
2047
|
+
}
|
|
2048
|
+
function CloseIcon2() {
|
|
1506
2049
|
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" }) });
|
|
1507
2050
|
}
|
|
1508
2051
|
|
|
@@ -1516,6 +2059,7 @@ exports.ChatRoomProvider = ChatRoomProvider;
|
|
|
1516
2059
|
exports.DEFAULT_LABELS = DEFAULT_LABELS;
|
|
1517
2060
|
exports.DialtribeChatProvider = DialtribeChatProvider;
|
|
1518
2061
|
exports.DialtribeMessages = DialtribeMessages;
|
|
2062
|
+
exports.NotificationsPanel = NotificationsPanel;
|
|
1519
2063
|
exports.parseReactions = parseReactions;
|
|
1520
2064
|
exports.useChatClient = useChatClient;
|
|
1521
2065
|
exports.useChatConnection = useChatConnection;
|
|
@@ -1523,5 +2067,6 @@ exports.useChatRoomContext = useChatRoomContext;
|
|
|
1523
2067
|
exports.useChatRooms = useChatRooms;
|
|
1524
2068
|
exports.useDialtribeChat = useDialtribeChat;
|
|
1525
2069
|
exports.useDialtribeMessages = useDialtribeMessages;
|
|
2070
|
+
exports.useDialtribeNotifications = useDialtribeNotifications;
|
|
1526
2071
|
//# sourceMappingURL=index.js.map
|
|
1527
2072
|
//# sourceMappingURL=index.js.map
|