Files: 2d319604d082cb2300af0e54c6416b00bdeb9884 / app / page / userShow.js
3279 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Array: MutantArray, computed, when, map } = require('mutant') |
3 | const pull = require('pull-stream') |
4 | const get = require('lodash/get') |
5 | |
6 | exports.gives = nest('app.page.userShow') |
7 | |
8 | exports.needs = nest({ |
9 | 'translations.sync.strings': 'first', |
10 | 'app.html.link': 'first', |
11 | 'app.html.threadCard': 'first', |
12 | 'about.html.image': 'first', |
13 | 'about.obs.name': 'first', |
14 | 'contact.async.follow': 'first', |
15 | 'contact.async.unfollow': 'first', |
16 | 'contact.obs.followers': 'first', |
17 | 'feed.pull.private': 'first', |
18 | 'feed.pull.rollup': 'first', |
19 | 'keys.sync.id': 'first', |
20 | 'state.obs.threads': 'first', |
21 | 'translations.sync.strings': 'first', |
22 | }) |
23 | |
24 | exports.create = (api) => { |
25 | return nest('app.page.userShow', userShow) |
26 | |
27 | function userShow (location) { |
28 | |
29 | const { feed } = location |
30 | const myId = api.keys.sync.id() |
31 | const name = api.about.obs.name(feed) |
32 | |
33 | const strings = api.translations.sync.strings() |
34 | |
35 | const { followers } = api.contact.obs |
36 | |
37 | const youFollowThem = computed(followers(feed), followers => followers.has(myId)) |
38 | const theyFollowYou = computed(followers(myId), followers => followers.has(feed)) |
39 | const youAreFriends = computed([youFollowThem, theyFollowYou], (a, b) => a && b) |
40 | |
41 | const ourRelationship = computed( |
42 | [youAreFriends, youFollowThem, theyFollowYou], |
43 | (youAreFriends, youFollowThem, theyFollowYou) => { |
44 | if (youAreFriends) return strings.userShow.state.friends |
45 | if (theyFollowYou) return strings.userShow.state.theyFollow |
46 | if (youFollowThem) return strings.userShow.state.youFollow |
47 | } |
48 | ) |
49 | const { unfollow, follow } = api.contact.async |
50 | const followButton = when(followers(myId).sync, |
51 | when(youFollowThem, |
52 | h('Button -subtle', { 'ev-click': () => unfollow(feed) }, strings.userShow.action.unfollow), |
53 | h('Button -primary', { 'ev-click': () => follow(feed) }, strings.userShow.action.follow) |
54 | ), |
55 | h('Button', { disabled: 'disabled' }, strings.loading ) |
56 | ) |
57 | |
58 | |
59 | const threads = MutantArray() |
60 | pull( |
61 | // next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']), |
62 | // api.feed.pull.private({reverse: true, limit: 100, live: false}), |
63 | api.feed.pull.private({reverse: true, live: false}), |
64 | pull.filter(msg => { |
65 | const recps = get(msg, 'value.content.recps') |
66 | if (!recps) return |
67 | |
68 | return recps |
69 | .map(r => typeof r === 'object' ? r.link : r) |
70 | .includes(feed) |
71 | }), |
72 | api.feed.pull.rollup(), |
73 | pull.drain(threads.push) |
74 | // Scroller(container, content, render, false, false) |
75 | ) |
76 | |
77 | const Link = api.app.html.link |
78 | |
79 | return h('Page -userShow', {title: name}, [ |
80 | h('div.container', [ |
81 | api.about.html.image(feed), |
82 | feed !== myId |
83 | ? h('div.friendship', [ |
84 | h('div.state', ourRelationship), |
85 | followButton |
86 | ]) : '', |
87 | // h('div', '...friends in common'), |
88 | // h('div', '...groups this person is in'), |
89 | feed !== myId |
90 | ? Link({ page: 'threadNew', feed }, h('Button -primary', strings.userShow.action.directMessage)) |
91 | : '', |
92 | h('div.threads', map(threads, api.app.html.threadCard)) |
93 | ]) |
94 | ]) |
95 | } |
96 | } |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 |
Built with git-ssb-web