diff --git a/apps/collections.json b/apps/collections.json index ef5bc6f2..0a351a6b 100644 --- a/apps/collections.json +++ b/apps/collections.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "📦", - "previous": "&tKFnpVGJPHFQHzK07kdrKuTNl8PQ38zIfDzDC7CaNLI=.sha256" + "previous": "&1C4JMrg9rjeS6OxHYblN7v1vNAEfDXkyRPDmnHhzPQo=.sha256" } \ No newline at end of file diff --git a/apps/collections/app.js b/apps/collections/app.js index 1a1a171e..2546e7a7 100644 --- a/apps/collections/app.js +++ b/apps/collections/app.js @@ -69,6 +69,13 @@ tfrpc.register(function get_hash(id, message) { return g_hash; }); +tfrpc.register(async function try_decrypt(id, content) { + return await ssb.privateMessageDecrypt(id, content); +}); +tfrpc.register(async function encrypt(id, recipients, content) { + return await ssb.privateMessageEncrypt(id, recipients, content); +}); + async function get_collections(kind) { let me = await ssb.getIdentities(); let them = await ssb.following(me, 2); diff --git a/apps/collections/tf-collection.js b/apps/collections/tf-collection.js index 3f4f8937..4217664b 100644 --- a/apps/collections/tf-collection.js +++ b/apps/collections/tf-collection.js @@ -25,8 +25,17 @@ class TfCollectionElement extends LitElement { this.collections_loading = 0; } - process_message(message) { + async process_message(message) { let content = JSON.parse(message.content); + if (typeof content == 'string') { + let x = await tfrpc.rpc.try_decrypt(this.whoami, content); + if (x) { + content = JSON.parse(x); + content.draft = true; + } else { + return; + } + } if (content?.key) { if (content?.tombstone) { delete this.by_id[content.key]; @@ -50,12 +59,13 @@ class TfCollectionElement extends LitElement { FROM messages JOIN json_each(?1) AS id ON messages.author = id.value WHERE json_extract(content, '$.type') = ?2 AND - (?3 IS NULL OR json_extract(content, '$.parent') = ?3) + (?3 IS NULL OR json_extract(content, '$.parent') = ?3) OR + content LIKE '"%' ORDER BY timestamp `, [JSON.stringify(visible), this.type, this.parent]); this.by_id = {}; for (let collection of collections) { - this.process_message(collection); + await this.process_message(collection); } this.collections = Object.values(this.by_id); } @@ -83,8 +93,9 @@ class TfCollectionElement extends LitElement { if (this.visible && this.visible.indexOf(message.author) != -1 && JSON.parse(message.content).type == this.type) { - this.process_message(message); - this.collections = [...Object.values(this.by_id)]; + this.process_message(message).then(function() { + this.collections = [...Object.values(this.by_id)]; + }); } } diff --git a/apps/collections/tf-collections-app.js b/apps/collections/tf-collections-app.js index 81c3cee4..f374119d 100644 --- a/apps/collections/tf-collections-app.js +++ b/apps/collections/tf-collections-app.js @@ -79,6 +79,11 @@ class TfCollectionsAppElement extends LitElement { 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); return this.shadowRoot.getElementById('docs').load(); diff --git a/apps/collections/tf-wiki-doc.js b/apps/collections/tf-wiki-doc.js index 4bc24cd9..63da6070 100644 --- a/apps/collections/tf-wiki-doc.js +++ b/apps/collections/tf-wiki-doc.js @@ -38,6 +38,18 @@ class TfWikiDocElement extends LitElement { this.is_editing = false; } + async on_save_draft() { + let id = await tfrpc.rpc.store_blob(this.blob); + this.dispatchEvent(new CustomEvent('publish', { + bubbles: true, + detail: { + id: id, + draft: true, + }, + })); + this.is_editing = false; + } + async on_publish() { let id = await tfrpc.rpc.store_blob(this.blob); this.dispatchEvent(new CustomEvent('publish', { @@ -61,6 +73,7 @@ class TfWikiDocElement extends LitElement { return html`
+