Files: cc5761a7888cf2028451fa4e3a4eedeadca0f595 / message / sync / is-blocked.js
740 bytesRaw
1 | const nest = require('depnest') |
2 | |
3 | exports.gives = nest('message.sync.isBlocked') |
4 | |
5 | exports.needs = nest({ |
6 | 'contact.obs.blocking': 'first', |
7 | 'contact.obs.raw': 'first', |
8 | 'keys.sync.id': 'first' |
9 | }) |
10 | |
11 | exports.create = function (api) { |
12 | var cache = null |
13 | |
14 | return nest('message.sync.isBlocked', function isBlockedMessage (msg, rootMessage) { |
15 | if (!cache) { |
16 | cache = api.contact.obs.blocking(api.keys.sync.id()) |
17 | } |
18 | |
19 | if (rootMessage) { |
20 | // check if the author of the root message blocks the author of the message |
21 | var rawContact = api.contact.obs.raw(rootMessage.value.author) |
22 | if (rawContact()[msg.value.author] === false) { |
23 | return true |
24 | } |
25 | } |
26 | |
27 | return cache().includes(msg.value.author) |
28 | }) |
29 | } |
30 |
Built with git-ssb-web