git ssb

2+

mixmix / ticktack



Tree: 36fdd005ea9c7306764cf0040cbb11101156f80a

Files: 36fdd005ea9c7306764cf0040cbb11101156f80a / message / html / subject.js

1391 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 try {
31 var _subject = getMsgSubject({ key: msg, value: api.message.sync.unbox(value) })
32 subject.set(_subject)
33 subjectCache[msg] = _subject
34 } catch (n) {
35 subject.set("broken message")
36 }
37
38 })
39
40 return subject
41 } else { return getMsgSubject(msg) }
42 }
43
44 function getMsgSubject(msg) {
45 const { subject, text } = msg.value.content
46 if (!(subject || text)) return
47
48 return subject
49 ? api.message.html.markdown(subject)
50 : api.message.html.markdown(title(text))
51 }
52}
53

Built with git-ssb-web