Files: e0439586cabe63fc84e88ff400edb18470cdec52 / message / obs / get.js
1054 bytesRaw
1 | var Value = require('mutant/value') |
2 | var ref = require('ssb-ref') |
3 | var nest = require('depnest') |
4 | |
5 | exports.needs = nest('sbot.async.get', 'first') |
6 | |
7 | exports.gives = nest('message.obs.get') |
8 | |
9 | exports.create = function (api) { |
10 | return nest('message.obs.get', function (key, hintMessage = null) { |
11 | if (!ref.isMsg(key)) throw new Error('a msg id must be specified') |
12 | var result = Value() |
13 | |
14 | api.sbot.async.get(key, (err, value) => { |
15 | if (err) { |
16 | // TODO: handle resolving out-of-order message! |
17 | |
18 | // guess the author |
19 | var possibleAuthor |
20 | if (hintMessage && hintMessage.value && hintMessage.content && hintMessage.value.content.reply && ref.isFeed(hintMessage.value.content.reply[key])) { |
21 | possibleAuthor = hintMessage.value.content.reply[key] |
22 | } |
23 | |
24 | result.set({ |
25 | key, |
26 | value: { |
27 | missing: true, |
28 | author: possibleAuthor |
29 | } |
30 | }) |
31 | } else { |
32 | result.set({ |
33 | key, |
34 | value |
35 | }) |
36 | } |
37 | }) |
38 | |
39 | return result |
40 | }) |
41 | } |
42 |
Built with git-ssb-web