aboutsummaryrefslogtreecommitdiff
path: root/lib/contacts.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-11-18 19:22:04 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-11-18 19:41:30 -1000
commit58cd6d811c22ab2eba24513595e176ecc91fad28 (patch)
treed0f938e92efd56f911b7b1a52f4f264cb94c333c /lib/contacts.js
parentf4016d4ba6a5039c709e83fb0a4492b96e9d09bd (diff)
downloadpatchfoo-58cd6d811c22ab2eba24513595e176ecc91fad28.tar.gz
patchfoo-58cd6d811c22ab2eba24513595e176ecc91fad28.zip
List enemies (mutually blocked)
as described in %OQNVmPmJiNRwT/FxCVxWQ09yQgPY1f20wjp50KnjFM8=.sha256
Diffstat (limited to 'lib/contacts.js')
-rw-r--r--lib/contacts.js21
1 files changed, 19 insertions, 2 deletions
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,
}