From 58cd6d811c22ab2eba24513595e176ecc91fad28 Mon Sep 17 00:00:00 2001 From: cel Date: Sun, 18 Nov 2018 19:22:04 -1000 Subject: List enemies (mutually blocked) as described in %OQNVmPmJiNRwT/FxCVxWQ09yQgPY1f20wjp50KnjFM8=.sha256 --- lib/contacts.js | 21 +++++++++++++++++++-- lib/serve.js | 12 ++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/contacts.js b/lib/contacts.js index 846cdf9..e1d4a0a 100644 --- a/lib/contacts.js +++ b/lib/contacts.js @@ -88,6 +88,7 @@ Contacts.prototype.createFriendsStream = function (opts, endCb) { var msgIds = opts.msgIds var follows = {}, followers = {} var blocks = {}, blockers = {} + var enemies = opts.enemies && {} return pull( many([ this._createContactStream(id, null), @@ -114,9 +115,21 @@ Contacts.prototype.createFriendsStream = function (opts, endCb) { } } else if (edge.value === false) { if (edge.source === id) { - blocks[edge.dest] = msgIds ? {feed: edge.dest, msg: edge.msg} : edge.dest + if (enemies && blockers[edge.dest]) { + var item2 = blockers[edge.dest] + delete blockers[edge.dest] + enemies[edge.dest] = msgIds ? {feed: edge.dest, msg: edge.msg, msg2: item2.msg} : edge.dest + } else { + blocks[edge.dest] = msgIds ? {feed: edge.dest, msg: edge.msg} : edge.dest + } } else if (edge.dest === id) { - blockers[edge.source] = msgIds ? {feed: edge.source, msg: edge.msg} : edge.source + if (enemies && blocks[edge.source]) { + var item2 = blocks[edge.source] + delete blocks[edge.source] + enemies[edge.source] = msgIds ? {feed: edge.source, msg: edge.msg, msg2: item2.msg} : edge.source + } else { + blockers[edge.source] = msgIds ? {feed: edge.source, msg: edge.msg} : edge.source + } } } }), @@ -130,6 +143,7 @@ Contacts.prototype.createFriendsStream = function (opts, endCb) { follows: Object.values(follows), blocks: Object.values(blocks), blockers: Object.values(blockers), + enemies: Object.values(enemies), }) }) } @@ -143,16 +157,19 @@ Contacts.prototype.createContactStreams = function (opts) { var followers = defer.source() var blocks = defer.source() var blockers = defer.source() + var enemies = defer.source() var friends = this.createFriendsStream(opts, function (err, more) { follows.resolve(err ? pull.error(err) : pull.values(more.follows)) followers.resolve(err ? pull.error(err) : pull.values(more.followers)) blocks.resolve(err ? pull.error(err) : pull.values(more.blocks)) blockers.resolve(err ? pull.error(err) : pull.values(more.blockers)) + enemies.resolve(err ? pull.error(err) : pull.values(more.enemies)) }) return { friends: friends, follows: follows, followers: followers, + enemies: enemies, blocks: blocks, blockers: blockers, } diff --git a/lib/serve.js b/lib/serve.js index 0ca35a6..3db1c3c 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -879,7 +879,11 @@ Serve.prototype.tags = function (path) { Serve.prototype.contacts = function (path) { var self = this var id = String(path).substr(1) - var contacts = self.app.contacts.createContactStreams({id: id, msgIds: true}) + var contacts = self.app.contacts.createContactStreams({ + id: id, + msgIds: true, + enemies: true + }) var render = self.app.render pull( @@ -895,7 +899,11 @@ Serve.prototype.contacts = function (path) { ph('h4', {}, 'Blocks'), render.friendsList('/contacts/')(contacts.blocks), ph('h4', {}, 'Blocked by'), - render.friendsList('/contacts/')(contacts.blockers) + render.friendsList('/contacts/')(contacts.blockers), + contacts.enemies ? [ + ph('h4', {}, 'Enemies'), + render.friendsList('/contacts/')(contacts.enemies), + ] : '' ]) ]), this.wrapPage('contacts: ' + id), -- cgit v1.2.3