git ssb

16+

Dominic / patchbay



Commit cde57d98f029001047a363e2ad736da3fc6bedd7

second attempt at base modules

Michael Williams committed on 12/18/2016, 8:34:35 AM
Parent: ca86f8a3ab637b07b9de5d26f1106bc0bc9ea03d

Files changed

modules_basic/avatar-edit.jschanged
modules_basic/avatar-image.jschanged
modules_basic/follow.jschanged
modules_basic/invite.jschanged
modules_basic/private.jschanged
modules_basic/setup.jschanged
modules_basic/thread.jschanged
modules_core/app.jschanged
modules_core/blob-url.jschanged
modules_core/crypto.jschanged
modules_core/index.jschanged
modules_core/message-confirm.jschanged
modules_core/sbot.jschanged
modules_core/config.jsadded
modules_core/keys.jsadded
modules_core/self-id.jsadded
modules_extra/audio-mp3.jschanged
modules_extra/git.jschanged
modules_extra/notifications.jschanged
package.jsonchanged
config.jsdeleted
keys.jsdeleted
modules_basic/avatar-edit.jsView
@@ -8,9 +8,8 @@
88 var getAvatar = require('ssb-avatar')
99 var plugs = require('../plugs')
1010 var ref = require('ssb-ref')
1111 var visualize = require('visualize-buffer')
12-var self_id = require('../keys').id
1312
1413 //var confirm = plugs.first(exports.message_confirm = [])
1514 //var sbot_blobs_add = plugs.first(exports.sbot_blobs_add = [])
1615 //var blob_url = plugs.first(exports.blob_url = [])
@@ -36,8 +35,9 @@
3635 )
3736 }
3837
3938 exports.needs = {
39 + self_id: 'first',
4040 message_confirm: 'first',
4141 sbot_blobs_add: 'first',
4242 blob_url: 'first',
4343 sbot_links: 'first',
@@ -46,8 +46,10 @@
4646
4747 exports.gives = 'avatar_edit'
4848
4949 exports.create = function (api) {
50 + var self_id = api.self_id
51 +
5052 return function (id) {
5153
5254 var img = visualize(new Buffer(id.substring(1), 'base64'), 256)
5355 img.classList.add('avatar--large')
modules_basic/avatar-image.jsView
@@ -6,16 +6,15 @@
66 var visualize = require('visualize-buffer')
77
88 var pull = require('pull-stream')
99
10-var self_id = require('../keys').id
11-
1210 //var plugs = require('../plugs')
1311 //var sbot_query = plugs.first(exports.sbot_query = [])
1412 //var blob_url = require('../plugs').first(exports.blob_url = [])
1513 //
1614
1715 exports.needs = {
16 + self_id: 'first',
1817 sbot_query: 'first',
1918 blob_url: 'first'
2019 }
2120
@@ -34,8 +33,9 @@
3433
3534 var last = 0
3635
3736 exports.create = function (api) {
37 + var self_id = api.self_id
3838 var avatars = {}
3939
4040 //blah blah
4141 return {
modules_basic/follow.jsView
@@ -15,8 +15,9 @@
1515 return value ? name : value === false ? 'un'+name : ''
1616 }
1717
1818 exports.needs = {
19 + self_id: 'first',
1920 avatar: 'first',
2021 avatar_name: 'first',
2122 avatar_link: 'first',
2223 message_confirm: 'first',
@@ -29,8 +30,10 @@
2930 avatar_action: true,
3031 }
3132
3233 exports.create = function (api) {
34 + var self_id = api.self_id
35 +
3336 var exports = {}
3437 exports.message_content =
3538 exports.message_content_mini = function (msg) {
3639 var content = msg.value.content
@@ -56,9 +59,8 @@
5659
5760 exports.avatar_action = function (id) {
5861 var follows_you, you_follow
5962
60- var self_id = require('../keys').id
6163 api.follower_of(self_id, id, function (err, f) {
6264 you_follow = f
6365 update()
6466 })
modules_basic/invite.jsView
@@ -1,8 +1,7 @@
11 'use strict'
22 var ref = require('ssb-ref')
33 var ssbClient = require('ssb-client')
4-var id = require('../keys').id
54 var h = require('hyperscript')
65
76 var Progress = require('hyperprogress')
87
@@ -11,8 +10,9 @@
1110 //var sbot_gossip_connect = plugs.first(exports.sbot_gossip_connect = [])
1211 //var follower_of = plugs.first(exports.follower_of = [])
1312
1413 exports.needs = {
14 + self_id: 'first',
1515 sbot_publish: 'first',
1616 sbot_gossip_connect: 'first',
1717 follower_of: 'first',
1818 invite_parse: 'first',
@@ -24,8 +24,10 @@
2424 screen_view: true
2525 }
2626
2727 exports.create = function (api) {
28 + var self_id = api.self_id
29 +
2830 var self
2931 return self = {
3032 invite_parse: function (invite) {
3133 return ref.parseInvite(invite)
@@ -47,12 +49,12 @@
4749 }, function (err, sbot) {
4850 if(err) return cb(err)
4951 onProgress('requesting follow...')
5052 console.log(sbot)
51- sbot.invite.use({feed: id}, function (err, msg) {
53 + sbot.invite.use({feed: self_id}, function (err, msg) {
5254
5355 //if they already follow us, just check we actually follow them.
54- if(err) api.follower_of(id, data.key, function (_err, follows) {
56 + if(err) api.follower_of(self_id, data.key, function (_err, follows) {
5557 if(follows) cb(err)
5658 else next()
5759 })
5860 else next()
modules_basic/private.jsView
@@ -19,8 +19,9 @@
1919 if(Array.isArray(ary)) return ary.map(iter)
2020 }
2121
2222 exports.needs = {
23 + self_id: 'first',
2324 message_render: 'first',
2425 message_compose: 'first',
2526 message_unbox: 'first',
2627 sbot_log: 'first',
@@ -36,8 +37,9 @@
3637 message_content_mini: true
3738 }
3839
3940 exports.create = function (api) {
41 + var self_id = api.self_id
4042
4143 function unbox () {
4244 return pull(
4345 pull.filter(function (msg) {
@@ -63,20 +65,19 @@
6365
6466 // if local id is different from sbot id, sbot won't have indexes of
6567 // private threads
6668 //TODO: put all private indexes client side.
67- var id = require('../keys').id
6869 api.sbot_whoami(function (err, feed) {
6970 if (err) return console.error(err)
70- if(id !== feed.id)
71 + if(self_id !== feed.id)
7172 return div.appendChild(h('h4',
7273 'Private messages are not supported in the lite client.'))
7374
7475 var compose = api.message_compose(
7576 {type: 'post', recps: [], private: true},
7677 {
7778 prepublish: function (msg) {
78- msg.recps = [id].concat(msg.mentions).filter(function (e) {
79 + msg.recps = [self_id].concat(msg.mentions).filter(function (e) {
7980 return ref.isFeed('string' === typeof e ? e : e.link)
8081 })
8182 if(!msg.recps.length)
8283 throw new Error('cannot make private message without recipients - just mention the user in an at reply in the message you send')
@@ -124,5 +125,4 @@
124125 }
125126 }
126127
127128 }
128-
modules_basic/setup.jsView
@@ -11,8 +11,9 @@
1111 //var sbot_query = plugs.first(exports.sbot_query = [])
1212 //var avatar = plugs.first(exports.avatar = [])
1313
1414 exports.needs = {
15 + self_id: 'first',
1516 avatar: 'first',
1617 avatar_edit: 'first',
1718 invite_parse: 'first',
1819 invite_accept: 'first',
@@ -37,16 +38,17 @@
3738 }}]
3839 }
3940
4041 exports.create = function (api) {
42 + var self_id = api.self_id
4143
4244 var exports = {}
4345
4446 //test whether we are connected to the ssb network.
4547 exports.setup_is_fresh_install = function (cb) {
4648 //test by checking whether you have any friends following you?
4749 pull(
48- api.sbot_query({query: followers_query(id), limit: 1, live: false}),
50 + api.sbot_query({query: followers_query(self_id), limit: 1, live: false}),
4951 pull.collect(function (err, ary) {
5052 cb(err, !!ary.length)
5153 })
5254 )
@@ -131,10 +133,8 @@
131133 exports.screen_view = function (path) {
132134
133135 if(path !== '/setup') return
134136
135- var id = require('../keys').id
136-
137137 //set up an avatar
138138
139139
140140 var status = h('span')
@@ -142,17 +142,17 @@
142142 return h('div.scroller', h('div.scroller__wrapper',
143143 h('h1', 'welcome to patchbay!'),
144144 h('div',
145145 'please choose avatar image and name',
146- api.avatar_edit(id)
146 + api.avatar_edit(self_id)
147147 ),
148148 h('h2', 'join network'),
149149 invite_form(),
150150 //show avatars of anyone on the same local network.
151151 //show realtime changes in your followers, especially for local.
152152
153153 exports.progress_bar(),
154- exports.setup_joined_network(require('../keys').id)
154 + exports.setup_joined_network(self_id)
155155 ))
156156 }
157157
158158 return exports
modules_basic/thread.jsView
@@ -4,9 +4,8 @@
44 var ref = require('ssb-ref')
55 var h = require('hyperscript')
66 var u = require('../util')
77 var Scroller = require('pull-scroll')
8-var self_id = require('../keys').id
98
109 function once (cont) {
1110 var ended = false
1211 return function (abort, cb) {
@@ -31,8 +30,9 @@
3130 //var sbot_get = plugs.first(exports.sbot_get = [])
3231 //var sbot_links = plugs.first(exports.sbot_links = [])
3332
3433 exports.needs = {
34 + self_id: 'first',
3535 message_render: 'first',
3636 message_name: 'first',
3737 message_compose: 'first',
3838 message_unbox: 'first',
@@ -43,8 +43,9 @@
4343 exports.gives = 'screen_view'
4444
4545
4646 exports.create = function (api) {
47 + var self_id = api.self_id
4748
4849 function getThread (root, cb) {
4950 //in this case, it's inconvienent that panel only takes
5051 //a stream. maybe it would be better to accept an array?
modules_core/app.jsView
@@ -1,5 +1,4 @@
1-var plugs = require('../plugs')
21 var h = require('hyperscript')
32
43 module.exports = {
54 needs: {screen_view: 'first'},
modules_core/blob-url.jsView
@@ -1,13 +1,13 @@
1-var config = require('../config')
2-
31 module.exports = {
2 + needs: {config: 'first'},
43 gives: 'blob_url',
5- create: function () {
4 + create: function (api) {
5 + var config = api.config
66 return function (link) {
77 if('string' == typeof link.link)
88 link = link.link
9- return config().blobsUrl + '/'+link
9 + return config.blobsUrl + '/'+link
1010 }
1111 }
1212 }
1313
modules_core/crypto.jsView
@@ -1,6 +1,5 @@
11 var ref = require('ssb-ref')
2-var keys = require('../keys')
32 var ssbKeys = require('ssb-keys')
43
54 function unbox_value(msg) {
65 var plaintext = ssbKeys.unbox(msg.content, keys)
@@ -18,13 +17,14 @@
1817
1918
2019 module.exports = {
2120
22- needs: {sbot_publish: 'first'},
21 + needs: {keys: 'first',sbot_publish: 'first'},
2322 gives: {
2423 message_unbox: true, message_box: true, publish: true
2524 },
2625 create: function (api) {
26 + var keys = api.keys
2727
2828 var exports = {}
2929 exports.message_unbox = function (msg) {
3030 if(msg.value) {
modules_core/index.jsView
@@ -1,12 +1,15 @@
11 module.exports = {
22 // "_screen_view.js": require('./_screen_view.js'),
33 "app.js": require('./app.js'),
44 "blob-url.js": require('./blob-url.js'),
5 + "config.js": require('./config.js'),
56 "crypto.js": require('./crypto.js'),
67 "file-input.js": require('./file-input.js'),
8 + "keys.js": require('./keys.js'),
79 "menu.js": require('./menu.js'),
810 "message-confirm.js": require('./message-confirm.js'),
911 "tabs.js": require('./tabs.js'),
10- "sbot.js": require('./sbot.js')
12 + "sbot.js": require('./sbot.js'),
13 + "self-id.js": require('./self-id.js')
1114 }
1215
modules_core/message-confirm.jsView
@@ -1,13 +1,13 @@
11 var lightbox = require('hyperlightbox')
22 var h = require('hyperscript')
33 var u = require('../util')
4-var self_id = require('../keys').id
54 //publish or add
65
76 var plugs = require('../plugs')
87
98 exports.needs = {
9 + self_id: 'first',
1010 publish: 'first', message_content: 'first', avatar: 'first',
1111 message_meta: 'map'
1212 }
1313
@@ -18,8 +18,10 @@
1818 //var avatar = plugs.first(exports.avatar = [])
1919 //var message_meta = plugs.map(exports.message_meta = [])
2020 //
2121 exports.create = function (api) {
22 + var self_id = api.self_id
23 +
2224 return function (content, cb) {
2325
2426 cb = cb || function () {}
2527
modules_core/sbot.jsView
@@ -2,10 +2,8 @@
22 var ssbKeys = require('ssb-keys')
33 var ref = require('ssb-ref')
44 var Reconnect = require('pull-reconnect')
55 var path = require('path')
6-var config = require('ssb-config/inject')(process.env.ssb_appname)
7-config.keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
86
97 function Hash (onHash) {
108 var buffers = []
119 return pull.through(function (data) {
@@ -24,18 +22,16 @@
2422 //also depends on having ssb-ws installed.
2523 //var createClient = require('ssb-lite')
2624 var createClient = require('ssb-client')
2725
28-var createConfig = require('ssb-config/inject')
29-
3026 var createFeed = require('ssb-feed')
31-var keys = require('../keys')
32-var ssbKeys = require('ssb-keys')
3327
3428 var cache = CACHE = {}
3529
3630 module.exports = {
3731 needs: {
32 + config: 'first',
33 + keys: 'first',
3834 connection_status: 'map'
3935 },
4036 gives: {
4137 // connection_status: true,
@@ -55,9 +51,10 @@
5551
5652 //module.exports = {
5753 create: function (api) {
5854
59- var opts = createConfig()
55 + var opts = api.config
56 + var keys = api.keys
6057 var sbot = null
6158 var connection_status = []
6259
6360 var rec = Reconnect(function (isConn) {
@@ -66,9 +63,9 @@
6663 }
6764
6865 createClient(keys, {
6966 manifest: require('../manifest.json'),
70- remote: require('../config')().remote,
67 + remote: config.remote,
7168 caps: config.caps
7269 }, function (err, _sbot) {
7370 if(err)
7471 return notify(err)
modules_core/config.jsView
@@ -1,0 +1,36 @@
1 +var extend = require('xtend')
2 +var Config = require('ssb-config/inject')
3 +var URL = require('url')
4 +
5 +module.exports = {
6 + gives: 'config',
7 + create: function () {
8 + var appName = process.env.ssb_appname
9 + var config = Config(appName)
10 +
11 + var remote = 'undefined' === typeof localStorage
12 + ? null //'ws://localhost:8989~shs:' + require('./keys')
13 + : localStorage.remote
14 +
15 + //TODO: use _several_ remotes, so if one goes down,
16 + // you can still communicate via another...
17 + // also, if a blob does not load, use another pub...
18 +
19 + //if we are the light client, get our blobs from the same domain.
20 + var blobsUrl
21 + if(remote) {
22 + var r = URL.parse(remote.split('~')[0])
23 + //this will work for ws and wss.
24 + r.protocol = r.protocol.replace('ws', 'http')
25 + r.pathname = '/blobs/get'
26 + blobsUrl = URL.format(r)
27 + }
28 + else
29 + blobsUrl = 'http://localhost:8989/blobs/get'
30 +
31 + return extend(config, {
32 + remote: remote,
33 + blobsUrl: blobsUrl
34 + })
35 + }
36 +}
modules_core/keys.jsView
@@ -1,0 +1,13 @@
1 +var ssbKeys = require('ssb-keys')
2 +var Path = require('path')
3 +
4 +module.exports = {
5 + needs: {config: 'first'},
6 + gives: 'keys',
7 + create: function (api) {
8 + var config = api.config
9 + var keysPath = Path.join(config.path, 'secret')
10 + var keys = ssbKeys.loadOrCreateSync(keysPath)
11 + return keys
12 + }
13 +}
modules_core/self-id.jsView
@@ -1,0 +1,7 @@
1 +module.exports = {
2 + needs: {keys: 'first'},
3 + gives: 'self_id',
4 + create: function (api) {
5 + return api.keys.id
6 + }
7 +}
modules_extra/audio-mp3.jsView
@@ -14,9 +14,9 @@
1414 exports.needs = {
1515 // message_link: 'first',
1616 // message_confirm: 'first',
1717 // sbot_links: 'first',
18- blobs_url: 'first'
18 + blob_url: 'first'
1919 }
2020
2121 exports.gives = 'message_content'
2222
modules_extra/git.jsView
@@ -20,8 +20,9 @@
2020 //var avatar_name = plugs.first(exports.avatar_name = [])
2121 //var markdown = plugs.first(exports.markdown = [])
2222
2323 exports.needs = {
24 + self_id: 'first',
2425 message_link: 'first',
2526 message_confirm: 'first',
2627 message_compose: 'first',
2728 sbot_links: 'first',
@@ -36,16 +37,14 @@
3637 message_meta: true,
3738 message_content: true
3839 }
3940
40-
41-var self_id = require('../keys').id
42-
4341 function shortRefName(ref) {
4442 return ref.replace(/^refs\/(heads|tags)\//, '')
4543 }
4644
4745 exports.create = function (api) {
46 + var self_id = api.self_id
4847
4948 function getRefs(msg) {
5049 var updates = new KVGraph('key')
5150 var _cb, _refs
@@ -134,9 +133,9 @@
134133 })
135134 )
136135 }
137136
138- //todo:
137 + //todo:
139138 function messageTimestampLink(msg) {
140139 var date = new Date(msg.value.timestamp)
141140 return h('a.timestamp', {
142141 timestamp: msg.value.timestamp,
@@ -514,6 +513,4 @@
514513 }
515514 }
516515 }
517516 }
518-
519-
modules_extra/notifications.jsView
@@ -14,8 +14,9 @@
1414 //var sbot_user_feed = plugs.first(exports.sbot_user_feed = [])
1515 //var message_unbox = plugs.first(exports.message_unbox = [])
1616
1717 exports.needs = {
18 + self_id: 'first',
1819 message_render: 'first',
1920 sbot_log: 'first',
2021 sbot_get: 'first',
2122 sbot_user_feed: 'first',
@@ -28,8 +29,10 @@
2829 screen_view: true
2930 }
3031
3132 exports.create = function (api) {
33 + var self_id = api.self_id
34 +
3235 function unbox() {
3336 return pull(
3437 pull.map(function (msg) {
3538 return msg.value && 'string' === typeof msg.value.content ?
@@ -124,11 +127,10 @@
124127 if(path === '/notifications') {
125128 var ids = {}
126129 var oldest
127130
128- var id = require('../keys').id
129- ids[id] = true
130- getFirstMessage(id, function (err, msg) {
131 + ids[self_id] = true
132 + getFirstMessage(self_id, function (err, msg) {
131133 if (err) return console.error(err)
132134 if (!oldest || msg.value.timestamp < oldest) {
133135 oldest = msg.value.timestamp
134136 }
@@ -166,5 +168,4 @@
166168 }
167169 }
168170 }
169171 }
170-
package.jsonView
@@ -52,9 +52,10 @@
5252 "ssb-sort": "^1.0.0",
5353 "ssb-ws": "^0.6.2",
5454 "suggest-box": "^2.2.1",
5555 "text-node-searcher": "^1.1.0",
56- "visualize-buffer": "0.0.0"
56 + "visualize-buffer": "0.0.0",
57 + "xtend": "^4.0.1"
5758 },
5859 "devDependencies": {
5960 "browselectrify": "^1.0.1",
6061 "electro": "^2.0.3",
config.jsView
@@ -1,32 +1,0 @@
1-
2-var URL = require('url')
3-
4-module.exports = function () {
5- var remote = 'undefined' === typeof localStorage
6- ? null //'ws://localhost:8989~shs:' + require('./keys')
7- : localStorage.remote
8-
9-
10- //TODO: use _several_ remotes, so if one goes down,
11- // you can still communicate via another...
12- // also, if a blob does not load, use another pub...
13-
14- //if we are the light client, get our blobs from the same domain.
15- var blobsUrl
16- if(remote) {
17- var r = URL.parse(remote.split('~')[0])
18- //this will work for ws and wss.
19- r.protocol = r.protocol.replace('ws', 'http')
20- r.pathname = '/blobs/get'
21- blobsUrl = URL.format(r)
22- }
23- else
24- blobsUrl = 'http://localhost:8989/blobs/get'
25-
26- return {
27- remote: remote,
28- blobsUrl: blobsUrl
29- }
30-}
31-
32-
keys.jsView
@@ -1,5 +1,0 @@
1-var config = require('ssb-config/inject')(process.env.ssb_appname)
2-var ssbKeys = require('ssb-keys')
3-var path = require('path')
4-module.exports = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
5-

Built with git-ssb-web