Files: dc5f4dc6989f09141fae9235f7690c01ebdc9e74 / app / html / app.js
3749 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Value, onceTrue } = 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 | '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 | 'invite.async.autofollow': 'first', |
17 | 'config.sync.load': 'first', |
18 | 'sbot.async.friendsGet': 'first', |
19 | 'sbot.async.get': 'first', |
20 | 'sbot.obs.connection': 'first' // EBT |
21 | }) |
22 | |
23 | var count = 0 // TODO - rm |
24 | |
25 | exports.create = (api) => { |
26 | var view |
27 | |
28 | return nest({ |
29 | 'app.html.app': function app () { |
30 | api.app.sync.initialize() |
31 | |
32 | view = Value() |
33 | var app = h('App', view) |
34 | api.history.obs.location()(renderLocation) |
35 | api.history.obs.location()(loc => console.log('location:', loc)) |
36 | |
37 | startApp() |
38 | |
39 | onceTrue(api.sbot.obs.connection, server => getMySeq(server)) // EBT |
40 | |
41 | return app |
42 | } |
43 | }) |
44 | |
45 | function getMySeq (server) { |
46 | console.log('REMOVE THIS') |
47 | // server.ebt.peerStatus(server.id, err, data) => { |
48 | // server.latestSequence(server.id, (err, seq) => { |
49 | // console.log(`${count} mins`) |
50 | // count = count + 1 |
51 | // console.log('actual seq:', seq) |
52 | // console.log(JSON.stringify(data, null, 2)) |
53 | // console.log('ticktack pubs', [ |
54 | // '@7xMrWP8708+LDvaJrRMRQJEixWYp4Oipa9ohqY7+NyQ=.ed25519', |
55 | // '@MflVZCcOBOUe6BLrm/8TyirkTu9/JtdnIJALcd8v5bc=.ed25519' |
56 | // ]) |
57 | // console.log('------------------') |
58 | // }) |
59 | // }) |
60 | |
61 | // setTimeout(() => getMySeq(server), 60000) |
62 | } |
63 | |
64 | function renderLocation (loc) { |
65 | var page = api.router.sync.router(loc) |
66 | if (page) { |
67 | view.set([ |
68 | api.app.html.header({location: loc, push: api.history.sync.push}), |
69 | api.app.html.warning(), |
70 | page |
71 | ]) |
72 | } |
73 | } |
74 | |
75 | function startApp () { |
76 | api.history.sync.push({page: 'splash'}) |
77 | |
78 | const delay = process.env.STARTUP_DELAY || 3500 |
79 | setTimeout(enterApp, delay) |
80 | } |
81 | |
82 | function enterApp () { |
83 | const isOnboarded = api.settings.sync.get('onboarded') |
84 | const initialPage = process.env.STARTUP_PAGE || 'blogIndex' |
85 | if (isOnboarded) { |
86 | autoPub() |
87 | api.history.sync.push({page: initialPage}) |
88 | } else { |
89 | api.history.sync.push({ |
90 | page: 'userEdit', |
91 | feed: api.keys.sync.id(), |
92 | callback: (err, didEdit) => { |
93 | if (err) throw new Error('Error editing profile', err) |
94 | |
95 | // if they clicked something, just mark them onboarded |
96 | api.settings.sync.set({ onboarded: true }) |
97 | |
98 | autoPub() |
99 | api.history.sync.push({page: initialPage}) |
100 | } |
101 | }) |
102 | } |
103 | } |
104 | |
105 | function autoPub () { |
106 | var invites = api.config.sync.load().autoinvites |
107 | if (!invites) { |
108 | console.log('no invites') |
109 | return |
110 | } |
111 | |
112 | useInvites(invites) |
113 | // TODO change it so that if you already have a bunch of friends you unfollow the pubs after they follow you? |
114 | |
115 | // var myKey = api.config.sync.load().keys.id |
116 | // api.sbot.async.friendsGet({dest: myKey}, function (err, friends) { |
117 | // // if you have less than 5 followers, maybe use the autoinvite |
118 | // if (Object.keys(friends).length <= 5) useInvites(invites) |
119 | // else console.log('no autoinvite - you have friends already') |
120 | // }) |
121 | |
122 | function useInvites (invites) { |
123 | invites.forEach(invite => { |
124 | console.log('using invite:', invite) |
125 | api.invite.async.autofollow(invite, (err, follows) => { |
126 | if (err) console.error('Autofollow error:', err) |
127 | else console.log('Autofollow success', follows) |
128 | }) |
129 | }) |
130 | } |
131 | } |
132 | } |
133 |
Built with git-ssb-web