git ssb

2+

mixmix / ticktack



Tree: 5f86bdb837a971c779cc9be81fd7c8e39090a252

Files: 5f86bdb837a971c779cc9be81fd7c8e39090a252 / app / html / app.js

2885 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 'invite.async.autofollow': 'first',
17 'config.sync.load': 'first',
18 'sbot.async.friendsGet': 'first'
19})
20
21exports.create = (api) => {
22 var view
23
24 return nest({
25 'app.html.app': function app () {
26 api.app.sync.initialize()
27
28 view = Value()
29 var app = h('App', view)
30 api.history.obs.location()(renderLocation)
31 api.history.obs.location()(loc => console.log('location:', loc))
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) {
42 view.set([
43 api.app.html.header({location: loc, push: api.history.sync.push}),
44 api.app.html.warning(),
45 page
46 ])
47 }
48 }
49
50 function startApp () {
51 api.history.sync.push({page: 'splash'})
52
53 const delay = process.env.STARTUP_DELAY || 3500
54 setTimeout(enterApp, delay)
55 }
56
57 function enterApp () {
58 const isOnboarded = api.settings.sync.get('onboarded')
59 const initialPage = process.env.STARTUP_PAGE || 'blogIndex'
60 if (isOnboarded) {
61 autoPub()
62 api.history.sync.push({page: initialPage})
63 } else {
64 api.history.sync.push({
65 page: 'userEdit',
66 feed: api.keys.sync.id(),
67 callback: (err, didEdit) => {
68 if (err) throw new Error('Error editing profile', err)
69
70 // if they clicked something, just mark them onboarded
71 api.settings.sync.set({ onboarded: true })
72
73 autoPub()
74 api.history.sync.push({page: initialPage})
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 // useInvites(invites)
88 // TODO change it so that if you already have a bunch of friends you unfollow the pubs after they follow you?
89
90 var myKey = api.config.sync.load().keys.id
91 api.sbot.async.friendsGet({dest: myKey}, function (err, friends) {
92 // if you have less than 5 followers, use the autoinvite
93 if (Object.keys(friends).length <= 5) useInvites(invites)
94 else console.log('no autoinvite - you have friends already')
95 })
96
97 function useInvites (invites) {
98 invites.forEach(invite => {
99 console.log('using invite:', invite)
100 api.invite.async.autofollow(invite, (err, follows) => {
101 if (err) console.error('Autofollow error:', err)
102 else console.log('Autofollow success', follows)
103 })
104 })
105 }
106 }
107}
108

Built with git-ssb-web