From 62710886441e174c8e988ef0ea3b58fb2cad654d Mon Sep 17 00:00:00 2001 From: ajvpot <553597+ajvpot@users.noreply.github.com> Date: Mon, 28 Jul 2025 00:00:00 +0000 Subject: [PATCH] a --- src/app/messages/page.tsx | 8 +++-- src/components/ChatBox.tsx | 46 ++++++++++++++++-------- src/components/ChatMessageItem.tsx | 58 +++++++++++++++++++++--------- 3 files changed, 79 insertions(+), 33 deletions(-) diff --git a/src/app/messages/page.tsx b/src/app/messages/page.tsx index 054e088..36e9a69 100644 --- a/src/app/messages/page.tsx +++ b/src/app/messages/page.tsx @@ -8,10 +8,12 @@ export default function MessagesPage() { const { config } = useConfig(); return ( -
+
{/* ChatBox component with all messages tab enabled and expanded behavior */} -
- +
+
+ +
); diff --git a/src/components/ChatBox.tsx b/src/components/ChatBox.tsx index 52974c9..b593249 100644 --- a/src/components/ChatBox.tsx +++ b/src/components/ChatBox.tsx @@ -5,6 +5,7 @@ import { useConfig } from "./ConfigContext"; import { decryptMeshcoreGroupMessage } from "../lib/meshcore"; import { getChannelIdFromKey } from "../lib/meshcore"; import ChatMessageItem, { ChatMessage } from "./ChatMessageItem"; +import RefreshButton from "./RefreshButton"; const PAGE_SIZE = 20; @@ -95,6 +96,13 @@ export default function ChatBox({ showAllMessagesTab = false, className = "", st } }; + const handleRefresh = () => { + setMessages([]); + setHasMore(true); + setLastBefore(undefined); + fetchMessages(undefined, true); + }; + return (
MeshCore Chat - {!startExpanded && ( - - )} + {!startExpanded && ( + + )} +
- {(!minimized || startExpanded) && ( + {(!minimized) && ( <> {showTabs && (
@@ -152,7 +171,6 @@ export default function ChatBox({ showAllMessagesTab = false, className = "", st key={msg.ingest_timestamp + (msg.origins?.join(',') ?? '') + i} msg={msg} showErrorRow={selectedKey.isAllMessages} - showChannelId={selectedKey.isAllMessages} /> ))} {hasMore && ( diff --git a/src/components/ChatMessageItem.tsx b/src/components/ChatMessageItem.tsx index 8136318..81b4422 100644 --- a/src/components/ChatMessageItem.tsx +++ b/src/components/ChatMessageItem.tsx @@ -24,7 +24,7 @@ function formatLocalTime(utcString: string): string { return utcDate.toLocaleString(); } -export default function ChatMessageItem({ msg, showErrorRow, showChannelId }: { msg: ChatMessage, showErrorRow?: boolean, showChannelId?: boolean }) { +export default function ChatMessageItem({ msg, showErrorRow }: { msg: ChatMessage, showErrorRow?: boolean }) { const { config } = useConfig(); const knownKeys = [ ...(config?.meshcoreKeys?.map((k: any) => k.privateKey) || []), @@ -32,6 +32,7 @@ export default function ChatMessageItem({ msg, showErrorRow, showChannelId }: { ]; const [parsed, setParsed] = useState(null); const [error, setError] = useState(null); + const [originsExpanded, setOriginsExpanded] = useState(false); useEffect(() => { let cancelled = false; @@ -63,22 +64,51 @@ export default function ChatMessageItem({ msg, showErrorRow, showChannelId }: { return () => { cancelled = true; }; }, [msg.encrypted_message, msg.mac, msg.channel_hash, knownKeys.join(",")]); + const origins = msg.origins && msg.origins.length > 0 ? msg.origins : []; + const originsCount = origins.length; + + const OriginsBox = () => ( +
+ + {originsExpanded && originsCount > 0 && ( +
+ {origins.map((origin, index) => ( +
+ {origin} +
+ ))} +
+ )} +
+ ); + if (parsed) { return (
{formatLocalTime(new Date(parsed.timestamp * 1000).toISOString())} type: {parsed.msgType} - {showChannelId && ( - channel: {msg.channel_hash} - )} + channel: {msg.channel_hash}
{parsed.sender} {parsed.sender && ": "} {parsed.text}
-
Relayed by: {msg.origins && msg.origins.length > 0 ? msg.origins.map(o => o.slice(0, 6)).join(", ") : "-"}
+
); } @@ -89,11 +119,9 @@ export default function ChatMessageItem({ msg, showErrorRow, showChannelId }: {
Error: {error} - {showChannelId && ( - channel: {msg.channel_hash} - )} + channel: {msg.channel_hash}
-
Relayed by: {msg.origins && msg.origins.length > 0 ? msg.origins.map(o => o.slice(0, 6)).join(", ") : "-"}
+
); }else{ @@ -103,14 +131,12 @@ export default function ChatMessageItem({ msg, showErrorRow, showChannelId }: { return (
-
- {formatLocalTime(msg.ingest_timestamp)} - {showChannelId && ( - channel: {msg.channel_hash} - )} -
+
+ {formatLocalTime(msg.ingest_timestamp)} + channel: {msg.channel_hash} +
-
Relayed by: {msg.origins && msg.origins.length > 0 ? msg.origins.map(o => o.slice(0, 6)).join(", ") : "-"}
+
); } \ No newline at end of file