From fbeef1b9ecef39198b00c51c9c86f26c86ca6b08 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 7 Oct 2019 18:53:21 -0700 Subject: [PATCH] Add about messages to profile view --- src/assets/style.css | 15 +++++++++++++++ src/pages/author.js | 4 +++- src/pages/models/about.js | 33 +++++++++++++++++++++++++++++++++ src/pages/models/lib/cooler.js | 5 ++++- src/pages/profile.js | 4 +++- src/pages/views/author.js | 33 +++++++++++++++++++++++++++++---- 6 files changed, 87 insertions(+), 7 deletions(-) diff --git a/src/assets/style.css b/src/assets/style.css index ad72fba..b66949c 100644 --- a/src/assets/style.css +++ b/src/assets/style.css @@ -373,3 +373,18 @@ summary { background: none; font-size: 50%; } + +table { + width: 100%; +} + +td, +th { + padding: 0.5rem; + outline: var(--thin-stroke) solid var(--bg-status); +} + +th { + text-align: left; + background-color: var(--bg-status); +} diff --git a/src/pages/author.js b/src/pages/author.js index bf14420..abad260 100644 --- a/src/pages/author.js +++ b/src/pages/author.js @@ -8,6 +8,7 @@ module.exports = async function authorPage (feedId) { const description = await about.description(feedId) const name = await about.name(feedId) const image = await about.image(feedId) + const aboutPairs = await about.all(feedId) const messages = await post.fromFeed(feedId) const avatarUrl = `/image/128/${encodeURIComponent(image)}` @@ -17,6 +18,7 @@ module.exports = async function authorPage (feedId) { messages, name, description, - avatarUrl + avatarUrl, + aboutPairs }) } diff --git a/src/pages/models/about.js b/src/pages/models/about.js index d09d2d7..30cde71 100644 --- a/src/pages/models/about.js +++ b/src/pages/models/about.js @@ -2,6 +2,7 @@ const cooler = require('./lib/cooler') const markdown = require('./lib/markdown') +const pull = require('pull-stream') const nullImage = `&${'0'.repeat(43)}=.sha256` @@ -40,5 +41,37 @@ module.exports = { } ) return markdown(raw) + }, + all: async (feedId) => { + const ssb = await cooler.connect() + const raw = await cooler.read( + ssb.about.read, { + dest: feedId + } + ) + + return new Promise((resolve, reject) => + pull( + raw, + pull.filter((message) => message.value.author === feedId), + pull.reduce((acc, cur) => { + const metaKeys = ['type', 'about'] + + Object.entries(cur.value.content).filter(([key]) => + metaKeys.includes(key) === false + ).forEach(([key, value]) => { + acc[key] = value + }) + + return acc + }, {}, (err, val) => { + if (err) { + reject(err) + } else { + resolve(val) + } + }) + ) + ) } } diff --git a/src/pages/models/lib/cooler.js b/src/pages/models/lib/cooler.js index fd37027..810e47d 100644 --- a/src/pages/models/lib/cooler.js +++ b/src/pages/models/lib/cooler.js @@ -10,7 +10,10 @@ const server = flotilla({ ws: { http: false } }) const rawConnect = () => new Promise((resolve, reject) => { ssbClient({ manifest: { - about: { socialValue: 'async' }, + about: { + socialValue: 'async', + read: 'source' + }, backlinks: { read: 'source' }, blobs: { get: 'source', want: 'async' }, createUserStream: 'source', diff --git a/src/pages/profile.js b/src/pages/profile.js index 10847bb..54b66d2 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -12,6 +12,7 @@ module.exports = async function profilePage () { const description = await about.description(feedId) const name = await about.name(feedId) const image = await about.image(feedId) + const aboutPairs = await about.all(feedId) const messages = await post.fromFeed(feedId) @@ -22,6 +23,7 @@ module.exports = async function profilePage () { messages, name, description, - avatarUrl + avatarUrl, + aboutPairs }) } diff --git a/src/pages/views/author.js b/src/pages/views/author.js index 3cef102..8ebb6a1 100644 --- a/src/pages/views/author.js +++ b/src/pages/views/author.js @@ -3,22 +3,45 @@ const highlightJs = require('highlight.js') const { article, + h1, header, img, - h1, + pre, section, - pre + table, + tbody, + td, + th, + tr } = require('hyperaxe') const post = require('./components/post') const template = require('./components/template') module.exports = ({ - avatarUrl, name, description, messages, feedId + aboutPairs, + avatarUrl, + description, + feedId, + messages, + name }) => { const mention = `[@${name}](${feedId})` const markdownMention = highlightJs.highlight('markdown', mention).value + const alreadyHandled = [ + 'description', + 'image', + 'name' + ] + const metaRows = Object.entries(aboutPairs) + .filter(([key]) => alreadyHandled.includes(key) === false) + .map(([key, value]) => tr(td(key), td(value))) + + const metaTable = metaRows.length > 0 + ? table(tbody(tr(th('key'), th('value')), metaRows)) + : null + const prefix = section({ class: 'message' }, header({ class: 'profile' }, img({ class: 'avatar', src: avatarUrl }), @@ -29,7 +52,9 @@ module.exports = ({ }), description !== '

null

\n' ? article({ innerHTML: description }) - : null) + : null, + metaTable + ) return template( prefix,