Radish alpha
r
Radicle desktop app
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `activity_by_id` tauri command
Sebastian Martinez committed 1 year ago
commit 3f88cedd40a655e0729cc2fb817af2af9084b76c
parent 9bed71d6071e91ff20eb39da54b8310d629edba7
3 files changed +57 -1
added 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;
+
};
modified 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<AppState>,
+
    rid: identity::RepoId,
+
    type_name: cob::TypeName,
+
    id: git::Oid,
+
) -> Result<Vec<serde_json::Value>, 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<serde_json::Value> = Vec::new();
+

+
    for op in ops.into_iter() {
+
        actions.extend(
+
            op.actions
+
                .iter()
+
                .filter_map(|action: &Vec<u8>| -> Option<serde_json::Value> {
+
                    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};

modified 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,