Files: b10ce2e3fb81fd4e7ded0080858d4a7ff1d508f9 / app / page / userShow.js
3515 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 | 'about.html.avatar': 'first', |
10 | 'about.obs.name': 'first', |
11 | 'app.html.link': 'first', |
12 | 'app.html.blogCard': 'first', |
13 | 'contact.async.follow': 'first', |
14 | 'contact.async.unfollow': 'first', |
15 | 'contact.obs.followers': 'first', |
16 | 'feed.pull.private': 'first', |
17 | 'feed.pull.rollup': 'first', |
18 | 'keys.sync.id': 'first', |
19 | 'state.obs.threads': 'first', |
20 | 'translations.sync.strings': 'first', |
21 | }) |
22 | |
23 | exports.create = (api) => { |
24 | return nest('app.page.userShow', userShow) |
25 | |
26 | function userShow (location) { |
27 | |
28 | const { feed } = location |
29 | const myId = api.keys.sync.id() |
30 | const name = api.about.obs.name(feed) |
31 | |
32 | const strings = api.translations.sync.strings() |
33 | |
34 | const { followers } = api.contact.obs |
35 | |
36 | const youFollowThem = computed(followers(feed), followers => followers.includes(myId)) |
37 | // const theyFollowYou = computed(followers(myId), followers => followers.includes(feed)) |
38 | // const youAreFriends = computed([youFollowThem, theyFollowYou], (a, b) => a && b) |
39 | |
40 | // const ourRelationship = computed( |
41 | // [youAreFriends, youFollowThem, theyFollowYou], |
42 | // (youAreFriends, youFollowThem, theyFollowYou) => { |
43 | // if (youAreFriends) return strings.userShow.state.friends |
44 | // if (theyFollowYou) return strings.userShow.state.theyFollow |
45 | // if (youFollowThem) return strings.userShow.state.youFollow |
46 | // } |
47 | // ) |
48 | const { unfollow, follow } = api.contact.async |
49 | const followButton = when(followers(myId).sync, |
50 | when(youFollowThem, |
51 | h('Button -primary', { 'ev-click': () => unfollow(feed) }, strings.userShow.action.unfollow), |
52 | h('Button -primary', { 'ev-click': () => follow(feed) }, strings.userShow.action.follow) |
53 | ), |
54 | h('Button', { disabled: 'disabled' }, strings.loading ) |
55 | ) |
56 | |
57 | const Link = api.app.html.link |
58 | const userEditButton = Link({ page: 'userEdit', feed }, h('i.fa.fa-pencil')) |
59 | const directMessageButton = Link({ page: 'threadNew', feed }, h('Button', strings.userShow.action.directMessage)) |
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(content, scrollerContent, render, false, false) |
77 | ) |
78 | |
79 | return h('Page -userShow', {title: name}, [ |
80 | h('div.content', [ |
81 | h('section.about', [ |
82 | api.about.html.avatar(feed, 'large'), |
83 | h('h1', [ |
84 | name, |
85 | feed === myId // Only expose own profile editing right now |
86 | ? userEditButton |
87 | : '' |
88 | ]), |
89 | feed !== myId |
90 | ? h('div.actions', [ |
91 | h('div.friendship', followButton), |
92 | h('div.directMessage', directMessageButton) |
93 | ]) |
94 | : '', |
95 | ]), |
96 | h('section.blogs', map(threads, api.app.html.blogCard)) |
97 | ]) |
98 | ]) |
99 | } |
100 | } |
101 | |
102 | |
103 |
Built with git-ssb-web