diff --git a/crates/radicle-tauri/bindings/IssueOps.ts b/crates/radicle-tauri/bindings/IssueOps.ts new file mode 100644 index 000000000..e48fefb82 --- /dev/null +++ b/crates/radicle-tauri/bindings/IssueOps.ts @@ -0,0 +1,10 @@ +// 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 { IssueAction } from "./IssueAction"; + +export type IssueOps = { + id: string; + action: IssueAction; + timestamp: number; + author: Author; +}; diff --git a/crates/radicle-tauri/src/commands/cob.rs b/crates/radicle-tauri/src/commands/cob.rs index 2529cd8b5..62cb74757 100644 --- a/crates/radicle-tauri/src/commands/cob.rs +++ b/crates/radicle-tauri/src/commands/cob.rs @@ -1,15 +1,27 @@ use base64::{engine::general_purpose::STANDARD, Engine as _}; +use radicle::cob; use radicle::git; use radicle::identity; use radicle::storage::{ReadRepository, ReadStorage}; -use crate::{error, AppState}; +use crate::{error, types, AppState}; pub mod draft; pub mod issue; pub mod patch; +#[derive(serde::Serialize, ts_rs::TS)] +#[ts(export)] +pub struct IssueOps { + #[ts(as = "String")] + id: git::Oid, + action: types::cobs::IssueAction, + #[ts(type = "number")] + timestamp: cob::Timestamp, + author: types::cobs::Author, +} + #[tauri::command] pub async fn get_file_by_oid( ctx: tauri::State<'_, AppState>, @@ -22,6 +34,39 @@ pub async fn get_file_by_oid( Ok::<_, error::Error>(STANDARD.encode(blob.content())) } +#[tauri::command] +pub fn activity_by_id( + ctx: tauri::State, + rid: identity::RepoId, + type_name: cob::TypeName, + id: git::Oid, +) -> Result, error::Error> { + let aliases = ctx.profile.aliases(); + let repo = ctx.profile.storage.repository(rid)?; + let ops = cob::store::ops(&id.into(), &type_name, &repo).unwrap(); + let mut actions: Vec = Vec::new(); + + for op in ops.into_iter() { + actions.extend( + op.actions + .iter() + .filter_map(|action: &Vec| -> Option { + serde_json::from_slice(action).ok() + }) + .map(|action| { + serde_json::json!({ + "id": op.id, + "action": action, + "author": types::cobs::Author::new(op.author.into(), &aliases), + "timestamp": op.timestamp + }) + }), + ) + } + + Ok::<_, error::Error>(actions) +} + mod query { use serde::{Deserialize, Serialize}; diff --git a/crates/radicle-tauri/src/lib.rs b/crates/radicle-tauri/src/lib.rs index bc5095e3e..403802436 100644 --- a/crates/radicle-tauri/src/lib.rs +++ b/crates/radicle-tauri/src/lib.rs @@ -77,6 +77,7 @@ pub fn run() { repo::repo_by_id, repo::diff_stats, cob::get_file_by_oid, + cob::activity_by_id, cob::issue::list_issues, cob::issue::issue_by_id, cob::issue::create_issue,