diff --git a/apps/wiki.json b/apps/wiki.json index 9ed4e2ba..ac880b4d 100644 --- a/apps/wiki.json +++ b/apps/wiki.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "📝", - "previous": "&5DCHb4dlFnAlInCiIb1v7XG+w/t11fVwbpqM8aVLEfQ=.sha256" + "previous": "&263ro6L8r7tRcrC7LjvY59gC72DlEM/nehd6s7S08sQ=.sha256" } \ No newline at end of file diff --git a/apps/wiki/app.js b/apps/wiki/app.js index ca1c91d0..88fee9eb 100644 --- a/apps/wiki/app.js +++ b/apps/wiki/app.js @@ -153,6 +153,7 @@ tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) { `, [JSON.stringify(ids), max_rowid ?? -1, rowid, kind, parent], function(row) { rows.push(row); }); + max_rowid = rowid; for (let row of rows) { if (await process_message(whoami, data, row, kind, parent)) { modified = true; diff --git a/apps/wiki/tf-collections-app.js b/apps/wiki/tf-collections-app.js index a9dcb9a9..c36e7d0d 100644 --- a/apps/wiki/tf-collections-app.js +++ b/apps/wiki/tf-collections-app.js @@ -43,6 +43,7 @@ class TfCollectionsAppElement extends LitElement { let wikis; while (true) { + console.log('read_wikis', max_rowid); [max_rowid, wikis] = await tfrpc.rpc.collection(this.owner_ids, 'wiki', undefined, max_rowid, wikis); this.wikis = wikis; this.update_wiki(); @@ -58,8 +59,10 @@ 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; @@ -130,23 +133,6 @@ class TfCollectionsAppElement extends LitElement { this.update_hash(); } - async on_wiki_publish(event) { - let blob_id = event.detail.id; - let message = { - type: 'wiki-doc', - key: this.wiki_doc.id, - parent: this.wiki_doc.parent, - blob: blob_id, - }; - if (event.detail.draft) { - message.recps = this.wiki_doc.editors; - print(message); - message = await tfrpc.rpc.encrypt(this.whoami, this.wiki_doc.editors, JSON.stringify(message)); - } - print(message); - await tfrpc.rpc.appendMessage(this.whoami, message); - } - render() { let self = this; return html` @@ -166,8 +152,7 @@ class TfCollectionsAppElement extends LitElement { ${this.wiki_doc && this.wiki_doc.parent === this.wiki?.id ? html` + .value=${this.wiki_doc}> ` : undefined} `; } diff --git a/apps/wiki/tf-wiki-doc.js b/apps/wiki/tf-wiki-doc.js index 7d30a195..a8cc75fc 100644 --- a/apps/wiki/tf-wiki-doc.js +++ b/apps/wiki/tf-wiki-doc.js @@ -38,27 +38,30 @@ class TfWikiDocElement extends LitElement { this.is_editing = false; } - async on_save_draft() { + async append_message(draft) { let id = await tfrpc.rpc.store_blob(this.blob); - this.dispatchEvent(new CustomEvent('publish', { - bubbles: true, - detail: { - id: id, - draft: true, - }, - })); + let message = { + type: 'wiki-doc', + key: this.value.id, + parent: this.value.parent, + blob: id, + }; + if (draft) { + message.recps = this.value.editors; + print(message); + message = await tfrpc.rpc.encrypt(this.whoami, this.value.editors, JSON.stringify(message)); + } + print(message); + await tfrpc.rpc.appendMessage(this.whoami, message); this.is_editing = false; } + async on_save_draft() { + return this.append_message(true); + } + async on_publish() { - let id = await tfrpc.rpc.store_blob(this.blob); - this.dispatchEvent(new CustomEvent('publish', { - bubbles: true, - detail: { - id: id, - }, - })); - this.is_editing = false; + return this.append_message(false); } render() {