git ssb

2+

mixmix / ticktack



Tree: a672ecc94225dcbe35054ea9e29271d4043e5eb8

Files: a672ecc94225dcbe35054ea9e29271d4043e5eb8 / app / html / app.js

2431 bytesRaw
1const nest = require('depnest')
2const { h, Value } = require('mutant')
3
4exports.gives = nest('app.html.app')
5
6exports.needs = nest({
7 'app.sync.initialize': 'map',
8 'app.html.header': 'first',
9 'history.obs.location': 'first',
10 'history.sync.push': 'first',
11 'keys.sync.id': 'first',
12 'router.sync.router': 'first',
13 'settings.sync.get': 'first',
14 'settings.sync.set': 'first',
15
16 'invite.async.autofollow': 'first',
17 'config.sync.load': 'first',
18 'sbot.async.friendsGet': 'first',
19 'sbot.async.get': 'first'
20})
21
22exports.create = (api) => {
23 var view
24
25 return nest({
26 'app.html.app': function app () {
27 api.app.sync.initialize()
28
29 view = Value()
30 var app = h('App', view)
31 api.history.obs.location()(renderLocation)
32
33 startApp()
34
35 return app
36 }
37 })
38
39 function renderLocation (loc) {
40 var page = api.router.sync.router(loc)
41 if (page) view.set([
42 api.app.html.header({location: loc, push: api.history.sync.push}),
43 page
44 ])
45 }
46
47 function startApp () {
48 api.history.sync.push({page: 'splash'})
49
50 setTimeout(enterApp, 2000)
51 }
52
53 function enterApp() {
54 const isOnboarded = api.settings.sync.get('onboarded')
55 if (isOnboarded) {
56 autoPub()
57 api.history.sync.push({page: 'blogIndex'})
58 }
59 else {
60 api.history.sync.push({
61 page:'userEdit',
62 feed: api.keys.sync.id(),
63 callback: (err, didEdit) => {
64 if (err) throw new Error ('Error editing profile', err)
65
66 // if they clicked something, just mark them onboarded
67 api.settings.sync.set({ onboarded: true })
68
69 autoPub()
70 api.history.sync.push({ page: 'blogIndex' })
71 }
72 })
73 }
74
75 }
76
77 function autoPub () {
78 var invite = api.config.sync.load().autoinvite
79 var self_id = api.config.sync.load().keys.id
80 if(invite) {
81 api.sbot.async.friendsGet({dest: self_id}, function (err, friends) {
82 //if you have less than 5 followers, maybe use the autoinvite
83 if(Object.keys(friends).length <= 5)
84 api.invite.async.autofollow(
85 invite,
86 function (err, follows) {
87 if (err) console.error('Autofollow error:', err)
88 else console.log('Autofollow success', follows)
89 }
90 )
91 else
92 console.log('no autoinvite - you have friends already')
93 })
94 }
95 else
96 console.log('no invite')
97 }
98}
99
100

Built with git-ssb-web