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