git ssb

16+

Dominic / patchbay



Tree: effce483881a7267ecf514acf90e05cc54fa3f31

Files: effce483881a7267ecf514acf90e05cc54fa3f31 / contact / html / relationships.js

4140 bytesRaw
1const nest = require('depnest')
2const { h, map, computed, when } = require('mutant')
3
4exports.gives = nest('contact.html.relationships')
5
6exports.needs = nest({
7 'about.html.image': 'first',
8 'about.obs.name': 'first',
9 'contact.async.follow': 'first',
10 'contact.async.unfollow': 'first',
11 'contact.async.block': 'first',
12 'contact.async.unblock': 'first',
13 'contact.obs.followers': 'first',
14 'contact.obs.following': 'first',
15 'contact.obs.blockers': 'first',
16 'keys.sync.id': 'first'
17})
18
19exports.create = function (api) {
20 return nest({
21 'contact.html.relationships': relationships
22 })
23
24 function relationships (id) {
25 var rawFollowing = api.contact.obs.following(id)
26 var rawFollowers = api.contact.obs.followers(id)
27
28 var friends = computed([rawFollowing, rawFollowers], (following, followers) => {
29 return [...following].filter(follow => followers.includes(follow))
30 })
31 var following = computed([rawFollowing, friends], (following, friends) => {
32 return [...following].filter(follow => !friends.includes(follow))
33 })
34 var followers = computed([rawFollowers, friends], (followers, friends) => {
35 return [...followers].filter(follower => !friends.includes(follower))
36 })
37
38 var myId = api.keys.sync.id()
39 var ImFollowing = api.contact.obs.following(myId)
40 var IFollowThem = computed([ImFollowing], ImFollowing => ImFollowing.includes(id))
41 var theyFollowMe = computed([rawFollowing], following => following.includes(myId))
42
43 var relationshipStatus = computed([IFollowThem, theyFollowMe], (IFollowThem, theyFollowMe) => {
44 return IFollowThem && theyFollowMe ? '- you are friends'
45 : IFollowThem ? '- you follow them'
46 : theyFollowMe ? '- they follow you'
47 : ''
48 })
49
50 function imageLink (id) {
51 return h('a',
52 { href: id, title: computed(api.about.obs.name(id), name => '@' + name) },
53 api.about.html.image(id)
54 )
55 }
56
57 const { unfollow, follow, block, unblock } = api.contact.async
58 const blockers = api.contact.obs.blockers(id)
59 const ImBlockingThem = computed(blockers, blockers => blockers.includes(myId))
60
61 return h('Relationships', [
62 h('header', 'Relationships'),
63 when(id !== myId,
64 h('div.your-status', [
65 h('header', 'Your status'),
66 h('section -friendship', [
67 when(ImFollowing.sync,
68 when(IFollowThem,
69 h('button', { 'ev-click': () => unfollow(id) }, 'Unfollow'),
70 h('button', { 'ev-click': () => follow(id) }, 'Follow')
71 ),
72 h('button', { disabled: 'disabled' }, 'Loading...')
73 ),
74 when(ImFollowing.sync, h('div.relationship-status', relationshipStatus)),
75 ]),
76 h('section -blocking', [
77 when(ImBlockingThem,
78 h('button', { 'ev-click': () => unblock(id, console.log) }, 'unblock'),
79 h('button', { 'ev-click': () => block(id, console.log) }, 'BLOCK')
80 ),
81 h('div.explainer', [
82 "Blocking tells everyone you don't want to communicate with a person.",
83 h('ul', [
84 h('li', 'You will no longer receive messages from this person'),
85 h('li', "This person won't get any new information about you (including this block)"),
86 h('li', "Your followers will see you have blocked this person - their apps need to know so that they don't pass your information on."),
87 ])
88 ])
89 ])
90 ])
91 ),
92 computed(blockers, blockers => {
93 if (blockers.length === 0) return ''
94
95 return h('div.blockers', [
96 h('header', 'Blocked by'),
97 h('section', blockers.map(imageLink))
98 ])
99 }),
100 h('div.friends', [
101 h('header', 'Friends'),
102 h('section', map(friends, imageLink))
103 ]),
104 h('div.follows', [
105 h('header', 'Follows'),
106 h('section', map(following, imageLink))
107 ]),
108 h('div.followers', [
109 h('header', 'Followers'),
110 h('section', map(followers, imageLink))
111 ])
112 ])
113 }
114}
115

Built with git-ssb-web