diff --git a/script/render-preview.mjs b/script/render-preview.mjs index e2fec6d..e60011f 100644 --- a/script/render-preview.mjs +++ b/script/render-preview.mjs @@ -24,8 +24,7 @@ const sample = { Icon: 'https://i.pravatar.cc/150?img=32', Name: 'carol', Content: '
Does anyone know how relay-based groups work?
', - Replies: 5, - Reactions: 8, + RelayUrl: 'relay.damus.io', }, { Link: 'https://app.flotilla.social/spaces/nos.lol/community?at=1700000000', @@ -34,8 +33,7 @@ const sample = { Name: 'bob', Content: 'Excited to share our new community space on Flotilla! Check it out.
', - Replies: 14, - Reactions: 32, + RelayUrl: 'nos.lol', }, ], unsubscribeUrl: 'https://app.flotilla.social/unsubscribe?token=abc123', diff --git a/src/digest.ts b/src/digest.ts index c9b2714..3426865 100644 --- a/src/digest.ts +++ b/src/digest.ts @@ -1,6 +1,5 @@ import { neventEncode, decode } from 'nostr-tools/nip19' import { - spec, sortBy, groupBy, displayList, @@ -10,7 +9,6 @@ import { parse, truncate, renderAsHtml } from '@welshman/content' import { TrustedEvent, normalizeRelayUrl, - getParentId, NOTE, COMMENT, REACTION, @@ -50,23 +48,23 @@ export class Digest { const getEventVariables = (event: TrustedEvent) => { const parsed = truncate(parse(event), { minLength: 400, maxLength: 800, mediaLength: 50 }) + const relayUrl = data.relayByEventId.get(event.id) + return { - Link: buildLink(event, handler, data.relayByEventId.get(event.id)), + Link: buildLink(event, handler, relayUrl), Timestamp: formatter.format(secondsToDate(event.created_at)), Icon: profilesByPubkey.get().get(event.pubkey)?.picture, Name: displayProfileByPubkey(event.pubkey), Content: renderAsHtml(parsed, { createElement, renderEntity }).toString(), - Replies: - repliesByParentId.get(event.id)?.filter((e) => [COMMENT, NOTE].includes(e.kind)) - ?.length || 0, - Reactions: repliesByParentId.get(event.id)?.filter(spec({ kind: REACTION }))?.length || 0, + RelayUrl: relayUrl + ? normalizeRelayUrl(relayUrl).replace(/^wss:\/\//, '').replace(/\/$/, '') + : '', } } - const { events, context } = data + const { events } = data const formatter = getFormatter() const handler = await this.loadHandler() - const repliesByParentId = groupBy(getParentId, context) const eventsByPubkey = groupBy((e) => e.pubkey, events) const userProfile = profilesByPubkey.get().get(this.sub.pubkey) const sorted = sortBy((e) => e.created_at, events).slice(0, 100) diff --git a/src/emails/digest.mjml b/src/emails/digest.mjml index 58f5e2d..4cf85f3 100644 --- a/src/emails/digest.mjml +++ b/src/emails/digest.mjml @@ -64,10 +64,7 @@