feat: add repo commands to the si cli
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-11-29 18:48:34 +07:00
parent 9b5c7a34db
commit 7721ddd6a8
9 changed files with 527 additions and 189 deletions
+67 -23
View File
@@ -11,7 +11,7 @@ use nostr::event::IntoEventBuilder;
use nostr::nips::nip19::Nip19Coordinate;
use nostr_connect::prelude::*;
use nostr_sdk::prelude::*;
use signed_core::{Announcement, Filters, RepoAddr};
use signed_core::{Announcement, Deletions, Filters, RepoAddr};
use signed_git::{GitCache, Repo};
use signed_nostr::{SignedAuthUrlHandler, UniversalSigner, Update};
@@ -41,8 +41,6 @@ pub enum BackendEvent {
status: PushStepStatus,
},
Error(String),
/// The relay list, profile and grasp list of a new identity were published; `Err` when no relay took them.
IdentityPublished(Result<(), String>),
}
impl BackendEvent {
@@ -231,7 +229,7 @@ impl Backend {
let task: Task<Result<(), Error>> = cx.spawn(async move |this, cx| {
let content = match user.await {
Ok(Some((_username, secret))) => String::from_utf8(secret)?,
_ => {
Ok(None) => {
this.update(cx, |this, cx| {
if this.session == session {
cx.emit(BackendEvent::SignerRequired);
@@ -239,6 +237,17 @@ impl Backend {
})?;
return Ok(());
}
Err(error) => {
this.update(cx, |this, cx| {
if this.session == session {
cx.emit(BackendEvent::error(format!(
"failed to read the stored credential: {error}"
)));
cx.emit(BackendEvent::SignerRequired);
}
})?;
return Ok(());
}
};
let result = async {
@@ -552,19 +561,13 @@ impl Backend {
.collect::<Vec<_>>();
cx.spawn(async move |this, cx| {
let published = futures::future::try_join_all(publishes)
.await
.map(|_| ())
.map_err(|error| {
format!("identity created, but publishing it failed: {error}")
});
this.update(cx, |_this, cx| {
if let Err(message) = &published {
cx.emit(BackendEvent::error(message.clone()));
}
cx.emit(BackendEvent::IdentityPublished(published));
})?;
if let Err(error) = futures::future::try_join_all(publishes).await {
this.update(cx, |_this, cx| {
cx.emit(BackendEvent::error(format!(
"identity created, but publishing it failed: {error}"
)));
})?;
}
Ok::<(), anyhow::Error>(())
})
@@ -1086,6 +1089,45 @@ impl Backend {
})
}
/// The latest announcement of `addr` and its latest state's `HEAD`, syncing the bootstrap relays when the database has neither.
pub async fn load_announcement(
client: &Client,
addr: &RepoAddr,
) -> Result<Option<(Announcement, Option<String>)>, Error> {
if let Some(found) = Self::stored_announcement(client, addr).await? {
return Ok(Some(found));
}
sync_bootstrap_only(client, addr.announcement_filter(), SyncOptions::default()).await?;
Self::stored_announcement(client, addr).await
}
async fn stored_announcement(
client: &Client,
addr: &RepoAddr,
) -> Result<Option<(Announcement, Option<String>)>, Error> {
let db = client.database();
let deletions = Deletions::from_events(db.query(Filters::deletions()).await?);
let announcement = db
.query(addr.announcement_filter())
.await?
.into_iter()
.filter(|event| !deletions.is_deleted(event))
.max_by_key(|event| event.created_at)
.and_then(|event| Announcement::from_event(&event));
let head = db
.query(addr.state_filter())
.await?
.into_iter()
.filter(|event| !deletions.is_deleted(event))
.max_by_key(|event| event.created_at)
.and_then(|event| SyncState::parse(&event).head);
Ok(announcement.map(|announcement| (announcement, head)))
}
fn bootstrap_user(&mut self, public_key: PublicKey, cx: &mut Context<Self>) {
let client = self.client.clone();
@@ -1161,8 +1203,9 @@ impl Backend {
self.passphrase_required
}
pub fn sign_out(&mut self, cx: &mut Context<Self>) -> Task<Result<(), Error>> {
pub fn sign_out(&mut self, cx: &mut Context<Self>) {
self.supersede_session();
// Nothing may be signed with the identity the user just left.
self.signer.swap_inner(Keys::generate());
self.current_user = None;
@@ -1173,11 +1216,6 @@ impl Backend {
});
let delete = cx.delete_credentials(USER_KEYRING);
cx.emit(BackendEvent::SignerChanged);
cx.emit(BackendEvent::SignerRequired);
cx.notify();
cx.spawn(async move |this, cx| {
if let Err(error) = delete.await {
this.update(cx, |_this, cx| {
@@ -1189,6 +1227,12 @@ impl Backend {
Ok::<(), Error>(())
})
.detach();
cx.emit(BackendEvent::SignerChanged);
cx.emit(BackendEvent::SignerRequired);
cx.notify();
}
fn sync_inbox(&mut self, cx: &mut Context<Self>) {
+2 -6
View File
@@ -34,12 +34,8 @@ pub use sync_status::{CheckoutSyncStatus, SyncEvent, SyncStatusDirectory, SyncSt
pub fn init(cx: &mut App) -> anyhow::Result<()> {
SettingsStore::set_global(cx.new(|_| SettingsStore::new(paths::settings_file())), cx);
let scan_paths = SettingsStore::global(cx)
.read(cx)
.settings()
.local_repos
.scan_paths
.clone();
let settings = SettingsStore::global(cx);
let scan_paths = settings.read(cx).settings().local_repos.scan_paths.clone();
for dir in [paths::nostr_dir(), paths::repos_dir()] {
if let Err(error) = std::fs::create_dir_all(dir) {