mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-03 10:40:30 +08:00
Add activity_by_id tauri command
This commit is contained in:
@@ -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;
|
||||
};
|
||||
@@ -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};
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user