···11require('depject')(
22- require('./modules_core'),
33- require('./modules_basic')
22+ // from more specialized to more general
33+ require('../patchbay/modules_core'),
44+ require('../patchbay/modules_basic')
45).app[0]()
55-66-
+1-70
decent/config.js
···11-22-var URL = require('url')
33-44-function loadRemote () {
55- var remote = null
66-77- if (typeof window !== 'undefined' && window.PATCHBAY_REMOTE) {
88- remote = window.PATCHBAY_REMOTE
99- }
1010-1111- return remote
1212-}
1313-1414-function rewriteRemoteForLocation (remote) {
1515- if (!remote || typeof window === 'undefined' || !window.location) return remote
1616-1717- try {
1818- var shsIndex = remote.indexOf('~shs:')
1919- if (shsIndex === -1) return remote
2020-2121- var base = remote.substring(0, shsIndex)
2222- var parsed = URL.parse(base)
2323- var key = remote.substring(shsIndex + 5)
2424- var loc = window.location
2525- var isLocal = parsed && (parsed.hostname === 'localhost' ||
2626- parsed.hostname === '127.0.0.1' || parsed.hostname === '::1')
2727-2828- if (!isLocal) return remote
2929-3030- var proto = loc.protocol === 'https:' ? 'wss' : 'ws'
3131- var hostname = loc.hostname || loc.host
3232- if (hostname && hostname.indexOf(':') !== -1 && hostname[0] !== '[')
3333- hostname = '[' + hostname + ']'
3434- var port = parsed && parsed.port ? parsed.port : loc.port
3535- var host = hostname + (port ? ':' + port : '')
3636-3737- return proto + '://' + host + '~shs:' + key
3838- } catch (e) {
3939- return remote
4040- }
4141-}
4242-4343-module.exports = function () {
4444- var remote = loadRemote()
4545-4646- // In the browser, rewrite localhost remotes to match the page host,
4747- // while preserving the pubkey and port from the original remote.
4848- remote = rewriteRemoteForLocation(remote)
4949-5050- //TODO: use _several_ remotes, so if one goes down,
5151- // you can still communicate via another...
5252- // also, if a blob does not load, use another pub...
5353-5454- //if we are the light client, get our blobs from the same domain.
5555- var blobsUrl
5656- if (remote) {
5757- var r = URL.parse(remote.split('~')[0])
5858- //this will work for ws and wss.
5959- r.protocol = r.protocol.replace('ws', 'http')
6060- r.pathname = '/blobs/get'
6161- blobsUrl = URL.format(r)
6262- }
6363- else
6464- blobsUrl = 'http://localhost:8989/blobs/get'
6565-6666- return {
6767- remote: remote,
6868- blobsUrl: blobsUrl
6969- }
7070-}
11+module.exports = require('../patchbay/config.js')
···11require('depject')(
22- require('./modules_embedded'),
33- require('./modules_basic'),
44- require('./modules_extra')
55-).plugs.app[0]()
66-77-88-99-22+ // from more specialized to more general
33+ require('../patchbay/modules_embedded'),
44+ require('../patchbay/modules_basic'),
55+ require('../patchbay/modules_extra')
66+).app[0]()
+2-3
decent/index.js
···11require('depject')(
22 // from more specialized to more general
33- require('./modules_extra'),
44- require('./modules_basic'),
33+ require('../patchbay/modules_extra'),
44+ require('../patchbay/modules_basic'),
55 require('./modules_core')
66).app[0]()
77-
···11-var h = require('hyperscript')
22-33-exports.needs = {signifier: 'first'}
44-55-exports.gives = 'avatar_link'
66-77-exports.create = function (api) {
88- return function (id, element) {
99-1010- var link = h('a.avatar', {href: "#"+id, title: id}, element)
1111-1212- api.signifier(id, function (_, names) {
1313- if(names.length)
1414- link.title = names[0].name + '\n '+id
1515- })
1616-1717- return link
1818- }
1919-}
2020-2121-2222-11+module.exports = require('../../patchbay/modules_basic/avatar-link.js')
+1-28
decent/modules_basic/avatar-name.js
···11-22-var signifier = require('../plugs').first(exports.signifier = [])
33-var h = require('hyperscript')
44-55-exports.needs = { signifier: 'first' }
66-77-exports.gives = 'avatar_name'
88-99-exports.create = function (api) {
1010-1111- return function name (id) {
1212- var n = h('span.avatar_name', id ? id.substring(0, 10) : "")
1313-1414- //choose the most popular name for this person.
1515- //for anything like this you'll see I have used sbot.links2
1616- //which is the ssb-links plugin. as you'll see the query interface
1717- //is pretty powerful!
1818- //TODO: "most popular" name is easily gameable.
1919- //must come up with something better than this.
2020-2121- api.signifier(id, function (_, names) {
2222- if(names.length) n.textContent = names[0].name
2323- })
2424-2525- return n
2626- }
2727-2828-}
11+module.exports = require('../../patchbay/modules_basic/avatar-name.js')
···11-var pull = require('pull-stream')
22-var Cat = require('pull-cat')
33-var sort = require('ssb-sort')
44-var ref = require('ssb-ref')
55-var h = require('hyperscript')
66-var u = require('../util')
77-var Scroller = require('pull-scroll')
88-var self_id = require('../keys').id
99-1010-function once (cont) {
1111- var ended = false
1212- return function (abort, cb) {
1313- if(abort) return cb(abort)
1414- else if (ended) return cb(ended)
1515- else
1616- cont(function (err, data) {
1717- if(err) return cb(ended = err)
1818- ended = true
1919- cb(null, data)
2020- })
2121- }
2222-}
2323-2424-//var plugs = require('../plugs')
2525-//
2626-//var message_render = plugs.first(exports.message_render = [])
2727-//var message_name = plugs.first(exports.message_name = [])
2828-//var message_compose = plugs.first(exports.message_compose = [])
2929-//var message_unbox = plugs.first(exports.message_unbox = [])
3030-//
3131-//var sbot_get = plugs.first(exports.sbot_get = [])
3232-//var sbot_links = plugs.first(exports.sbot_links = [])
3333-3434-exports.needs = {
3535- message_render: 'first',
3636- message_name: 'first',
3737- message_compose: 'first',
3838- message_unbox: 'first',
3939- sbot_get: 'first',
4040- sbot_links: 'first'
4141-}
4242-4343-exports.gives = 'screen_view'
4444-4545-4646-exports.create = function (api) {
4747-4848- function getThread (root, cb) {
4949- //in this case, it's inconvienent that panel only takes
5050- //a stream. maybe it would be better to accept an array?
5151-5252- api.sbot_get(root, function (err, value) {
5353- if (err) return cb(err)
5454- var msg = {key: root, value: value}
5555- // if(value.content.root) return getThread(value.content.root, cb)
5656-5757- pull(
5858- api.sbot_links({rel: 'root', dest: root, values: true, keys: true}),
5959- pull.collect(function (err, ary) {
6060- if(err) return cb(err)
6161- ary.unshift(msg)
6262- cb(null, ary)
6363- })
6464- )
6565- })
6666-6767- }
6868-6969- return function (id) {
7070- if(ref.isMsg(id)) {
7171- function normalizeId (value) {
7272- try { return decodeURIComponent(value) } catch (err) { return value }
7373- }
7474- var normalizedId = normalizeId(id)
7575- var autoOpen = false
7676- try {
7777- autoOpen = window.sessionStorage.getItem('decent_reply_intent') === normalizedId
7878- if (autoOpen) window.sessionStorage.removeItem('decent_reply_intent')
7979- } catch (err) {}
8080-8181- var meta = {
8282- type: 'post',
8383- root: id,
8484- branch: id //mutated when thread is loaded.
8585- }
8686-8787- var content = h('div.column.scroller__content')
8888- var div = h('div.column.scroller',
8989- {style: {'overflow-y': 'auto'}},
9090- h('div.scroller__wrapper',
9191- content,
9292- api.message_compose(
9393- meta,
9494- {
9595- shrink: false,
9696- placeholder: 'Write a reply',
9797- modal: true,
9898- triggerLabel: 'Reply',
9999- title: 'Reply',
100100- autoOpen: autoOpen,
101101- listenReplyEvents: true
102102- }
103103- )
104104- )
105105- )
106106-107107- api.message_name(id, function (err, name) {})
108108-109109- pull(
110110- api.sbot_links({
111111- rel: 'root', dest: id, keys: true, old: false
112112- }),
113113- pull.drain(function (msg) {
114114- loadThread() //redraw thread
115115- }, function () {} )
116116- )
117117-118118-119119- function loadThread () {
120120- getThread(id, function (err, thread) {
121121- //would probably be better keep an id for each message element
122122- //(i.e. message key) and then update it if necessary.
123123- //also, it may have moved (say, if you received a missing message)
124124- content.innerHTML = ''
125125- if(err) return content.appendChild(h('pre', err.stack))
126126-127127- //decrypt
128128- thread = thread.map(function (msg) {
129129- return 'string' === typeof msg.value.content ? api.message_unbox(msg) : msg
130130- })
131131-132132- if(err) return content.appendChild(h('pre', err.stack))
133133- sort(thread).map(api.message_render).filter(Boolean).forEach(function (el) {
134134- content.appendChild(el)
135135- })
136136-137137- var branches = sort.heads(thread)
138138- meta.branch = branches.length > 1 ? branches : branches[0]
139139- meta.root = thread[0].value.content.root || thread[0].key
140140- meta.channel = thread[0].value.content.channel
141141-142142- var recps = thread[0].value.content.recps
143143- var private = thread[0].value.private
144144- if(private) {
145145- if(recps)
146146- meta.recps = recps
147147- else
148148- meta.recps = [thread[0].value.author, self_id]
149149- }
150150- })
151151- }
152152-153153- loadThread()
154154- return div
155155- }
156156- }
157157-}
11+module.exports = require('../../patchbay/modules_basic/thread.js')
+1-28
decent/modules_basic/timestamp.js
···11-var h = require('hyperscript')
22-var human = require('human-time')
33-44-exports.needs = {}
55-66-exports.gives = 'message_meta'
77-88-exports.create = function () {
99-1010- function updateTimestampEl(el) {
1111- el.firstChild.nodeValue = human(new Date(el.timestamp))
1212- return el
1313- }
1414-1515- setInterval(function () {
1616- var els = [].slice.call(document.querySelectorAll('.timestamp'))
1717- els.forEach(updateTimestampEl)
1818- }, 60e3)
1919-2020- return function (msg) {
2121- return updateTimestampEl(h('a.enter.timestamp', {
2222- href: '#'+msg.key,
2323- timestamp: msg.value.timestamp,
2424- title: new Date(msg.value.timestamp)
2525- }, ''))
2626- }
2727-2828-}
11+module.exports = require('../../patchbay/modules_basic/timestamp.js')
+1-10
decent/modules_core/_screen_view.js
···11-22-//this is just an UGLY HACK, because depject does not
33-//support recursion...
44-55-//used by tabs and split views
66-77-var sv = require('../plugs').first(exports.screen_view = [])
88-exports._screen_view = function (value) {
99- return sv(value)
1010-}
11+module.exports = require('../../patchbay/modules_core/_screen_view.js')