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
impl AccountDatabase
Sourcepub fn open(
path: impl AsRef<Path>,
account_id: String,
) -> Result<Self, SoftchatError>
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.
Sourcepub fn info(&self) -> Result<AccountDatabaseInfo, SoftchatError>
pub fn info(&self) -> Result<AccountDatabaseInfo, SoftchatError>
Return schema, revision, and journal information.
§Errors
Returns a stable persistence error if metadata cannot be read.
Sourcepub fn revision(&self) -> Result<i64, SoftchatError>
pub fn revision(&self) -> Result<i64, SoftchatError>
Return the current monotonic database revision.
§Errors
Returns a stable persistence error if metadata cannot be read.
Sourcepub fn diagnostics(&self) -> Result<AccountDiagnostics, SoftchatError>
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.
Sourcepub fn ingest(
&mut self,
identity: &LocalIdentity,
events: Vec<SignedEvent>,
received_at: i64,
) -> Result<StoredIngestion, SoftchatError>
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.
Sourcepub 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>
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.
Sourcepub fn enqueue_signed(
&mut self,
identity: &LocalIdentity,
operation_id: String,
events: Vec<SignedEvent>,
relay_urls: Vec<String>,
now: i64,
) -> Result<AccountOperationResult, SoftchatError>
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.
Sourcepub fn claim_deliveries(
&mut self,
lease_id: String,
relay_url: String,
now: i64,
lease_duration_seconds: u32,
) -> Result<Option<ClaimedDelivery>, SoftchatError>
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.
Sourcepub fn mark_socket_written(
&mut self,
claim: &DeliveryClaim,
intent_ids: Vec<String>,
) -> Result<AccountMutationResult, SoftchatError>
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.
Sourcepub fn apply_relay_results(
&mut self,
claim: &DeliveryClaim,
results: Vec<RelayDeliveryResult>,
) -> Result<AccountMutationResult, SoftchatError>
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.
Sourcepub fn release_claim(
&mut self,
claim: &DeliveryClaim,
) -> Result<AccountMutationResult, SoftchatError>
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.
Sourcepub fn operation(
&self,
operation_id: &str,
) -> Result<OperationSnapshot, SoftchatError>
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.
Sourcepub fn operations(
&self,
limit: u32,
) -> Result<Vec<OperationSnapshot>, SoftchatError>
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.
Sourcepub fn retry_operation(
&mut self,
operation_id: &str,
) -> Result<AccountOperationResult, SoftchatError>
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.
Sourcepub fn cancel_operation(
&mut self,
operation_id: &str,
) -> Result<AccountOperationResult, SoftchatError>
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.
Sourcepub fn relay_catalog(&self) -> Result<Vec<RelayCatalogEntry>, SoftchatError>
pub fn relay_catalog(&self) -> Result<Vec<RelayCatalogEntry>, SoftchatError>
Return the complete persisted relay catalog.
§Errors
Returns a stable relay-catalog or persistence error.
Sourcepub fn reconcile_relay_catalog(
&mut self,
discovered: Vec<DnsRelayRecord>,
refreshed_at: i64,
fallback_url: String,
dns_authenticated: bool,
) -> Result<StoredRelayCatalogPlan, SoftchatError>
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.
Sourcepub fn add_custom_relay(
&mut self,
relay_url: String,
created_at: i64,
) -> Result<RelayCatalogMutation, SoftchatError>
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.
Sourcepub fn exclude_relay(
&mut self,
relay_url: String,
now: i64,
) -> Result<RelayCatalogMutation, SoftchatError>
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.
Sourcepub fn restore_automatic_relays(
&mut self,
now: i64,
) -> Result<RelayCatalogMutation, SoftchatError>
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.
Sourcepub fn set_active_relay(
&mut self,
relay_url: String,
now: i64,
) -> Result<RelayCatalogMutation, SoftchatError>
pub fn set_active_relay( &mut self, relay_url: String, now: i64, ) -> Result<RelayCatalogMutation, SoftchatError>
Sourcepub fn relay_failover_candidates(
&self,
failed_url: String,
) -> Result<Vec<String>, SoftchatError>
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.
Sourcepub fn rotate_failed_relay(
&mut self,
failed_url: String,
now: i64,
) -> Result<RelayFailoverMutation, SoftchatError>
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.
Sourcepub fn list_conversations(
&self,
limit: u32,
offset: u32,
) -> Result<Vec<ConversationSummary>, SoftchatError>
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.
Sourcepub fn list_conversation_views(
&self,
limit: u32,
offset: u32,
) -> Result<Vec<ConversationView>, SoftchatError>
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.
Sourcepub fn list_messages(
&self,
conversation_id: &str,
before_created_at: Option<i64>,
limit: u32,
) -> Result<Vec<AccountMessage>, SoftchatError>
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.
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub fn list_known_public_keys(
&self,
limit: u32,
offset: u32,
) -> Result<Vec<String>, SoftchatError>
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.
Sourcepub fn put_local_contact(
&mut self,
contact: LocalContactRecord,
) -> Result<AccountMutationResult, SoftchatError>
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.
Sourcepub fn remove_local_contact(
&mut self,
public_key: String,
) -> Result<AccountMutationResult, SoftchatError>
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.
Sourcepub fn local_contacts(
&self,
limit: u32,
offset: u32,
) -> Result<Vec<LocalContactRecord>, SoftchatError>
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.
Sourcepub fn replace_stickers(
&mut self,
stickers: Vec<StickerRecord>,
) -> Result<AccountMutationResult, SoftchatError>
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.
Sourcepub fn stickers(&self) -> Result<Vec<StickerRecord>, SoftchatError>
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.
Sourcepub fn put_link_preview(
&mut self,
preview: LinkPreviewRecord,
) -> Result<AccountMutationResult, SoftchatError>
pub fn put_link_preview( &mut self, preview: LinkPreviewRecord, ) -> Result<AccountMutationResult, SoftchatError>
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.
Sourcepub fn link_preview(
&self,
url: String,
) -> Result<Option<LinkPreviewRecord>, SoftchatError>
pub fn link_preview( &self, url: String, ) -> Result<Option<LinkPreviewRecord>, SoftchatError>
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.
Sourcepub fn clear(&mut self) -> Result<AccountMutationResult, SoftchatError>
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.
Sourcepub fn event_json(&self, event_id: &str) -> Result<String, SoftchatError>
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.
Sourcepub fn event_jsons(
&self,
event_ids: Vec<String>,
) -> Result<Vec<StoredEventJson>, SoftchatError>
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.
Sourcepub fn sync_fingerprints(
&self,
since_timestamp: Option<i64>,
until_timestamp: i64,
limit: u32,
) -> Result<Vec<NegentropyItem>, SoftchatError>
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.
Sourcepub fn sync_checkpoint(
&self,
sync_id: &str,
) -> Result<Option<i64>, SoftchatError>
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.
Sourcepub fn save_sync_checkpoint(
&mut self,
sync_id: &str,
checkpoint_timestamp: i64,
now: i64,
) -> Result<AccountMutationResult, SoftchatError>
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.
Sourcepub fn reset_sync(
&mut self,
now: i64,
) -> Result<AccountMutationResult, SoftchatError>
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.