git ssb

16+

Dominic / patchbay



Tree: 930ea9397ccd5144d16edc91e33b1d5d3d881737

Files: 930ea9397ccd5144d16edc91e33b1d5d3d881737 / router / sync / routes.js

1441 bytesRaw
1const nest = require('depnest')
2const { isBlob, isFeed, isMsg } = require('ssb-ref')
3
4exports.gives = nest('router.sync.routes')
5
6exports.needs = nest({
7 'app.page': {
8 'errors': 'first',
9 'all': 'first',
10 'feed': 'first',
11 'private': 'first',
12 'notifications': 'first',
13 'profile': 'first',
14 'search': 'first',
15 'blob': 'first',
16 'thread': 'first',
17 'channel': 'first'
18 },
19 'keys.sync.id': 'first'
20})
21
22exports.create = (api) => {
23 return nest('router.sync.routes', (sofar = []) => {
24 const myId = api.keys.sync.id()
25 const pages = api.app.page
26
27 // loc = location
28 const routes = [
29 [ loc => loc.page === 'all', pages.all ],
30 [ loc => loc.page === 'feed', pages.feed ],
31 [ loc => loc.page === 'private', pages.private ],
32 [ loc => loc.page === 'notifications', pages.notifications ],
33 [ loc => loc.page === 'errors', pages.errors ],
34 [ loc => loc.page === 'profile', () => pages.profile({ feed: myId }) ],
35 [ loc => loc.page === 'search' && loc.query, pages.search ],
36
37 [ loc => isBlob(loc.blob), pages.blob ],
38 [ loc => isPresent(loc.channel), pages.channel ],
39 [ loc => isFeed(loc.feed), pages.profile ],
40 [ loc => isMsg(loc.key), pages.thread ]
41 ]
42
43 // stack already loaded routes on top of these
44 return [...sofar, ...routes]
45 })
46}
47
48function isPresent (content) {
49 return typeof content === 'string' && content.length > 1
50}
51

Built with git-ssb-web