Skip to main content

AccountDatabase

Struct AccountDatabase 

Source
pub struct AccountDatabase { /* private fields */ }
Expand description

One account-scoped SQLite owner.

The type is intentionally synchronous. Native language facades serialize a database handle and Android invokes it on its I/O dispatcher. Rust never calls a platform database callback and never owns a background thread.

Implementations§

Source§

impl AccountDatabase

Source

pub fn open( path: impl AsRef<Path>, account_id: String, ) -> Result<Self, SoftchatError>

Open or create one account database and apply Rust-owned migrations.

§Errors

Returns a stable account or persistence error for an invalid path, account mismatch, foreign schema, unsupported schema, or SQLite failure.

Source

pub fn info(&self) -> Result<AccountDatabaseInfo, SoftchatError>

Return schema, revision, and journal information.

§Errors

Returns a stable persistence error if metadata cannot be read.

Source

pub fn revision(&self) -> Result<i64, SoftchatError>

Return the current monotonic database revision.

§Errors

Returns a stable persistence error if metadata cannot be read.

Source

pub fn diagnostics(&self) -> Result<AccountDiagnostics, SoftchatError>

Return redacted bounded account health without exposing event or key data.

§Errors

Returns a stable persistence error if SQLite metadata is inconsistent.

Source

pub fn ingest( &mut self, identity: &LocalIdentity, events: Vec<SignedEvent>, received_at: i64, ) -> Result<StoredIngestion, SoftchatError>

Authenticate, unwrap, classify, and atomically persist incoming events.

Ephemeral projections are authenticated and reported in the receipt but never written to durable history.

§Errors

Returns stable event, envelope, account, projection, or persistence errors. No partial transaction is committed.

Source

pub fn enqueue_rumor( &mut self, identity: &LocalIdentity, operation_id: String, rumor: RumorEvent, recipients: Vec<String>, notification_recipients: Vec<String>, relay_urls: Vec<String>, kind: Nip59EnvelopeKind, now: i64, ) -> Result<AccountOperationResult, SoftchatError>

Create and atomically persist one idempotent NIP-59 operation.

The local sender copy is authenticated and projected in the same transaction as event copies and delivery intents. Reusing an existing operation ID returns its current state without generating new wrappers.

§Errors

Returns stable operation, identity, envelope, relay, or persistence errors. No socket may send until this method succeeds.

Source

pub fn enqueue_signed( &mut self, identity: &LocalIdentity, operation_id: String, events: Vec<SignedEvent>, relay_urls: Vec<String>, now: i64, ) -> Result<AccountOperationResult, SoftchatError>

Atomically persist already signed direct events and delivery intents.

This is intended for authenticated direct protocol events such as NIP-42 and NIP-98, not for bypassing private-chat wrapping.

§Errors

Returns stable event, operation, relay, or persistence errors.

Source

pub fn claim_deliveries( &mut self, lease_id: String, relay_url: String, now: i64, lease_duration_seconds: u32, ) -> Result<Option<ClaimedDelivery>, SoftchatError>

Claim pending work, recover expired leases, and return exact payloads.

§Errors

Returns a stable delivery or persistence error for a malformed lease, state conflict, invalid timestamp, or SQLite failure.

Source

pub fn mark_socket_written( &mut self, claim: &DeliveryClaim, intent_ids: Vec<String>, ) -> Result<AccountMutationResult, SoftchatError>

Commit that selected leased payloads were written to a socket.

Socket write is not relay acceptance.

§Errors

Returns a stable delivery or persistence error for stale lease state.

Source

pub fn apply_relay_results( &mut self, claim: &DeliveryClaim, results: Vec<RelayDeliveryResult>, ) -> Result<AccountMutationResult, SoftchatError>

Commit correlated terminal or retryable relay results.

§Errors

Returns a stable delivery or persistence error for stale or contradictory state.

Source

pub fn release_claim( &mut self, claim: &DeliveryClaim, ) -> Result<AccountMutationResult, SoftchatError>

Release unfinished leased work after cancellation or transport loss.

§Errors

Returns a stable delivery or persistence error for stale lease state.

Source

pub fn operation( &self, operation_id: &str, ) -> Result<OperationSnapshot, SoftchatError>

Return one operation’s current durable aggregate state.

§Errors

Returns a stable account or persistence error when the operation is unknown or its durable rows are inconsistent.

Source

pub fn operations( &self, limit: u32, ) -> Result<Vec<OperationSnapshot>, SoftchatError>

Return a bounded newest-first page of durable outgoing operations.

§Errors

Returns a stable bound, operation, or persistence error.

Source

pub fn retry_operation( &mut self, operation_id: &str, ) -> Result<AccountOperationResult, SoftchatError>

