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