Skip to content

Commit

Permalink
Add activity_by_id tauri command
Browse files Browse the repository at this point in the history
Allows getting the history of a COB, passing the type_name, rid and oid
  • Loading branch information
sebastinez committed Oct 10, 2024
1 parent 98bd1ee commit 12ba472
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
35 changes: 34 additions & 1 deletion crates/radicle-tauri/src/commands/cob.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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;
Expand All @@ -22,6 +23,38 @@ 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().rev() {
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!({
"action": action,
"author": types::cobs::Author::new(op.author.into(), &aliases),
"timestamp": op.timestamp
})
}),
)
}

Ok::<_, error::Error>(actions)
}

mod query {
use serde::{Deserialize, Serialize};

Expand Down
1 change: 1 addition & 0 deletions crates/radicle-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/views/repo/Issue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import capitalize from "lodash/capitalize";
import { formatTimestamp, formatOid, issueStatusColor } from "@app/lib/utils";
import { invoke } from "@tauri-apps/api/core";
import Border from "@app/components/Border.svelte";
import CopyableId from "@app/components/CopyableId.svelte";
Expand All @@ -21,6 +22,13 @@
export let issues: Issue[];
export let config: Config;
// Test example how to get the history of a cob similar to the `rad cob log` output
$: void invoke("activity_by_id", {
rid: repo.rid,
id: issue.id,
typeName: "xyz.radicle.issue",
}).then(console.log);
$: project = repo.payloads["xyz.radicle.project"]!;
</script>

Expand Down
8 changes: 8 additions & 0 deletions src/views/repo/Patch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import type { RepoInfo } from "@bindings/RepoInfo";
import type { Revision } from "@bindings/Revision";
import { invoke } from "@tauri-apps/api/core";
import { formatTimestamp, formatOid, patchStatusColor } from "@app/lib/utils";
import Border from "@app/components/Border.svelte";
Expand All @@ -21,6 +22,13 @@
export let revisions: Revision[];
export let config: Config;
// Test example how to get the history of a cob similar to the `rad cob log` output
$: void invoke("activity_by_id", {
rid: repo.rid,
id: patch.id,
typeName: "xyz.radicle.patch",
}).then(console.log);
$: project = repo.payloads["xyz.radicle.project"]!;
</script>

Expand Down

0 comments on commit 12ba472

Please sign in to comment.