Commit 81ca6a35c2987aabfa0164ebca0408a78e413dcf
Merge branch 'query-relationships'
Dominic Tarr committed on 8/28/2016, 11:19:19 AMParent: b0f09a2c61341125b8d3bbbaac3e7db729e6db79
Parent: e5a455ab50c75f6fa12e819d2f9d1340000de68a
Files changed
modules/avatar-edit.js | changed |
modules/avatar-profile.js | changed |
modules/follow.js | changed |
modules/relationships.js | changed |
modules/avatar-edit.js | ||
---|---|---|
@@ -135,16 +135,4 @@ | ||
135 | 135 | ) |
136 | 136 | ) |
137 | 137 | } |
138 | 138 | |
139 | - | |
140 | - | |
141 | - | |
142 | - | |
143 | - | |
144 | - | |
145 | - | |
146 | - | |
147 | - | |
148 | - | |
149 | - | |
150 | - |
modules/avatar-profile.js | ||
---|---|---|
@@ -23,31 +23,52 @@ | ||
23 | 23 | return avatar_image_link(id, 'thumbnail') |
24 | 24 | } |
25 | 25 | |
26 | 26 | exports.avatar_profile = function (id) { |
27 | - return h('div.column.profile', | |
28 | - avatar_edit(id), | |
29 | - avatar_action(id), | |
30 | 27 | |
31 | - h('div.profile__relationships.column', | |
28 | + var follows_el = h('div.profile__follows.wrap') | |
29 | + var friends_el = h('div.profile__friendss.wrap') | |
30 | + var followers_el = h('div.profile__followers.wrap') | |
31 | + var a, b | |
32 | 32 | |
33 | - h('strong', 'follows'), | |
34 | - streamToList(pull( | |
35 | - follows(id), | |
36 | - pull.unique(), | |
37 | - pull.map(image_link) | |
38 | - ), h('div.profile__follows.wrap')), | |
33 | + pull(follows(id), pull.unique(), pull.collect(function (err, ary) { | |
34 | + a = ary || []; next() | |
35 | + })) | |
36 | + pull(followers(id), pull.unique(), pull.collect(function (err, ary) { | |
37 | + b = ary || {}; next() | |
38 | + })) | |
39 | 39 | |
40 | - h('strong', 'followers'), | |
41 | - streamToList(pull( | |
42 | - followers(id), | |
43 | - pull.unique(), | |
44 | - pull.map(image_link) | |
45 | - ), h('div.profile__followers.wrap')) | |
46 | - ) | |
47 | - ) | |
48 | -} | |
40 | + function next () { | |
41 | + if(!(a && b)) return | |
42 | + var _c = [], _a = [], _b = [] | |
49 | 43 | |
44 | + a.forEach(function (id) { | |
45 | + if(!~b.indexOf(id)) _a.push(id) | |
46 | + else _c.push(id) | |
47 | + }) | |
48 | + b.forEach(function (id) { | |
49 | + if(!~_c.indexOf(id)) _b.push(id) | |
50 | + }) | |
51 | + function add (ary, el) { | |
52 | + ary.forEach(function (id) { el.appendChild(image_link(id)) }) | |
53 | + } | |
50 | 54 | |
55 | + add(_a, follows_el) | |
56 | + add(_c, friends_el) | |
57 | + add(_b, followers_el) | |
58 | + } | |
51 | 59 | |
52 | 60 | |
61 | + return h('div.column.profile', | |
62 | + avatar_edit(id), | |
63 | + avatar_action(id), | |
64 | + h('div.profile__relationships.column', | |
65 | + h('strong', 'follows'), | |
66 | + follows_el, | |
67 | + h('strong', 'friends'), | |
68 | + friends_el, | |
69 | + h('strong', 'followers'), | |
70 | + followers_el | |
71 | + ) | |
72 | + ) | |
73 | +} | |
53 | 74 |
modules/follow.js | ||
---|---|---|
@@ -19,43 +19,20 @@ | ||
19 | 19 | return h('div.contact', relation, avatar(msg.value.content.contact, 'thumbnail')) |
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
23 | -var sbot_links2 = plugs.first(exports.sbot_links2 = []) | |
24 | 23 | var message_confirm = plugs.first(exports.message_confirm = []) |
24 | +var follower_of = plugs.first(exports.follower_of = []) | |
25 | 25 | |
26 | -function follows (source, dest, cb) { | |
27 | - pull( | |
28 | - sbot_links2({query:[ | |
29 | - {$filter: { | |
30 | - source: source, | |
31 | - dest: dest, | |
32 | - rel: ['contact', {$gt: null}] | |
33 | - }}, | |
34 | - {$map: { | |
35 | - timestamp: 'timestamp', follows: ["rel", 1] | |
36 | - }} | |
37 | - ]}), | |
38 | - pull.collect(function (err, ary) { | |
39 | - if(err) return cb(err) | |
40 | - cb(null, | |
41 | - ary.length ? ary.sort(function (a, b) { | |
42 | - return a.timestamp - b.timestamp | |
43 | - }).pop().follows : false | |
44 | - ) | |
45 | - }) | |
46 | - ) | |
47 | -} | |
48 | - | |
49 | 26 | exports.avatar_action = function (id) { |
50 | 27 | var follows_you, you_follow |
51 | 28 | |
52 | 29 | var self_id = require('../keys').id |
53 | - follows(self_id, id, function (err, f) { | |
30 | + follower_of(self_id, id, function (err, f) { | |
54 | 31 | you_follow = f |
55 | 32 | update() |
56 | 33 | }) |
57 | - follows(id, self_id, function (err, f) { | |
34 | + follower_of(id, self_id, function (err, f) { | |
58 | 35 | follows_you = f |
59 | 36 | update() |
60 | 37 | }) |
61 | 38 | |
@@ -88,23 +65,4 @@ | ||
88 | 65 | |
89 | 66 | |
90 | 67 | |
91 | 68 | |
92 | - | |
93 | - | |
94 | - | |
95 | - | |
96 | - | |
97 | - | |
98 | - | |
99 | - | |
100 | - | |
101 | - | |
102 | - | |
103 | - | |
104 | - | |
105 | - | |
106 | - | |
107 | - | |
108 | - | |
109 | - | |
110 | - |
modules/relationships.js | ||
---|---|---|
@@ -1,23 +1,50 @@ | ||
1 | - | |
1 | +var pull = require('pull-stream') | |
2 | 2 | var plugs = require('../plugs') |
3 | 3 | |
4 | -var sbot_links2 = plugs.first(exports.sbot_links2 = []) | |
4 | +var sbot_query = plugs.first(exports.sbot_query = []) | |
5 | 5 | |
6 | 6 | //this is a bit crude, and doesn't actually show unfollows yet. |
7 | 7 | |
8 | +function makeQuery (a, b) { | |
9 | + return {"$filter": { | |
10 | + value: { | |
11 | + author: a, | |
12 | + content: { | |
13 | + type: 'contact', | |
14 | + contact: b, | |
15 | + following: true | |
16 | + } | |
17 | + }, | |
18 | + }} | |
19 | +} | |
20 | + | |
21 | + | |
8 | 22 | exports.follows = function (id, cb) { |
9 | - return sbot_links2({query: [ | |
10 | - {"$filter": {"source": id, "rel": ["contact", true, false] }}, | |
11 | - {"$map": "dest"} | |
23 | + return sbot_query({query: [ | |
24 | + makeQuery(id, {$prefix:"@"}), | |
25 | + {"$map": ['value', 'content', 'contact']} | |
12 | 26 | ]}) |
13 | 27 | } |
14 | 28 | |
15 | 29 | exports.followers = function (id) { |
16 | - return sbot_links2({query: [ | |
17 | - {"$filter": {"dest": id, "rel": ["contact", true, false] }}, | |
18 | - {"$map": "source"} | |
30 | + return sbot_query({query: [ | |
31 | + makeQuery({$prefix:"@"}, id), | |
32 | + {"$map": ['value', 'author']} | |
19 | 33 | ]}) |
20 | 34 | } |
21 | 35 | |
36 | +exports.follower_of = function (source, dest, cb) { | |
37 | + pull( | |
38 | + sbot_query({query: [ | |
39 | + makeQuery(source, dest), | |
40 | + {$map: ['value', 'content', 'following']} | |
41 | + ]}), | |
42 | + pull.collect(function (err, ary) { | |
43 | + if(err) return cb(err) | |
44 | + else cb(null, ary.pop()) //will be true, or undefined/false | |
45 | + }) | |
46 | + ) | |
47 | +} | |
22 | 48 | |
23 | 49 | |
50 | + |
Built with git-ssb-web