git ssb

2+

mixmix / ticktack



Tree: fd90a69c5a2931ed4ec735c57c4b2ebb42bcfe42

Files: fd90a69c5a2931ed4ec735c57c4b2ebb42bcfe42 / app / html / thread.js

1519 bytesRaw
1const nest = require('depnest')
2const { h, Array: MutantArray, map } = require('mutant')
3const pull = require('pull-stream')
4const last = require('lodash/last')
5const get = require('lodash/last')
6
7exports.gives = nest('app.html.thread')
8
9exports.needs = nest({
10 'app.sync.goTo': 'first'
11})
12
13exports.create = (api) => {
14 return nest('app.html.thread', thread)
15
16 function thread (source) {
17 // location here can expected to be: { page: 'home' }
18
19 const chunkedThread = buildChunkedThreadObs(source)
20
21 const { goTo } = api.app.sync
22 const threadView = h('Thread',
23 map(chunkedThread, chunk => {
24 return h('div' , [
25 h('div', '---'),
26
27 map(chunk, msg => {
28 return h('div', {style: { margin: '10px', background: 'white' }}, msg.value.content.text) // TODO (mix): use lodash/get
29 })
30 ])
31 })
32 )
33
34 return threadView
35 }
36}
37
38function buildChunkedThreadObs (source) {
39 var chunkedThread = MutantArray()
40
41 var _chunk = null
42 var _lastMsg = null
43
44 pull(
45 source,
46 pull.drain(msg => {
47 if (!_lastMsg || !isSameAuthor(_lastMsg, msg))
48 createNewChunk(msg)
49 else
50 _chunk.push(msg)
51
52 _lastMsg = msg
53 })
54 )
55
56 function createNewChunk (msg) {
57 const newChunk = MutantArray()
58 newChunk.push(msg)
59 chunkedThread.push(newChunk)
60 _chunk = newChunk
61 }
62
63 return chunkedThread
64}
65
66function isSameAuthor (msgA, msgB) {
67 // TODO (mix) use lodash/get
68 return msgA.value.author === msgB.value.author
69}
70
71

Built with git-ssb-web