Files: e39763f409d19a3fb6f6c9052dccd36946f8be25 / app / page / userShow.js
3875 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.image': '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 | 'unread.sync.isUnread': 'first' |
22 | }) |
23 | |
24 | exports.create = (api) => { |
25 | var isUnread = api.unread.sync.isUnread |
26 | return nest('app.page.userShow', userShow) |
27 | |
28 | function userShow (location) { |
29 | |
30 | const { feed } = location |
31 | const myId = api.keys.sync.id() |
32 | const name = api.about.obs.name(feed) |
33 | |
34 | const strings = api.translations.sync.strings() |
35 | |
36 | const { followers } = api.contact.obs |
37 | |
38 | const youFollowThem = computed(followers(feed), followers => followers.includes(myId)) |
39 | // const theyFollowYou = computed(followers(myId), followers => followers.includes(feed)) |
40 | // const youAreFriends = computed([youFollowThem, theyFollowYou], (a, b) => a && b) |
41 | |
42 | // const ourRelationship = computed( |
43 | // [youAreFriends, youFollowThem, theyFollowYou], |
44 | // (youAreFriends, youFollowThem, theyFollowYou) => { |
45 | // if (youAreFriends) return strings.userShow.state.friends |
46 | // if (theyFollowYou) return strings.userShow.state.theyFollow |
47 | // if (youFollowThem) return strings.userShow.state.youFollow |
48 | // } |
49 | // ) |
50 | const { unfollow, follow } = api.contact.async |
51 | const followButton = when(followers(myId).sync, |
52 | when(youFollowThem, |
53 | h('Button -primary', { 'ev-click': () => unfollow(feed) }, strings.userShow.action.unfollow), |
54 | h('Button -primary', { 'ev-click': () => follow(feed) }, strings.userShow.action.follow) |
55 | ), |
56 | h('Button', { disabled: 'disabled' }, strings.loading ) |
57 | ) |
58 | |
59 | const Link = api.app.html.link |
60 | const userEditButton = Link({ page: 'userEdit', feed }, h('i.fa.fa-pencil')) |
61 | const directMessageButton = Link({ page: 'threadNew', feed }, h('Button', strings.userShow.action.directMessage)) |
62 | |
63 | const threads = MutantArray() |
64 | pull( |
65 | // next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']), |
66 | // api.feed.pull.private({reverse: true, limit: 100, live: false}), |
67 | api.feed.pull.private({reverse: true, live: false}), |
68 | pull.filter(msg => { |
69 | const recps = get(msg, 'value.content.recps') |
70 | if (!recps) return |
71 | |
72 | return recps |
73 | .map(r => typeof r === 'object' ? r.link : r) |
74 | .includes(feed) |
75 | }), |
76 | api.feed.pull.rollup(), |
77 | //unread state should not be in this file... |
78 | pull.through(function (thread) { |
79 | if(isUnread(thread)) |
80 | thread.unread = true |
81 | thread.replies.forEach(function (data) { |
82 | if(isUnread(data)) |
83 | thread.unread = data.unread = true |
84 | }) |
85 | }), |
86 | pull.drain(threads.push) |
87 | // Scroller(content, scrollerContent, render, false, false) |
88 | ) |
89 | |
90 | return h('Page -userShow', {title: name}, [ |
91 | h('div.content', [ |
92 | h('section.about', [ |
93 | api.about.html.image(feed), |
94 | h('h1', [ |
95 | name, |
96 | feed === myId // Only expose own profile editing right now |
97 | ? userEditButton |
98 | : '' |
99 | ]), |
100 | feed !== myId |
101 | ? h('div.actions', [ |
102 | h('div.friendship', followButton), |
103 | h('div.directMessage', directMessageButton) |
104 | ]) |
105 | : '', |
106 | ]), |
107 | h('section.blogs', map(threads, api.app.html.blogCard)) |
108 | ]) |
109 | ]) |
110 | } |
111 | } |
112 | |
113 |
Built with git-ssb-web