From b23bc0b16b57017ed830a5a7ecd759e5b60e5b26 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 9 Nov 2023 17:39:05 +0000 Subject: [PATCH] Trying to work toward multiple users. List wikis of people you are following. Also hook in to the lit updated event. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4626 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/wiki.json | 2 +- apps/wiki/app.js | 12 ++++++++---- apps/wiki/tf-collections-app.js | 26 ++++++++++++++++++++------ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/apps/wiki.json b/apps/wiki.json index cd04a522..ee815625 100644 --- a/apps/wiki.json +++ b/apps/wiki.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "📝", - "previous": "&N1wA9DJ6RacaPG52I+ZEhWbbVvf3U1Dcvouh0UkfkG0=.sha256" + "previous": "&YeaTOrnB4mPU2htPCtcLH9Ys1rXyyulEroR2gkU7zKw=.sha256" } \ No newline at end of file diff --git a/apps/wiki/app.js b/apps/wiki/app.js index 045cc284..187a9675 100644 --- a/apps/wiki/app.js +++ b/apps/wiki/app.js @@ -127,10 +127,11 @@ async function process_message(whoami, collection, message, kind, parent) { return true; } -tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) { +tfrpc.register(async function collection(ids, kind, parent, max_rowid, data, include_private) { let whoami = await ssb.getIdentities(); data = data ?? {}; let rowid = 0; + let first = true; await ssb.sqlAsync('SELECT MAX(rowid) AS rowid FROM messages', [], function(row) { rowid = row.rowid; }); @@ -140,10 +141,12 @@ tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) { await ssb.sqlAsync('SELECT MAX(rowid) AS rowid FROM messages', [], function(row) { rowid = row.rowid; }); + first = false; } let modified = false; let rows = []; + print(include_private ? true: false, ids); await ssb.sqlAsync(` SELECT messages.id, author, content, timestamp FROM messages @@ -153,17 +156,18 @@ tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) { messages.rowid <= ?3 AND ((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) { + (?6 AND content LIKE '"%')) + `, [JSON.stringify(ids), max_rowid ?? -1, rowid, kind, parent, include_private ? true : false], function(row) { rows.push(row); }); + print('done'); max_rowid = rowid; for (let row of rows) { if (await process_message(whoami, data, row, kind, parent)) { modified = true; } } - if (modified) { + if (first || modified) { break; } } diff --git a/apps/wiki/tf-collections-app.js b/apps/wiki/tf-collections-app.js index cb47d6e0..5a600a1b 100644 --- a/apps/wiki/tf-collections-app.js +++ b/apps/wiki/tf-collections-app.js @@ -41,10 +41,18 @@ class TfCollectionsAppElement extends LitElement { async read_wikis() { let max_rowid; let wikis; + let start_whoami = this.whoami; while (true) { - console.log('read_wikis', max_rowid); - [max_rowid, wikis] = await tfrpc.rpc.collection(this.owner_ids, 'wiki', undefined, max_rowid, wikis); + console.log('read_wikis', this.whoami); + let following = Object.keys(await tfrpc.rpc.following([this.whoami]), 2); + console.log('following', following); + [max_rowid, wikis] = await tfrpc.rpc.collection(following, 'wiki', undefined, max_rowid, wikis, false); + console.log('read ->', wikis); + if (this.whoami !== start_whoami) { + break; + } + console.log('wikis =>', wikis); this.wikis = wikis; this.update_wiki(); } @@ -59,10 +67,8 @@ class TfCollectionsAppElement extends LitElement { let wiki_docs; while (true) { - console.log('read_wiki_docs', max_rowid); [max_rowid, wiki_docs] = await tfrpc.rpc.collection(this.owner_ids, 'wiki-doc', this.wiki?.id, max_rowid, wiki_docs); if (this.wiki?.id !== start_id) { - console.log('ending read_wiki_docs'); break; } this.wiki_docs = wiki_docs; @@ -188,6 +194,14 @@ class TfCollectionsAppElement extends LitElement { this.update_hash(); } + updated(changed_properties) { + if (changed_properties.has('whoami')) { + this.wikis = {}; + this.wiki_docs = {}; + this.read_wikis(); + } + } + render() { let self = this; return html` @@ -195,14 +209,14 @@ class TfCollectionsAppElement extends LitElement {
- + @change=${this.on_wiki_changed}>`)} ${keyed(this.wiki_doc?.id, html`