From cab1d14603bd68d677021edd23faca18108b5425 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Sat, 12 Nov 2022 08:46:51 +0100 Subject: [PATCH] feed: add reply to info Add reply to event id and if available relay info. Relay info is not always available, see positional e tags (DEPRECATED) NIP-10. --- src/main.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index 1e6b623..ef4bcc9 100644 --- a/src/main.js +++ b/src/main.js @@ -62,17 +62,20 @@ const subscription = pool.sub({ } }); +const hasEventTag = tag => tag[0] === 'e'; +const getShortTagId = tag => `${tag[1].slice(0, 7)}${tag[2] ? '@' + tag[2] : ''}`; + function renderTextNote(evt, relay) { if (evt.tags.length) { console.log('has tags', evt) } const [host, img, time, userName] = getMetadata(evt, relay); + const isReply = evt.tags.some(hasEventTag); const body = elem('div', {className: 'mbox-body', title: dateTime.format(time)}, [ renderProfile(userName, host), - elem('div', {}, evt.id), + elem('div', {}, isReply ? `reply to ${evt.tags.filter(hasEventTag).map(getShortTagId).join(' and ')}` : evt.id), evt.content // text ]); - const isReply = evt.tags.some(tag => tag[0] === 'e'); rendernArticle([img, body], isReply && {className: 'mbox-reply'}); }