git ssb

2+

mixmix / ticktack



Commit 963223adf0b2978b4a3b94648b98620052008579

change threads to use existing observable from patchcore

mix irving committed on 8/9/2017, 1:20:23 AM
Parent: a73aa37ff93b9ce8d191f6ab8ad82e4c673126f2

Files changed

app/html/thread.jschanged
app/page/private.jschanged
app/html/thread.jsView
@@ -8,50 +8,49 @@
88
99 exports.needs = nest({
1010 'about.html.image': 'first',
1111 'app.sync.goTo': 'first',
12+ 'feed.obs.thread': 'first',
1213 'message.html.markdown': 'first'
1314 })
1415
1516 exports.create = (api) => {
1617 return nest('app.html.thread', thread)
1718
18- function thread (source) {
19+ function thread (id) {
1920 // location here can expected to be: { page: 'home' }
2021
21- const chunkedThread = buildChunkedThreadObs(source)
2222
2323 var myId = '@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519'
2424 // TODO (mix) use keys.sync.id
2525
26+ const thread = api.feed.obs.thread(id)
27+ const chunkedMessages = buildChunkedMessages(thread.messages)
28+
2629 const { goTo } = api.app.sync
2730 const threadView = h('Thread',
28- map(chunkedThread, chunk => {
31+ map(chunkedMessages, chunk => {
32+ const author = get(chunk, '[0].value.author')
2933
30- return computed(chunk, chunk => {
31- const author = get(chunk, '[0].value.author')
32- if (author === myId) {
33- return h('div.my-chunk', [
34+ return author === myId
35+ ? h('div.my-chunk', [
3436 h('div.avatar'),
3537 h('div.msgs', map(chunk, msg => {
3638 return h('div.msg-row', [
3739 h('div.spacer'),
3840 message(msg)
3941 ])
4042 }))
4143 ])
42- } else {
43- return h('div.other-chunk', [
44- h('div.avatar', api.about.html.image(author)),
44+ : h('div.other-chunk', [
45+ h('div.avatar', when(author, api.about.html.image(author))),
4546 h('div.msgs', map(chunk, msg => {
4647 return h('div.msg-row', [
4748 message(msg),
4849 h('div.spacer')
4950 ])
5051 }))
5152 ])
52- }
53- })
5453 })
5554 )
5655
5756 function message (msg) {
@@ -63,34 +62,33 @@
6362 return threadView
6463 }
6564 }
6665
67-function buildChunkedThreadObs (source) {
68- var chunkedThread = MutantArray()
66+function buildChunkedMessages (messagesObs) {
67+ return computed(messagesObs, msgs => {
68+ var chunkedMessages = MutantArray()
6969
70- var _chunk = null
71- var _lastMsg = null
72-
73- pull(
74- source,
75- pull.drain(msg => {
70+ var _chunk = null
71+ var _lastMsg = null
72+
73+ msgs.forEach(msg => {
7674 if (!_lastMsg || !isSameAuthor(_lastMsg, msg))
7775 createNewChunk(msg)
7876 else
7977 _chunk.push(msg)
8078
8179 _lastMsg = msg
8280 })
83- )
8481
85- function createNewChunk (msg) {
86- const newChunk = MutantArray()
87- newChunk.push(msg)
88- chunkedThread.push(newChunk)
89- _chunk = newChunk
90- }
82+ function createNewChunk (msg) {
83+ const newChunk = MutantArray()
84+ newChunk.push(msg)
85+ chunkedMessages.push(newChunk)
86+ _chunk = newChunk
87+ }
9188
92- return chunkedThread
89+ return chunkedMessages
90+ })
9391 }
9492
9593 function isSameAuthor (msgA, msgB) {
9694 // TODO (mix) use lodash/get
app/page/private.jsView
@@ -18,11 +18,12 @@
1818 // location here can expected to be an ssb-message
1919 const { goTo } = api.app.sync
2020
2121 // TODO (mix) : swap for actual source, derived from location
22- const source = pull.values(dummyThread)
23- const thread = api.app.html.thread(source)
2422
23+ const id = '%fXXZgQrwnj7F+Y19H0IXxNriuvPFoahvusih3UzpkfA=.sha256'
24+ const thread = api.app.html.thread(id)
25+
2526 return h('div', [
2627 h('h1', 'Private message'),
2728 h('div', { 'ev-click': () => goTo({ page: 'home' }) }, 'Home'),
2829 thread

Built with git-ssb-web