diff --git a/src/helpers/nostr/communities.ts b/src/helpers/nostr/communities.ts index cc4813a9d..b0b48e337 100644 --- a/src/helpers/nostr/communities.ts +++ b/src/helpers/nostr/communities.ts @@ -1,5 +1,6 @@ import { validateEvent } from "nostr-tools"; import { NostrEvent, isDTag, isETag, isPTag } from "../../types/nostr-event"; +import { getMatchLink, getMatchNostrLink } from "../regexp"; export const SUBSCRIBED_COMMUNITIES_LIST_IDENTIFIER = "communities"; export const COMMUNITY_DEFINITION_KIND = 34550; @@ -30,7 +31,11 @@ export function getCommunityRules(community: NostrEvent) { } export function getPostSubject(event: NostrEvent) { - return event.tags.find((t) => t[0] === "subject")?.[1] || event.content.match(/^[^\n\t]+/); + const subject = event.tags.find((t) => t[0] === "subject")?.[1]; + if (subject) return subject; + const firstLine = event.content.match(/^[^\n\t]+/)?.[0]; + if (!firstLine) return; + if (!getMatchNostrLink().test(firstLine) && !getMatchLink().test(firstLine)) return firstLine; } export function getApprovedEmbeddedNote(approval: NostrEvent) { diff --git a/src/views/community/views/newest.tsx b/src/views/community/views/newest.tsx index 0f35e735b..d7cc79098 100644 --- a/src/views/community/views/newest.tsx +++ b/src/views/community/views/newest.tsx @@ -52,18 +52,24 @@ const ApprovedEvent = memo( [navigate, to], ); + const subject = getPostSubject(event); + return ( - - - - - - {getPostSubject(event)} - - - + + + {subject ? ( + + + + {getPostSubject(event)} + + + + ) : ( + + )}