From 61a3226e144dcbc6e5ca795e79800de8e0be4ecb Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 4 Nov 2023 23:03:14 +0000 Subject: [PATCH] Fix some wiki issues I found while making journal. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4608 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/wiki.json | 2 +- apps/wiki/app.js | 19 ++++++++++++------- apps/wiki/tf-collections-app.js | 1 - 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/wiki.json b/apps/wiki.json index abd17ed7..7568b98e 100644 --- a/apps/wiki.json +++ b/apps/wiki.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "📝", - "previous": "&IJPpdyG/+rYiBwT0loE38hisCHZ2T/i7lpA3a2+wBgA=.sha256" + "previous": "&uHuaLkW5F8E1aJ58hpoz72hWZZHIT2gaExUFSb8D6eI=.sha256" } \ No newline at end of file diff --git a/apps/wiki/app.js b/apps/wiki/app.js index c07c2a1b..e6d047f8 100644 --- a/apps/wiki/app.js +++ b/apps/wiki/app.js @@ -95,7 +95,7 @@ async function process_message(whoami, collection, message, kind, parent) { if (typeof content == 'string') { let x; for (let id of whoami) { - x = await tfrpc.rpc.try_decrypt(whoami, content); + x = await ssb.privateMessageDecrypt(id, content); if (x) { content = JSON.parse(x); content.draft = true; @@ -105,18 +105,19 @@ async function process_message(whoami, collection, message, kind, parent) { if (!x) { return; } - if (content.type !== type || + if (content.type !== kind || (parent && content.parent !== parent)) { return; } } else { content.draft = false; } + print(message.id, content); if (content?.key) { if (content?.tombstone) { delete collection[content.key]; - } else if (collection[content.key]) { - collection[content.key] = Object.assign(collection[content.key], content); + } else { + collection[content.key] = Object.assign(collection[content.key] || {}, content); } } else { collection[message.id] = Object.assign(content, {id: message.id}); @@ -140,6 +141,7 @@ tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) { } let modified = false; + let rows = []; await ssb.sqlAsync(` SELECT messages.id, author, content, timestamp FROM messages @@ -150,11 +152,14 @@ tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) { ((json_extract(messages.content, '$.type') = ?4 AND (?5 IS NULL OR json_extract(messages.content, '$.parent') = ?5)) OR content LIKE '"%') - `, [JSON.stringify(ids), max_rowid ?? -1, rowid, kind, parent], function(row) { - if (process_message(whoami, data, row, kind, parent)) { + `, [JSON.stringify(ids), max_rowid ?? -1, rowid, kind, parent], function(row) { + rows.push(row); + }); + for (let row of rows) { + if (await process_message(whoami, data, row, kind, parent)) { modified = true; } - }); + } if (modified) { break; } diff --git a/apps/wiki/tf-collections-app.js b/apps/wiki/tf-collections-app.js index d8605374..2b135d2b 100644 --- a/apps/wiki/tf-collections-app.js +++ b/apps/wiki/tf-collections-app.js @@ -141,7 +141,6 @@ class TfCollectionsAppElement extends LitElement { } print(message); await tfrpc.rpc.appendMessage(this.whoami, message); - return this.shadowRoot.getElementById('docs').load(); } render() {