@poolse/react-ui 1.0.0-beta.0 → 1.0.1-beta.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/dist/index.cjs +305 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -2
- package/dist/index.d.ts +76 -2
- package/dist/index.js +301 -56
- package/dist/index.js.map +1 -1
- package/dist/styles.css +228 -9
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useMembers, useAttachmentUrl, useReactions, useMe, useThread, useMessages, useTyping, useRealtimeStatus, useAttachmentUpload, useConversations } from '@poolse/react';
|
|
2
|
+
import { useMembers, useAttachmentUrl, useUser, useReactions, useMe, useThread, useMessages, useTyping, useRealtimeStatus, useAttachmentUpload, useConversations } from '@poolse/react';
|
|
3
3
|
import { useEffect, useState, useRef, Fragment as Fragment$1, useMemo } from 'react';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
import ReactMarkdown from 'react-markdown';
|
|
6
|
+
import remarkGfm from 'remark-gfm';
|
|
5
7
|
|
|
6
8
|
// src/ConversationView.tsx
|
|
7
9
|
var FONT_HREF = "https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,600;12..96,800&family=Hanken+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap";
|
|
@@ -40,6 +42,40 @@ function PoolseFonts() {
|
|
|
40
42
|
return null;
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
// src/listAutocomplete.ts
|
|
46
|
+
var UNORDERED_RE = /^(\s*)([-*+]) (.*)$/;
|
|
47
|
+
var ORDERED_RE = /^(\s*)(\d+)\. (.*)$/;
|
|
48
|
+
function handleListEnter(value, caret) {
|
|
49
|
+
const lineStart = value.lastIndexOf("\n", caret - 1) + 1;
|
|
50
|
+
const lineEnd = (() => {
|
|
51
|
+
const nl = value.indexOf("\n", caret);
|
|
52
|
+
return nl === -1 ? value.length : nl;
|
|
53
|
+
})();
|
|
54
|
+
const currentLine = value.slice(lineStart, lineEnd);
|
|
55
|
+
const unordered = UNORDERED_RE.exec(currentLine);
|
|
56
|
+
const ordered = ORDERED_RE.exec(currentLine);
|
|
57
|
+
const match = unordered ?? ordered;
|
|
58
|
+
if (!match) return null;
|
|
59
|
+
const indent = match[1] ?? "";
|
|
60
|
+
const marker = match[2] ?? "";
|
|
61
|
+
const content = match[3] ?? "";
|
|
62
|
+
if (content === "") {
|
|
63
|
+
const before2 = value.slice(0, lineStart);
|
|
64
|
+
const after2 = value.slice(lineEnd);
|
|
65
|
+
return { kind: "end", value: before2 + after2, caret: lineStart };
|
|
66
|
+
}
|
|
67
|
+
const nextMarker = ordered ? `${parseInt(marker, 10) + 1}.` : marker;
|
|
68
|
+
const prefix = `
|
|
69
|
+
${indent}${nextMarker} `;
|
|
70
|
+
const before = value.slice(0, caret);
|
|
71
|
+
const after = value.slice(caret);
|
|
72
|
+
return {
|
|
73
|
+
kind: "continue",
|
|
74
|
+
value: before + prefix + after,
|
|
75
|
+
caret: caret + prefix.length
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
43
79
|
// src/icons-data.ts
|
|
44
80
|
var ICONS = {
|
|
45
81
|
attachment: {
|
|
@@ -348,6 +384,17 @@ function MentionInput({
|
|
|
348
384
|
}
|
|
349
385
|
}
|
|
350
386
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
387
|
+
const ta = e.currentTarget;
|
|
388
|
+
const caret = ta.selectionStart;
|
|
389
|
+
const result = handleListEnter(value, caret);
|
|
390
|
+
if (result) {
|
|
391
|
+
e.preventDefault();
|
|
392
|
+
setValue(result.value);
|
|
393
|
+
requestAnimationFrame(() => {
|
|
394
|
+
taRef.current?.setSelectionRange(result.caret, result.caret);
|
|
395
|
+
});
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
351
398
|
e.preventDefault();
|
|
352
399
|
void submit();
|
|
353
400
|
}
|
|
@@ -444,6 +491,7 @@ function MessageComposer({
|
|
|
444
491
|
}) {
|
|
445
492
|
const [value, setValue] = useState("");
|
|
446
493
|
const [sending, setSending] = useState(false);
|
|
494
|
+
const taRef = useRef(null);
|
|
447
495
|
const submit = async () => {
|
|
448
496
|
const trimmed = value.trim();
|
|
449
497
|
if (!trimmed || sending) return;
|
|
@@ -457,6 +505,17 @@ function MessageComposer({
|
|
|
457
505
|
};
|
|
458
506
|
const onKeyDown = (e) => {
|
|
459
507
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
508
|
+
const ta = e.currentTarget;
|
|
509
|
+
const caret = ta.selectionStart;
|
|
510
|
+
const result = handleListEnter(value, caret);
|
|
511
|
+
if (result) {
|
|
512
|
+
e.preventDefault();
|
|
513
|
+
setValue(result.value);
|
|
514
|
+
requestAnimationFrame(() => {
|
|
515
|
+
taRef.current?.setSelectionRange(result.caret, result.caret);
|
|
516
|
+
});
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
460
519
|
e.preventDefault();
|
|
461
520
|
void submit();
|
|
462
521
|
}
|
|
@@ -490,6 +549,7 @@ function MessageComposer({
|
|
|
490
549
|
/* @__PURE__ */ jsx(
|
|
491
550
|
"textarea",
|
|
492
551
|
{
|
|
552
|
+
ref: taRef,
|
|
493
553
|
className: "poolse-composer__input",
|
|
494
554
|
rows: 1,
|
|
495
555
|
value,
|
|
@@ -636,24 +696,87 @@ function formatBytes(n) {
|
|
|
636
696
|
if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
637
697
|
return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
638
698
|
}
|
|
699
|
+
function Avatar({ src, name, online, size = "md", className }) {
|
|
700
|
+
const initials = computeInitials(name);
|
|
701
|
+
const classes = [
|
|
702
|
+
"poolse-avatar",
|
|
703
|
+
size === "sm" ? "poolse-avatar--sm" : null,
|
|
704
|
+
size === "lg" ? "poolse-avatar--lg" : null,
|
|
705
|
+
className
|
|
706
|
+
].filter(Boolean).join(" ");
|
|
707
|
+
return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
|
|
708
|
+
src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
|
|
709
|
+
online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
|
|
710
|
+
] });
|
|
711
|
+
}
|
|
712
|
+
function computeInitials(name) {
|
|
713
|
+
if (!name) return "?";
|
|
714
|
+
const parts = name.trim().split(/\s+/).slice(0, 2);
|
|
715
|
+
return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// src/userColor.ts
|
|
719
|
+
var PALETTE = [
|
|
720
|
+
"#6366f1",
|
|
721
|
+
// indigo
|
|
722
|
+
"#10b981",
|
|
723
|
+
// emerald
|
|
724
|
+
"#f59e0b",
|
|
725
|
+
// amber
|
|
726
|
+
"#ec4899",
|
|
727
|
+
// rose
|
|
728
|
+
"#0ea5e9",
|
|
729
|
+
// sky
|
|
730
|
+
"#8b5cf6",
|
|
731
|
+
// violet
|
|
732
|
+
"#14b8a6",
|
|
733
|
+
// teal
|
|
734
|
+
"#d946ef"
|
|
735
|
+
// fuchsia
|
|
736
|
+
];
|
|
737
|
+
function userColor(userId) {
|
|
738
|
+
let h = 0;
|
|
739
|
+
for (let i = 0; i < userId.length; i++) {
|
|
740
|
+
h = h * 31 + userId.charCodeAt(i) | 0;
|
|
741
|
+
}
|
|
742
|
+
return PALETTE[Math.abs(h) % PALETTE.length];
|
|
743
|
+
}
|
|
639
744
|
function MessageBubble({
|
|
640
745
|
message,
|
|
641
746
|
currentUserId,
|
|
642
747
|
readState,
|
|
643
748
|
labelFor,
|
|
644
|
-
onQuotedClick
|
|
749
|
+
onQuotedClick,
|
|
750
|
+
groupPosition = "standalone",
|
|
751
|
+
maxBodyLength = 0,
|
|
752
|
+
markdown = false,
|
|
753
|
+
showSenderName = false
|
|
645
754
|
}) {
|
|
646
755
|
const isSelf = currentUserId !== null && message.sender_id === currentUserId;
|
|
756
|
+
const [expanded, setExpanded] = useState(false);
|
|
757
|
+
const { profile: sender } = useUser(!isSelf ? message.sender_id : null);
|
|
758
|
+
const senderFallbackName = message.sender_id ? `User ${message.sender_id.slice(0, 6)}` : "Unknown";
|
|
759
|
+
const senderName = sender?.displayName ?? senderFallbackName;
|
|
760
|
+
const senderColorHex = message.sender_id ? userColor(message.sender_id) : "currentColor";
|
|
761
|
+
const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
|
|
647
762
|
const className = [
|
|
648
763
|
"poolse-message",
|
|
649
|
-
isSelf ? "poolse-message--self" : "poolse-message--other"
|
|
764
|
+
isSelf ? "poolse-message--self" : "poolse-message--other",
|
|
765
|
+
// Group-position modifier — CSS uses it to toggle which corners
|
|
766
|
+
// get the asymmetric tail vs. fully-rounded treatment.
|
|
767
|
+
`poolse-message--${groupPosition}`
|
|
650
768
|
].join(" ");
|
|
769
|
+
const rawBody = message.body ?? "";
|
|
770
|
+
const TRIM_BUFFER = 40;
|
|
771
|
+
const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
|
|
772
|
+
const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
|
|
651
773
|
const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
|
|
652
774
|
hour: "2-digit",
|
|
653
775
|
minute: "2-digit"
|
|
654
776
|
}) : "";
|
|
655
777
|
const showQuoteCard = message.quoted_message !== void 0 && message.quoted_message !== null ? "full" : message.quoted_message_id ? "placeholder" : null;
|
|
656
778
|
return /* @__PURE__ */ jsxs("div", { className, children: [
|
|
779
|
+
renderSenderName && /* @__PURE__ */ jsx("div", { className: "poolse-message__sender", style: { color: senderColorHex }, children: senderName }),
|
|
657
780
|
showQuoteCard === "full" && /* @__PURE__ */ jsx(
|
|
658
781
|
QuotedCard,
|
|
659
782
|
{
|
|
@@ -664,7 +787,44 @@ function MessageBubble({
|
|
|
664
787
|
}
|
|
665
788
|
),
|
|
666
789
|
showQuoteCard === "placeholder" && /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
|
|
667
|
-
message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */
|
|
790
|
+
message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsxs("div", { className: "poolse-message__body", children: [
|
|
791
|
+
markdown ? /* @__PURE__ */ jsx(
|
|
792
|
+
ReactMarkdown,
|
|
793
|
+
{
|
|
794
|
+
remarkPlugins: [remarkGfm],
|
|
795
|
+
components: {
|
|
796
|
+
// Force links to a new tab + no opener — chat content
|
|
797
|
+
// is user-supplied so security defaults matter.
|
|
798
|
+
a: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("a", { ...props, target: "_blank", rel: "noopener noreferrer nofollow" })
|
|
799
|
+
},
|
|
800
|
+
children: displayBody
|
|
801
|
+
}
|
|
802
|
+
) : /* @__PURE__ */ jsx("span", { children: displayBody }),
|
|
803
|
+
shouldTrim && /* @__PURE__ */ jsx(
|
|
804
|
+
"button",
|
|
805
|
+
{
|
|
806
|
+
type: "button",
|
|
807
|
+
className: "poolse-message__read-more",
|
|
808
|
+
onClick: (e) => {
|
|
809
|
+
e.stopPropagation();
|
|
810
|
+
setExpanded(true);
|
|
811
|
+
},
|
|
812
|
+
children: "Read more"
|
|
813
|
+
}
|
|
814
|
+
),
|
|
815
|
+
!shouldTrim && expanded && rawBody.length > maxBodyLength + TRIM_BUFFER && /* @__PURE__ */ jsx(
|
|
816
|
+
"button",
|
|
817
|
+
{
|
|
818
|
+
type: "button",
|
|
819
|
+
className: "poolse-message__read-more",
|
|
820
|
+
onClick: (e) => {
|
|
821
|
+
e.stopPropagation();
|
|
822
|
+
setExpanded(false);
|
|
823
|
+
},
|
|
824
|
+
children: "Show less"
|
|
825
|
+
}
|
|
826
|
+
)
|
|
827
|
+
] }),
|
|
668
828
|
/* @__PURE__ */ jsxs("span", { className: "poolse-message__meta", children: [
|
|
669
829
|
/* @__PURE__ */ jsx("span", { children: time }),
|
|
670
830
|
message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
|
|
@@ -966,8 +1126,16 @@ function MessageRow({
|
|
|
966
1126
|
onOpenThread,
|
|
967
1127
|
onQuote,
|
|
968
1128
|
labelFor,
|
|
969
|
-
onQuotedClick
|
|
1129
|
+
onQuotedClick,
|
|
1130
|
+
groupPosition = "standalone",
|
|
1131
|
+
maxBodyLength = 0,
|
|
1132
|
+
markdown = false,
|
|
1133
|
+
showSenderName = false,
|
|
1134
|
+
showAvatar = false
|
|
970
1135
|
}) {
|
|
1136
|
+
const { profile: senderProfile } = useUser(msg.sender_id);
|
|
1137
|
+
const senderFallbackName = msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown";
|
|
1138
|
+
const senderName = senderProfile?.displayName ?? senderFallbackName;
|
|
971
1139
|
const isSelf = meId !== null && msg.sender_id === meId;
|
|
972
1140
|
const reactionsHook = useReactions(reactions ? msg.id : "", {
|
|
973
1141
|
conversationId: msg.conversation_id,
|
|
@@ -984,7 +1152,15 @@ function MessageRow({
|
|
|
984
1152
|
return /* @__PURE__ */ jsxs(
|
|
985
1153
|
"div",
|
|
986
1154
|
{
|
|
987
|
-
className:
|
|
1155
|
+
className: [
|
|
1156
|
+
"poolse-message-row",
|
|
1157
|
+
isSelf ? "poolse-message-row--right" : "",
|
|
1158
|
+
// Modifier mirrors the bubble's groupPosition so the CSS can
|
|
1159
|
+
// tighten the inter-bubble gap inside a cluster (first/middle/
|
|
1160
|
+
// last) and widen it between clusters (standalone or the
|
|
1161
|
+
// first of a new run).
|
|
1162
|
+
`poolse-message-row--${groupPosition}`
|
|
1163
|
+
].filter(Boolean).join(" "),
|
|
988
1164
|
"data-message-id": msg.id,
|
|
989
1165
|
children: [
|
|
990
1166
|
editing ? /* @__PURE__ */ jsx(
|
|
@@ -998,13 +1174,27 @@ function MessageRow({
|
|
|
998
1174
|
onCancel: handleCancel
|
|
999
1175
|
}
|
|
1000
1176
|
) : /* @__PURE__ */ jsx(
|
|
1001
|
-
|
|
1177
|
+
BubbleWithAvatar,
|
|
1002
1178
|
{
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1179
|
+
isSelf,
|
|
1180
|
+
showAvatar,
|
|
1181
|
+
groupPosition,
|
|
1182
|
+
senderName,
|
|
1183
|
+
avatarUrl: senderProfile?.avatarUrl ?? null,
|
|
1184
|
+
children: /* @__PURE__ */ jsx(
|
|
1185
|
+
MessageBubble,
|
|
1186
|
+
{
|
|
1187
|
+
message: msg,
|
|
1188
|
+
currentUserId: meId,
|
|
1189
|
+
groupPosition,
|
|
1190
|
+
maxBodyLength,
|
|
1191
|
+
markdown,
|
|
1192
|
+
showSenderName,
|
|
1193
|
+
...readState ? { readState } : {},
|
|
1194
|
+
...labelFor ? { labelFor } : {},
|
|
1195
|
+
...onQuotedClick ? { onQuotedClick } : {}
|
|
1196
|
+
}
|
|
1197
|
+
)
|
|
1008
1198
|
}
|
|
1009
1199
|
),
|
|
1010
1200
|
showAttachments && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__attachments ${isSelf ? "is-self" : ""}`, children: msg.attachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
|
|
@@ -1093,6 +1283,21 @@ function InlineReactions({
|
|
|
1093
1283
|
);
|
|
1094
1284
|
}) });
|
|
1095
1285
|
}
|
|
1286
|
+
function BubbleWithAvatar({
|
|
1287
|
+
isSelf,
|
|
1288
|
+
showAvatar,
|
|
1289
|
+
groupPosition,
|
|
1290
|
+
senderName,
|
|
1291
|
+
avatarUrl,
|
|
1292
|
+
children
|
|
1293
|
+
}) {
|
|
1294
|
+
if (isSelf || !showAvatar) return /* @__PURE__ */ jsx(Fragment, { children });
|
|
1295
|
+
const isLastOfCluster = groupPosition === "last" || groupPosition === "standalone";
|
|
1296
|
+
return /* @__PURE__ */ jsxs("div", { className: "poolse-bubble-shell", children: [
|
|
1297
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-bubble-shell__avatar", children: isLastOfCluster ? /* @__PURE__ */ jsx(Avatar, { src: avatarUrl, name: senderName, size: "sm" }) : null }),
|
|
1298
|
+
children
|
|
1299
|
+
] });
|
|
1300
|
+
}
|
|
1096
1301
|
function ThreadView({
|
|
1097
1302
|
conversationId,
|
|
1098
1303
|
rootMessage,
|
|
@@ -1182,6 +1387,13 @@ function ConversationView({
|
|
|
1182
1387
|
threads = TRUE,
|
|
1183
1388
|
quotations = TRUE,
|
|
1184
1389
|
readReceipts = TRUE,
|
|
1390
|
+
markdown = TRUE,
|
|
1391
|
+
maxBodyLength = 200,
|
|
1392
|
+
grouping = TRUE,
|
|
1393
|
+
groupingWindowMs = 5 * 60 * 1e3,
|
|
1394
|
+
daySeparators = TRUE,
|
|
1395
|
+
senderLabels = "auto",
|
|
1396
|
+
avatars = "auto",
|
|
1185
1397
|
onMarkedRead
|
|
1186
1398
|
}) {
|
|
1187
1399
|
usePoolseFonts(loadFonts);
|
|
@@ -1199,8 +1411,12 @@ function ConversationView({
|
|
|
1199
1411
|
} = useMessages(conversationId);
|
|
1200
1412
|
const { typing, signalTyping } = useTyping(conversationId);
|
|
1201
1413
|
const status = useRealtimeStatus();
|
|
1202
|
-
const
|
|
1414
|
+
const wantsMemberCount = senderLabels === "auto" || avatars === "auto";
|
|
1415
|
+
const membersOn = mentions || readReceipts || wantsMemberCount;
|
|
1203
1416
|
const { members } = useMembers(membersOn ? conversationId : "");
|
|
1417
|
+
const isGroupChat = members.length > 2;
|
|
1418
|
+
const showSenderLabelsResolved = senderLabels === "always" || senderLabels === "auto" && isGroupChat;
|
|
1419
|
+
const showAvatarsResolved = avatars === "always" || avatars === "auto" && isGroupChat;
|
|
1204
1420
|
const listRef = useRef(null);
|
|
1205
1421
|
const lastMessageIdRef = useRef(null);
|
|
1206
1422
|
const bottomSentinelRef = useRef(null);
|
|
@@ -1347,10 +1563,14 @@ function ConversationView({
|
|
|
1347
1563
|
] }),
|
|
1348
1564
|
/* @__PURE__ */ jsxs("div", { className: "poolse-conversation__messages", ref: listRef, children: [
|
|
1349
1565
|
hasMore && !loading && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older messages" }),
|
|
1350
|
-
loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg) => {
|
|
1566
|
+
loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg, idx) => {
|
|
1351
1567
|
if (renderMessage) {
|
|
1352
1568
|
return /* @__PURE__ */ jsx(Fragment$1, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
|
|
1353
1569
|
}
|
|
1570
|
+
const prev = idx > 0 ? messages[idx - 1] ?? null : null;
|
|
1571
|
+
const next = idx < messages.length - 1 ? messages[idx + 1] ?? null : null;
|
|
1572
|
+
const groupPosition = grouping ? computeGroupPosition(msg, prev, next, groupingWindowMs) : "standalone";
|
|
1573
|
+
const showDaySeparator = daySeparators && (prev === null || !sameDay(msg.inserted_at, prev.inserted_at));
|
|
1354
1574
|
const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
|
|
1355
1575
|
const original = messages.find((m) => m.id === msg.quoted_message_id);
|
|
1356
1576
|
if (!original) return msg;
|
|
@@ -1367,32 +1587,39 @@ function ConversationView({
|
|
|
1367
1587
|
})() : msg;
|
|
1368
1588
|
const isSelf = me !== null && msg.sender_id === me.id;
|
|
1369
1589
|
const readState = readReceipts && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
|
|
1370
|
-
return /* @__PURE__ */
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1590
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
1591
|
+
showDaySeparator && /* @__PURE__ */ jsx("div", { className: "poolse-day-separator", "aria-hidden": "false", children: /* @__PURE__ */ jsx("span", { children: formatDayLabel(msg.inserted_at) }) }),
|
|
1592
|
+
/* @__PURE__ */ jsx(
|
|
1593
|
+
MessageRow,
|
|
1594
|
+
{
|
|
1595
|
+
msg: enriched,
|
|
1596
|
+
meId: me?.id ?? null,
|
|
1597
|
+
reactions,
|
|
1598
|
+
attachments,
|
|
1599
|
+
actions,
|
|
1600
|
+
threads,
|
|
1601
|
+
quotations,
|
|
1602
|
+
groupPosition,
|
|
1603
|
+
maxBodyLength,
|
|
1604
|
+
markdown,
|
|
1605
|
+
showSenderName: showSenderLabelsResolved,
|
|
1606
|
+
showAvatar: showAvatarsResolved,
|
|
1607
|
+
...readState ? { readState } : {},
|
|
1608
|
+
...labelFor ? { labelFor } : {},
|
|
1609
|
+
editing: editingId === msg.id,
|
|
1610
|
+
onStartEdit: () => setEditingId(msg.id),
|
|
1611
|
+
onCancelEdit: () => setEditingId(null),
|
|
1612
|
+
onSaveEdit: async (body) => {
|
|
1613
|
+
await edit(msg.id, body);
|
|
1614
|
+
setEditingId(null);
|
|
1615
|
+
},
|
|
1616
|
+
onDelete: () => void deleteMsg(msg.id),
|
|
1617
|
+
onOpenThread: () => setThreadRootId(msg.id),
|
|
1618
|
+
onQuote: () => setReplyingTo(msg),
|
|
1619
|
+
onQuotedClick: scrollToOriginal
|
|
1620
|
+
}
|
|
1621
|
+
)
|
|
1622
|
+
] }, msg.id);
|
|
1396
1623
|
}),
|
|
1397
1624
|
error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
|
|
1398
1625
|
"Failed to load: ",
|
|
@@ -1463,23 +1690,41 @@ function AttachmentPickerButton({
|
|
|
1463
1690
|
)
|
|
1464
1691
|
] });
|
|
1465
1692
|
}
|
|
1466
|
-
function
|
|
1467
|
-
const
|
|
1468
|
-
const
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
].filter(Boolean).join(" ");
|
|
1474
|
-
return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
|
|
1475
|
-
src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
|
|
1476
|
-
online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
|
|
1477
|
-
] });
|
|
1693
|
+
function computeGroupPosition(msg, prev, next, windowMs) {
|
|
1694
|
+
const continuesPrev = sameGroup(msg, prev, windowMs);
|
|
1695
|
+
const continuesNext = sameGroup(next, msg, windowMs);
|
|
1696
|
+
if (continuesPrev && continuesNext) return "middle";
|
|
1697
|
+
if (continuesPrev) return "last";
|
|
1698
|
+
if (continuesNext) return "first";
|
|
1699
|
+
return "standalone";
|
|
1478
1700
|
}
|
|
1479
|
-
function
|
|
1480
|
-
if (!
|
|
1481
|
-
|
|
1482
|
-
|
|
1701
|
+
function sameGroup(a, b, windowMs) {
|
|
1702
|
+
if (!a || !b) return false;
|
|
1703
|
+
if (a.sender_id !== b.sender_id) return false;
|
|
1704
|
+
if (!sameDay(a.inserted_at, b.inserted_at)) return false;
|
|
1705
|
+
const ta = new Date(a.inserted_at).getTime();
|
|
1706
|
+
const tb = new Date(b.inserted_at).getTime();
|
|
1707
|
+
return Math.abs(ta - tb) <= windowMs;
|
|
1708
|
+
}
|
|
1709
|
+
function sameDay(a, b) {
|
|
1710
|
+
const da = new Date(a);
|
|
1711
|
+
const db = new Date(b);
|
|
1712
|
+
return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth() && da.getDate() === db.getDate();
|
|
1713
|
+
}
|
|
1714
|
+
function formatDayLabel(iso) {
|
|
1715
|
+
const d = new Date(iso);
|
|
1716
|
+
const now = /* @__PURE__ */ new Date();
|
|
1717
|
+
const startOfDay = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
1718
|
+
const diffDays = Math.floor((startOfDay(now) - startOfDay(d)) / 864e5);
|
|
1719
|
+
if (diffDays === 0) return "Today";
|
|
1720
|
+
if (diffDays === 1) return "Yesterday";
|
|
1721
|
+
if (diffDays < 7) {
|
|
1722
|
+
return d.toLocaleDateString(void 0, { weekday: "long" });
|
|
1723
|
+
}
|
|
1724
|
+
if (d.getFullYear() === now.getFullYear()) {
|
|
1725
|
+
return d.toLocaleDateString(void 0, { weekday: "short", day: "numeric", month: "short" });
|
|
1726
|
+
}
|
|
1727
|
+
return d.toLocaleDateString(void 0, { day: "numeric", month: "short", year: "numeric" });
|
|
1483
1728
|
}
|
|
1484
1729
|
function ConversationList({
|
|
1485
1730
|
selectedId,
|