Requeue terminally rejected intents for an explicit user retry.

Accepted copies are never duplicated. Repeating retry while work is already queued is idempotent.

§Errors

Returns a stable account or persistence error for an unknown operation or an operation with active leased work.

Source

pub fn cancel_operation( &mut self, operation_id: &str, ) -> Result<AccountOperationResult, SoftchatError>

Cancel every unclaimed delivery intent that is still safe to cancel.

Accepted or rejected terminal rows remain exact history. Active leases must first be released by the transport run.

§Errors

Returns a stable account or delivery-state error for unknown or active work.

Source

pub fn relay_catalog(&self) -> Result<Vec<RelayCatalogEntry>, SoftchatError>

Return the complete persisted relay catalog.

§Errors

Returns a stable relay-catalog or persistence error.

Source

pub fn reconcile_relay_catalog( &mut self, discovered: Vec<DnsRelayRecord>, refreshed_at: i64, fallback_url: String, dns_authenticated: bool, ) -> Result<StoredRelayCatalogPlan, SoftchatError>

Reconcile authenticated discovery and persist the complete result.

§Errors

Returns a stable relay-catalog or persistence error.

Source

pub fn add_custom_relay( &mut self, relay_url: String, created_at: i64, ) -> Result<RelayCatalogMutation, SoftchatError>

Add or reactivate one custom relay and persist the catalog.

§Errors

Returns a stable relay-catalog or persistence error.

Source

pub fn exclude_relay( &mut self, relay_url: String, now: i64, ) -> Result<RelayCatalogMutation, SoftchatError>

Exclude or remove one relay and persist the catalog.

§Errors

Returns a stable relay-catalog or persistence error.

Source

pub fn restore_automatic_relays( &mut self, now: i64, ) -> Result<RelayCatalogMutation, SoftchatError>

Restore automatic relays and persist the catalog.

§Errors

Returns a stable relay-catalog or persistence error.

Source

pub fn set_active_relay( &mut self, relay_url: String, now: i64, ) -> Result<RelayCatalogMutation, SoftchatError>

Select and persist one active relay.

§Errors

Returns a stable relay-catalog or persistence error.

Source

pub fn relay_failover_candidates( &self, failed_url: String, ) -> Result<Vec<String>, SoftchatError>

Return effective failover candidates from durable catalog state.

§Errors

Returns a stable relay-catalog or persistence error.

Source

pub fn rotate_failed_relay( &mut self, failed_url: String, now: i64, ) -> Result<RelayFailoverMutation, SoftchatError>

Atomically rotate away from a failed relay and rebind unfinished intent.

§Errors

Returns a stable catalog, delivery-state, or persistence error.

Source

pub fn list_conversations( &self, limit: u32, offset: u32, ) -> Result<Vec<ConversationSummary>, SoftchatError>

Return a newest-first bounded conversation page.

§Errors

Returns a stable account or persistence error for an invalid limit or inconsistent projection data.

Source

pub fn list_conversation_views( &self, limit: u32, offset: u32, ) -> Result<Vec<ConversationView>, SoftchatError>

Return complete newest-first conversation-list rows in one bounded call.

This avoids one Android-to-Rust transition per conversation while keeping exact event values and effective edit/deletion state in Rust.

§Errors

Returns a stable account or persistence error for invalid bounds or inconsistent projection data.

Source

pub fn list_messages( &self, conversation_id: &str, before_created_at: Option<i64>, limit: u32, ) -> Result<Vec<AccountMessage>, SoftchatError>

Return a newest-first bounded message page for one conversation.

Passing before_created_at excludes messages at or after that timestamp. Callers that need lossless same-timestamp paging should use the returned event ID as an application cursor in a later SDK revision.

§Errors

Returns a stable account or persistence error for malformed input.

Source

pub fn list_projections( &self, kind: Option<ProjectionKind>, logical_event_id: String, conversation_id: String, target_event_id: String, author_public_key: String, before_created_at: Option<i64>, limit: u32, offset: u32, ) -> Result<Vec<AccountProjection>, SoftchatError>

Return a bounded newest-first authenticated projection page.

Empty string filters are ignored. This one query surface supports subjects, reactions, deletions, edits, profiles, contacts, application data, and detail screens without duplicating protocol interpretation in Android.

§Errors

Returns a stable account, event, or persistence error for invalid filters, limits, or stored truth.

Source

pub fn list_event_nodes( &self, kind: Option<ProjectionKind>, logical_event_id: String, conversation_id: String, target_event_id: String, author_public_key: String, before_created_at: Option<i64>, limit: u32, offset: u32, ) -> Result<Vec<AccountEventNode>, SoftchatError>

