Files: 48e2cdec810952a1c79bffd16684974c8c841222 / modules / follow.js
2190 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_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 | |
28 | exports.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 | |
38 | var message_confirm = plugs.first(exports.message_confirm = []) |
39 | var follower_of = plugs.first(exports.follower_of = []) |
40 | |
41 | exports.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