Commit 40388d6b54ff2c0d8c314271ce81dcbd0d3797d2
remove git messages public feed, link to git.scuttlebot.io
closes #453Matt McKegg committed on 4/7/2017, 4:31:20 AM
Parent: b377f63e047d25ee2299ad387a17206e4eccd585
Files changed
main-window.js | changed |
modules/app/sync/external-handler/git.js | added |
modules/feed/html/rollup.js | changed |
modules/feed/pull/summary.js | changed |
plugs/message/html/render/git.js | deleted |
styles/message.mcss | changed |
main-window.js | ||
---|---|---|
@@ -23,12 +23,14 @@ | ||
23 | 23 | |
24 | 24 | var api = entry(sockets, nest({ |
25 | 25 | 'keys.sync.id': 'first', |
26 | 26 | 'sbot.obs.connection': 'first', |
27 | + 'sbot.async.get': 'first', | |
27 | 28 | 'blob.sync.url': 'first', |
28 | 29 | 'page.html.render': 'first', |
29 | 30 | 'app.html.search': 'first', |
30 | 31 | 'app.views': 'first', |
32 | + 'app.sync.externalHandler': 'first', | |
31 | 33 | 'app.html.progressNotifier': 'first', |
32 | 34 | 'profile.sheet.edit': 'first' |
33 | 35 | })) |
34 | 36 | |
@@ -88,8 +90,17 @@ | ||
88 | 90 | if (external) { |
89 | 91 | electron.shell.openExternal(href) |
90 | 92 | } else if (href[0] === '&') { |
91 | 93 | electron.shell.openExternal(api.blob.sync.url(href)) |
94 | + } else if (href[0] === '%') { | |
95 | + getExternalHandler(href, (err, handler) => { | |
96 | + if (err) throw err | |
97 | + if (handler) { | |
98 | + handler(href) | |
99 | + } else { | |
100 | + views.setView(href) | |
101 | + } | |
102 | + }) | |
92 | 103 | } else { |
93 | 104 | views.setView(href) |
94 | 105 | } |
95 | 106 | }) |
@@ -97,8 +108,15 @@ | ||
97 | 108 | return container |
98 | 109 | |
99 | 110 | // scoped |
100 | 111 | |
112 | + function getExternalHandler (key, cb) { | |
113 | + api.sbot.async.get(key, function (err, value) { | |
114 | + if (err) return cb(err) | |
115 | + cb(null, api.app.sync.externalHandler({key, value})) | |
116 | + }) | |
117 | + } | |
118 | + | |
101 | 119 | function tab (name, view) { |
102 | 120 | var instance = views.get(view) |
103 | 121 | return h('a', { |
104 | 122 | 'ev-click': function (ev) { |
modules/app/sync/external-handler/git.js | ||
---|---|---|
@@ -1,0 +1,22 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const {shell} = require('electron') | |
3 | + | |
4 | +exports.gives = nest('app.sync.externalHandler') | |
5 | + | |
6 | +var viewer = 'http://git.scuttlebot.io' | |
7 | +var gitMessageTypes = [ | |
8 | + 'git-repo', | |
9 | + 'git-update', | |
10 | + 'issue', | |
11 | + 'issue-edit', | |
12 | + 'pull-request' | |
13 | +] | |
14 | + | |
15 | +exports.create = (api) => { | |
16 | + return nest('app.sync.externalHandler', function (msg) { | |
17 | + if (!gitMessageTypes.includes(msg.value.content.type)) return | |
18 | + return function gitHandler (id) { | |
19 | + shell.openExternal(`${viewer}/${encodeURIComponent(id)}`) | |
20 | + } | |
21 | + }) | |
22 | +} |
modules/feed/html/rollup.js | ||
---|---|---|
@@ -15,8 +15,9 @@ | ||
15 | 15 | 'message.html': { |
16 | 16 | render: 'first', |
17 | 17 | link: 'first' |
18 | 18 | }, |
19 | + 'app.sync.externalHandler': 'first', | |
19 | 20 | 'sbot.async.get': 'first', |
20 | 21 | 'keys.sync.id': 'first', |
21 | 22 | 'about.obs.name': 'first', |
22 | 23 | feed: { |
@@ -71,10 +72,14 @@ | ||
71 | 72 | pull( |
72 | 73 | getStream({old: false}), |
73 | 74 | pull.drain((item) => { |
74 | 75 | var type = item && item.value && item.value.content.type |
76 | + | |
77 | + // ignore message handled by another app | |
78 | + if (api.app.sync.externalHandler(item)) return | |
79 | + | |
75 | 80 | if (type && type !== 'vote' && typeof item.value.content === 'object' && item.value.timestamp > twoDaysAgo()) { |
76 | - if (item.value && item.value.author === api.keys.sync.id() && !updates() && type !== 'git-update') { | |
81 | + if (item.value && item.value.author === api.keys.sync.id() && !updates()) { | |
77 | 82 | return refresh() |
78 | 83 | } |
79 | 84 | if (filter) { |
80 | 85 | var update = (item.value.content.type === 'post' && item.value.content.root) ? { |
@@ -136,10 +141,12 @@ | ||
136 | 141 | pull( |
137 | 142 | api.feed.pull.summary(getStream, {windowSize, bumpFilter}, () => { |
138 | 143 | sync.set(true) |
139 | 144 | }), |
140 | - pull.asyncMap(ensureAuthor), | |
145 | + pull.asyncMap(ensureMessageAndAuthor), | |
141 | 146 | pull.filter((item) => { |
147 | + // ignore messages that are handled by other apps | |
148 | + if (item.rootMessage && api.app.sync.externalHandler(item.rootMessage)) return | |
142 | 149 | if (filter) { |
143 | 150 | return filter(item) |
144 | 151 | } else { |
145 | 152 | return true |
@@ -229,16 +236,22 @@ | ||
229 | 236 | return h('div') |
230 | 237 | } |
231 | 238 | } |
232 | 239 | |
233 | - function ensureAuthor (item, cb) { | |
240 | + function ensureMessageAndAuthor (item, cb) { | |
234 | 241 | if (item.type === 'message' && !item.message) { |
235 | - api.sbot.async.get(item.messageId, (_, value) => { | |
236 | - if (value) { | |
237 | - item.author = value.author | |
238 | - } | |
242 | + if (item.message) { | |
243 | + item.rootMessage = item.message | |
239 | 244 | cb(null, item) |
240 | - }) | |
245 | + } else { | |
246 | + api.sbot.async.get(item.messageId, (_, value) => { | |
247 | + if (value) { | |
248 | + item.author = value.author | |
249 | + item.rootMessage = {key: item.messageId, value} | |
250 | + } | |
251 | + cb(null, item) | |
252 | + }) | |
253 | + } | |
241 | 254 | } else { |
242 | 255 | cb(null, item) |
243 | 256 | } |
244 | 257 | } |
modules/feed/pull/summary.js | ||
---|---|---|
@@ -85,10 +85,10 @@ | ||
85 | 85 | } |
86 | 86 | } |
87 | 87 | } |
88 | 88 | } else { |
89 | - if (c.root || (c.type === 'git-update' && c.repo)) { | |
90 | - const group = ensureMessage(c.root || c.repo, messageUpdates) | |
89 | + if (c.root) { | |
90 | + const group = ensureMessage(c.root, messageUpdates) | |
91 | 91 | group.fromTime = fromTime |
92 | 92 | group.lastUpdateType = 'reply' |
93 | 93 | group.repliesFrom.add(msg.value.author) |
94 | 94 | SortedArray.add(group.replies, msg, compareUserTimestamp) |
plugs/message/html/render/git.js | ||
---|---|---|
@@ -1,46 +1,0 @@ | ||
1 | -var {h, when} = require('mutant') | |
2 | -var nest = require('depnest') | |
3 | -var extend = require('xtend') | |
4 | - | |
5 | -exports.needs = nest({ | |
6 | - 'message.html': { | |
7 | - decorate: 'reduce', | |
8 | - layout: 'first', | |
9 | - link: 'first', | |
10 | - markdown: 'first' | |
11 | - } | |
12 | -}) | |
13 | - | |
14 | -exports.gives = nest('message.html.render') | |
15 | - | |
16 | -exports.create = function (api) { | |
17 | - return nest('message.html.render', function renderMessage (msg, opts) { | |
18 | - if (msg.value.content.type !== 'git-update') return | |
19 | - var element = api.message.html.layout(msg, extend({ | |
20 | - content: messageContent(msg), | |
21 | - layout: 'mini' | |
22 | - }, opts)) | |
23 | - | |
24 | - return api.message.html.decorate(element, { msg }) | |
25 | - }) | |
26 | - | |
27 | - function messageContent (msg) { | |
28 | - var commits = msg.value.content.commits || [] | |
29 | - return [ | |
30 | - h('a', {href: msg.key, title: commitSummary(commits)}, [ | |
31 | - 'pushed', | |
32 | - when(commits, [' ', pluralizeCommits(commits)]) | |
33 | - ]), | |
34 | - ' to ', | |
35 | - api.message.html.link(msg.value.content.repo) | |
36 | - ] | |
37 | - } | |
38 | -} | |
39 | - | |
40 | -function pluralizeCommits (commits) { | |
41 | - return when(commits.length === 1, '1 commit', `${commits.length} commits`) | |
42 | -} | |
43 | - | |
44 | -function commitSummary (commits) { | |
45 | - return commits.map(commit => `- ${commit.title}`).join('\n') | |
46 | -} |
Built with git-ssb-web