Commit 473ab796d9ba662aa1f1665d60c10838dc0c35d9
load names, avatars, digs from cached data
Dominic Tarr committed on 8/3/2016, 11:16:37 PMParent: 9abd057463439027a5ac4f40d5f7e5f0316deb6c
Files changed
modules/avatar-image.js | changed |
modules/like.js | changed |
modules/message.js | changed |
modules/names.js | changed |
modules/public.js | changed |
modules/search-box.js | changed |
modules/avatar-image.js | ||
---|---|---|
@@ -3,25 +3,96 @@ | ||
3 | 3 | var h = require('hyperscript') |
4 | 4 | var ref = require('ssb-ref') |
5 | 5 | |
6 | 6 | var plugs = require('../plugs') |
7 | -var sbot_links = plugs.first(exports.sbot_links = []) | |
7 | +var sbot_query = plugs.first(exports.sbot_query = []) | |
8 | 8 | var blob_url = require('../plugs').first(exports.blob_url = []) |
9 | 9 | |
10 | +var pull = require('pull-stream') | |
11 | + | |
10 | 12 | var id = require('../keys').id |
11 | 13 | |
12 | 14 | var default_avatar = '&qjeAs8+uMXLlyovT4JnEpMwTNDx/QXHfOl2nv2u0VCM=.sha256' |
13 | 15 | |
16 | +var avatars = AVATARS = {} | |
17 | + | |
18 | +function isFunction (f) { | |
19 | + return 'function' === typeof f | |
20 | +} | |
21 | + | |
22 | +var self_id = require('../keys').id | |
23 | + | |
24 | +var ready = false | |
25 | +var waiting = [] | |
26 | + | |
27 | +var last = 0 | |
28 | + | |
29 | +//blah blah | |
30 | +setTimeout(function () { | |
31 | +pull( | |
32 | + sbot_query({ | |
33 | + query: [{ | |
34 | + $filter: { | |
35 | + timestamp: {$gt: last || 0 }, | |
36 | + value: { content: { | |
37 | + type: "about", | |
38 | + about: {$prefix: "@"}, | |
39 | + image: {link: {$prefix: "&"}} | |
40 | + }} | |
41 | + }}, | |
42 | + { | |
43 | + $map: { | |
44 | + id: ["value", "content", "about"], | |
45 | + image: ["value", "content", "image", "link"], | |
46 | + by: ["value", "author"], | |
47 | + ts: 'timestamp' | |
48 | + }}], | |
49 | + live: true | |
50 | + }), | |
51 | + pull.drain(function (a) { | |
52 | + if(a.sync) { | |
53 | + ready = true | |
54 | + while(waiting.length) waiting.shift()() | |
55 | + return | |
56 | + } | |
57 | + last = a.ts | |
58 | + //set image for avatar. | |
59 | + //overwrite another avatar | |
60 | + //you picked. | |
61 | + if( | |
62 | + //if there is no avatar | |
63 | + (!avatars[a.id]) || | |
64 | + //if i chose this avatar | |
65 | + (a.by == self_id) || | |
66 | + //they chose their own avatar, | |
67 | + //and current avatar was not chosen by me | |
68 | + (a.by === a.id && avatars[a.id].by != self_id) | |
69 | + ) | |
70 | + avatars[a.id] = a | |
71 | + | |
72 | + }) | |
73 | +) | |
74 | +}) | |
75 | + | |
14 | 76 | exports.avatar_image = function (author, classes) { |
15 | 77 | classes = classes || '' |
16 | 78 | if(classes && 'string' === typeof classes) classes = '.avatar--'+classes |
17 | 79 | |
18 | 80 | var img = h('img'+classes, {src: blob_url(default_avatar)}) |
19 | - getAvatar({links: sbot_links}, id, author, function (err, avatar) { | |
20 | - if (err) return console.error(err) | |
21 | - if(ref.isBlob(avatar.image)) | |
22 | - img.src = blob_url(avatar.image) | |
23 | - }) | |
81 | +// getAvatar({links: sbot_links}, id, author, function (err, avatar) { | |
82 | +// if (err) return console.error(err) | |
83 | +// if(ref.isBlob(avatar.image)) | |
84 | +// img.src = blob_url(avatar.image) | |
85 | +// }) | |
86 | + | |
87 | + function go () { | |
88 | + if(avatars[author]) img.src = blob_url(avatars[author].image) | |
89 | + } | |
90 | + | |
91 | + if(!ready) | |
92 | + waiting.push(go) | |
93 | + else go() | |
94 | + | |
24 | 95 | return img |
25 | 96 | } |
26 | 97 | |
27 | 98 |
modules/like.js | ||
---|---|---|
@@ -18,21 +18,24 @@ | ||
18 | 18 | ) |
19 | 19 | } |
20 | 20 | |
21 | 21 | exports.message_meta = function (msg, sbot) { |
22 | - | |
23 | 22 | var digs = h('a') |
24 | 23 | |
25 | - pull( | |
26 | - sbot_links({dest: msg.key, rel: 'vote'}), | |
27 | - pull.collect(function (err, votes) { | |
28 | - if(votes.length === 1) | |
29 | - digs.textContent = ' 1 Dig' | |
30 | - if(votes.length > 1) | |
31 | - digs.textContent = ' ' + votes.length + ' Digs' | |
32 | - }) | |
33 | - ) | |
24 | + var votes = [] | |
25 | + for(var k in CACHE) { | |
26 | + if(CACHE[k].content.type == 'vote' && | |
27 | + (CACHE[k].content.vote == msg.key || | |
28 | + CACHE[k].content.vote.link == msg.key | |
29 | + )) | |
30 | + votes.push({source: CACHE[k].author, dest: k, rel: 'vote'}) | |
31 | + } | |
34 | 32 | |
33 | + if(votes.length === 1) | |
34 | + digs.textContent = ' 1 Dig' | |
35 | + if(votes.length > 1) | |
36 | + digs.textContent = ' ' + votes.length + ' Digs' | |
37 | + | |
35 | 38 | return digs |
36 | 39 | } |
37 | 40 | |
38 | 41 | exports.message_action = function (msg, sbot) { |
modules/message.js | ||
---|---|---|
@@ -16,22 +16,39 @@ | ||
16 | 16 | exports.message_render = function (msg, sbot) { |
17 | 17 | var el = message_content(msg) |
18 | 18 | if(!el) return |
19 | 19 | |
20 | + var links = [] | |
21 | + for(var k in CACHE) { | |
22 | + var _msg = CACHE[k] | |
23 | + if(_msg.content.type == 'post' && Array.isArray(_msg.content.mentions)) { | |
24 | + for(var i = 0; i < _msg.content.mentions.length; i++) | |
25 | + if(_msg.content.mentions[i].link == msg.key) | |
26 | + links.push(k) | |
27 | + } | |
28 | + } | |
29 | + | |
20 | 30 | var backlinks = h('div.backlinks') |
31 | + if(links.length) | |
32 | + backlinks.appendChild(h('label', 'backlinks:', | |
33 | + h('div', links.map(function (key) { | |
34 | + return message_link(key) | |
35 | + })) | |
36 | + )) | |
21 | 37 | |
22 | - pull( | |
23 | - sbot_links({dest: msg.key, rel: 'mentions', keys: true}), | |
24 | - pull.collect(function (err, links) { | |
25 | - if(links.length) | |
26 | - backlinks.appendChild(h('label', 'backlinks:', | |
27 | - h('div', links.map(function (link) { | |
28 | - return message_link(link.key) | |
29 | - })) | |
30 | - )) | |
31 | - }) | |
32 | - ) | |
33 | 38 | |
39 | +// pull( | |
40 | +// sbot_links({dest: msg.key, rel: 'mentions', keys: true}), | |
41 | +// pull.collect(function (err, links) { | |
42 | +// if(links.length) | |
43 | +// backlinks.appendChild(h('label', 'backlinks:', | |
44 | +// h('div', links.map(function (link) { | |
45 | +// return message_link(link.key) | |
46 | +// })) | |
47 | +// )) | |
48 | +// }) | |
49 | +// ) | |
50 | + | |
34 | 51 | var msg = h('div.message', |
35 | 52 | h('div.title.row', |
36 | 53 | h('div.avatar', avatar(msg.value.author, 'thumbnail')), |
37 | 54 | h('div.message_meta.row', message_meta(msg)) |
@@ -60,4 +77,7 @@ | ||
60 | 77 | |
61 | 78 | |
62 | 79 | |
63 | 80 | |
81 | + | |
82 | + | |
83 | + |
modules/names.js | ||
---|---|---|
@@ -57,9 +57,9 @@ | ||
57 | 57 | } |
58 | 58 | |
59 | 59 | //union with this query... |
60 | 60 | |
61 | -var names = [] | |
61 | +var names = NAMES = [] | |
62 | 62 | function update(name) { |
63 | 63 | var n = names.find(function (e) { |
64 | 64 | return e.id == name.id && e.name == e.name |
65 | 65 | }) |
@@ -102,9 +102,9 @@ | ||
102 | 102 | //in this case: [name, id] |
103 | 103 | mfr.reduce(merge), |
104 | 104 | pull.collect(function (err, ary) { |
105 | 105 | if(!err) { |
106 | - names = ary | |
106 | + NAMES = names = ary | |
107 | 107 | ready = true |
108 | 108 | while(waiting.length) waiting.shift()() |
109 | 109 | } |
110 | 110 | }) |
modules/public.js | ||
---|---|---|
@@ -8,8 +8,10 @@ | ||
8 | 8 | var message_render = plugs.first(exports.message_render = []) |
9 | 9 | var message_compose = plugs.first(exports.message_compose = []) |
10 | 10 | var sbot_log = plugs.first(exports.sbot_log = []) |
11 | 11 | |
12 | +var HighWatermark = require('pull-high-watermark') | |
13 | + | |
12 | 14 | exports.screen_view = function (path, sbot) { |
13 | 15 | if(path === '/public') { |
14 | 16 | |
15 | 17 | var content = h('div.column.scroller__content') |
@@ -27,8 +29,9 @@ | ||
27 | 29 | ) |
28 | 30 | |
29 | 31 | pull( |
30 | 32 | u.next(sbot_log, {reverse: true, limit: 100, live: false}), |
33 | +// HighWatermark(100), | |
31 | 34 | Scroller(div, content, message_render, false, false) |
32 | 35 | ) |
33 | 36 | |
34 | 37 | return div |
Built with git-ssb-web