Return a bounded page of authenticated projections with use-case state.

Filtering and edit/deletion/reply semantics execute in the same Rust database owner as ingestion. Android receives complete immutable values and never issues SQL or reinterprets protocol tags.

§Errors

Returns a stable account, event, or persistence error for invalid filters, limits, or stored truth.

Source

pub fn list_known_public_keys( &self, limit: u32, offset: u32, ) -> Result<Vec<String>, SoftchatError>

Return bounded canonical public keys known to account state.

§Errors

Returns a stable account or persistence error for an invalid limit or inconsistent stored truth.

Source

pub fn put_local_contact( &mut self, contact: LocalContactRecord, ) -> Result<AccountMutationResult, SoftchatError>

Insert or replace one bounded Android-local contact.

This does not create or impersonate authenticated kind-0 metadata.

§Errors

Returns a stable account or persistence error for an invalid key, name, timestamp, or SQLite failure.

Source

pub fn remove_local_contact( &mut self, public_key: String, ) -> Result<AccountMutationResult, SoftchatError>

Remove one Android-local contact idempotently.

§Errors

Returns a stable account or persistence error for an invalid key or SQLite failure.

Source

pub fn local_contacts( &self, limit: u32, offset: u32, ) -> Result<Vec<LocalContactRecord>, SoftchatError>

Return a bounded stable page of Android-local contacts.

§Errors

Returns a stable account or persistence error for invalid bounds or malformed stored state.

Source

pub fn replace_stickers( &mut self, stickers: Vec<StickerRecord>, ) -> Result<AccountMutationResult, SoftchatError>

Atomically replace the complete bounded custom-emoji/sticker cache.

The cache is use-case state rather than protocol truth, but remains in the Rust-owned account database so Android never owns a second SQLite schema.

§Errors

Returns a stable account or persistence error for invalid names, URLs, emoji bounds, duplicates, or SQLite failure.

Source

pub fn stickers(&self) -> Result<Vec<StickerRecord>, SoftchatError>

Return the complete bounded sticker cache in stable name order.

§Errors

Returns a stable persistence error for malformed stored state.

Insert or replace one bounded link-preview cache result.

§Errors

Returns a stable account or persistence error for invalid URLs, text bounds, timestamps, or SQLite failure.

Return one cached link preview by its exact validated URL.

§Errors

Returns a stable account or persistence error for an invalid URL or malformed stored result.

Source

pub fn clear(&mut self) -> Result<AccountMutationResult, SoftchatError>

Clear every account-owned row while retaining binding and revision.

Relay catalog and account settings are recreated at safe defaults in the same transaction. The authoritative table inventory includes the standalone FTS table and transport-result journal.

§Errors

Returns a stable persistence error if the atomic clear fails.

Source

pub fn event_json(&self, event_id: &str) -> Result<String, SoftchatError>

Return exact canonical signed-event JSON by outer event ID.

§Errors

Returns a stable event or persistence error when the ID is malformed, unknown, or unreadable.

Source

pub fn event_jsons( &self, event_ids: Vec<String>, ) -> Result<Vec<StoredEventJson>, SoftchatError>

Return exact event JSON for a bounded unique ID set.

This executes synchronization resend actions without exposing a database adapter to Android.

§Errors

Returns a stable event, account, or persistence error for malformed, duplicate, excessive, or unknown IDs.

Source

pub fn sync_fingerprints( &self, since_timestamp: Option<i64>, until_timestamp: i64, limit: u32, ) -> Result<Vec<NegentropyItem>, SoftchatError>

Load one bounded authenticated fingerprint snapshot for synchronization.

§Errors

Returns a stable sync or persistence error for invalid ranges, limits, or database state.

Source

pub fn sync_checkpoint( &self, sync_id: &str, ) -> Result<Option<i64>, SoftchatError>

Return a previously committed synchronization checkpoint.

§Errors

Returns a stable sync or persistence error for an invalid ID or database state.

Source

pub fn save_sync_checkpoint( &mut self, sync_id: &str, checkpoint_timestamp: i64, now: i64, ) -> Result<AccountMutationResult, SoftchatError>

Atomically persist one synchronization checkpoint.

§Errors

Returns a stable sync or persistence error for invalid input or a failed transaction.

Source

pub fn reset_sync( &mut self, now: i64, ) -> Result<AccountMutationResult, SoftchatError>

Remove every durable synchronization checkpoint and wake observers.

Authenticated event truth is retained. The next synchronization run therefore reconciles the complete retained history instead of downloading an unverified replacement database.

§Errors

Returns a stable timestamp or persistence error.

Trait Implementations§

Source§

impl Debug for AccountDatabase

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,