diff --git a/apps/cory/index.json b/apps/cory/index.json index 1ffdd6bb..c34c742e 100644 --- a/apps/cory/index.json +++ b/apps/cory/index.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&LPDR4ZoE/qdPy9djmNFUfblXk7W1znMbwuAXp3/zWPI=.sha256","index.html":"&zwiRwroNQ1SnCsq97zB8dRiGwY4H+ii4ZtuKR385zdI=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&uD6N8xUmrjXwIr95nkH/YjuZST6W1Q2MuJ8u6Vcmo6Q=.sha256","tf-message.js":"&KjVh7zASx0TZtZTsS6lJ7T70K9tyXcf+ink4vK7gSWI=.sha256","tf.js":"&Kf578HPfGnoog7LmW2Nof8dQldS04Opl26CE5+nsFLA=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&jkL7crcAyW2KFUlHb43k+cY6JN9Ee3F0gy6ba4p70kg=.sha256","index.html":"&zwiRwroNQ1SnCsq97zB8dRiGwY4H+ii4ZtuKR385zdI=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&taC9THJslxAMy72UIplFjALJx1VHv2l+qfjWoRhhrS4=.sha256","tf-message.js":"&KjVh7zASx0TZtZTsS6lJ7T70K9tyXcf+ink4vK7gSWI=.sha256","tf.js":"&u6n7Eqa1ryFuL9AhlYeJ/WzXYh6zxECKVfhG8/ecRM8=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}} \ No newline at end of file diff --git a/apps/cory/index/app.js b/apps/cory/index/app.js index 810c35cc..2f7dcc78 100644 --- a/apps/cory/index/app.js +++ b/apps/cory/index/app.js @@ -151,6 +151,7 @@ function fnv32a(value) async function getRecentPostIds(db, id, ids, limit) { const k_version = 9; + const k_batch_max = 8; var o = await db.get(id + ':recent_posts'); var recent = []; var f = o ? JSON.parse(o) : o; @@ -158,27 +159,38 @@ async function getRecentPostIds(db, id, ids, limit) { if (!f || f.version != k_version || f.ids_hash != ids_hash) { f = {recent: [], rowid: 0, version: k_version, ids_hash: ids_hash}; } + var row_id_max = 0; await ssb.sqlStream( - "SELECT "+ - " rowid, "+ - " id, "+ - " timestamp "+ - "FROM messages "+ - "WHERE "+ - " rowid > ? AND "+ - " author IN (" + ids.map(x => '?').join(", ") + ") AND "+ - " json_extract(content, '$.type') IN ('post', 'tildefriends-app') "+ - "UNION SELECT MAX(rowid) as rowid, NULL, NULL FROM messages "+ - "ORDER BY timestamp DESC LIMIT ?", - [].concat([f.rowid], ids, [limit + 1]), + "SELECT MAX(rowid) as rowid FROM messages ORDER BY timestamp DESC LIMIT ?", + [], function(row) { - if (row.id) { - recent.push(row.id); - } - if (row.rowid) { - f.rowid = row.rowid; - } + row_id_max = row.rowid; }); + for (var i = 0; i < ids.length; i += k_batch_max) { + var ids_batch = ids.slice(i, Math.min(i + k_batch_max, ids.length)); + await ssb.sqlStream( + "SELECT "+ + " rowid, "+ + " id, "+ + " timestamp "+ + "FROM messages "+ + "WHERE "+ + " rowid > ? AND "+ + " rowid <= ? AND "+ + " author IN (" + ids_batch.map(x => '?').join(", ") + ") AND "+ + " json_extract(content, '$.type') IN ('post', 'tildefriends-app') "+ + "ORDER BY timestamp DESC LIMIT ?", + [].concat([f.rowid, row_id_max], ids_batch, [limit]), + function(row) { + if (row.id) { + recent.push(row.id); + } + if (row.rowid) { + f.rowid = Math.max(row.rowid, f.rowid); + } + }); + } + f.recent.sort((x, y) => x.timestamp - y.timestamp); f.recent = [].concat(recent, f.recent).slice(0, limit); var j = JSON.stringify(f); if (o != j) { diff --git a/apps/cory/index/tf-user.js b/apps/cory/index/tf-user.js index 233021cd..1613bd10 100644 --- a/apps/cory/index/tf-user.js +++ b/apps/cory/index/tf-user.js @@ -13,16 +13,22 @@ Vue.component('tf-user', { computed: { following: { get: function() { - return g_data.users[g_data.whoami] && - g_data.users[g_data.whoami].following && - g_data.users[g_data.whoami].following.indexOf(this.id) != -1; + return g_data.users && + g_data.users[g_data.whoami] && + g_data.users[g_data.whoami].following[this.id]; }, set: function(newValue) { - if (g_data.users[g_data.whoami] && - g_data.users[g_data.whoami].following) { - if (newValue && g_data.users[g_data.whoami].following.indexOf(this.id) == -1) { + var already_following = + g_data.users && + g_data.users[g_data.whoami] && + g_data.users[g_data.whoami].following && + g_data.users[g_data.whoami].following[this.id]; + if (newValue && !already_following) { + if (confirm("Are you sure you want to follow " + this.id + "?")) { window.parent.postMessage({appendMessage: {type: "contact", following: true, contact: this.id}}, '*'); - } else if (!newValue) { + } + } else if (!newValue && already_following) { + if (confirm("Are you sure you want to unfollow " + this.id + "?")) { window.parent.postMessage({appendMessage: {type: "contact", following: false, contact: this.id}}, '*'); } } @@ -49,8 +55,10 @@ Vue.component('tf-user', { } }, }, - template: ` - {{users[id] && users[id].name ? users[id].name : id}} + template: ` + + {{users[id] && users[id].name ? users[id].name : id}} + {{id}} {{users[id] && users[id].name ? users[id].name : id}} @@ -72,18 +80,18 @@ Vue.component('tf-user', {
Following
Followers - + Following - + - Save Profile + Save Profile Close
diff --git a/apps/cory/index/tf.js b/apps/cory/index/tf.js index 87568764..e8c8b580 100644 --- a/apps/cory/index/tf.js +++ b/apps/cory/index/tf.js @@ -55,12 +55,22 @@ function processMessages() { if (!g_data.users[event.data.followers.id]) { Vue.set(g_data.users, event.data.followers.id, {}); } - Vue.set(g_data.users[event.data.followers.id], 'followers', event.data.followers.users); + if (!g_data.users[event.data.followers.id].followers) { + Vue.set(g_data.users[event.data.followers.id], 'followers', {}); + } + for (let user of event.data.followers.users) { + Vue.set(g_data.users[event.data.followers.id].followers, user, true); + } } else if (key == 'following') { if (!g_data.users[event.data.following.id]) { Vue.set(g_data.users, event.data.following.id, {}); } - Vue.set(g_data.users[event.data.following.id], 'following', event.data.following.users); + if (!g_data.users[event.data.following.id].following) { + Vue.set(g_data.users[event.data.following.id], 'following', {}); + } + for (let user of event.data.following.users) { + Vue.set(g_data.users[event.data.following.id].following, user, true); + } } else if (key == 'broadcasts') { g_data.broadcasts = event.data.broadcasts; } else if (key == 'pubs') { diff --git a/src/ssb.db.c b/src/ssb.db.c index 673441e8..be4431df 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -457,7 +457,7 @@ void tf_ssb_db_visit_query(tf_ssb_t* ssb, const char* query, const JSValue binds } else { - printf("prepare failed: %s\n", sqlite3_errmsg(db)); + printf("prepare failed: %s: %s\n", sqlite3_errmsg(db), query); } sqlite3_set_authorizer(db, NULL, NULL); }