diff --git a/apps/cory/index.json b/apps/cory/index.json index 9d0c463a..18edb3db 100644 --- a/apps/cory/index.json +++ b/apps/cory/index.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&qvp1qQcymJp9pWxnZXA9/VXFt6FRGj9JCAxNCt/afsU=.sha256","index.html":"&sXphZUl6JQm0Cd4UOVqPZu13PDhqQqFk/EOmKneaEhY=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&V9Ol799hM6i1PZDbAS91CMhgx7aENDTJnT+KrwK4Lh4=.sha256","tf-message.js":"&e811GqoyT6JhNrgXA1rCB/Y7ggtbOz2xcZP5+rQrrws=.sha256","tf.js":"&lYgDJTZaYTvss6Ykzmr3o6KBc6hPFiEzPn6DR3R5Peo=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&KQoBrrw9o/ngsLCeS+1yTNWBWzzjm1tPQTJZ+LQaL98=.sha256","index.html":"&UdGmQAbbLedvG7wpsDZRcpZl05jwUe61GDLACoHANYg=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&V9Ol799hM6i1PZDbAS91CMhgx7aENDTJnT+KrwK4Lh4=.sha256","tf-message.js":"&VNC8ptzGXWAVl9LBBZfrk3YmweA8PQ02d7/wZxWXoAA=.sha256","tf.js":"&Vcdlau6e9yBimrokJzoSPvRIS5BNWXcrVO+cO9TUKBg=.sha256"}} \ No newline at end of file diff --git a/apps/cory/index/app.js b/apps/cory/index/app.js index 0aeb6c89..a4c735b7 100644 --- a/apps/cory/index/app.js +++ b/apps/cory/index/app.js @@ -1,7 +1,7 @@ "use strict"; const k_posts_max = 20; -const k_votes_max = 100; +const k_votes_max = 20; async function following(db, id) { var o = await db.get(id + ":following"); @@ -188,7 +188,7 @@ async function getRecentPostIds(db, id, ids, limit) { async function getVotes(db, id) { var o = await db.get(id + ":votes"); - const k_version = 3; + const k_version = 5; var votes = []; var f = o ? JSON.parse(o) : o; if (!f || f.version != k_version) { @@ -231,12 +231,7 @@ async function getPosts(db, ids) { await ssb.sqlStream( "SELECT rowid, * FROM messages WHERE id IN (" + ids.map(x => "?").join(", ") + ")", ids, - function(row) { - try { - posts.push(row); - } catch { - } - }); + row => posts.push(row)); } return posts; } @@ -278,21 +273,19 @@ async function refresh() { return root && posts.every(post => post.id != root); }); return [].concat(posts, await getPosts(db, roots)); - }).then(async function(posts) { - posts.forEach(async function(post) { - await app.postMessage({message: post}); - }); + }).then(function(posts) { + return Promise.all(posts.map(x => app.postMessage({message: x}))); }); - f.forEach(async function(id) { - await Promise.all([ - getVotes(db, id).then(async function(votes) { - return Promise.all(votes.map(vote => app.postMessage({vote: vote}))); + Promise.all(f.map(function(id) { + return Promise.all([ + getVotes(db, id).then(function(votes) { + return app.postMessage({votes: votes}); }), - getAbout(db, id).then(async function(user) { + getAbout(db, id).then(function(user) { return app.postMessage({user: {user: id, about: user}}); }), ]); - }); + })); }), sendUser(db, whoami), ]); diff --git a/apps/cory/index/index.html b/apps/cory/index/index.html index dd102e72..10a21c79 100644 --- a/apps/cory/index/index.html +++ b/apps/cory/index/index.html @@ -73,7 +73,13 @@ Submit Post - + diff --git a/apps/cory/index/tf-message.js b/apps/cory/index/tf-message.js index 837c7532..d2276f48 100644 --- a/apps/cory/index/tf-message.js +++ b/apps/cory/index/tf-message.js @@ -1,5 +1,5 @@ Vue.component('tf-message', { - props: ['message', 'messages'], + props: ['message', 'messages', 'votes'], data: function() { return { showRaw: false } }, computed: { content_json: function() { @@ -17,15 +17,10 @@ Vue.component('tf-message', { } catch {} }); }, - votes: function() { - return []; + votes2: function() { var id = this.message.id; - return this.votes.filter(function (x) { - try { - var j = JSON.parse(x.content); - return j.type == 'vote' && j.vote.link == id; - } catch {} - }).reduce(function (accum, value) { + var votes = this.votes[id] || []; + return votes.reduce(function (accum, value) { var expression = JSON.parse(value.content).vote.expression; if (!accum[expression]) { accum[expression] = []; @@ -79,9 +74,9 @@ Vue.component('tf-message', {
{{content_json.following ? '==>' : '=/=>'}}
{{message.content}}
- - - {{vote + (votes[vote].length > 1 ? ' (' + votes[vote].length + ')' : '')}} + + + {{vote + (votes2[vote].length > 1 ? ' (' + votes2[vote].length + ')' : '')}} `, diff --git a/apps/cory/index/tf.js b/apps/cory/index/tf.js index b7d3635d..d5c41072 100644 --- a/apps/cory/index/tf.js +++ b/apps/cory/index/tf.js @@ -10,7 +10,7 @@ var g_data = { show_user_dialog: null, connect: null, pubs: [], - votes: [], + votes: {}, apps: {}, share_app: null, }; @@ -38,6 +38,14 @@ window.addEventListener('message', function(event) { g_data.pubs = event.data.pubs; } else if (key == 'apps') { g_data.apps = event.data.apps; + } else if (key == 'votes') { + event.data.votes.forEach(function(vote) { + var link = JSON.parse(vote.content).vote.link; + if (!g_data.votes[link]) { + Vue.set(g_data.votes, link, []); + } + g_data.votes[link].push(vote); + }); } else if (key == 'clear') { Object.keys(g_data_initial).forEach(function(key) { Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key]))); diff --git a/core/client.js b/core/client.js index e358fffa..0b47af32 100644 --- a/core/client.js +++ b/core/client.js @@ -231,7 +231,6 @@ function save() { type: "tildefriends-app", files: Object.fromEntries(Object.keys(gFiles).map(x => [x, gFiles[x].id || gApp.files[x]])), }; - console.log(app); Object.values(gFiles).forEach(function(file) { delete file.id; }); gApp = JSON.parse(JSON.stringify(app)); @@ -285,7 +284,6 @@ function save() { var anySkipped = false; Object.values(gFiles).forEach(function(file) { if (file.doc.isClean(file.generation)) { - console.log("Not saving clean file."); anySkipped = true; return; } @@ -320,7 +318,6 @@ function save() { always(); }); - console.log("Saving file"); file.request.open("POST", "/save", true); file.request.setRequestHeader("Content-Type", "text/plain"); file.request.send(file.doc.getValue());