git ssb

16+

Dominic / patchbay



Tree: 7da1b2adbfa620cd35e8dcf31baf0f7d82bc9874

Files: 7da1b2adbfa620cd35e8dcf31baf0f7d82bc9874 / modules_basic / follow.js

2216 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 =
17exports.message_content_mini = function (msg) {
18 var content = msg.value.content
19 if(content.type == 'contact' && content.contact) {
20 var relation = isRelated(content.following, 'follows')
21 if(content.blocking) relation = 'blocks'
22 return [
23 relation, ' ',
24 avatar_link(content.contact, avatar_name(content.contact), '')
25 ]
26 }
27}
28
29exports.message_content = function (msg) {
30
31 var content = msg.value.content
32 if(content.type == 'contact' && content.contact) {
33 var relation = isRelated(content.following, 'follows')
34 if(content.blocking) relation = 'blocks'
35 return h('div.contact', relation, avatar(msg.value.content.contact, 'thumbnail'))
36 }
37}
38
39var message_confirm = plugs.first(exports.message_confirm = [])
40var follower_of = plugs.first(exports.follower_of = [])
41
42exports.avatar_action = function (id) {
43 var follows_you, you_follow
44
45 var self_id = require('../keys').id
46 follower_of(self_id, id, function (err, f) {
47 you_follow = f
48 update()
49 })
50 follower_of(id, self_id, function (err, f) {
51 follows_you = f
52 update()
53 })
54
55 var state = h('label')
56 var label = h('label')
57
58 function update () {
59 state.textContent = (
60 follows_you && you_follow ? 'friend'
61 : follows_you ? 'follows you'
62 : you_follow ? 'you follow'
63 : ''
64 )
65
66 label.textContent = you_follow ? 'unfollow' : 'follow'
67 }
68
69 return h('div', state,
70 h('a', {href:'#', onclick: function () {
71 message_confirm({
72 type: 'contact',
73 contact: id,
74 following: !you_follow
75 }, function (err) {
76 //TODO: update after following.
77 })
78 }}, h('br'), label)
79 )
80}
81
82
83
84
85

Built with git-ssb-web