From 43dbe2b7b71bb79d714d24113f5389434b186ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Mon, 6 Jan 2025 15:42:46 -0600 Subject: [PATCH] Enable patch revision body editing and adding reactions --- src/views/repo/Patch.svelte | 70 +++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/src/views/repo/Patch.svelte b/src/views/repo/Patch.svelte index 13b3ef504..4fc1d0c13 100644 --- a/src/views/repo/Patch.svelte +++ b/src/views/repo/Patch.svelte @@ -2,14 +2,17 @@ import type { Author } from "@bindings/cob/Author"; import type { Config } from "@bindings/config/Config"; import type { Diff } from "@bindings/diff/Diff"; + import type { Embed } from "@bindings/cob/thread/Embed"; import type { PaginatedQuery } from "@bindings/cob/PaginatedQuery"; import type { Patch } from "@bindings/cob/patch/Patch"; import type { PatchStatus } from "./router"; import type { RepoInfo } from "@bindings/repo/RepoInfo"; import type { Revision } from "@bindings/cob/patch/Revision"; + import partial from "lodash/partial"; + import * as roles from "@app/lib/roles"; - import { formatOid } from "@app/lib/utils"; + import { formatOid, publicKeyFromDid } from "@app/lib/utils"; import { invoke } from "@app/lib/invoke"; import { nodeRunning } from "@app/lib/events"; @@ -163,6 +166,57 @@ }), ]); } + + async function editRevision( + revisionId: string, + description: string, + embeds: Embed[], + ) { + try { + await invoke("edit_patch", { + rid: repo.rid, + cobId: patch.id, + action: { + type: "revision.edit", + revision: revisionId, + description, + embeds, + }, + opts: { announce: $nodeRunning && $announce }, + }); + } catch (error) { + console.error("Patch revision editing failed: ", error); + } finally { + await reload(); + } + } + + async function reactOnRevision( + publicKey: string, + revisionId: string, + authors: Author[], + reaction: string, + ) { + try { + await invoke("edit_patch", { + rid: repo.rid, + cobId: patch.id, + action: { + type: "revision.react", + revision: revisionId, + reaction, + active: !authors.find( + ({ did }) => publicKeyFromDid(did) === publicKey, + ), + }, + opts: { announce: $nodeRunning && $announce }, + }); + } catch (error) { + console.error("Editing reactions failed", error); + } finally { + await reload(); + } + }