git ssb

2+

mixmix / ticktack



Commit 26eb63b836af90470db4e83dd22d952a85c08061

only load threads once, and use the correct branch for them

Dominic Tarr committed on 12/8/2017, 6:49:09 AM
Parent: b02d5837685a7fb8e42751b875db010b8ec801c6

Files changed

app/html/comments.jschanged
app/html/thread.jschanged
app/page/blogShow.jschanged
app/page/threadShow.jschanged
app/html/comments.jsView
@@ -19,10 +19,10 @@
1919
2020 exports.create = (api) => {
2121 return nest('app.html.comments', comments)
2222
23- function comments (root) {
24- const { messages, channel, lastId: branch } = api.feed.obs.thread(root)
23+ function comments (thread) {
24+ const { messages, channel, lastId: branch } = thread
2525
2626 // TODO - move this up into Patchcore
2727 var debouncer = null
2828 const messagesTree = computed(throttle(messages, 200), msgs => {
app/html/thread.jsView
@@ -15,13 +15,12 @@
1515 'unread.sync.isUnread': 'first'
1616 })
1717
1818 exports.create = (api) => {
19- return nest('app.html.thread', thread)
20-
21- function thread (root) {
19+ return nest('app.html.thread', function (thread) {
20+ //catch any code that still uses this the old way...
21+ if('string' === typeof thread) throw new Error('thread should be observable')
2222 const myId = api.keys.sync.id()
23- const thread = api.feed.obs.thread(root)
2423 const chunkedMessages = buildChunkedMessages(thread.messages)
2524
2625 const threadView = h('Thread',
2726 map(chunkedMessages, chunk => {
@@ -61,9 +60,9 @@
6160 threadView.subject = computed(thread.messages, msgs => {
6261 return get(msgs, '[0].value.content.subject')
6362 })
6463 return threadView
65- }
64+ })
6665 }
6766
6867 function buildChunkedMessages (messagesObs) {
6968 return computed(throttle(messagesObs, 200), msgs => {
@@ -100,4 +99,7 @@
10099 // TODO (mix) use lodash/get
101100 return msgA.value.author === msgB.value.author
102101 }
103102
103+
104+
105+
app/page/blogShow.jsView
@@ -34,14 +34,12 @@
3434
3535 const blog = api.blog.html.content(blogMsg)
3636 const title = api.blog.html.title(blogMsg)
3737
38- //app.html.comments also loads the thread obs.
39- const comments = api.app.html.comments(blogMsg.key)
38+ const thread = api.feed.obs.thread(blogMsg.key)
39+ const comments = api.app.html.comments(thread)
40+ const branch = thread.lastId
4041
41- //loads entire thread, just to get the branch.
42- const { lastId: branch } = api.feed.obs.thread(blogMsg.key)
43-
4442 const { timeago, channel, markdown, compose } = api.message.html
4543
4644 return h('Page -blogShow', [
4745 api.app.html.context({ page: 'discover' }), // HACK to highlight discover
@@ -74,4 +72,7 @@
7472 }
7573 }
7674
7775
76+
77+
78+
app/page/threadShow.jsView
@@ -8,9 +8,10 @@
88 exports.needs = nest({
99 'app.html.context': 'first',
1010 'app.html.thread': 'first',
1111 'message.html.compose': 'first',
12- 'unread.sync.markRead': 'first'
12+ 'unread.sync.markRead': 'first',
13+ 'feed.obs.thread': 'first'
1314 })
1415
1516 exports.create = (api) => {
1617 return nest('app.page.threadShow', threadShow)
@@ -21,16 +22,14 @@
2122 const root = get(value, 'content.root', key)
2223 const channel = get(value, 'content.channel')
2324
2425 //unread state is set in here...
25- const thread = api.app.html.thread(root)
26+ const thread = api.feed.obs.thread(root)
2627
2728 const meta = {
2829 type: 'post',
2930 root,
30- //XXX incorrect branch
31- branch: get(last(location.replies), 'key'),
32- // >> lastId? CHECK THIS LOGIC
31+ branch: thread.lastId,
3332 channel,
3433 recps: get(location, 'value.content.recps')
3534 }
3635 const composer = api.message.html.compose({ meta, shrink: false })
@@ -38,9 +37,9 @@
3837 return h('Page -threadShow', [
3938 api.app.html.context(location),
4039 h('div.content', [
4140 when(thread.subject, h('h1', thread.subject)),
42- thread,
41+ api.app.html.thread(thread),
4342 composer
4443 ]),
4544 ])
4645 }
@@ -50,4 +49,8 @@
5049
5150
5251
5352
53+
54+
55+
56+

Built with git-ssb-web