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