git ssb

0+

ev / minbase



Tree: f1cc08ac986f18880000b780dae6fb2043e76948

Files: f1cc08ac986f18880000b780dae6fb2043e76948 / modules / follow.js

2380 bytesRaw
1var h = require('hyperscript')
2var u = require('../util')
3var pull = require('pull-stream')
4var avatar = require('./avatar')
5
6//render a message when someone follows someone,
7//so you see new users
8function isRelated(value, name) {
9 return value ? name : value === false ? 'un'+name : ''
10}
11
12exports.needs = {
13 message_confirm: 'first',
14 follower_of: 'first'
15}
16
17exports.gives = {
18 message_content_mini: true,
19 avatar_action: true,
20}
21
22exports.create = function (api) {
23 exports.message_content_mini = function (msg) {
24 var content = msg.value.content
25 if(content.type == 'contact' && msg.value.content.contact) {
26 var relation = isRelated(msg.value.content.following, 'follows')
27 if(msg.value.content.blocking) relation = 'blocks'
28 return [
29 relation, ' ',
30 h('a', {href: '#' + msg.value.content.contact}, avatar.name(msg.value.content.contact))
31 ]
32 }
33 }
34
35 /*exports.message_content = function (msg) {
36
37 var content = msg.value.content
38 if(content.type == 'contact' && content.contact) {
39 var relation = isRelated(content.following, 'follows')
40 if(content.blocking) relation = 'blocks'
41 return h('div.contact', relation, h('a', {href: msg.value.content.contact}, api.avatar(msg.value.content.contact, 'thumbnail')))
42 }
43 }*/
44
45 exports.avatar_action = function (id) {
46 var follows_you, you_follow
47
48 var self_id = require('../keys').id
49 api.follower_of(self_id, id, function (err, f) {
50 you_follow = f
51 update()
52 })
53 api.follower_of(id, self_id, function (err, f) {
54 follows_you = f
55 update()
56 })
57
58 var state = h('label')
59 var label = h('span')
60
61 function update () {
62 state.textContent = (
63 follows_you && you_follow ? 'Friend'
64 : follows_you ? 'Follower'
65 : you_follow ? 'Following'
66 : ''
67 )
68
69 label.textContent = you_follow ? 'Unfollow' : 'Follow'
70 }
71
72 return h('a', {href:'#', onclick: function (e) {
73 e.preventDefault()
74 api.message_confirm({
75 type: 'contact',
76 contact: id,
77 following: !you_follow
78 }, function (err, msg) {
79 if (err) return console.error(err)
80 you_follow = msg.value.content.following
81 update()
82 })
83 }}, h('button.btn', label))
84 }
85 return exports
86}
87

Built with git-ssb-web