git ssb

2+

mixmix / ticktack



Tree: f3a07a62ed183316f08c7c0cf24dcb767afd29b1

Files: f3a07a62ed183316f08c7c0cf24dcb767afd29b1 / app / html / app.js

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

Built with git-ssb-web