git ssb

2+

mixmix / ticktack



Tree: adca29179dee2177af6fefa725c91581ffef5395

Files: adca29179dee2177af6fefa725c91581ffef5395 / message / html / subject.js

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

Built with git-ssb-web