pub struct Chatlist {
    ids: Vec<(ChatId, Option<MsgId>)>,
}
Expand description

An object representing a single chatlist in memory.

Chatlist objects contain chat IDs and, if possible, message IDs belonging to them. The chatlist object is not updated; if you want an update, you have to recreate the object.

For a typical chat overview, the idea is to get the list of all chats via dc_get_chatlist() without any listflags (see below) and to implement a “virtual list” or so (the count of chats is known by chatlist.len()).

Only for the items that are in view (the list may have several hundreds chats), the UI should call chatlist.get_summary() then. chatlist.get_summary() provides all elements needed for painting the item.

On a click of such an item, the UI should change to the chat view and get all messages from this view via dc_get_chat_msgs(). Again, a “virtual list” is created (the count of messages is known) and for each messages that is scrolled into view, dc_get_msg() is called then.

Why no listflags? Without listflags, dc_get_chatlist() adds the archive “link” automatically as needed. The UI can just render these items differently then.

Fields§

§ids: Vec<(ChatId, Option<MsgId>)>

Stores pairs of chat_id, message_id

Implementations§

source§

impl Chatlist

source

pub async fn try_load( context: &Context, listflags: usize, query: Option<&str>, query_contact_id: Option<ContactId> ) -> Result<Self>

Get a list of chats. The list can be filtered by query parameters.

The list is already sorted and starts with the most recent chat in use. The sorting takes care of invalid sending dates, drafts and chats without messages. Clients should not try to re-sort the list as this would be an expensive action and would result in inconsistencies between clients.

To get information about each entry, use eg. chatlist.get_summary().

By default, the function adds some special entries to the list. These special entries can be identified by the ID returned by chatlist.get_chat_id():

  • DC_CHAT_ID_ARCHIVED_LINK (6) - this special chat is present if the user has archived any chat using dc_set_chat_visibility(). The UI should show a link as “Show archived chats”, if the user clicks this item, the UI should show a list of all archived chats that can be created by this function hen using the DC_GCL_ARCHIVED_ONLY flag.
  • DC_CHAT_ID_ALLDONE_HINT (7) - this special chat is present if DC_GCL_ADD_ALLDONE_HINT is added to listflags and if there are only archived chats.

The listflags is a combination of flags:

  • if the flag DC_GCL_ARCHIVED_ONLY is set, only archived chats are returned. if DC_GCL_ARCHIVED_ONLY is not set, only unarchived chats are returned and the pseudo-chat DC_CHAT_ID_ARCHIVED_LINK is added if there are any archived chats
  • the flag DC_GCL_FOR_FORWARDING sorts “Saved messages” to the top of the chatlist and hides the device-chat and contact requests typically used on forwarding, may be combined with DC_GCL_NO_SPECIALS
  • if the flag DC_GCL_NO_SPECIALS is set, archive link is not added to the list (may be used eg. for selecting chats on forwarding, the flag is not needed when DC_GCL_ARCHIVED_ONLY is already set)
  • if the flag DC_GCL_ADD_ALLDONE_HINT is set, DC_CHAT_ID_ALLDONE_HINT is added as needed. query: An optional query for filtering the list. Only chats matching this query are returned. When is:unread is contained in the query, the chatlist is filtered such that only chats with unread messages show up. query_contact_id: An optional contact ID for filtering the list. Only chats including this contact ID are returned.
source

pub(crate) async fn from_chat_ids( context: &Context, chat_ids: &[ChatId] ) -> Result<Self>

Converts list of chat IDs to a chatlist.

source

pub fn len(&self) -> usize

Find out the number of chats.

source

pub fn is_empty(&self) -> bool

Returns true if chatlist is empty.

source

pub fn get_chat_id(&self, index: usize) -> Result<ChatId>

Get a single chat ID of a chatlist.

To get the message object from the message ID, use dc_get_chat().

source

pub fn get_msg_id(&self, index: usize) -> Result<Option<MsgId>>

Get a single message ID of a chatlist.

To get the message object from the message ID, use dc_get_msg().

source

pub async fn get_summary( &self, context: &Context, index: usize, chat: Option<&Chat> ) -> Result<Summary>

Returns a summary for a given chatlist index.

source

pub async fn get_summary2( context: &Context, chat_id: ChatId, lastmsg_id: Option<MsgId>, chat: Option<&Chat> ) -> Result<Summary>

Returns a summary for a given chatlist item.

source

pub fn get_index_for_id(&self, id: ChatId) -> Option<usize>

Returns chatlist item position for the given chat ID.

source

pub fn iter(&self) -> impl Iterator<Item = &(ChatId, Option<MsgId>)>

An iterator visiting all chatlist items.

Trait Implementations§

source§

impl Debug for Chatlist

source§

fn fmt(&self, f: &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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
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