From 996f0817f65e4df7b070fb5a75d52408fb416458 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 18 Oct 2024 16:10:23 +0200 Subject: [PATCH] Return comments and replies instead of Oids --- Cargo.lock | 1 + crates/radicle-tauri/Cargo.toml | 1 + crates/radicle-tauri/bindings/Comment.ts | 3 +- crates/radicle-tauri/src/commands/thread.rs | 47 ++++++++++++++++----- crates/radicle-tauri/src/types/cobs.rs | 3 +- crates/radicle-tauri/src/types/thread.rs | 12 +++--- 6 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15fa9dc4e..343ba6ec4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3992,6 +3992,7 @@ version = "0.0.0" dependencies = [ "anyhow", "base64 0.22.1", + "localtime", "log", "radicle", "radicle-surf", diff --git a/crates/radicle-tauri/Cargo.toml b/crates/radicle-tauri/Cargo.toml index b7e14c727..3aa72dcc6 100644 --- a/crates/radicle-tauri/Cargo.toml +++ b/crates/radicle-tauri/Cargo.toml @@ -18,6 +18,7 @@ tauri-build = { version = "2.0.1", features = ["isolation"] } anyhow = { version = "1.0.90" } base64 = { version = "0.22.1" } log = { version = "0.4.22" } +localtime = { version = "1.3.1" } radicle = { git = "https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git" } radicle-surf = { version = "0.22.1", features = ["serde"] } serde = { version = "1.0.210", features = ["derive"] } diff --git a/crates/radicle-tauri/bindings/Comment.ts b/crates/radicle-tauri/bindings/Comment.ts index 1de75121c..e6f8c0e60 100644 --- a/crates/radicle-tauri/bindings/Comment.ts +++ b/crates/radicle-tauri/bindings/Comment.ts @@ -1,10 +1,9 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { Author } from "./Author"; import type { Edit } from "./Edit"; -import type { Never } from "./Never"; import type { Reaction } from "./Reaction"; -export type Comment = { +export type Comment = { id: string; author: Author; edits: Array; diff --git a/crates/radicle-tauri/src/commands/thread.rs b/crates/radicle-tauri/src/commands/thread.rs index c7dc0018f..c9626c1aa 100644 --- a/crates/radicle-tauri/src/commands/thread.rs +++ b/crates/radicle-tauri/src/commands/thread.rs @@ -1,4 +1,6 @@ -use radicle::git::Oid; +use localtime::LocalTime; + +use radicle::cob; use radicle::identity; use radicle::node::Handle; use radicle::storage::ReadStorage; @@ -15,7 +17,8 @@ pub fn create_issue_comment( rid: identity::RepoId, new: thread::NewIssueComment, opts: cobs::CobOptions, -) -> Result { +) -> Result, Error> { + let aliases = &ctx.profile.aliases(); let mut node = Node::new(ctx.profile.socket()); let signer = ctx.profile.signer()?; let repo = ctx.profile.storage.repository(rid)?; @@ -25,13 +28,24 @@ pub fn create_issue_comment( let (root_id, _) = issue.root(); *root_id }); - let oid = issue.comment(new.body, id, new.embeds, &signer)?; + let oid = issue.comment(new.body.clone(), id, new.embeds.clone(), &signer)?; if opts.announce() { node.announce_refs(rid)?; } - Ok::<_, Error>(oid) + Ok(thread::Comment::::new( + oid, + cob::thread::Comment::new( + *signer.public_key(), + new.body, + id.into(), + None, + new.embeds, + LocalTime::now().into(), + ), + aliases, + )) } #[tauri::command] @@ -40,18 +54,20 @@ pub fn create_patch_comment( rid: identity::RepoId, new: thread::NewPatchComment, opts: cobs::CobOptions, -) -> Result { +) -> Result, Error> { + let aliases = &ctx.profile.aliases(); let mut node = Node::new(ctx.profile.socket()); let signer = ctx.profile.signer()?; let repo = ctx.profile.storage.repository(rid)?; let mut patches = ctx.profile.patches_mut(&repo)?; let mut patch = patches.get_mut(&new.id.into())?; + let n = new.clone(); let oid = patch.comment( new.revision.into(), - new.body, - new.reply_to, - new.location.map(|l| l.into()), - new.embeds, + n.body, + n.reply_to, + n.location.map(|l| l.into()), + n.embeds, &signer, )?; @@ -59,5 +75,16 @@ pub fn create_patch_comment( node.announce_refs(rid)?; } - Ok::<_, Error>(oid) + Ok(thread::Comment::::new( + oid, + cob::thread::Comment::new( + *signer.public_key(), + new.body, + new.reply_to, + new.location.map(|l| l.into()), + new.embeds, + LocalTime::now().into(), + ), + aliases, + )) } diff --git a/crates/radicle-tauri/src/types/cobs.rs b/crates/radicle-tauri/src/types/cobs.rs index ed0d4d66c..36d5b4c9f 100644 --- a/crates/radicle-tauri/src/types/cobs.rs +++ b/crates/radicle-tauri/src/types/cobs.rs @@ -12,6 +12,7 @@ use radicle::node::{Alias, AliasStore}; use radicle::patch; use radicle::storage::git; +use crate::types::cobs; use crate::types::thread; #[derive(Serialize, TS)] @@ -45,7 +46,7 @@ pub struct Issue { #[ts(type = "{ status: 'closed', reason: 'other' | 'solved' } | { status: 'open' } ")] state: issue::State, assignees: Vec, - discussion: Vec, + discussion: Vec>, #[ts(as = "Vec")] labels: Vec, #[ts(type = "number")] diff --git a/crates/radicle-tauri/src/types/thread.rs b/crates/radicle-tauri/src/types/thread.rs index b2f4b3380..2f8b56066 100644 --- a/crates/radicle-tauri/src/types/thread.rs +++ b/crates/radicle-tauri/src/types/thread.rs @@ -23,7 +23,7 @@ pub struct CreateReviewComment { #[derive(Serialize, TS)] #[serde(rename_all = "camelCase")] -pub struct Comment { +pub struct Comment { #[ts(as = "String")] id: cob::thread::CommentId, author: cobs::Author, @@ -65,7 +65,7 @@ impl Comment { } } -impl Comment { +impl Comment { pub fn new( id: cob::thread::CommentId, comment: cob::thread::Comment, @@ -91,7 +91,7 @@ impl Comment { } } -#[derive(TS, Serialize, Deserialize)] +#[derive(Clone, TS, Serialize, Deserialize)] #[ts(export)] #[serde(rename_all = "camelCase")] pub struct NewIssueComment { @@ -105,7 +105,7 @@ pub struct NewIssueComment { pub embeds: Vec>, } -#[derive(TS, Serialize, Deserialize)] +#[derive(Clone, TS, Serialize, Deserialize)] #[ts(export)] #[serde(rename_all = "camelCase")] pub struct NewPatchComment { @@ -122,7 +122,7 @@ pub struct NewPatchComment { pub embeds: Vec>, } -#[derive(TS, Serialize, Deserialize)] +#[derive(Clone, TS, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[ts(export)] pub struct CodeLocation { @@ -166,7 +166,7 @@ impl From for cob::CodeLocation { } } -#[derive(TS, Serialize, Deserialize)] +#[derive(Clone, TS, Serialize, Deserialize)] #[serde(rename_all = "camelCase", tag = "type")] #[ts(export)] pub enum CodeRange {