feed: improve recommend server (kind 2) messages
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

- check that event.content is a valid WSS url, drop otherwise
- fix bug that rendered the same server recommendation twice
pull/59/head
OFF0 2 years ago
parent 2dd9cf633a
commit a3de8f1595
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -500,17 +500,25 @@ const sortEventCreatedAt = (created_at) => (
Math.abs(a - created_at) < Math.abs(b - created_at) ? -1 : 1 Math.abs(a - created_at) < Math.abs(b - created_at) ? -1 : 1
); );
function isWssUrl(string) {
try {
return 'wss:' === new URL(string).protocol;
} catch (err) {
return false;
}
}
function handleRecommendServer(evt, relay) { function handleRecommendServer(evt, relay) {
if (feedDomMap[evt.id]) { if (feedDomMap[evt.id] || !isWssUrl(evt.content)) {
return; return;
} }
const art = renderRecommendServer(evt, relay); const art = renderRecommendServer(evt, relay);
if (textNoteList.length < 2) { if (textNoteList.length < 2) {
feedContainer.append(art); feedContainer.append(art);
return; } else {
}
const closestTextNotes = textNoteList.sort(sortEventCreatedAt(evt.created_at)); const closestTextNotes = textNoteList.sort(sortEventCreatedAt(evt.created_at));
feedDomMap[closestTextNotes[0].id].after(art); feedDomMap[closestTextNotes[0].id].after(art);
}
feedDomMap[evt.id] = art; feedDomMap[evt.id] = art;
} }

Loading…
Cancel
Save