diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-12 17:53:27 -0700 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-12 18:51:16 -0700 |
commit | a755d08d1cdfde6a9a48de38d8fdd779148709b8 (patch) | |
tree | 0ff0ffdc48fac7c82ea2b82471325a2074a802d5 /lib/serve.js | |
parent | 84e5ab8d6281beeeadb18d7c411157498638749a (diff) | |
download | patchfoo-a755d08d1cdfde6a9a48de38d8fdd779148709b8.tar.gz patchfoo-a755d08d1cdfde6a9a48de38d8fdd779148709b8.zip |
Add (un)follow button
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 42 |
1 files changed, 41 insertions, 1 deletions
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())) |