Files: 8a6dee20553eb2c7dc78f6ae843306099b24b093 / message / obs / backlinks.js
868 bytesRaw
1 | var nest = require('depnest') |
2 | var computed = require('mutant/computed') |
3 | |
4 | exports.needs = nest({ |
5 | 'backlinks.obs.for': 'first', |
6 | 'message.sync.root': 'first' |
7 | }) |
8 | |
9 | exports.gives = nest('message.obs.backlinks', true) |
10 | |
11 | exports.create = function (api) { |
12 | return nest({ |
13 | // DEPRECATED: should use backlinks.obs.for |
14 | 'message.obs.backlinks': (id) => backlinks(id) |
15 | }) |
16 | |
17 | function backlinks (id) { |
18 | return computed([api.backlinks.obs.for(id)], (msgs) => { |
19 | return msgs.map(map).filter((backlink) => { |
20 | return backlink.type !== 'vote' && backlink.type !== 'about' |
21 | }) |
22 | }) |
23 | } |
24 | |
25 | function map (msg) { |
26 | return { |
27 | dest: msg.dest, |
28 | id: msg.key, |
29 | timestamp: msg.timestamp, |
30 | type: msg.value.content.type, |
31 | root: api.message.sync.root(msg), |
32 | branch: msg.value.content.branch, |
33 | author: msg.value.author |
34 | } |
35 | } |
36 | } |
37 |
Built with git-ssb-web