git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 3738a10330418ba685af21142b05c622732f4eec

move backlinks stuff into message.html.backlinks and use for all layouts

Matt McKegg committed on 6/8/2017, 12:12:56 AM
Parent: 3111373d72c14d67653f9863dbf6db812181252b

Files changed

modules/message/html/backlinks.jsadded
modules/page/html/render/message.jschanged
plugs/message/html/layout/default.jschanged
plugs/message/html/layout/mini.jschanged
modules/message/html/backlinks.jsView
@@ -1,0 +1,56 @@
1+var nest = require('depnest')
2+var { h, map, computed } = require('mutant')
3+
4+exports.needs = nest({
5+ 'message.obs': {
6+ backlinks: 'first',
7+ forks: 'first',
8+ name: 'first',
9+ author: 'first'
10+ },
11+ 'profile.html.person': 'first'
12+})
13+
14+exports.gives = nest('message.html.backlinks')
15+
16+exports.create = function (api) {
17+ return nest('message.html.backlinks', function (msg, {includeReferences = true, includeForks = true} = {}) {
18+ var references = includeReferences ? api.message.obs.backlinks(msg.key) : []
19+ var forks = (includeForks && msg.value.content.root) ? api.message.obs.forks(msg.key) : []
20+ return [
21+ map(forks, msgId => {
22+ return h('a.backlink', {
23+ href: msgId,
24+ title: msgId
25+ }, [
26+ h('strong', [
27+ authorLink(msgId), ' forked this discussion:'
28+ ]), ' ',
29+ api.message.obs.name(msgId)
30+ ])
31+ }),
32+ map(references, msgId => {
33+ return h('a.backlink', {
34+ href: msgId,
35+ title: msgId
36+ }, [
37+ h('strong', [
38+ authorLink(msgId), ' referenced this message:'
39+ ]), ' ',
40+ api.message.obs.name(msgId)
41+ ])
42+ })
43+ ]
44+ })
45+
46+ function authorLink (msgId) {
47+ var author = api.message.obs.author(msgId)
48+ return computed(author, author => {
49+ if (author) {
50+ return api.profile.html.person(author)
51+ } else {
52+ return 'Someone'
53+ }
54+ })
55+ }
56+}
modules/page/html/render/message.jsView
@@ -59,9 +59,9 @@
5959 h('div.messages', [
6060 when(thread.branchId, h('a.full', {href: thread.rootId}, ['View full thread'])),
6161 map(thread.messages, (msg) => {
6262 return computed([msg, thread.previousKey(msg)], (msg, previousId) => {
63- return api.message.html.render(msg, {pageId: id, previousId, backlinks: true})
63+ return api.message.html.render(msg, {pageId: id, previousId, includeReferences: true})
6464 })
6565 })
6666 ]),
6767 compose
plugs/message/html/layout/default.jsView
@@ -11,9 +11,10 @@
1111 'message.html': {
1212 link: 'first',
1313 meta: 'map',
1414 action: 'map',
15- timestamp: 'first'
15+ timestamp: 'first',
16+ backlinks: 'first'
1617 },
1718 'about.html.image': 'first'
1819 })
1920
@@ -21,41 +22,35 @@
2122
2223 exports.create = function (api) {
2324 return nest('message.html.layout', layout)
2425
25- function layout (msg, opts) {
26- if (!(opts.layout === undefined || opts.layout === 'default')) return
26+ function layout (msg, {layout, previousId, priority, content, includeReferences}) {
27+ if (!(layout === undefined || layout === 'default')) return
2728
28- var backlinks = opts.backlinks ? api.message.obs.backlinks(msg.key) : []
29- var forks = msg.value.content.root ? api.message.obs.forks(msg.key) : []
30-
3129 var classList = ['Message']
3230 var replyInfo = null
3331
3432 if (msg.value.content.root) {
3533 classList.push('-reply')
3634 var branch = msg.value.content.branch
3735 if (branch) {
38- if (!opts.previousId || (opts.previousId && last(branch) && opts.previousId !== last(branch))) {
36+ if (!previousId || (previousId && last(branch) && previousId !== last(branch))) {
3937 replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))])
4038 }
4139 }
4240 } else if (msg.value.content.project) {
4341 replyInfo = h('span', ['on ', api.message.html.link(msg.value.content.project)])
4442 }
4543
46- if (opts.priority === 2) {
44+ if (priority === 2) {
4745 classList.push('-new')
4846 }
4947
5048 return h('div', {
5149 classList
5250 }, [
53- messageHeader(msg, {
54- replyInfo,
55- priority: opts.priority
56- }),
57- h('section', [opts.content]),
51+ messageHeader(msg, { replyInfo, priority }),
52+ h('section', [content]),
5853 computed(msg.key, (key) => {
5954 if (ref.isMsg(key)) {
6055 return h('footer', [
6156 h('div.actions', [
@@ -63,37 +58,16 @@
6358 ])
6459 ])
6560 }
6661 }),
67- map(forks, msgId => {
68- return h('a.backlink', {
69- href: msgId,
70- title: msgId
71- }, [
72- h('strong', [
73- authorLink(msgId), ' forked this discussion:'
74- ]), ' ',
75- api.message.obs.name(msgId)
76- ])
77- }),
78- map(backlinks, msgId => {
79- return h('a.backlink', {
80- href: msgId,
81- title: msgId
82- }, [
83- h('strong', [
84- authorLink(msgId), ' referenced this message:'
85- ]), ' ',
86- api.message.obs.name(msgId)
87- ])
88- })
62+ api.message.html.backlinks(msg, {includeReferences})
8963 ])
9064
9165 // scoped
9266
9367 function messageHeader (msg, {replyInfo, priority}) {
9468 var additionalMeta = []
95- if (opts.priority >= 2) {
69+ if (priority >= 2) {
9670 additionalMeta.push(h('span.flag -new', {title: 'New Message'}))
9771 }
9872 return h('header', [
9973 h('div.main', [
@@ -115,19 +89,8 @@
11589 additionalMeta
11690 ])
11791 ])
11892 }
119-
120- function authorLink (msgId) {
121- var author = api.message.obs.author(msgId)
122- return computed(author, author => {
123- if (author) {
124- return api.profile.html.person(author)
125- } else {
126- return 'Someone'
127- }
128- })
129- }
13093 }
13194 }
13295
13396 function last (array) {
plugs/message/html/layout/mini.jsView
@@ -9,9 +9,10 @@
99 'message.html': {
1010 link: 'first',
1111 meta: 'map',
1212 action: 'map',
13- timestamp: 'first'
13+ timestamp: 'first',
14+ backlinks: 'first'
1415 },
1516 'about.html.image': 'first'
1617 })
1718
@@ -19,40 +20,37 @@
1920
2021 exports.create = function (api) {
2122 return nest('message.html.layout', layout)
2223
23- function layout (msg, opts) {
24- if (!(opts.layout === 'mini')) return
24+ function layout (msg, {layout, previousId, priority, miniContent, content, includeReferences}) {
25+ if (!(layout === 'mini')) return
2526
26- var backlinks = opts.backlinks ? api.message.obs.backlinks(msg.key) : []
2727 var classList = ['Message -mini']
2828 var replyInfo = null
2929
3030 if (msg.value.content.root) {
3131 classList.push('-reply')
3232 var branch = msg.value.content.branch
3333 if (branch) {
34- if (!opts.previousId || (opts.previousId && last(branch) && opts.previousId !== last(branch))) {
34+ if (!previousId || (previousId && last(branch) && previousId !== last(branch))) {
3535 replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))])
3636 }
3737 }
3838 } else if (msg.value.content.project) {
3939 replyInfo = h('span', ['on ', api.message.html.link(msg.value.content.project)])
4040 }
4141
42- if (opts.priority === 2) {
42+ if (priority === 2) {
4343 classList.push('-new')
4444 }
4545
4646 return h('div', {
4747 classList
4848 }, [
4949 messageHeader(msg, {
50- replyInfo,
51- priority: opts.priority,
52- miniContent: opts.miniContent
50+ replyInfo, priority, miniContent
5351 }),
54- h('section', [opts.content]),
52+ h('section', [content]),
5553 computed(msg.key, (key) => {
5654 if (ref.isMsg(key)) {
5755 return h('footer', [
5856 h('div.actions', [
@@ -60,23 +58,16 @@
6058 ])
6159 ])
6260 }
6361 }),
64- map(backlinks, backlink => {
65- return h('a.backlink', {
66- href: backlink,
67- title: backlink
68- }, [
69- h('strong', 'Referenced from'), ' ', api.message.obs.name(backlink)
70- ])
71- })
62+ api.message.html.backlinks(msg, {includeReferences})
7263 ])
7364
7465 // scoped
7566
7667 function messageHeader (msg, {replyInfo, priority, miniContent}) {
7768 var additionalMeta = []
78- if (opts.priority >= 2) {
69+ if (priority >= 2) {
7970 additionalMeta.push(h('span.flag -new', {title: 'New Message'}))
8071 }
8172 return h('header', [
8273 h('div.main', [

Built with git-ssb-web