Support selecting a thread and showing related messages (by a rather brute force search). Sort child messages in the reverse order of top level messages, because that's how we roll.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3754 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
d51eb64c8e
commit
35b7eb511a
@ -1 +1 @@
|
||||
{"type":"tildefriends-app","files":{"app.js":"&+Q+L0IpjsqRhedfyBVkrZASqXtLArzn+/SwycrDaL60=.sha256","index.html":"&/CE4CuVKI56h5tfAHF0kzCXbLfhVjWzsM8aZAB9HpEM=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&/shEzHxwgMAgtiJE5QzpWayMvwHt/G0dhwgujwQHtn0=.sha256","tf.js":"&k1spHFz1z0DroPr/95QBOjR3RVeCJi61TK4i2Xr37uE=.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"}}
|
||||
{"type":"tildefriends-app","files":{"app.js":"&qrR7s0k3vd/aGg03JurUTRMzWyPIEMwGiKAEYNpHpT8=.sha256","index.html":"&/CE4CuVKI56h5tfAHF0kzCXbLfhVjWzsM8aZAB9HpEM=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&A/R6o9GsaDTEyoAIS8EE1ATCfugBlhdS+jdMz7vsfsM=.sha256","tf.js":"&gJUMwBsssB+Suy/NTUjcB3JeloFLvV18i6egqvThaVY=.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"}}
|
@ -209,6 +209,48 @@ async function getRecentPostIds(db, id, ids, limit) {
|
||||
return f.recent.map(x => x.id);
|
||||
}
|
||||
|
||||
async function getRelatedPostIds(db, message, ids, limit) {
|
||||
const k_batch_max = 16;
|
||||
var recent = [];
|
||||
var row_id_max = 0;
|
||||
await ssb.sqlStream(
|
||||
"SELECT MAX(rowid) as rowid FROM messages",
|
||||
[],
|
||||
function(row) {
|
||||
row_id_max = row.rowid;
|
||||
});
|
||||
var id = message.id;
|
||||
try {
|
||||
id = JSON.parse(message.content).root || id;
|
||||
} catch {
|
||||
}
|
||||
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 "+
|
||||
" timestamp >= ? AND "+
|
||||
" rowid <= ? AND "+
|
||||
" author IN (" + ids_batch.map(x => '?').join(", ") + ") AND "+
|
||||
" json_extract(content, '$.type') = 'post' AND "+
|
||||
" json_extract(content, '$.root') = ? "+
|
||||
"ORDER BY timestamp DESC LIMIT ?",
|
||||
[].concat([message.timestamp, row_id_max], ids_batch, [id, limit]),
|
||||
function(row) {
|
||||
if (row.id) {
|
||||
recent.push({id: row.id, timestamp: row.timestamp});
|
||||
}
|
||||
});
|
||||
}
|
||||
recent.sort((x, y) => y.timestamp - x.timestamp);
|
||||
recent = recent.slice(0, limit);
|
||||
return recent.map(x => x.id);
|
||||
}
|
||||
|
||||
async function getVotes(db, id) {
|
||||
var o = await db.get(id + ":votes");
|
||||
const k_version = 7;
|
||||
@ -291,7 +333,13 @@ async function refresh(selected) {
|
||||
ssb.connections().then(connections => app.postMessage({connections: connections})),
|
||||
core.apps().then(apps => app.postMessage({apps: apps})),
|
||||
]);
|
||||
var ids = await getRecentPostIds(db, whoami, g_selected, k_posts_max);
|
||||
var ids;
|
||||
if (selected && selected.length == 1 && selected[0].startsWith('%')) {
|
||||
var m = await getPosts(db, selected);
|
||||
ids = m.length ? await getRelatedPostIds(db, m[0], all_followed, k_posts_max) : [];
|
||||
} else {
|
||||
ids = await getRecentPostIds(db, whoami, g_selected, k_posts_max);
|
||||
}
|
||||
var posts = await getPosts(db, ids);
|
||||
var roots = posts.map(function(x) {
|
||||
try {
|
||||
|
@ -46,10 +46,16 @@ Vue.component('tf-message', {
|
||||
'*');
|
||||
}
|
||||
},
|
||||
show_message: function() {
|
||||
window.parent.postMessage({action: 'setHash', hash: this.message.id}, '*');
|
||||
},
|
||||
},
|
||||
template: `<md-app class="md-elevation-8" style="margin: 1em" v-if="!content_json || ['pub', 'vote'].indexOf(content_json.type) == -1">
|
||||
<md-app-toolbar>
|
||||
<h3>
|
||||
<md-button class="md-icon-button" @click="show_message">
|
||||
<md-icon>percent</md-icon>
|
||||
</md-button>
|
||||
<tf-user :id="message.author"></tf-user>
|
||||
</h3>
|
||||
<div style="font-size: x-small">
|
||||
|
@ -44,7 +44,7 @@ function processMessages() {
|
||||
for (let message of g_data.messages) {
|
||||
if (root == message.id) {
|
||||
message.children.push(new_message);
|
||||
message.children.sort((x, y) => y.timestamp - x.timestamp);
|
||||
message.children.sort((x, y) => x.timestamp - y.timestamp);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
@ -53,7 +53,7 @@ function processMessages() {
|
||||
for (let message of g_data.messages) {
|
||||
if (JSON.parse(message.content).root == new_message.id) {
|
||||
new_message.children.push(message);
|
||||
new_message.children.sort((x, y) => y.timestamp - x.timestamp);
|
||||
new_message.children.sort((x, y) => x.timestamp - y.timestamp);
|
||||
removed[message.id] = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user