git ssb

16+

Dominic / patchbay



Tree: 48e2cdec810952a1c79bffd16684974c8c841222

Files: 48e2cdec810952a1c79bffd16684974c8c841222 / modules / follow.js

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

Built with git-ssb-web