git ssb

0+

Dominic / yap-patch



Commit 76a136d4fbdd78dab9a7b6f40385a810d6512d86

update

Dominic Tarr committed on 8/31/2019, 3:41:11 PM
Parent: cb2a914cb1b67be199e798ca44039444c43341fc

Files changed

friends.jschanged
index.jschanged
message-link.jschanged
messages/post.jschanged
public.jschanged
thread.jschanged
backlinks.jsadded
likes.jsadded
post-name.jsadded
friends.jsView
@@ -26,9 +26,9 @@
2626 return [
2727 'div.'+label,
2828 ['h2', tr(label)],
2929 ].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})})
3131 })).concat(
3232 //TODO make this a link to a page showing friends.
3333 list.length > limit ? '...' + tr('AndMore', list.length-limit) : ''
3434 )
index.jsView
@@ -1,4 +1,6 @@
1 +var Tr = require('./translations')
2 +
13 module.exports = function (sbot) {
24 return function (use) {
35 //view (and filtered views) on the raw log
46 use('public', require('./public')(sbot))
@@ -12,16 +14,22 @@
1214 use('messages/vote', require('./messages/vote')(sbot))
1315 use.map('messages', 'post', 'messages/post')
1416 use.map('messages', 'vote', 'messages/vote')
1517
18 + use('names/post', require('./post-name')(sbot))
19 +// use.map('messageName', 'post', 'names/post')
20 +
1621 use.list('menu', 'public/menu')
1722 use('thread', require('./thread')(sbot))
1823 use('private', require('./private')(sbot))
1924 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')]
2226 })
2327 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')
2432 use('friends', require('./friends')(sbot))
2533 use('messageLink', require('./message-link')(sbot))
2634 use('channelLink', require('./channel-link')(sbot))
2735 }
message-link.jsView
@@ -3,21 +3,25 @@
33 module.exports = function (sbot) {
44 return function (data, apply) {
55
66 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',
810 {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 + ]]
1115 }
1216
1317 if(data.key && data.value && data.value.content && data.value.content.type)
1418 return link(data)
1519 else if(data.id)
1620 return function (cb) {
1721 sbot.get(data, function (err, msg) {
1822 var _data = {key: data.id, value: msg}
19- cb(null, link(data))
23 + cb(null, link(_data))
2024 })
2125 }
2226 }
2327 }
messages/post.jsView
@@ -1,40 +1,19 @@
1-var ref = require('ssb-ref')
2-var niceAgo = require('nice-ago')
31 var htmlEscape = require('html-escape')
42
53 var u = require('yap-util')
6-var toUrl = u.toUrl
74
85 module.exports = u.createRenderer(function render (data, apply) {
96 var since = apply.since
107 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 + })
4019 })
public.jsView
@@ -61,9 +61,9 @@
6161 apply('avatar', {
6262 id: opts.author,
6363 name: true,
6464 image: false,
65- href: toUrl('friends', {id: opts.author})
65 + href: toUrl('patch/friends', {id: opts.author})
6666 }): '',
6767 ' ',
6868
6969 //load previous from a url, so that it can be updated by coherence
thread.jsView
@@ -39,34 +39,8 @@
3939 return o && 'object' === typeof o
4040 }
4141 var isArray = Array.isArray
4242
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-
6943 module.exports = function (sbot) {
7044 return function (opts, apply, req) {
7145 var context = req.cookies
7246 var since = apply.since
@@ -103,50 +77,22 @@
10377 return apply('avatar', e)
10478 })]
10579 cb(null,
10680 ['div.thread',
107- apply.cacheAttrs(apply.toUrl('thread', opts), data.key, since),
81 + apply.cacheAttrs(apply.toUrl('patch/thread', opts), data.key, since),
10882 ary[0].value.content.text && ['title', msum.title(ary[0].value.content.text)],
10983 recipients,
11084 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
14995 }),
15096 apply('compose', {
15197 content: {
15298 type: 'post',
backlinks.jsView
@@ -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.jsView
@@ -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.jsView
@@ -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