git ssb

16+

Dominic / patchbay



Tree: 3c5dd43a2f6adbcaaad339b0a31e11f7d87eec1f

Files: 3c5dd43a2f6adbcaaad339b0a31e11f7d87eec1f / modules / follow.js

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

Built with git-ssb-web