Drafts. Boom.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4597 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-11-02 00:45:20 +00:00
parent c6ae9313cc
commit 2ce5bc73d5
5 changed files with 42 additions and 6 deletions

View File

@ -1,5 +1,5 @@
{ {
"type": "tildefriends-app", "type": "tildefriends-app",
"emoji": "📦", "emoji": "📦",
"previous": "&tKFnpVGJPHFQHzK07kdrKuTNl8PQ38zIfDzDC7CaNLI=.sha256" "previous": "&1C4JMrg9rjeS6OxHYblN7v1vNAEfDXkyRPDmnHhzPQo=.sha256"
} }

View File

@ -69,6 +69,13 @@ tfrpc.register(function get_hash(id, message) {
return g_hash; 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) { async function get_collections(kind) {
let me = await ssb.getIdentities(); let me = await ssb.getIdentities();
let them = await ssb.following(me, 2); let them = await ssb.following(me, 2);

View File

@ -25,8 +25,17 @@ class TfCollectionElement extends LitElement {
this.collections_loading = 0; this.collections_loading = 0;
} }
process_message(message) { async process_message(message) {
let content = JSON.parse(message.content); 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?.key) {
if (content?.tombstone) { if (content?.tombstone) {
delete this.by_id[content.key]; 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 FROM messages JOIN json_each(?1) AS id ON messages.author = id.value
WHERE WHERE
json_extract(content, '$.type') = ?2 AND 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 ORDER BY timestamp
`, [JSON.stringify(visible), this.type, this.parent]); `, [JSON.stringify(visible), this.type, this.parent]);
this.by_id = {}; this.by_id = {};
for (let collection of collections) { for (let collection of collections) {
this.process_message(collection); await this.process_message(collection);
} }
this.collections = Object.values(this.by_id); this.collections = Object.values(this.by_id);
} }
@ -83,8 +93,9 @@ class TfCollectionElement extends LitElement {
if (this.visible && if (this.visible &&
this.visible.indexOf(message.author) != -1 && this.visible.indexOf(message.author) != -1 &&
JSON.parse(message.content).type == this.type) { JSON.parse(message.content).type == this.type) {
this.process_message(message); this.process_message(message).then(function() {
this.collections = [...Object.values(this.by_id)]; this.collections = [...Object.values(this.by_id)];
});
} }
} }

View File

@ -79,6 +79,11 @@ class TfCollectionsAppElement extends LitElement {
parent: this.wiki_doc.parent, parent: this.wiki_doc.parent,
blob: blob_id, 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); print(message);
await tfrpc.rpc.appendMessage(this.whoami, message); await tfrpc.rpc.appendMessage(this.whoami, message);
return this.shadowRoot.getElementById('docs').load(); return this.shadowRoot.getElementById('docs').load();

View File

@ -38,6 +38,18 @@ class TfWikiDocElement extends LitElement {
this.is_editing = false; 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() { async on_publish() {
let id = await tfrpc.rpc.store_blob(this.blob); let id = await tfrpc.rpc.store_blob(this.blob);
this.dispatchEvent(new CustomEvent('publish', { this.dispatchEvent(new CustomEvent('publish', {
@ -61,6 +73,7 @@ class TfWikiDocElement extends LitElement {
return html` return html`
<div style="display: inline-flex; flex-direction: row"> <div style="display: inline-flex; flex-direction: row">
<button ?disabled=${!this.whoami || this.is_editing} @click=${() => self.is_editing = true}>Edit</button> <button ?disabled=${!this.whoami || this.is_editing} @click=${() => self.is_editing = true}>Edit</button>
<button ?disabled=${this.blob == this.blob_original} @click=${this.on_save_draft}>Save Draft</button>
<button ?disabled=${this.blob == this.blob_original} @click=${this.on_publish}>Publish</button> <button ?disabled=${this.blob == this.blob_original} @click=${this.on_publish}>Publish</button>
<button ?disabled=${!this.is_editing} @click=${this.on_discard}>Discard</button> <button ?disabled=${!this.is_editing} @click=${this.on_discard}>Discard</button>
</div> </div>