Files: bf250c5c301cdcd83a84b88c89dd0d55db5fb8d7 / message / html / subject.js
1097 bytesRaw
1 | const nest = require('depnest') |
2 | const { computed, Value } = require('mutant') |
3 | const { title } = require('markdown-summary') |
4 | const { isMsg } = require('ssb-ref') |
5 | |
6 | |
7 | exports.gives = nest('message.html.subject') |
8 | |
9 | exports.needs = nest({ |
10 | 'message.html.markdown': 'first', |
11 | 'message.sync.unbox': 'first', |
12 | 'sbot.async.get': 'first', |
13 | }) |
14 | |
15 | exports.create = function (api) { |
16 | return nest('message.html.subject', subject) |
17 | |
18 | function subject (msg) { |
19 | if (msg === undefined) debugger |
20 | // test if it's a message ref, or a full message object |
21 | if (isMsg(msg)) { |
22 | var subject = Value() |
23 | |
24 | api.sbot.async.get(msg, (err, value) => { |
25 | if (err) throw err |
26 | |
27 | subject.set(getMsgSubject({ |
28 | key: msg, |
29 | value: api.message.sync.unbox(value) |
30 | })) |
31 | }) |
32 | |
33 | return subject |
34 | } |
35 | else |
36 | return getMsgSubject(msg) |
37 | } |
38 | |
39 | function getMsgSubject (msg) { |
40 | const { subject, text } = msg.value.content |
41 | if(!(subject || text)) return |
42 | |
43 | return subject |
44 | ? api.message.html.markdown(subject) |
45 | : api.message.html.markdown(title(text)) |
46 | } |
47 | } |
48 | |
49 |
Built with git-ssb-web