aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-12 17:53:27 -0700
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-12 18:51:16 -0700
commita755d08d1cdfde6a9a48de38d8fdd779148709b8 (patch)
tree0ff0ffdc48fac7c82ea2b82471325a2074a802d5 /lib
parent84e5ab8d6281beeeadb18d7c411157498638749a (diff)
downloadpatchfoo-a755d08d1cdfde6a9a48de38d8fdd779148709b8.tar.gz
patchfoo-a755d08d1cdfde6a9a48de38d8fdd779148709b8.zip
Add (un)follow button
Diffstat (limited to 'lib')
-rw-r--r--lib/app.js15
-rw-r--r--lib/serve.js42
2 files changed, 56 insertions, 1 deletions
diff --git a/lib/app.js b/lib/app.js
index 6cc71a0..465e45b 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -201,6 +201,21 @@ App.prototype.streamPeers = function (opts) {
})
}
+App.prototype.getFollow = function (source, dest, cb) {
+ var self = this
+ pull(
+ self.sbot.links({source: source, dest: dest, rel: 'contact', values: true}),
+ pull.filter(function (msg) {
+ var c = msg && msg.value && msg.value.content
+ return c && c.type === 'contact'
+ }),
+ pull.reduce(function (doesFollow, msg) {
+ var c = msg.value.content
+ return !!c.following
+ }, false, cb)
+ )
+}
+
App.prototype.getFollows = function (id, cb) {
var self = this
pull(
diff --git a/lib/serve.js b/lib/serve.js
index ec63b59..9137bc5 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -116,6 +116,7 @@ Serve.prototype.go = function () {
if (err) next(err)
else if (data.action === 'publish') self.publishJSON(next)
else if (data.action === 'vote') self.publishVote(next)
+ else if (data.action === 'contact') self.publishContact(next)
else next()
}
@@ -152,6 +153,15 @@ Serve.prototype.publishVote = function (cb) {
this.publish(content, cb)
}
+Serve.prototype.publishContact = function (cb) {
+ var content = {
+ type: 'contact',
+ contact: this.data.contact,
+ following: !!this.data.following
+ }
+ this.publish(content, cb)
+}
+
Serve.prototype.publish = function (content, cb) {
var self = this
var done = multicb({pluck: 1, spread: true})
@@ -827,14 +837,32 @@ Serve.prototype.friendList = function (friends, cb) {
return list
}
+var relationships = [
+ '',
+ 'followed',
+ 'follows you',
+ 'friend'
+]
+
+var relationshipActions = [
+ 'follow',
+ 'unfollow',
+ 'follow back',
+ 'unfriend'
+]
+
Serve.prototype.wrapUserFeed = function (isScrolled, id) {
var self = this
+ var myId = self.app.sbot.id
return u.hyperwrap(function (thread, cb) {
var done = multicb({pluck: 1, spread: true})
self.app.getAbout(id, done())
+ self.app.getFollow(myId, id, done())
+ self.app.getFollow(id, myId, done())
if (!isScrolled) self.app.getFriendInfo(id, done())
- done(function (err, about, info) {
+ done(function (err, about, weFollowThem, theyFollowUs, info) {
if (err) return cb(err)
+ var relationshipI = weFollowThem | theyFollowUs<<1
var done = multicb({pluck: 1, spread: true})
done()(null, [
h('section.ssb-feed',
@@ -848,6 +876,18 @@ Serve.prototype.wrapUserFeed = function (isScrolled, id) {
{innerHTML: self.app.render.markdown(about.description)}) : ''
)),
isScrolled ? '' : [
+ id === myId ? '' : h('tr',
+ h('td'),
+ h('td.follow-info', h('form', {action: '', method: 'post'},
+ relationships[relationshipI], ' ',
+ h('input', {type: 'hidden', name: 'action', value: 'contact'}),
+ h('input', {type: 'hidden', name: 'contact', value: id}),
+ h('input', {type: 'hidden', name: 'following',
+ value: weFollowThem ? '' : 'following'}),
+ h('input', {type: 'submit',
+ value: relationshipActions[relationshipI]})
+ ))
+ ),
h('tr',
h('td', 'friends:'),
h('td', self.friendList(info.friends, done()))