a demonstration replicated social networking web app built with anproto
wiredove.net/
social
ed25519
protocols
1const isPlainObject = (value) => {
2 if (!value || typeof value !== 'object') { return false }
3 return Object.getPrototypeOf(value) === Object.prototype
4}
5
6export const parseSharePayload = (hash) => {
7 if (!hash || typeof hash !== 'string') { return null }
8 if (!hash.startsWith('share=')) { return null }
9 try {
10 const raw = decodeURIComponent(hash.slice(6))
11 const data = JSON.parse(raw)
12 if (!isPlainObject(data)) { return null }
13 return data
14 } catch (err) {
15 return null
16 }
17}
18
19const normalizeText = (value) => {
20 if (typeof value !== 'string') { return '' }
21 return value.trim()
22}
23
24export const buildShareMessage = (payload) => {
25 if (!payload || typeof payload !== 'object') { return '' }
26 const text = normalizeText(payload.text)
27 const url = normalizeText(payload.url)
28 const title = normalizeText(payload.title)
29 const linkLabel = title || url
30 const link = url ? `[${linkLabel}](${url})` : ''
31 if (!link) { return text }
32 if (!text) { return link }
33 if (text.includes(url)) { return text }
34 return `${text}\n\n${link}`
35}