Files: 53223b8604d4abb25d4300575f28f0076460a02e / message / obs / backlinks.js
934 bytesRaw
1 | var nest = require('depnest') |
2 | var computed = require('mutant/computed') |
3 | |
4 | exports.needs = nest({ |
5 | 'backlinks.obs.for': 'first' |
6 | }) |
7 | |
8 | exports.gives = nest('message.obs.backlinks', true) |
9 | |
10 | exports.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