app/html/context.jsView |
---|
1 | 1 | const nest = require('depnest') |
2 | | -const { h, computed, map, when } = require('mutant') |
| 2 | +const { h, computed, map, when, Array: MutantArray } = require('mutant') |
| 3 | +const pull = require('pull-stream') |
| 4 | +const next = require('pull-next-step') |
3 | 5 | |
4 | 6 | exports.gives = nest('app.html.context') |
5 | 7 | |
6 | 8 | exports.needs = nest({ |
| 9 | + 'about.html.image': 'first', |
| 10 | + 'about.obs.name': 'first', |
7 | 11 | 'app.html.link': 'first', |
| 12 | + 'feed.pull.private': 'first', |
| 13 | + 'keys.sync.id': 'first', |
8 | 14 | 'translations.sync.strings': 'first', |
9 | 15 | }) |
10 | 16 | |
11 | 17 | |
12 | 18 | exports.create = (api) => { |
13 | 19 | return nest('app.html.context', (location) => { |
14 | 20 | |
15 | 21 | const strings = api.translations.sync.strings() |
| 22 | + const myKey = api.keys.sync.id() |
16 | 23 | |
17 | 24 | const discover = { |
18 | | - notification: 1, |
| 25 | + notifications: Math.floor(Math.random()*5+1), |
19 | 26 | imageEl: h('i.fa.fa-binoculars'), |
20 | 27 | name: strings.blogIndex.title, |
21 | 28 | location: { page: 'blogIndex' }, |
22 | | - selected: location.page === 'blogIndex' |
| 29 | + selected: ['blogIndex', 'home'].includes(location.page) |
23 | 30 | } |
| 31 | + var nearby = [] |
24 | 32 | |
25 | | - const nearby = [] |
26 | | - const friendsWithThreads = [] |
| 33 | + var recentPeersContacted = MutantArray([]) |
27 | 34 | |
| 35 | + pull( |
| 36 | + next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']), |
| 37 | + |
| 38 | + pull.filter(msg => msg.value.content.recps), |
| 39 | + pull.drain(msg => { |
| 40 | + msg.value.content.recps |
| 41 | + .map(recp => typeof recp === 'object' ? recp.link : recp) |
| 42 | + .filter(recp => recp != myKey) |
| 43 | + .forEach(recp => { |
| 44 | + if (!recentPeersContacted.includes(recp)) |
| 45 | + recentPeersContacted.push(recp) |
| 46 | + }) |
| 47 | + }) |
| 48 | + ) |
| 49 | + |
28 | 50 | return h('Context -feed', [ |
29 | 51 | h('div.level.-one', [ |
30 | 52 | Option(discover), |
31 | 53 | map(nearby, Option), |
32 | | - map(friendsWithThreads, Option) |
| 54 | + map(recentPeersContacted, key => Option({ |
| 55 | + notifications: Math.random() > 0.7 ? Math.floor(Math.random()*9+1) : 0, |
| 56 | + imageEl: api.about.html.image(key), |
| 57 | + name: api.about.obs.name(key), |
| 58 | + location: { page: 'userShow', feed: key }, |
| 59 | + selected: location.feed === key |
| 60 | + })) |
33 | 61 | ]), |
34 | 62 | |
35 | 63 | ]) |
36 | 64 | |
37 | 65 | |
38 | | - function Option ({ notification = 0, imageEl, name, location, selected }) { |
| 66 | + function Option ({ notifications = 0, imageEl, name, location, selected }) { |
39 | 67 | return h('Option', { className: selected ? '-selected' : '' }, [ |
40 | 68 | h('div.circle', [ |
41 | | - when(notification, h('div.alert', notification)), |
| 69 | + when(notifications, h('div.alert', notifications)), |
42 | 70 | imageEl |
43 | 71 | ]), |
44 | 72 | api.app.html.link(location, name), |
45 | 73 | ]) |