Skip to main content

ChatState

Struct ChatState 

Source
pub struct ChatState {
    pub profiles: Vec<Profile>,
    pub chats: Vec<Chat>,
    pub interner: NpubInterner,
    pub is_syncing: bool,
    pub db_loaded: bool,
    pub cache_stats: CacheStats,
}

Fields§

§profiles: Vec<Profile>§chats: Vec<Chat>§interner: NpubInterner§is_syncing: bool§db_loaded: bool§cache_stats: CacheStats

Implementations§

Source§

impl ChatState

Source

pub fn new() -> Self

Source

pub fn merge_db_profiles( &mut self, slim_profiles: Vec<SlimProfile>, my_npub: &str, )

Source

pub fn insert_or_replace_profile(&mut self, npub: &str, profile: Profile)

Source

pub fn get_profile(&self, npub: &str) -> Option<&Profile>

Source

pub fn get_profile_mut(&mut self, npub: &str) -> Option<&mut Profile>

Source

pub fn get_profile_by_id(&self, id: u16) -> Option<&Profile>

Source

pub fn get_profile_mut_by_id(&mut self, id: u16) -> Option<&mut Profile>

Source

pub fn serialize_profile(&self, id: u16) -> Option<SlimProfile>

Source

pub fn get_chat(&self, id: &str) -> Option<&Chat>

Source

pub fn get_chat_mut(&mut self, id: &str) -> Option<&mut Chat>

Source

pub fn create_dm_chat(&mut self, their_npub: &str) -> String

Source

pub fn ensure_community_chat(&mut self, channel_id: &str)

Ensure a Community channel chat exists, created as ChatType::Community.

Source

pub fn upsert_community_chat( &mut self, channel_id: &str, name: &str, description: &str, community_id: &str, is_owner: bool, has_icon: bool, owner_npub: Option<&str>, created_at_ms: Option<u64>, dissolved: bool, protocol: ConcordProtocol, )

Create-or-update a Community channel chat with its display metadata, so the chat row carries name/description/owning-community directly (and persists + loads like any DM — no separate hydrate). is_owner/has_icon are stored as “true”/“1” strings in custom_fields. The caller persists the row (save_slim_chat).

Source

pub fn add_message_to_chat(&mut self, chat_id: &str, message: Message) -> bool

Source

pub fn add_messages_to_chat_batch( &mut self, chat_id: &str, messages: Vec<Message>, ) -> usize

Source

pub fn add_message_to_participant( &mut self, their_npub: &str, message: Message, ) -> bool

Add a message to a participant’s DM chat. Creates profile if missing.

Unlike the src-tauri version, emitting profile_update is the caller’s responsibility.

Source

pub fn find_message(&self, message_id: &str) -> Option<(&Chat, Message)>

Source

pub fn find_chat_for_message(&self, message_id: &str) -> Option<(usize, String)>

Source

pub fn update_message<F>( &mut self, message_id: &str, f: F, ) -> Option<(String, Message)>
where F: FnOnce(&mut CompactMessage),

Source

pub fn update_message_in_chat<F>( &mut self, chat_id: &str, message_id: &str, f: F, ) -> Option<Message>
where F: FnOnce(&mut CompactMessage),

Source

pub fn finalize_pending_message( &mut self, chat_id: &str, pending_id: &str, real_id: &str, ) -> Option<(String, Message)>

Source

pub fn update_attachment<F>( &mut self, chat_hint: &str, msg_id: &str, attachment_id: &str, f: F, ) -> bool
where F: FnOnce(&mut CompactAttachment),

Source

pub fn add_attachment_to_message( &mut self, chat_id: &str, msg_id: &str, attachment: CompactAttachment, ) -> bool

Source

pub fn add_reaction_to_message( &mut self, message_id: &str, reaction: Reaction, ) -> Option<(String, bool)>

Source

pub fn find_reaction( &self, reaction_id: &str, ) -> Option<(String, String, String, bool)>

Locate a reaction by its event id across all chats. Returns (chat_id, parent_message_id, author_npub, is_community).

Source

pub fn remove_reaction_from_message( &mut self, message_id: &str, reaction_id: &str, ) -> Option<(String, Message)>

Remove a reaction from its parent message. Returns (chat_id, updated Message) for the UI refresh, or None if the reaction wasn’t present.

Source

pub fn remove_message(&mut self, message_id: &str) -> Option<(String, Message)>

Source

pub fn message_exists(&self, message_id: &str) -> bool

Source

pub fn sum_unread_from(&self, counts: &HashMap<String, u32>) -> u32

Sum DB-computed per-chat unread counts, applying the same muted/blocked filters as [count_unread_messages] but sourcing each COUNT from counts (chat_identifier → unread) rather than walking in-memory messages — so it’s correct even when only the last message per chat is in RAM (the boot state). Muted chats and blocked-DM contacts contribute 0.

Source

pub fn count_unread_messages(&self) -> u32

Source

pub fn update_typing_and_get_active( &mut self, chat_id: &str, npub: &str, expires_at: u64, ) -> Vec<String>

Trait Implementations§

Source§

impl Clone for ChatState

Source§

fn clone(&self) -> ChatState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChatState

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ChatState

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more