pub struct ChatEngine { /* private fields */ }Expand description
The chat engine: contacts, rooms, history, and a pluggable transport.
Implementations§
Source§impl ChatEngine
impl ChatEngine
Sourcepub fn new(
identity: ChatIdentity,
contacts: Vec<Contact>,
groups: Vec<Group>,
history: History,
transport: Arc<dyn Transport>,
own_nym_address: impl Into<String>,
) -> Self
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.
Sourcepub fn identity(&self) -> &ChatIdentity
pub fn identity(&self) -> &ChatIdentity
This device’s chat identity.
Sourcepub fn transport_name(&self) -> &'static str
pub fn transport_name(&self) -> &'static str
Short name of the transport in use.
Sourcepub fn set_status(&mut self, status: &str) -> Result<()>
pub fn set_status(&mut self, status: &str) -> Result<()>
Set self status. Status is local; it is not broadcast to contacts.
Sourcepub fn add_contact(&mut self, contact: Contact) -> Contact
pub fn add_contact(&mut self, contact: Contact) -> Contact
Add a contact, or update its petname/Nym address when the key exists.
Sourcepub fn remove_contact(&mut self, pubkey: &str) -> bool
pub fn remove_contact(&mut self, pubkey: &str) -> bool
Remove a contact by public key. Returns whether anything was removed.
Sourcepub fn create_group(
&mut self,
name: &str,
member_pubkeys: &[String],
) -> Result<(Group, String)>
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.
Sourcepub fn join_group(&mut self, invite_json: &str) -> Result<Group>
pub fn join_group(&mut self, invite_json: &str) -> Result<Group>
Join a room from an invite. The invite must include this chat identity.
Sourcepub fn remove_group(&mut self, group_id: &str) -> bool
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.
Sourcepub fn group_invite(&self, group_id: &str) -> Result<String>
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.
Sourcepub fn send_dm(&mut self, peer_pub: &str, body: &str) -> Result<ChatMessage>
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.
Sourcepub fn send_group(
&mut self,
group_id: &str,
body: &str,
) -> Result<GroupSendReport>
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.
Sourcepub fn receive(&mut self, payload: &[u8]) -> Result<Option<ChatMessage>>
pub fn receive(&mut self, payload: &[u8]) -> Result<Option<ChatMessage>>
Open and verify an inbound sealed DM. Returns None for a duplicate.
Sourcepub fn receive_any(&mut self, payload: &[u8]) -> Result<Option<ChatMessage>>
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.
Sourcepub fn receive_group(&mut self, payload: &[u8]) -> Result<Option<ChatMessage>>
pub fn receive_group(&mut self, payload: &[u8]) -> Result<Option<ChatMessage>>
Open and verify an inbound sealed room message. Returns None for a
duplicate.
Sourcepub fn deliver_demo(
&mut self,
sender: &ChatIdentity,
body: &str,
) -> Result<Option<ChatMessage>>
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.
Sourcepub fn deliver_demo_group(
&mut self,
sender: &ChatIdentity,
group_id: &str,
body: &str,
) -> Result<Option<ChatMessage>>
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.
Sourcepub fn history_for(&self, peer_pub: &str, limit: usize) -> Vec<ChatMessage>
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.
Sourcepub fn group_history(&self, group_id: &str, limit: usize) -> Vec<ChatMessage>
pub fn group_history(&self, group_id: &str, limit: usize) -> Vec<ChatMessage>
Newest-last messages for a room. limit of 0 returns everything.
Sourcepub fn conversations(&self) -> Vec<ConversationSummary>
pub fn conversations(&self) -> Vec<ConversationSummary>
Direct-message conversations, most recent first. Rooms are excluded;
use ChatEngine::group_summaries for those.
Sourcepub fn group_summaries(&self) -> Vec<GroupSummary>
pub fn group_summaries(&self) -> Vec<GroupSummary>
Rooms with their local member list and last message, most recent first.
Sourcepub fn clear_history(&mut self) -> Result<()>
pub fn clear_history(&mut self) -> Result<()>
Delete every stored message from the history journals.