update backend

This commit is contained in:
2026-09-22 14:33:41 +07:00
parent 7e7d13cbfc
commit 8914685c3d
17 changed files with 2575 additions and 971 deletions
+21 -17
View File
@@ -10,12 +10,14 @@ use concord::cord04::roles::{Permissions, citation_ok};
use concord::derive::{
channel_group_key, control_group_key, control_signer_group_key, guestbook_group_key,
};
use concord::store::{self, CommunityState};
use concord::state::{CommunityState, list_entry};
use concord::{ChannelId, CommunityId, Epoch, GroupKey};
use gpui::AsyncApp;
use nostr_sdk::prelude::*;
use state::UniversalSigner;
use crate::cache;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PlaneKind {
Control(Epoch),
@@ -126,7 +128,7 @@ where
}
let state = CommunityState::from_genesis(&genesis, &editions, at_secs.saturating_mul(1000))?;
store::save_state(client, &state).await?;
cache::save_state(client, &state).await?;
publish_wraps(client, &genesis.wraps, &state.relays).await;
@@ -199,7 +201,7 @@ where
return Ok(());
}
let entry = store::list_entry(state, name);
let entry = list_entry(state, name);
let list = match held {
Some(held) => held.joined(entry),
None => CommunityList::default().joined(entry),
@@ -282,10 +284,10 @@ pub async fn load(
) -> Result<Vec<CommunityState>> {
let list = match load_list(client, signer, self_pk).await? {
Some(list) => list,
None => return store::load_states(client).await,
None => return cache::load_states(client).await,
};
let mut held: BTreeMap<CommunityId, CommunityState> = store::load_states(client)
let mut held: BTreeMap<CommunityId, CommunityState> = cache::load_states(client)
.await?
.into_iter()
.map(|state| (state.id, state))
@@ -314,7 +316,7 @@ pub async fn load(
None => fresh,
};
store::save_state(client, &state).await?;
cache::save_state(client, &state).await?;
held.insert(entry.community_id, state);
}
@@ -458,7 +460,7 @@ pub async fn fold(client: &Client, state: &CommunityState) -> Result<Option<Snap
if let Ok((opened, rumor)) =
concord::cord03::open(wrap, &plane.group, &channel, epoch)
{
store::cache_rumor(client, &channel, &opened).await?;
cache::cache_rumor(client, &channel, &opened).await?;
observe(&mut observed, rumor.author, rumor.at_ms);
}
}
@@ -507,7 +509,7 @@ pub async fn fold(client: &Client, state: &CommunityState) -> Result<Option<Snap
let mut state = state.clone();
state.apply_fold(&control);
store::save_state(client, &state).await?;
cache::save_state(client, &state).await?;
Ok(Some(Snapshot {
state,
@@ -551,14 +553,14 @@ mod tests {
control_root: None,
control_pks: BTreeMap::from([(0, control_pk)]),
channels: vec![
concord::store::ChannelKeyRef {
concord::state::ChannelKeyRef {
id: general,
name: "general".to_owned(),
private: false,
epoch: Epoch(0),
key: None,
},
concord::store::ChannelKeyRef {
concord::state::ChannelKeyRef {
id: ChannelId::from_bytes([0x9d; 32]),
name: "staff".to_owned(),
private: true,
@@ -569,6 +571,7 @@ mod tests {
relays: vec![RelayUrl::parse("wss://relay.example").expect("a url")],
heads: Vec::new(),
banned: BTreeSet::new(),
cursors: BTreeMap::new(),
dissolved: false,
added_at_ms: 0,
};
@@ -611,7 +614,7 @@ mod tests {
root_epoch: Epoch(0),
control_root: Some([0x03; 32]),
control_pks: BTreeMap::from([(0, control_pk)]),
channels: vec![concord::store::ChannelKeyRef {
channels: vec![concord::state::ChannelKeyRef {
id: ChannelId::from_bytes([0x9c; 32]),
name: "general".to_owned(),
private: false,
@@ -621,6 +624,7 @@ mod tests {
relays: Vec::new(),
heads: Vec::new(),
banned: BTreeSet::new(),
cursors: BTreeMap::new(),
dissolved: false,
added_at_ms: 1_700_000_000_000,
}
@@ -806,11 +810,11 @@ mod tests {
CommunityId::from_bytes([0x42; 32]),
Keys::generate().public_key(),
);
let list = CommunityList::default().joined(store::list_entry(&listed, "coop"));
let list = CommunityList::default().joined(list_entry(&listed, "coop"));
store_fragment(&client, &signer, &list).await;
assert!(
store::load_state(&client, &listed.id)
cache::load_state(&client, &listed.id)
.await
.expect("reads")
.is_none()
@@ -833,7 +837,7 @@ mod tests {
// Discovery writes the document, so the next load is warm.
assert_eq!(
store::load_state(&client, &listed.id)
cache::load_state(&client, &listed.id)
.await
.expect("reads")
.map(|state| state.id),
@@ -860,9 +864,9 @@ mod tests {
Keys::generate().public_key(),
);
let list = CommunityList::default().joined(store::list_entry(&listed, "listed"));
let list = CommunityList::default().joined(list_entry(&listed, "listed"));
store_fragment(&client, &signer, &list).await;
store::save_state(&client, &local).await.expect("saves");
cache::save_state(&client, &local).await.expect("saves");
let loaded = load(&client, &signer, keys.public_key())
.await
@@ -886,7 +890,7 @@ mod tests {
CommunityId::from_bytes([0x42; 32]),
Keys::generate().public_key(),
);
store::save_state(&client, &local).await.expect("saves");
cache::save_state(&client, &local).await.expect("saves");
let list = CommunityList::default().tombstoned(local.id, u64::MAX);
store_fragment(&client, &signer, &list).await;