git ssb

2+

mixmix / ticktack



Tree: 4a58e38afe8d7cd5659d286607457aeb91ee7638

Files: 4a58e38afe8d7cd5659d286607457aeb91ee7638 / app / page / userShow.js

3132 bytesRaw
1const nest = require('depnest')
2const { h, Array: MutantArray, computed, when, map } = require('mutant')
3const pull = require('pull-stream')
4const get = require('lodash/get')
5
6exports.gives = nest('app.page.userShow')
7
8exports.needs = nest({
9 'about.html.avatar': 'first',
10 'about.obs.name': 'first',
11 'app.html.link': 'first',
12 'app.html.blogCard': 'first',
13 'contact.html.follow': 'first',
14 'feed.pull.rollup': 'first',
15 'sbot.pull.userFeed': 'first',
16 'keys.sync.id': 'first',
17 'translations.sync.strings': 'first',
18 'unread.sync.isUnread': 'first'
19})
20
21exports.create = (api) => {
22 var isUnread = api.unread.sync.isUnread
23 return nest('app.page.userShow', userShow)
24
25 function userShow (location) {
26
27 const { feed } = location
28 const myId = api.keys.sync.id()
29 const name = api.about.obs.name(feed)
30
31 const strings = api.translations.sync.strings()
32
33 // const { followers } = api.contact.obs
34
35 // const youFollowThem = computed(followers(feed), followers => followers.includes(myId))
36 // const theyFollowYou = computed(followers(myId), followers => followers.includes(feed))
37 // const youAreFriends = computed([youFollowThem, theyFollowYou], (a, b) => a && b)
38
39 // const ourRelationship = computed(
40 // [youAreFriends, youFollowThem, theyFollowYou],
41 // (youAreFriends, youFollowThem, theyFollowYou) => {
42 // if (youAreFriends) return strings.userShow.state.friends
43 // if (theyFollowYou) return strings.userShow.state.theyFollow
44 // if (youFollowThem) return strings.userShow.state.youFollow
45 // }
46 // )
47
48 const Link = api.app.html.link
49 const userEditButton = Link({ page: 'userEdit', feed }, h('i.fa.fa-pencil'))
50 const directMessageButton = Link({ page: 'threadNew', feed }, h('Button', strings.userShow.action.directMessage))
51
52 const BLOG_TYPES = ['blog', 'post']
53 const blogs = MutantArray()
54 pull(
55 api.sbot.pull.userFeed({id: feed, reverse: true, live: false}),
56 pull.filter(msg => BLOG_TYPES.includes(get(msg, 'value.content.type'))),
57 // pull.filter(msg => get(msg, 'value.content.root') === undefined),
58 api.feed.pull.rollup(),
59 //unread state should not be in this file...
60 pull.through(function (blog) {
61 if(isUnread(blog))
62 blog.unread = true
63 blog.replies.forEach(function (data) {
64 if(isUnread(data))
65 blog.unread = data.unread = true
66 })
67 }),
68 pull.drain(blogs.push)
69 // TODO - new Scroller ?
70 )
71
72 return h('Page -userShow', {title: name}, [
73 h('div.content', [
74 h('section.about', [
75 api.about.html.avatar(feed, 'large'),
76 h('h1', [
77 name,
78 feed === myId // Only expose own profile editing right now
79 ? userEditButton
80 : ''
81 ]),
82 feed !== myId
83 ? h('div.actions', [
84 api.contact.html.follow(feed),
85 h('div.directMessage', directMessageButton)
86 ])
87 : '',
88 ]),
89 h('section.blogs', map(blogs, api.app.html.blogCard))
90 ])
91 ])
92 }
93}
94
95

Built with git-ssb-web