Add relationship info to author pages

This commit is contained in:
Christian Bundy 2019-12-07 14:58:08 -08:00
parent 63e1dea1a2
commit 62bd34b553
No known key found for this signature in database
GPG Key ID: EB541AAEF4366237
6 changed files with 72 additions and 8 deletions

View File

@ -1,12 +1,12 @@
# Roadmap
- [ ] Get
- [ ] Author
- [x] Author
- [x] Name
- [x] Description
- [x] Image
- [ ] Follow / unfollow (public)
- [ ] Block / unblock (public)
- [x] Follow / unfollow (public)
- [x] Block / unblock (public)
- [x] Likes
- [x] Metadata ("about" messages)
- [x] Markdown mention

View File

@ -2,6 +2,7 @@
const about = require('./models/about')
const post = require('./models/post')
const friend = require('./models/friend')
const authorView = require('./views/author')
module.exports = async function authorPage (feedId) {
@ -10,6 +11,7 @@ module.exports = async function authorPage (feedId) {
const image = await about.image(feedId)
const aboutPairs = await about.all(feedId)
const messages = await post.fromFeed(feedId)
const relationship = await friend.getRelationship(feedId)
const avatarUrl = `/image/128/${encodeURIComponent(image)}`
@ -19,6 +21,7 @@ module.exports = async function authorPage (feedId) {
name,
description,
avatarUrl,
aboutPairs
aboutPairs,
relationship
})
}

View File

@ -0,0 +1,53 @@
'use strict'
const cooler = require('./lib/cooler')
module.exports = {
isFollowing: async (feedId) => {
const ssb = await cooler.connect()
const { id } = await cooler.get(ssb.whoami)
const isFollowing = await cooler.get(
ssb.friends.isFollowing,
{
source: id,
dest: feedId
}
)
return isFollowing
},
getRelationship: async (feedId) => {
const ssb = await cooler.connect()
const { id } = await cooler.get(ssb.whoami)
if (feedId === id) {
return 'this is you'
}
const isFollowing = await cooler.get(
ssb.friends.isFollowing,
{
source: id,
dest: feedId
}
)
const isBlocking = await cooler.get(
ssb.friends.isBlocking,
{
source: id,
dest: feedId
}
)
if (isFollowing === true && isBlocking === false) {
return 'you are following'
} else if (isFollowing === false && isBlocking === true) {
return 'you are blocking'
} else if (isFollowing === false && isBlocking === false) {
return 'you are not following or blocking'
} else {
return 'you are following and blocking (!)'
}
}
}

View File

@ -31,7 +31,11 @@ const rawConnect = () => new Promise((resolve, reject) => {
status: 'async',
whoami: 'sync',
tangle: { branch: 'async' },
query: { read: 'source' }
query: { read: 'source' },
friends: {
isFollowing: 'async',
isBlocking: 'async'
}
}
}, (err, api) => {
if (err) {

View File

@ -23,6 +23,7 @@ module.exports = async function profilePage () {
name,
description,
avatarUrl,
aboutPairs
aboutPairs,
relationship: null
})
}

View File

@ -10,6 +10,7 @@ const {
img,
pre,
section,
span,
table,
tbody,
td,
@ -27,7 +28,8 @@ module.exports = ({
description,
feedId,
messages,
name
name,
relationship
}) => {
const mention = `[@${name}](${feedId})`
const markdownMention = highlightJs.highlight('markdown', mention).value
@ -63,7 +65,8 @@ module.exports = ({
: null,
metaTable,
footer(
a({ href: `/likes/${encodeURIComponent(feedId)}` }, 'view likes')
a({ href: `/likes/${encodeURIComponent(feedId)}` }, 'view likes'),
span(relationship)
)
)