From 4c7e7d8e1c903cd72ec9b949733e58fc636110a5 Mon Sep 17 00:00:00 2001 From: ajvpot <553597+ajvpot@users.noreply.github.com> Date: Mon, 15 Sep 2025 04:36:14 +0200 Subject: [PATCH] highlights for discord --- scripts/lib/discord.ts | 12 +++++++--- src/components/ChatMessageItem.tsx | 35 ++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/scripts/lib/discord.ts b/scripts/lib/discord.ts index e4191ea..2aa4d47 100644 --- a/scripts/lib/discord.ts +++ b/scripts/lib/discord.ts @@ -2,6 +2,8 @@ * Discord webhook integration utilities for posting and updating messages */ +import { createNodeSearchUrl, processNodeMentionsForMarkdown } from '../../src/lib/node-utils'; + export interface DiscordWebhookMessage { content?: string; username?: string; @@ -184,13 +186,17 @@ export function formatMeshcoreMessageForDiscord( } ): DiscordWebhookMessage { const sender = decrypted?.sender || 'Unknown'; - const text = decrypted?.text || '[Encrypted Message]'; + const rawText = decrypted?.text || '[Encrypted Message]'; + + // Process node mentions (@[Node Name]) and convert to Discord markdown links + const processedText = processNodeMentionsForMarkdown(rawText); // Calculate how many times the message was heard const heardCount = message.origin_path_info ? message.origin_path_info.length : 0; - // Format the message content with the requested format - const content = `${text}\n-# _Heard ${heardCount} times by [MeshExplorer](https://map.w0z.is/messages)_`; + // Create URL to search page with node name prefilled and exact match enabled + const senderSearchUrl = createNodeSearchUrl(sender); + const content = `${processedText}\n-# _Heard ${heardCount} times_ | [Node Info](${senderSearchUrl})`; // Generate profile picture URL using the new API const profilePictureUrl = `https://map.w0z.is/api/meshcore/profilepicture.png?name=${encodeURIComponent(sender)}&v=3`; diff --git a/src/components/ChatMessageItem.tsx b/src/components/ChatMessageItem.tsx index dc8b9d5..22cfee8 100644 --- a/src/components/ChatMessageItem.tsx +++ b/src/components/ChatMessageItem.tsx @@ -4,6 +4,7 @@ import { useConfig } from "./ConfigContext"; import { useMessageDecryption } from "@/hooks/useMessageDecryption"; import PathVisualization, { PathData } from "./PathVisualization"; import NodeLinkWithHover from "./NodeLinkWithHover"; +import { findNodeMentions } from "@/lib/node-utils"; export interface ChatMessage { message_id: string; @@ -29,9 +30,39 @@ function formatLocalTime(utcString: string): string { } function ChatMessageContent({ text }: { text: string }) { - // Combined regex to match both URLs and @[node_name] patterns - const combinedRegex = /(https?:\/\/[^\s]+|@\[[^\]]+\])/g; + // Use utility function to find node mentions + const nodeMentions = findNodeMentions(text); + // If no node mentions, handle only URLs + if (nodeMentions.length === 0) { + const urlRegex = /(https?:\/\/[^\s]+)/g; + const parts = text.split(urlRegex); + + return ( + <> + {parts.map((part, index) => { + // Check if it's a URL + if (/^https?:\/\//.test(part)) { + return ( + + {part} + + ); + } + return part; + })} + + ); + } + + // Process text with both URLs and node mentions + const combinedRegex = /(https?:\/\/[^\s]+|@\[[^\]]+\])/g; const parts = text.split(combinedRegex); return (