From c7b4eb97124284b5c2f9d27a78fbcd83abf3d88a Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 10 Nov 2017 07:56:13 +1300 Subject: Add block button --- lib/app.js | 15 ++++++++------- lib/serve.js | 37 ++++++++++++++----------------------- 2 files changed, 22 insertions(+), 30 deletions(-) (limited to 'lib') diff --git a/lib/app.js b/lib/app.js index c2beb69..0adf59a 100644 --- a/lib/app.js +++ b/lib/app.js @@ -395,20 +395,21 @@ App.prototype.streamPeers = function (opts) { }) } -App.prototype.getFollow = function (source, dest, cb) { +App.prototype.getContact = function (source, dest, cb) { var self = this pull( - self.sbot.links({source: source, dest: dest, rel: 'contact', reverse: true, + self.sbot.links({source: source, dest: dest, rel: 'contact', values: true, meta: false, keys: false}), pull.filter(function (value) { var c = value && value.content return c && c.type === 'contact' }), - pull.take(1), - pull.collect(function (err, msgs) { - if (err) return cb(err) - cb(null, msgs[0] && !!msgs[0].content.following) - }) + pull.reduce(function (acc, value) { + // trinary logic from ssb-friends + return value.content.following ? true + : value.content.flagged || value.content.blocking ? false + : acc + }, null, cb) ) } diff --git a/lib/serve.js b/lib/serve.js index 11630e4..6d3786d 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -193,8 +193,11 @@ Serve.prototype.publishContact = function (cb) { var content = { type: 'contact', contact: this.data.contact, - following: !!this.data.following } + if (this.data.follow) content.following = true + if (this.data.block) content.blocking = true + if (this.data.unfollow) content.following = false + if (this.data.unblock) content.blocking = false this.publish(content, cb) } @@ -1499,20 +1502,6 @@ Serve.prototype.renderIdsList = function () { ) } -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 @@ -1520,11 +1509,10 @@ Serve.prototype.wrapUserFeed = function (isScrolled, 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()) - done(function (err, about, weFollowThem, theyFollowUs) { + self.app.getContact(myId, id, done()) + self.app.getContact(id, myId, done()) + done(function (err, about, contactToThem, contactFromThem) { if (err) return cb(err) - var relationshipI = weFollowThem | theyFollowUs<<1 var done = multicb({pluck: 1, spread: true}) done()(null, [ h('section.ssb-feed', @@ -1558,13 +1546,16 @@ Serve.prototype.wrapUserFeed = function (isScrolled, id) { id === myId ? '' : h('tr', h('td'), h('td.follow-info', h('form', {action: '', method: 'post'}, - relationships[relationshipI], ' ', + contactFromThem ? contactToThem ? 'friend ' : 'follows you ' : + contactFromThem === false ? 'blocks you ' : '', 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]}) + name: contactToThem ? 'unfollow' : 'follow', + value: contactToThem ? 'unfollow' : 'follow'}), ' ', + h('input', {type: 'submit', + name: contactToThem === false ? 'unblock' : 'block', + value: contactToThem === false ? 'unblock' : 'block'}) )) ) ] -- cgit v1.2.3