Files: 8c68dbb9a3b69a0cf0e0dd503ef059a873189cd5 / app / html / app.js
2661 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Value } = require('mutant') |
3 | |
4 | exports.gives = nest('app.html.app') |
5 | |
6 | exports.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 | |
22 | exports.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 | api.history.obs.location()(loc => console.log('location:', loc)) |
33 | |
34 | startApp() |
35 | |
36 | return app |
37 | } |
38 | }) |
39 | |
40 | function renderLocation (loc) { |
41 | var page = api.router.sync.router(loc) |
42 | if (page) view.set([ |
43 | api.app.html.header({location: loc, push: api.history.sync.push}), |
44 | page |
45 | ]) |
46 | } |
47 | |
48 | function startApp () { |
49 | api.history.sync.push({page: 'splash'}) |
50 | |
51 | const delay = process.env.STARTUP_DELAY || 2000 |
52 | setTimeout(enterApp, delay) |
53 | } |
54 | |
55 | function enterApp() { |
56 | const isOnboarded = api.settings.sync.get('onboarded') |
57 | const initialPage = process.env.STARTUP_PAGE || 'blogIndex' |
58 | if (isOnboarded) { |
59 | autoPub() |
60 | api.history.sync.push({page: initialPage}) |
61 | } |
62 | else { |
63 | api.history.sync.push({ |
64 | page:'userEdit', |
65 | feed: api.keys.sync.id(), |
66 | callback: (err, didEdit) => { |
67 | if (err) throw new Error ('Error editing profile', err) |
68 | |
69 | // if they clicked something, just mark them onboarded |
70 | api.settings.sync.set({ onboarded: true }) |
71 | |
72 | autoPub() |
73 | api.history.sync.push({page: initialPage}) |
74 | } |
75 | }) |
76 | } |
77 | |
78 | } |
79 | |
80 | function autoPub () { |
81 | var invites = api.config.sync.load().autoinvites |
82 | if(!invites) { |
83 | console.log('no invites') |
84 | return |
85 | } |
86 | |
87 | var self_id = api.config.sync.load().keys.id |
88 | api.sbot.async.friendsGet({dest: self_id}, function (err, friends) { |
89 | //if you have less than 5 followers, maybe use the autoinvite |
90 | if(Object.keys(friends).length <= 5) |
91 | invites.forEach(invite => { |
92 | console.log('using invite:', invite) |
93 | api.invite.async.autofollow(invite, (err, follows) => { |
94 | if (err) console.error('Autofollow error:', err) |
95 | else console.log('Autofollow success', follows) |
96 | }) |
97 | }) |
98 | else |
99 | console.log('no autoinvite - you have friends already') |
100 | }) |
101 | } |
102 | } |
103 | |
104 |
Built with git-ssb-web