Commit 9216a0ee5a7da1602222d794ef538ca059e1face
quick hack at better rollup of git-update messages (still not great)
Matt McKegg committed on 11/4/2016, 3:47:15 AMParent: fa40e97eba905e02fa26262401aa38c50f6de16b
Files changed
lib/feed-summary.js | changed |
modules/message-name.js | changed |
modules/message.js | changed |
modules/git-mini-messages.js | added |
package.json | changed |
styles/message.mcss | changed |
styles/patchbay-tweaks.css | changed |
lib/feed-summary.js | ||
---|---|---|
@@ -74,10 +74,10 @@ | ||
74 | 74 | } |
75 | 75 | } |
76 | 76 | } |
77 | 77 | } else { |
78 | - if (c.root) { | |
79 | - const group = ensureMessage(c.root, messageUpdates) | |
78 | + if (c.root || (c.type === 'git-update' && c.repo)) { | |
79 | + const group = ensureMessage(c.root || c.repo, messageUpdates) | |
80 | 80 | group.fromTime = fromTime |
81 | 81 | group.lastUpdateType = 'reply' |
82 | 82 | group.repliesFrom.add(msg.value.author) |
83 | 83 | SortedArray.add(group.replies, msg, compareUserTimestamp) |
modules/message-name.js | ||
---|---|---|
@@ -1,15 +1,20 @@ | ||
1 | +var plugs = require('patchbay/plugs') | |
2 | +var sbot_links = plugs.first(exports.sbot_links = []) | |
3 | +var get_id = plugs.first(exports.get_id = []) | |
4 | +var sbot_get = plugs.first(exports.sbot_get = []) | |
5 | +var getAvatar = require('ssb-avatar') | |
1 | 6 | |
2 | -var sbot_get = require('patchbay/plugs').first(exports.sbot_get = []) | |
3 | - | |
4 | 7 | exports.message_name = function (id, cb) { |
5 | 8 | sbot_get(id, function (err, value) { |
6 | 9 | if (err && err.name === 'NotFoundError') { |
7 | 10 | return cb(null, id.substring(0, 10) + '...(missing)') |
8 | 11 | } else if (value.content.type === 'post' && typeof value.content.text === 'string') { |
9 | 12 | if (value.content.text.trim()) { |
10 | 13 | return cb(null, titleFromMarkdown(value.content.text, 40)) |
11 | 14 | } |
15 | + } else if (value.content.type === 'git-repo') { | |
16 | + return getRepoName(id, cb) | |
12 | 17 | } else if (typeof value.content.text === 'string') { |
13 | 18 | return cb(null, value.content.type + ': ' + titleFromMarkdown(value.content.text, 30)) |
14 | 19 | } |
15 | 20 | |
@@ -26,4 +31,14 @@ | ||
26 | 31 | text = text.substring(0, max - 2) + '...' |
27 | 32 | } |
28 | 33 | return text |
29 | 34 | } |
35 | + | |
36 | +function getRepoName (id, cb) { | |
37 | + getAvatar({ | |
38 | + links: sbot_links, | |
39 | + get: sbot_get | |
40 | + }, get_id(), id, function (err, avatar) { | |
41 | + if (err) return cb(err) | |
42 | + cb(null, avatar.name) | |
43 | + }) | |
44 | +} |
modules/message.js | ||
---|---|---|
@@ -33,13 +33,13 @@ | ||
33 | 33 | var div = h('Message', { |
34 | 34 | 'ev-contextmenu': contextMenu.bind(null, msg) |
35 | 35 | }, [ |
36 | 36 | h('header', [ |
37 | - h('div', [ | |
37 | + h('div.mini', [ | |
38 | 38 | avatar_link(msg.value.author, avatar_name(msg.value.author), ''), |
39 | 39 | ' ', elMini |
40 | 40 | ]), |
41 | - h('div.message_meta.row', [message_meta(msg)]) | |
41 | + h('div.meta', [message_main_meta(msg)]) | |
42 | 42 | ]) |
43 | 43 | ]) |
44 | 44 | div.setAttribute('tabindex', '0') |
45 | 45 | return div |
modules/git-mini-messages.js | ||
---|---|---|
@@ -1,0 +1,22 @@ | ||
1 | +var h = require('../lib/h') | |
2 | +var when = require('@mmckegg/mutant/when') | |
3 | +var plugs = require('patchbay/plugs') | |
4 | +var message_link = plugs.first(exports.message_link = []) | |
5 | + | |
6 | +exports.message_content = exports.message_content_mini = function (msg, sbot) { | |
7 | + if (msg.value.content.type === 'git-update') { | |
8 | + var commits = msg.value.content.commits || [] | |
9 | + return [ | |
10 | + h('a', {href: `#${msg.key}`}, [ | |
11 | + 'pushed', | |
12 | + when(commits, [' ', pluralizeCommits(commits)]) | |
13 | + ]), | |
14 | + ' to ', | |
15 | + message_link(msg.value.content.repo) | |
16 | + ] | |
17 | + } | |
18 | +} | |
19 | + | |
20 | +function pluralizeCommits (commits) { | |
21 | + return when(commits.length === 1, '1 commit', `${commits.length} commits`) | |
22 | +} |
package.json | ||
---|---|---|
@@ -38,8 +38,9 @@ | ||
38 | 38 | "pull-pushable": "^2.0.1", |
39 | 39 | "pull-stream": "~3.4.5", |
40 | 40 | "scuttlebot": "~9.2.0", |
41 | 41 | "sorted-array-functions": "~1.0.0", |
42 | + "ssb-avatar": "^0.2.0", | |
42 | 43 | "ssb-blobs": "~0.1.7", |
43 | 44 | "ssb-keys": "~7.0.0", |
44 | 45 | "ssb-links": "~2.0.0", |
45 | 46 | "ssb-query": "~0.1.1", |
Built with git-ssb-web