git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: 428676644191b3fcf658e49167d835bb682488a2

Files: 428676644191b3fcf658e49167d835bb682488a2 / message / obs / backlinks.js

934 bytesRaw
1var nest = require('depnest')
2var computed = require('mutant/computed')
3
4exports.needs = nest({
5 'backlinks.obs.for': 'first'
6})
7
8exports.gives = nest('message.obs.backlinks', true)
9
10exports.create = function (api) {
11 return nest({
12 // DEPRECATED: should use backlinks.obs.for
13 'message.obs.backlinks': (id) => backlinks(id)
14 })
15
16 function backlinks (id) {
17 return computed([api.backlinks.obs.for(id)], (msgs) => {
18 return msgs.map(map).filter((backlink) => {
19 return backlink.type !== 'vote' && backlink.type !== 'about'
20 })
21 }, {
22 // objects coming down this stream will be immutable
23 comparer: (a, b) => a === b
24 })
25 }
26
27 function map (msg) {
28 return {
29 dest: msg.dest,
30 id: msg.key,
31 timestamp: msg.timestamp,
32 type: msg.value.content.type,
33 root: msg.value.content.root,
34 branch: msg.value.content.branch,
35 author: msg.value.author
36 }
37 }
38}
39

Built with git-ssb-web