secure-scuttlebot classic
at main 88 lines 2.1 kB view raw
1var h = require('hyperscript') 2var pull = require('pull-stream') 3 4//var plugs = require('../plugs') 5//var avatar_image_link = plugs.first(exports.avatar_image_link = []) 6//var avatar_action = plugs.map(exports.avatar_action = []) 7//var avatar_edit = plugs.first(exports.avatar_edit = []) 8 9//var follows = plugs.first(exports.follows = []) 10//var followers = plugs.first(exports.followers = []) 11// 12exports.needs = { 13 avatar_image_link: 'first', 14 avatar_action: 'map', 15 avatar_edit: 'first', 16 follows: 'first', 17 followers: 'first' 18} 19 20exports.gives = 'avatar_profile' 21 22function streamToList(stream, el) { 23 pull( 24 stream, 25 pull.drain(function (item) { 26 if(item) el.appendChild(item) 27 }) 28 ) 29 return el 30} 31 32exports.create = function (api) { 33 34 function image_link (id) { 35 return api.avatar_image_link(id, 'thumbnail') 36 } 37 38 return function (id) { 39 40 var follows_el = h('div.profile__follows.wrap') 41 var friends_el = h('div.profile__friendss.wrap') 42 var followers_el = h('div.profile__followers.wrap') 43 var a, b 44 45 pull(api.follows(id), pull.unique(), pull.collect(function (err, ary) { 46 a = ary || []; next() 47 })) 48 pull(api.followers(id), pull.unique(), pull.collect(function (err, ary) { 49 b = ary || {}; next() 50 })) 51 52 function next () { 53 if(!(a && b)) return 54 var _c = [], _a = [], _b = [] 55 56 a.forEach(function (id) { 57 if(!~b.indexOf(id)) _a.push(id) 58 else _c.push(id) 59 }) 60 b.forEach(function (id) { 61 if(!~_c.indexOf(id)) _b.push(id) 62 }) 63 function add (ary, el) { 64 ary.forEach(function (id) { el.appendChild(image_link(id)) }) 65 } 66 67 add(_a, follows_el) 68 add(_c, friends_el) 69 add(_b, followers_el) 70 } 71 72 73 return h('div.column.profile', 74 api.avatar_edit(id), 75 api.avatar_action(id), 76 h('div.profile__relationships.column', 77 h('strong', 'follows'), 78 follows_el, 79 h('strong', 'friends'), 80 friends_el, 81 h('strong', 'followers'), 82 followers_el 83 ) 84 ) 85 } 86 87} 88