Skip to content

Commit

Permalink
Return comments and replies instead of Oids
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez authored and rudolfs committed Oct 22, 2024
1 parent 7267961 commit 996f081
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/radicle-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 1 addition & 2 deletions crates/radicle-tauri/bindings/Comment.ts
Original file line number Diff line number Diff line change
@@ -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<T = Never> = {
export type Comment<T> = {
id: string;
author: Author;
edits: Array<Edit>;
Expand Down
47 changes: 37 additions & 10 deletions crates/radicle-tauri/src/commands/thread.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +17,8 @@ pub fn create_issue_comment(
rid: identity::RepoId,
new: thread::NewIssueComment,
opts: cobs::CobOptions,
) -> Result<Oid, Error> {
) -> Result<thread::Comment<cobs::Never>, 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)?;
Expand All @@ -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::<cobs::Never>::new(
oid,
cob::thread::Comment::new(
*signer.public_key(),
new.body,
id.into(),
None,
new.embeds,
LocalTime::now().into(),
),
aliases,
))
}

#[tauri::command]
Expand All @@ -40,24 +54,37 @@ pub fn create_patch_comment(
rid: identity::RepoId,
new: thread::NewPatchComment,
opts: cobs::CobOptions,
) -> Result<Oid, Error> {
) -> Result<thread::Comment<thread::CodeLocation>, 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,
)?;

if opts.announce() {
node.announce_refs(rid)?;
}

Ok::<_, Error>(oid)
Ok(thread::Comment::<thread::CodeLocation>::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,
))
}
3 changes: 2 additions & 1 deletion crates/radicle-tauri/src/types/cobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -45,7 +46,7 @@ pub struct Issue {
#[ts(type = "{ status: 'closed', reason: 'other' | 'solved' } | { status: 'open' } ")]
state: issue::State,
assignees: Vec<Author>,
discussion: Vec<thread::Comment>,
discussion: Vec<thread::Comment<cobs::Never>>,
#[ts(as = "Vec<String>")]
labels: Vec<cob::Label>,
#[ts(type = "number")]
Expand Down
12 changes: 6 additions & 6 deletions crates/radicle-tauri/src/types/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct CreateReviewComment {

#[derive(Serialize, TS)]
#[serde(rename_all = "camelCase")]
pub struct Comment<T = cobs::Never> {
pub struct Comment<T> {
#[ts(as = "String")]
id: cob::thread::CommentId,
author: cobs::Author,
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Comment<CodeLocation> {
}
}

impl Comment {
impl Comment<cobs::Never> {
pub fn new(
id: cob::thread::CommentId,
comment: cob::thread::Comment,
Expand All @@ -91,7 +91,7 @@ impl Comment {
}
}

#[derive(TS, Serialize, Deserialize)]
#[derive(Clone, TS, Serialize, Deserialize)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
pub struct NewIssueComment {
Expand All @@ -105,7 +105,7 @@ pub struct NewIssueComment {
pub embeds: Vec<cob::Embed<cob::Uri>>,
}

#[derive(TS, Serialize, Deserialize)]
#[derive(Clone, TS, Serialize, Deserialize)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
pub struct NewPatchComment {
Expand All @@ -122,7 +122,7 @@ pub struct NewPatchComment {
pub embeds: Vec<cob::Embed<cob::Uri>>,
}

#[derive(TS, Serialize, Deserialize)]
#[derive(Clone, TS, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[ts(export)]
pub struct CodeLocation {
Expand Down Expand Up @@ -166,7 +166,7 @@ impl From<CodeLocation> for cob::CodeLocation {
}
}

#[derive(TS, Serialize, Deserialize)]
#[derive(Clone, TS, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", tag = "type")]
#[ts(export)]
pub enum CodeRange {
Expand Down

0 comments on commit 996f081

Please sign in to comment.