Commit 76a136d4fbdd78dab9a7b6f40385a810d6512d86
update
Dominic Tarr committed on 8/31/2019, 3:41:11 PMParent: cb2a914cb1b67be199e798ca44039444c43341fc
Files changed
friends.js | changed |
index.js | changed |
message-link.js | changed |
messages/post.js | changed |
public.js | changed |
thread.js | changed |
backlinks.js | added |
likes.js | added |
post-name.js | added |
friends.js | ||
---|---|---|
@@ -26,9 +26,9 @@ | ||
26 | 26 … | return [ |
27 | 27 … | 'div.'+label, |
28 | 28 … | ['h2', tr(label)], |
29 | 29 … | ].concat(list.slice(0, limit).map(function (e) { |
30 | - return apply('avatar', {id: e, image: true, name: false, href: toUrl('friends', {id: e})}) | |
30 … | + return apply('avatar', {id: e, image: true, name: false, href: toUrl('patch/friends', {id: e})}) | |
31 | 31 … | })).concat( |
32 | 32 … | //TODO make this a link to a page showing friends. |
33 | 33 … | list.length > limit ? '...' + tr('AndMore', list.length-limit) : '' |
34 | 34 … | ) |
index.js | ||
---|---|---|
@@ -1,4 +1,6 @@ | ||
1 … | +var Tr = require('./translations') | |
2 … | + | |
1 | 3 … | module.exports = function (sbot) { |
2 | 4 … | return function (use) { |
3 | 5 … | //view (and filtered views) on the raw log |
4 | 6 … | use('public', require('./public')(sbot)) |
@@ -12,16 +14,22 @@ | ||
12 | 14 … | use('messages/vote', require('./messages/vote')(sbot)) |
13 | 15 … | use.map('messages', 'post', 'messages/post') |
14 | 16 … | use.map('messages', 'vote', 'messages/vote') |
15 | 17 … | |
18 … | + use('names/post', require('./post-name')(sbot)) | |
19 … | +// use.map('messageName', 'post', 'names/post') | |
20 … | + | |
16 | 21 … | use.list('menu', 'public/menu') |
17 | 22 … | use('thread', require('./thread')(sbot)) |
18 | 23 … | use('private', require('./private')(sbot)) |
19 | 24 … | use('private/menu', function (opts, apply, req) { |
20 | - var tr = require('./translations')(req.cookies.lang) | |
21 | - return ['a', {href: '/patch/private'}, tr('Private')] | |
25 … | + return ['a', {href: '/patch/private'}, Tr(req.cookies.lang)('Private')] | |
22 | 26 … | }) |
23 | 27 … | use.list('menu', 'private/menu') |
28 … | + use('likes', require('./likes')(sbot)), | |
29 … | + use.list('extra', 'likes') | |
30 … | + use('backlinks', require('./backlinks')(sbot)), | |
31 … | + use.list('extra', 'backlinks') | |
24 | 32 … | use('friends', require('./friends')(sbot)) |
25 | 33 … | use('messageLink', require('./message-link')(sbot)) |
26 | 34 … | use('channelLink', require('./channel-link')(sbot)) |
27 | 35 … | } |
message-link.js | ||
---|---|---|
@@ -3,21 +3,25 @@ | ||
3 | 3 … | module.exports = function (sbot) { |
4 | 4 … | return function (data, apply) { |
5 | 5 … | |
6 | 6 … | function link (data) { |
7 | - return ['a', | |
7 … | + return ['div.MessageLink', | |
8 … | + data.value && data.value.author && apply('avatar', {id: data.value.author, image: true}), | |
9 … | + ['a', | |
8 | 10 … | {href: apply.toUrl('message', {id: data.key})}, |
9 | - msum.title(data.value.content.text) | |
10 | - ] | |
11 … | + data.value && data.value.content && data.value.content.text | |
12 … | + ? msum.title(data.value.content.text) | |
13 … | + : data.key | |
14 … | + ]] | |
11 | 15 … | } |
12 | 16 … | |
13 | 17 … | if(data.key && data.value && data.value.content && data.value.content.type) |
14 | 18 … | return link(data) |
15 | 19 … | else if(data.id) |
16 | 20 … | return function (cb) { |
17 | 21 … | sbot.get(data, function (err, msg) { |
18 | 22 … | var _data = {key: data.id, value: msg} |
19 | - cb(null, link(data)) | |
23 … | + cb(null, link(_data)) | |
20 | 24 … | }) |
21 | 25 … | } |
22 | 26 … | } |
23 | 27 … | } |
messages/post.js | ||
---|---|---|
@@ -1,40 +1,19 @@ | ||
1 | -var ref = require('ssb-ref') | |
2 | -var niceAgo = require('nice-ago') | |
3 | 1 … | var htmlEscape = require('html-escape') |
4 | 2 … | |
5 | 3 … | var u = require('yap-util') |
6 | -var toUrl = u.toUrl | |
7 | 4 … | |
8 | 5 … | module.exports = u.createRenderer(function render (data, apply) { |
9 | 6 … | var since = apply.since |
10 | 7 … | var time = data.value.timestamp || data.timestamp |
11 | - return ['div.Message', | |
12 | - apply.cacheAttrs(toUrl('message', {id: data.key}), data.key, since), | |
13 | - ['div.MessageSide', | |
14 | - apply('avatar', {id: data.value.author, name: false, image: true}), | |
15 | - ['a', { | |
16 | - href: toUrl('message', {id: data.key}), | |
17 | - title: new Date(time)+'\n'+data.key | |
18 | - }, | |
19 | - ''+niceAgo(Date.now(), time) | |
20 | - ] | |
21 | - ], | |
22 | - ['div.MessageMain', | |
23 | - ['div.MessageMeta', | |
24 | - apply('avatar', {id: data.value.author, name: true, image: false}), | |
25 | - /* | |
26 | - h('label.type', data.value.content.type), | |
27 | - */ | |
28 | - ['label.msgId', data.key], | |
29 | - | |
30 | - data.value.content.channel | |
31 | - ? ['a', {href: toUrl('patch/public', {channel: data.value.content.channel})}, '#'+data.value.content.channel] | |
32 | - : '', | |
33 | - | |
34 | - ['a', {href: toUrl('patch/thread', {id: data.value.content.root || data.key})}, 'Thread'] | |
35 | - | |
36 | - ], | |
37 | - ['div.MessageContent', u.markdown(data.value.content)] | |
38 | - ] | |
39 | - ] | |
8 … | + return apply('messageLayout', { | |
9 … | + id: data.key, | |
10 … | + author: data.value.author, | |
11 … | + ts: time, | |
12 … | + content: u.markdown(data.value.content), | |
13 … | + meta: [ | |
14 … | + data.value.content.channel | |
15 … | + && ['a', {href: toUrl('patch/public', {channel: data.value.content.channel})}, '#'+data.value.content.channel], | |
16 … | + ['a', {href: toUrl('patch/thread', {id: data.value.content.root || data.key})}, 'Thread'] | |
17 … | + ].filter(Boolean), | |
18 … | + }) | |
40 | 19 … | }) |
public.js | ||
---|---|---|
@@ -61,9 +61,9 @@ | ||
61 | 61 … | apply('avatar', { |
62 | 62 … | id: opts.author, |
63 | 63 … | name: true, |
64 | 64 … | image: false, |
65 | - href: toUrl('friends', {id: opts.author}) | |
65 … | + href: toUrl('patch/friends', {id: opts.author}) | |
66 | 66 … | }): '', |
67 | 67 … | ' ', |
68 | 68 … | |
69 | 69 … | //load previous from a url, so that it can be updated by coherence |
thread.js | ||
---|---|---|
@@ -39,34 +39,8 @@ | ||
39 | 39 … | return o && 'object' === typeof o |
40 | 40 … | } |
41 | 41 … | var isArray = Array.isArray |
42 | 42 … | |
43 | -function backlinks (sbot, id, cb) { | |
44 | - var likes = [], backlinks = [] | |
45 | - pull( | |
46 | - sbot.links({dest: id, values: true}), | |
47 | - pull.drain(function (e) { | |
48 | - var content = e.value.content | |
49 | - var vote = content.vote | |
50 | - if(isObject(vote) && | |
51 | - vote.value == 1 && vote.link == id) | |
52 | - likes.push(e) | |
53 | - else if(content.type == 'post' && isArray(content.mentions)) { | |
54 | - for(var i in content.mentions) { | |
55 | - var m = content.mentions[i] | |
56 | - if(m && m.link == id) { | |
57 | - backlinks.push(e) | |
58 | - return //if something links twice, don't back link it twice | |
59 | - } | |
60 | - } | |
61 | - } | |
62 | - }, function () { | |
63 | - cb(null, likes, backlinks) | |
64 | - }) | |
65 | - ) | |
66 | -} | |
67 | - | |
68 | - | |
69 | 43 … | module.exports = function (sbot) { |
70 | 44 … | return function (opts, apply, req) { |
71 | 45 … | var context = req.cookies |
72 | 46 … | var since = apply.since |
@@ -103,50 +77,22 @@ | ||
103 | 77 … | return apply('avatar', e) |
104 | 78 … | })] |
105 | 79 … | cb(null, |
106 | 80 … | ['div.thread', |
107 | - apply.cacheAttrs(apply.toUrl('thread', opts), data.key, since), | |
81 … | + apply.cacheAttrs(apply.toUrl('patch/thread', opts), data.key, since), | |
108 | 82 … | ary[0].value.content.text && ['title', msum.title(ary[0].value.content.text)], |
109 | 83 … | recipients, |
110 | 84 … | ary.map(function (data) { |
111 | - return ['div.MessageContainer', | |
112 | - apply('message', data), | |
113 | - function (cb) { | |
114 | - backlinks(sbot, data.key, function (err, likes, backlinks) { | |
115 | - if(err) return cb(err) | |
116 | - | |
117 | - var expression = tr('Like') | |
118 | - cb(null, ['div.MessageExtra', | |
119 | - apply('publish', { | |
120 | - id: context.id, | |
121 | - suggestedRecps: data.value.author, | |
122 | - content: { | |
123 | - type: 'vote', | |
124 | - root: root, branch: branch, | |
125 | - vote: { | |
126 | - link:data.key, value: 1, | |
127 | - expression: expression | |
128 | - }, | |
129 | - channel: data.value.content.channel, | |
130 | - recps: recps | |
131 | - }, | |
132 | - name: expression + ' ' + (likes.length ? '('+likes.length+')' : '') | |
133 | - }), | |
134 | - (backlinks.length ? | |
135 | - ['ul.MessageBacklinks', | |
136 | - backlinks.map(function (e) { | |
137 | - return ['li', apply('avatar', {id:e.value.author}), | |
138 | - ' ', | |
139 | - apply('/patch/messageLink', e), | |
140 | - ' ', | |
141 | - e.value.content.channel && apply('/patch/channelLink', e.value.content.channel) | |
142 | - ] | |
143 | - }) | |
144 | - ] : '') | |
145 | - ]) | |
146 | - }) | |
147 | - } | |
148 | - ] | |
85 … | + var msg = apply('messageLayout', { | |
86 … | + id: data.key, | |
87 … | + author: data.value.author, | |
88 … | + content: u.markdown(data.value.content), | |
89 … | + root: root, branch: branch, | |
90 … | + ts: data.value.timestamp || data.timestamp, | |
91 … | + meta: [], | |
92 … | + extra: true | |
93 … | + }) | |
94 … | + return msg | |
149 | 95 … | }), |
150 | 96 … | apply('compose', { |
151 | 97 … | content: { |
152 | 98 … | type: 'post', |
backlinks.js | ||
---|---|---|
@@ -1,0 +1,18 @@ | ||
1 … | +var pull = require('pull-stream') | |
2 … | + | |
3 … | +module.exports = function (sbot) { | |
4 … | + return function (opts, apply) { | |
5 … | + return function (cb) { | |
6 … | + pull( | |
7 … | + sbot.links({dest: opts.id, rel: 'mentions', values: true}), | |
8 … | + pull.collect(function (err, ary) { | |
9 … | + cb(null, ['div.BackLinks'].concat(ary.filter(function (e) { | |
10 … | + return e.value.content.type != 'vote' | |
11 … | + }).map(function (e) { | |
12 … | + return apply('/patch/messageLink', e) | |
13 … | + }))) | |
14 … | + }) | |
15 … | + ) | |
16 … | + } | |
17 … | + } | |
18 … | +} |
likes.js | ||
---|---|---|
@@ -1,0 +1,36 @@ | ||
1 … | +var ref = require('ssb-ref') | |
2 … | +var pull = require('pull-stream') | |
3 … | + | |
4 … | +module.exports = function (sbot) { | |
5 … | + return function (opts, apply, req) { | |
6 … | + id = req.cookies.id || sbot.id | |
7 … | + if(!ref.isMsg(opts.root)) throw new Error('/likes requires msg root') | |
8 … | +// console.log('Likes', opts) | |
9 … | + var expression = 'Yup' | |
10 … | + return function (cb) { | |
11 … | + pull( | |
12 … | + sbot.links({dest: opts.id, rel: 'vote'}), | |
13 … | + pull.collect(function (err, ary) { | |
14 … | + // return cb(null, ['button', 'Yup2']) | |
15 … | + | |
16 … | + cb(null, apply('publish', { | |
17 … | + id: id, | |
18 … | +// suggestedRecps: data.value.author, | |
19 … | + content: { | |
20 … | + type: 'vote', | |
21 … | + root: opts.root, branch: opts.branch, | |
22 … | + vote: { | |
23 … | + link:opts.id, value: 1, | |
24 … | + expression: expression//Tr(req.cookies.lang)('Like') | |
25 … | + }, | |
26 … | + channel: opts.channel, | |
27 … | + recps: opts.recps | |
28 … | + }, | |
29 … | + name: expression + ' ' + (ary.length ? '('+ary.length+')' : '') | |
30 … | + }) | |
31 … | + ) | |
32 … | + }) | |
33 … | + ) | |
34 … | + } | |
35 … | + } | |
36 … | +} |
post-name.js | ||
---|---|---|
@@ -1,0 +1,25 @@ | ||
1 … | +var msum = require('markdown-summary') | |
2 … | + | |
3 … | + | |
4 … | + | |
5 … | +module.exports = function (sbot) { | |
6 … | + return function (data, apply) { | |
7 … | + | |
8 … | + function link (data) { | |
9 … | + return ['a', | |
10 … | + {href: apply.toUrl('message', {id: data.key})}, | |
11 … | + data.value.content.text ? msum.title(data.value.content.text) : data.key | |
12 … | + ] | |
13 … | + } | |
14 … | + | |
15 … | + if(data.key && data.value && data.value.content && data.value.content.type) | |
16 … | + return link(data) | |
17 … | + else if(data.id) | |
18 … | + return function (cb) { | |
19 … | + sbot.get(data, function (err, msg) { | |
20 … | + var _data = {key: data.id, value: msg} | |
21 … | + cb(null, link(data)) | |
22 … | + }) | |
23 … | + } | |
24 … | + } | |
25 … | +} |
Built with git-ssb-web