Files: 50a8f45832d95d56a26433d9cd66e7453416a55e / app / page / userShow.js
3262 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 | const path = require('path') |
6 | |
7 | exports.gives = nest('app.page.userShow') |
8 | |
9 | exports.needs = nest({ |
10 | 'about.html.avatar': 'first', |
11 | 'about.obs.name': 'first', |
12 | 'about.obs.description': 'first', |
13 | 'app.html.context': 'first', |
14 | 'app.html.link': 'first', |
15 | 'app.html.blogCard': 'first', |
16 | 'app.html.blogNav': 'first', |
17 | 'app.html.scroller': 'first', |
18 | 'contact.html.follow': 'first', |
19 | 'feed.pull.profile': 'first', |
20 | 'feed.pull.rollup': 'first', |
21 | 'message.html.markdown': 'first', |
22 | 'keys.sync.id': 'first', |
23 | 'sbot.pull.userFeed': 'first', |
24 | 'translations.sync.strings': 'first', |
25 | 'unread.sync.isUnread': 'first' |
26 | }) |
27 | |
28 | exports.create = (api) => { |
29 | var isUnread = api.unread.sync.isUnread |
30 | return nest('app.page.userShow', userShow) |
31 | |
32 | function userShow (location) { |
33 | const { feed } = location |
34 | const myId = api.keys.sync.id() |
35 | |
36 | const strings = api.translations.sync.strings() |
37 | |
38 | const Link = api.app.html.link |
39 | const userEditButton = Link( |
40 | { page: 'userEdit', feed }, |
41 | // h('i.fa.fa-pencil') |
42 | h('img', { src: path.join(__dirname, '../../assets', 'edit.png') }) |
43 | ) |
44 | const directMessageButton = Link({ page: 'threadNew', feed }, h('Button', strings.userShow.action.directMessage)) |
45 | |
46 | const BLOG_TYPES = ['blog', 'post'] |
47 | |
48 | // TODO return some of this ? |
49 | // but maybe this shouldn't be done here ? |
50 | // pull.through(function (blog) { |
51 | // if(isUnread(blog)) |
52 | // blog.unread = true |
53 | // blog.replies.forEach(function (data) { // this was fed rollups |
54 | // if(isUnread(data)) |
55 | // blog.unread = data.unread = true |
56 | // }) |
57 | // }), |
58 | |
59 | const prepend = [ |
60 | api.app.html.blogNav(location), |
61 | h('section.about', [ |
62 | api.about.html.avatar(feed, 'large'), |
63 | h('h1', [ |
64 | api.about.obs.name(feed), |
65 | feed === myId // Only expose own profile editing right now |
66 | ? userEditButton |
67 | : '' |
68 | ]), |
69 | h('div.introduction', computed(api.about.obs.description(feed), d => api.message.html.markdown(d || ''))), |
70 | feed !== myId |
71 | ? h('div.actions', [ |
72 | api.contact.html.follow(feed), |
73 | h('div.directMessage', directMessageButton) |
74 | ]) |
75 | : '', |
76 | ]), |
77 | ] |
78 | |
79 | const store = MutantArray() |
80 | // store(console.log) |
81 | |
82 | return h('Page -userShow', [ |
83 | api.app.html.context(location), |
84 | api.app.html.scroller({ |
85 | classList: ['content'], |
86 | prepend, |
87 | // stream: api.feed.pull.profile(feed), |
88 | stream: opts => api.sbot.pull.userFeed(Object.assign({}, { id: feed }, opts)), |
89 | indexProperty: ['value', 'sequence'], |
90 | filter: () => pull( |
91 | // pull.filter(msg => get(msg, 'value.author') === feed), |
92 | pull.filter(msg => typeof msg.value.content !== 'string'), |
93 | pull.filter(msg => get(msg, 'value.content.root') === undefined), |
94 | pull.filter(msg => BLOG_TYPES.includes(get(msg, 'value.content.type'))) |
95 | ), |
96 | render: blog => { |
97 | return api.app.html.blogCard(blog) |
98 | }, |
99 | store |
100 | }) |
101 | ]) |
102 | } |
103 | } |
104 | |
105 |
Built with git-ssb-web