From c57b0a2f2f25c27c374278ed066d81b9df2e2d23 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 1 Feb 2022 01:47:18 +0000 Subject: [PATCH] Fixed some problems linking messages with their threads in the UI. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3811 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/cory/docs.json | 2 +- apps/cory/docs/id_refactor.md | 2 +- apps/cory/index.json | 2 +- apps/cory/index/tf.js | 67 +++++++++++++++++++---------------- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/apps/cory/docs.json b/apps/cory/docs.json index 620a0f70..60036586 100644 --- a/apps/cory/docs.json +++ b/apps/cory/docs.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&WCq6ssQedT5denXPXlz2BswPD6hmt++EmWIMIDUMurA=.sha256","index.md":"&5EeOHUkDadC+lJsDsKXbfrVDQdePyOHZ7KwaJtR5mrs=.sha256","todo.md":"&U6hrQ6cfJ6+Uvg+wA7ahpCQaM2XiYXKjZUOz2iZDSGM=.sha256","structure.md":"&T+CBfT9XP6ooKFvD1ZCI9hsutqsNIamfBxtAho0HtlU=.sha256","guide.md":"&SgnGL0+rjetY2o9A2+lVRbNvHIkqKwMnZr9gXWneIlc=.sha256","id_refactor.md":"&RCGnByvk25SuPQ5wywVwgOhAFIxOeoUm17sD24XSSZw=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&WCq6ssQedT5denXPXlz2BswPD6hmt++EmWIMIDUMurA=.sha256","index.md":"&5EeOHUkDadC+lJsDsKXbfrVDQdePyOHZ7KwaJtR5mrs=.sha256","todo.md":"&U6hrQ6cfJ6+Uvg+wA7ahpCQaM2XiYXKjZUOz2iZDSGM=.sha256","structure.md":"&T+CBfT9XP6ooKFvD1ZCI9hsutqsNIamfBxtAho0HtlU=.sha256","guide.md":"&SgnGL0+rjetY2o9A2+lVRbNvHIkqKwMnZr9gXWneIlc=.sha256","id_refactor.md":"&8yoYd14gX2Z3ppktVrPYf4qR78fuwAlvrtsWkSCkWUA=.sha256"}} \ No newline at end of file diff --git a/apps/cory/docs/id_refactor.md b/apps/cory/docs/id_refactor.md index 3202aed6..b70cba18 100644 --- a/apps/cory/docs/id_refactor.md +++ b/apps/cory/docs/id_refactor.md @@ -7,7 +7,7 @@ ## Schema - separate table to discourage leakage - - `CREATE TABLE identities (user TEXT, public TEXT, secret TEXT);' + - `CREATE TABLE identities (user TEXT, public TEXT, secret TEXT);` ## API - `ssb.createIdentity()` -> `id` diff --git a/apps/cory/index.json b/apps/cory/index.json index 4ef0b011..e95b3fe9 100644 --- a/apps/cory/index.json +++ b/apps/cory/index.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&iqkvaTLEbxeintzHb07jiFncdg3N1aS8h8ZNUzy7MZI=.sha256","index.html":"&ko7qv1Ihzmw8ibXr0RinyzNBc2xNzcGDQDPO9X3JAAQ=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&wyqn+8yC3O/m6LfZrR5RIfd6+g+rVCUaPCPT3FcQsPg=.sha256","tf.js":"&/yKh5E/PLaK/M3tivdldiEDnpeYQYyuLHWjjdM/QpxE=.sha256","commonmark.min.js":"&EP0OeR9zyLwZannz+0ga4s9AGES2RLvvIIQYHqqV6+k=.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","tf-shared.js":"&+qPP3g4CAUlkt8K4iBCZ+F5Fy6N7fu6MggvSVss2juE=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&iqkvaTLEbxeintzHb07jiFncdg3N1aS8h8ZNUzy7MZI=.sha256","index.html":"&ko7qv1Ihzmw8ibXr0RinyzNBc2xNzcGDQDPO9X3JAAQ=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&wyqn+8yC3O/m6LfZrR5RIfd6+g+rVCUaPCPT3FcQsPg=.sha256","tf.js":"&XAGSA200wKbWaBG+aMWgoC+c2mleeAFiNbzaypDc6vU=.sha256","commonmark.min.js":"&EP0OeR9zyLwZannz+0ga4s9AGES2RLvvIIQYHqqV6+k=.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","tf-shared.js":"&+qPP3g4CAUlkt8K4iBCZ+F5Fy6N7fu6MggvSVss2juE=.sha256"}} \ No newline at end of file diff --git a/apps/cory/index/tf.js b/apps/cory/index/tf.js index 5ba1851c..f2e712da 100644 --- a/apps/cory/index/tf.js +++ b/apps/cory/index/tf.js @@ -3,6 +3,7 @@ var g_data = { whoami: null, connections: [], messages: [], + messages_by_id: {}, users: {}, broadcasts: [], show_connect_dialog: false, @@ -42,45 +43,43 @@ function processMessages() { new_message.children = []; var found = false; var root = JSON.parse(new_message.content).root; - if (root) { - for (let message of g_data.messages) { - if (root == message.id) { - message.children.push(new_message); - message.children.sort((x, y) => x.timestamp - y.timestamp); - found = true; - } + + /* If we had inserted a fake root, replace it if we see the real message. */ + if (g_data.messages_by_id[new_message.id]) { + var old_message = g_data.messages_by_id[new_message.id]; + new_message.children = old_message.children; + for (let child of new_message.children) { + child.parent = new_message; } - if (!found) { + if (old_message.parent) { + old_message.parent.children = old_message.parent.children.filter(x => x != old_message); + } else { + g_data.messages = g_data.messages.filter(x => x != old_message); + } + } + + Vue.set(g_data.messages_by_id, new_message.id, new_message); + + if (root) { + /* If we don't know of the message's root, add it. */ + if (!g_data.messages_by_id[root]) { var fake_root = { id: root, - children: [new_message], + children: [], timestamp: new_message.timestamp, content: '{}', }; + Vue.set(g_data.messages_by_id, root, fake_root); g_data.messages.push(fake_root); g_data.messages.sort((x, y) => y.timestamp - x.timestamp); found = true; } - } - var removed = {}; - 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) => x.timestamp - y.timestamp); - removed[message.id] = true; - } - } - g_data.messages = g_data.messages.filter(x => !removed[x.id]); - if (!found) { - for (let message of g_data.messages) { - if (message.id == new_message.id) { - new_message.children = message.children; - Vue.set(g_data.messages, g_data.messages.indexOf(message), new_message); - found = true; - } - } - } - if (!found) { + var message = g_data.messages_by_id[root]; + new_message.parent = message; + message.children.push(new_message); + message.children.sort((x, y) => x.timestamp - y.timestamp); + } else { + /* This is just a new message with no root. Add it. */ g_data.messages.push(new_message); g_data.messages.sort((x, y) => y.timestamp - x.timestamp); } @@ -136,6 +135,14 @@ function processMessages() { g_data.load_time = (new Date() - g_load_start) / 1000; g_data.loading = false; g_data.times = event.data.times; + + function dump(messages, indent) { + for (let m of messages) { + console.log(indent + m.id); + dump(m.children, indent + ' '); + } + } + dump(g_data.messages, ''); } else if (key == 'unread') { g_data.unread += event.data.unread; } else if (key == 'hash') { @@ -186,7 +193,7 @@ window.addEventListener('load', function() { message.mentions = Object.values(g_data.mentions); } window.parent.postMessage({appendMessage: message}, '*'); - document.getElementById('post_text').value = ''; + g_data.post_text = null; Vue.set(g_data, 'mentions', {}); g_data.reply_root = null; g_data.reply_branch = null;