Add relationship info to author pages
This commit is contained in:
@ -1,12 +1,12 @@
|
|||||||
# Roadmap
|
# Roadmap
|
||||||
|
|
||||||
- [ ] Get
|
- [ ] Get
|
||||||
- [ ] Author
|
- [x] Author
|
||||||
- [x] Name
|
- [x] Name
|
||||||
- [x] Description
|
- [x] Description
|
||||||
- [x] Image
|
- [x] Image
|
||||||
- [ ] Follow / unfollow (public)
|
- [x] Follow / unfollow (public)
|
||||||
- [ ] Block / unblock (public)
|
- [x] Block / unblock (public)
|
||||||
- [x] Likes
|
- [x] Likes
|
||||||
- [x] Metadata ("about" messages)
|
- [x] Metadata ("about" messages)
|
||||||
- [x] Markdown mention
|
- [x] Markdown mention
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const about = require('./models/about')
|
const about = require('./models/about')
|
||||||
const post = require('./models/post')
|
const post = require('./models/post')
|
||||||
|
const friend = require('./models/friend')
|
||||||
const authorView = require('./views/author')
|
const authorView = require('./views/author')
|
||||||
|
|
||||||
module.exports = async function authorPage (feedId) {
|
module.exports = async function authorPage (feedId) {
|
||||||
@ -10,6 +11,7 @@ module.exports = async function authorPage (feedId) {
|
|||||||
const image = await about.image(feedId)
|
const image = await about.image(feedId)
|
||||||
const aboutPairs = await about.all(feedId)
|
const aboutPairs = await about.all(feedId)
|
||||||
const messages = await post.fromFeed(feedId)
|
const messages = await post.fromFeed(feedId)
|
||||||
|
const relationship = await friend.getRelationship(feedId)
|
||||||
|
|
||||||
const avatarUrl = `/image/128/${encodeURIComponent(image)}`
|
const avatarUrl = `/image/128/${encodeURIComponent(image)}`
|
||||||
|
|
||||||
@ -19,6 +21,7 @@ module.exports = async function authorPage (feedId) {
|
|||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
avatarUrl,
|
avatarUrl,
|
||||||
aboutPairs
|
aboutPairs,
|
||||||
|
relationship
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
53
src/pages/models/friend.js
Normal file
53
src/pages/models/friend.js
Normal 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 (!)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -31,7 +31,11 @@ const rawConnect = () => new Promise((resolve, reject) => {
|
|||||||
status: 'async',
|
status: 'async',
|
||||||
whoami: 'sync',
|
whoami: 'sync',
|
||||||
tangle: { branch: 'async' },
|
tangle: { branch: 'async' },
|
||||||
query: { read: 'source' }
|
query: { read: 'source' },
|
||||||
|
friends: {
|
||||||
|
isFollowing: 'async',
|
||||||
|
isBlocking: 'async'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, (err, api) => {
|
}, (err, api) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -23,6 +23,7 @@ module.exports = async function profilePage () {
|
|||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
avatarUrl,
|
avatarUrl,
|
||||||
aboutPairs
|
aboutPairs,
|
||||||
|
relationship: null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ const {
|
|||||||
img,
|
img,
|
||||||
pre,
|
pre,
|
||||||
section,
|
section,
|
||||||
|
span,
|
||||||
table,
|
table,
|
||||||
tbody,
|
tbody,
|
||||||
td,
|
td,
|
||||||
@ -27,7 +28,8 @@ module.exports = ({
|
|||||||
description,
|
description,
|
||||||
feedId,
|
feedId,
|
||||||
messages,
|
messages,
|
||||||
name
|
name,
|
||||||
|
relationship
|
||||||
}) => {
|
}) => {
|
||||||
const mention = `[@${name}](${feedId})`
|
const mention = `[@${name}](${feedId})`
|
||||||
const markdownMention = highlightJs.highlight('markdown', mention).value
|
const markdownMention = highlightJs.highlight('markdown', mention).value
|
||||||
@ -63,7 +65,8 @@ module.exports = ({
|
|||||||
: null,
|
: null,
|
||||||
metaTable,
|
metaTable,
|
||||||
footer(
|
footer(
|
||||||
a({ href: `/likes/${encodeURIComponent(feedId)}` }, 'view likes')
|
a({ href: `/likes/${encodeURIComponent(feedId)}` }, 'view likes'),
|
||||||
|
span(relationship)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user