Files: e44d1090738a1f2de11a91d4eb82926eeb8dcb86 / modules / follow.js
2216 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var plugs = require('../plugs') |
4 | var avatar = plugs.first(exports.avatar = []) |
5 | var avatar_name = plugs.first(exports.avatar_name = []) |
6 | var avatar_link = plugs.first(exports.avatar_link = []) |
7 | var pull = require('pull-stream') |
8 | var plugs = require('../plugs') |
9 | |
10 | //render a message when someone follows someone, |
11 | //so you see new users |
12 | function isRelated(value, name) { |
13 | return value ? name : value === false ? 'un'+name : '' |
14 | } |
15 | |
16 | exports.message_content = |
17 | exports.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 | |
29 | exports.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 | |
39 | var message_confirm = plugs.first(exports.message_confirm = []) |
40 | var follower_of = plugs.first(exports.follower_of = []) |
41 | |
42 | exports.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