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
impl Chatlist
sourcepub async fn try_load(
context: &Context,
listflags: usize,
query: Option<&str>,
query_contact_id: Option<ContactId>,
) -> Result<Self>
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.
sourcepub(crate) async fn from_chat_ids(
context: &Context,
chat_ids: &[ChatId],
) -> Result<Self>
pub(crate) async fn from_chat_ids( context: &Context, chat_ids: &[ChatId], ) -> Result<Self>
Converts list of chat IDs to a chatlist.
sourcepub fn get_chat_id(&self, index: usize) -> Result<ChatId>
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().
sourcepub fn get_msg_id(&self, index: usize) -> Result<Option<MsgId>>
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().
sourcepub async fn get_summary(
&self,
context: &Context,
index: usize,
chat: Option<&Chat>,
) -> Result<Summary>
pub async fn get_summary( &self, context: &Context, index: usize, chat: Option<&Chat>, ) -> Result<Summary>
Returns a summary for a given chatlist index.
sourcepub async fn get_summary2(
context: &Context,
chat_id: ChatId,
lastmsg_id: Option<MsgId>,
chat: Option<&Chat>,
) -> Result<Summary>
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.
sourcepub fn get_index_for_id(&self, id: ChatId) -> Option<usize>
pub fn get_index_for_id(&self, id: ChatId) -> Option<usize>
Returns chatlist item position for the given chat ID.