git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 40388d6b54ff2c0d8c314271ce81dcbd0d3797d2

remove git messages public feed, link to git.scuttlebot.io

closes #453
Matt McKegg committed on 4/7/2017, 4:31:20 AM
Parent: b377f63e047d25ee2299ad387a17206e4eccd585

Files changed

main-window.jschanged
modules/app/sync/external-handler/git.jsadded
modules/feed/html/rollup.jschanged
modules/feed/pull/summary.jschanged
plugs/message/html/render/git.jsdeleted
styles/message.mcsschanged
main-window.jsView
@@ -23,12 +23,14 @@
2323
2424 var api = entry(sockets, nest({
2525 'keys.sync.id': 'first',
2626 'sbot.obs.connection': 'first',
27+ 'sbot.async.get': 'first',
2728 'blob.sync.url': 'first',
2829 'page.html.render': 'first',
2930 'app.html.search': 'first',
3031 'app.views': 'first',
32+ 'app.sync.externalHandler': 'first',
3133 'app.html.progressNotifier': 'first',
3234 'profile.sheet.edit': 'first'
3335 }))
3436
@@ -88,8 +90,17 @@
8890 if (external) {
8991 electron.shell.openExternal(href)
9092 } else if (href[0] === '&') {
9193 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+ })
92103 } else {
93104 views.setView(href)
94105 }
95106 })
@@ -97,8 +108,15 @@
97108 return container
98109
99110 // scoped
100111
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+
101119 function tab (name, view) {
102120 var instance = views.get(view)
103121 return h('a', {
104122 'ev-click': function (ev) {
modules/app/sync/external-handler/git.jsView
@@ -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.jsView
@@ -15,8 +15,9 @@
1515 'message.html': {
1616 render: 'first',
1717 link: 'first'
1818 },
19+ 'app.sync.externalHandler': 'first',
1920 'sbot.async.get': 'first',
2021 'keys.sync.id': 'first',
2122 'about.obs.name': 'first',
2223 feed: {
@@ -71,10 +72,14 @@
7172 pull(
7273 getStream({old: false}),
7374 pull.drain((item) => {
7475 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+
7580 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()) {
7782 return refresh()
7883 }
7984 if (filter) {
8085 var update = (item.value.content.type === 'post' && item.value.content.root) ? {
@@ -136,10 +141,12 @@
136141 pull(
137142 api.feed.pull.summary(getStream, {windowSize, bumpFilter}, () => {
138143 sync.set(true)
139144 }),
140- pull.asyncMap(ensureAuthor),
145+ pull.asyncMap(ensureMessageAndAuthor),
141146 pull.filter((item) => {
147+ // ignore messages that are handled by other apps
148+ if (item.rootMessage && api.app.sync.externalHandler(item.rootMessage)) return
142149 if (filter) {
143150 return filter(item)
144151 } else {
145152 return true
@@ -229,16 +236,22 @@
229236 return h('div')
230237 }
231238 }
232239
233- function ensureAuthor (item, cb) {
240+ function ensureMessageAndAuthor (item, cb) {
234241 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
239244 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+ }
241254 } else {
242255 cb(null, item)
243256 }
244257 }
modules/feed/pull/summary.jsView
@@ -85,10 +85,10 @@
8585 }
8686 }
8787 }
8888 } 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)
9191 group.fromTime = fromTime
9292 group.lastUpdateType = 'reply'
9393 group.repliesFrom.add(msg.value.author)
9494 SortedArray.add(group.replies, msg, compareUserTimestamp)
plugs/message/html/render/git.jsView
@@ -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-}
styles/message.mcssView
@@ -32,8 +32,14 @@
3232 max-height: 200px
3333 }
3434 }
3535
36+ -mini {
37+ header {
38+ margin-bottom: 15px
39+ }
40+ }
41+
3642 -reply {
3743 font-size: 100%
3844 header {
3945 div.main {

Built with git-ssb-web