diff options
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())) |