Skip to main content

ChatEngine

Struct ChatEngine 

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

The chat engine: contacts, rooms, history, and a pluggable transport.

Implementations§

Source§

impl ChatEngine

Source

pub fn new( identity: ChatIdentity, contacts: Vec<Contact>, groups: Vec<Group>, history: History, transport: Arc<dyn Transport>, own_nym_address: impl Into<String>, ) -> Self

Build an engine from already-loaded state.

own_nym_address is this device’s Nym address; an empty string means the engine is running against a mock transport.

Source

pub fn identity(&self) -> &ChatIdentity

This device’s chat identity.

Source

pub fn contacts(&self) -> &[Contact]

Saved contacts, sorted by petname.

Source

pub fn groups(&self) -> &[Group]

Rooms known on this device.

Source

pub fn group(&self, group_id: &str) -> Option<&Group>

Look up a room by id.

Source

pub fn history(&self) -> &History

The local encrypted history store.

Source

pub fn transport_name(&self) -> &'static str

Short name of the transport in use.

Source

pub fn status(&self) -> &str

Current self status: online, away, dnd, or invisible.

Source

pub fn set_status(&mut self, status: &str) -> Result<()>

Set self status. Status is local; it is not broadcast to contacts.

Source

pub fn contact(&self, pubkey: &str) -> Option<&Contact>

Look up a saved contact by public key.

Source

pub fn add_contact(&mut self, contact: Contact) -> Contact

Add a contact, or update its petname/Nym address when the key exists.

Source

pub fn remove_contact(&mut self, pubkey: &str) -> bool

Remove a contact by public key. Returns whether anything was removed.

Source

pub fn create_group( &mut self, name: &str, member_pubkeys: &[String], ) -> Result<(Group, String)>

Create a room, including the selected saved contacts and this identity. Returns the room and the signed invite JSON for the other members.

Source

pub fn join_group(&mut self, invite_json: &str) -> Result<Group>

Join a room from an invite. The invite must include this chat identity.

Source

pub fn remove_group(&mut self, group_id: &str) -> bool

Forget a room locally. Returns whether anything was removed. This does not notify other members and does not rotate the room key.

Source

pub fn group_invite(&self, group_id: &str) -> Result<String>

Re-export the signed invite for a saved room, to hand to a new member.

Source

pub fn send_dm(&mut self, peer_pub: &str, body: &str) -> Result<ChatMessage>

Send a 1:1 message. The transport receives the sealed envelope; the plaintext only exists in memory and in the encrypted history journal.

Source

pub fn send_group( &mut self, group_id: &str, body: &str, ) -> Result<GroupSendReport>

Fan out one sealed room message to every member except this identity.

Source

pub fn receive(&mut self, payload: &[u8]) -> Result<Option<ChatMessage>>

Open and verify an inbound sealed DM. Returns None for a duplicate.

Source

pub fn receive_any(&mut self, payload: &[u8]) -> Result<Option<ChatMessage>>

Dispatch an inbound payload by envelope shape: room messages carry a gid, DMs carry the sealed-box epub.

Source

pub fn receive_group(&mut self, payload: &[u8]) -> Result<Option<ChatMessage>>

Open and verify an inbound sealed room message. Returns None for a duplicate.

Source

pub fn deliver_demo( &mut self, sender: &ChatIdentity, body: &str, ) -> Result<Option<ChatMessage>>

Test/demo helper: seal a message from sender to this engine and feed it through the normal DM receive path.

Source

pub fn deliver_demo_group( &mut self, sender: &ChatIdentity, group_id: &str, body: &str, ) -> Result<Option<ChatMessage>>

Test/demo helper for rooms: sign with sender, seal with the room key, then run the normal group receive path.

Source

pub fn history_for(&self, peer_pub: &str, limit: usize) -> Vec<ChatMessage>

Newest-last messages for the DM with peer_pub. limit of 0 returns everything.

Source

pub fn group_history(&self, group_id: &str, limit: usize) -> Vec<ChatMessage>

Newest-last messages for a room. limit of 0 returns everything.

Source

pub fn conversations(&self) -> Vec<ConversationSummary>

Direct-message conversations, most recent first. Rooms are excluded; use ChatEngine::group_summaries for those.

Source

pub fn group_summaries(&self) -> Vec<GroupSummary>

Rooms with their local member list and last message, most recent first.

Source

pub fn clear_history(&mut self) -> Result<()>

Delete every stored message from the history journals.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

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

Source§

fn vzip(self) -> V