git ssb

16+

Dominic / patchbay



Commit 81ca6a35c2987aabfa0164ebca0408a78e413dcf

Merge branch 'query-relationships'

Dominic Tarr committed on 8/28/2016, 11:19:19 AM
Parent: b0f09a2c61341125b8d3bbbaac3e7db729e6db79
Parent: e5a455ab50c75f6fa12e819d2f9d1340000de68a

Files changed

modules/avatar-edit.jschanged
modules/avatar-profile.jschanged
modules/follow.jschanged
modules/relationships.jschanged
modules/avatar-edit.jsView
@@ -135,16 +135,4 @@
135135 )
136136 )
137137 }
138138
139-
140-
141-
142-
143-
144-
145-
146-
147-
148-
149-
150-
modules/avatar-profile.jsView
@@ -23,31 +23,52 @@
2323 return avatar_image_link(id, 'thumbnail')
2424 }
2525
2626 exports.avatar_profile = function (id) {
27- return h('div.column.profile',
28- avatar_edit(id),
29- avatar_action(id),
3027
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
3232
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+ }))
3939
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 = []
4943
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+ }
5054
55+ add(_a, follows_el)
56+ add(_c, friends_el)
57+ add(_b, followers_el)
58+ }
5159
5260
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+}
5374
modules/follow.jsView
@@ -19,43 +19,20 @@
1919 return h('div.contact', relation, avatar(msg.value.content.contact, 'thumbnail'))
2020 }
2121 }
2222
23-var sbot_links2 = plugs.first(exports.sbot_links2 = [])
2423 var message_confirm = plugs.first(exports.message_confirm = [])
24+var follower_of = plugs.first(exports.follower_of = [])
2525
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-
4926 exports.avatar_action = function (id) {
5027 var follows_you, you_follow
5128
5229 var self_id = require('../keys').id
53- follows(self_id, id, function (err, f) {
30+ follower_of(self_id, id, function (err, f) {
5431 you_follow = f
5532 update()
5633 })
57- follows(id, self_id, function (err, f) {
34+ follower_of(id, self_id, function (err, f) {
5835 follows_you = f
5936 update()
6037 })
6138
@@ -88,23 +65,4 @@
8865
8966
9067
9168
92-
93-
94-
95-
96-
97-
98-
99-
100-
101-
102-
103-
104-
105-
106-
107-
108-
109-
110-
modules/relationships.jsView
@@ -1,23 +1,50 @@
1-
1+var pull = require('pull-stream')
22 var plugs = require('../plugs')
33
4-var sbot_links2 = plugs.first(exports.sbot_links2 = [])
4+var sbot_query = plugs.first(exports.sbot_query = [])
55
66 //this is a bit crude, and doesn't actually show unfollows yet.
77
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+
822 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']}
1226 ]})
1327 }
1428
1529 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']}
1933 ]})
2034 }
2135
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+}
2248
2349
50+

Built with git-ssb-web