git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 47416e4ca950ed7de91562f1c6ede9486e4aa6d9

add message/thread view

Matt McKegg committed on 2/15/2017, 12:20:30 PM
Parent: 03d17cff841c2fed3e864e0b507f5e8045e4a356

Files changed

modules/feed/html/thread.jsadded
modules/page/html/render/message.jsadded
plugs/message/html/layout/default.jschanged
styles/feed-event.mcsschanged
styles/message.mcsschanged
styles/thread.mcssadded
modules/feed/html/thread.jsView
@@ -1,0 +1,26 @@
1+var { h, computed, map } = require('mutant')
2+var nest = require('depnest')
3+
4+exports.needs = nest({
5+ 'feed.obs.thread': 'first',
6+ 'message.html.render': 'first'
7+})
8+
9+exports.gives = nest('feed.html.thread')
10+
11+exports.create = function (api) {
12+ return nest('feed.html.thread', function (rootId) {
13+ var thread = api.feed.obs.thread(rootId)
14+
15+ var container = h('div', {className: 'Thread'}, [
16+ map(thread.messages, (msg) => {
17+ return computed([msg, thread.previousKey(msg)], (msg, previousId) => {
18+ return api.message.html.render(msg, {previousId})
19+ })
20+ })
21+ ])
22+
23+ container.sync = thread.sync
24+ return container
25+ })
26+}
modules/page/html/render/message.jsView
@@ -1,0 +1,40 @@
1+var { h, when, send, Value, Proxy, watch } = require('mutant')
2+var pull = require('pull-stream')
3+var nest = require('depnest')
4+var ref = require('ssb-ref')
5+
6+exports.needs = nest({
7+ 'keys.sync.id': 'first',
8+ 'feed.html.thread': 'first',
9+ 'message.html.render': 'first',
10+ 'sbot.async.get': 'first'
11+})
12+
13+exports.gives = nest('page.html.render')
14+
15+exports.create = function (api) {
16+ return nest('page.html.render', function channel (id) {
17+ if (!ref.isMsg(id)) return
18+ var loader = h('div', {className: 'Loading -large'})
19+ var result = Proxy(loader)
20+
21+ api.sbot.async.get(id, (err, value) => {
22+ if (err) return result.set(h('div', {className: 'Error'}, ['Cannot load thead']))
23+ if (value.content.root) {
24+ result.set(h('div', {className: 'FeedEvent'}, [
25+ h('a.full', {href: value.content.root}, ['View full thread']),
26+ h('div.replies', [
27+ api.message.html.render({key: id, value})
28+ ])
29+ ]))
30+ } else {
31+ var thread = api.feed.html.thread(id)
32+ result.set(when(thread.sync, thread, loader))
33+ }
34+ })
35+
36+ return h('div', {className: 'SplitView'}, [
37+ h('div.main', result)
38+ ])
39+ })
40+}
plugs/message/html/layout/default.jsView
@@ -24,12 +24,13 @@
2424 var replyInfo = null
2525
2626 if (msg.value.content.root) {
2727 classList.push('-reply')
28- if (!opts.previousId) {
29- replyInfo = h('span', ['in reply to ', api.message.html.link(msg.value.content.root)])
30- } else if (opts.previousId && last(msg.value.content.branch) && opts.previousId !== last(msg.value.content.branch)) {
31- replyInfo = h('span', ['in reply to ', api.message.html.link(last(msg.value.content.branch))])
28+ var branch = msg.value.content.branch
29+ if (branch) {
30+ if (!opts.previousId || (opts.previousId && last(branch) && opts.previousId !== last(branch))) {
31+ replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))])
32+ }
3233 }
3334 }
3435
3536 return h('div', {
styles/feed-event.mcssView
@@ -1,7 +1,6 @@
11 FeedEvent {
22 display: flex
3- flex: 1
43 flex-direction: column
54 background: white
65 max-width: 700px
76 margin: 10px auto
styles/message.mcssView
@@ -5,8 +5,9 @@
55 border: 1px solid #f5f5f5
66 background: white
77 position: relative
88 font-size: 120%
9+ flex-shrink: 0
910
1011 :focus {
1112 z-index: 1
1213 }
styles/thread.mcssView
@@ -1,0 +1,6 @@
1+Thread {
2+ flex: 1
3+ max-width: 700px
4+ width: 100%
5+ margin: 10px auto
6+}

Built with git-ssb-web