MCPcopy Create free account
hub / github.com/chatmail/core / get_message_stats

Function get_message_stats

src/stats.rs:540–570  ·  view source on GitHub ↗

- `last_msg_id`: The last msg_id that was already counted in the previous stats. Only messages newer than that will be counted. - `one_one_chats`: If true, only messages in 1:1 chats are counted. If false, only messages in other chats (groups and broadcast channels) are counted.

(context: &Context)

Source from the content-addressed store, hash-verified

538/// - `one_one_chats`: If true, only messages in 1:1 chats are counted.
539/// If false, only messages in other chats (groups and broadcast channels) are counted.
540async fn get_message_stats(context: &Context) -> Result<BTreeMap<Chattype, MessageStats>> {
541 let mut map: BTreeMap<Chattype, MessageStats> = context
542 .sql
543 .query_map_collect(
544 "SELECT chattype, verified, unverified_encrypted, unencrypted, only_to_self
545 FROM stats_msgs",
546 (),
547 |row| {
548 let chattype: Chattype = row.get(0)?;
549 let verified: u32 = row.get(1)?;
550 let unverified_encrypted: u32 = row.get(2)?;
551 let unencrypted: u32 = row.get(3)?;
552 let only_to_self: u32 = row.get(4)?;
553 let message_stats = MessageStats {
554 verified,
555 unverified_encrypted,
556 unencrypted,
557 only_to_self,
558 };
559 Ok((chattype, message_stats))
560 },
561 )
562 .await?;
563
564 // Fill zeroes if a chattype wasn't present:
565 for chattype in [Chattype::Group, Chattype::Single, Chattype::OutBroadcast] {
566 map.entry(chattype).or_default();
567 }
568
569 Ok(map)
570}
571
572pub(crate) async fn update_message_stats(context: &Context) -> Result<()> {
573 for chattype in [Chattype::Single, Chattype::Group, Chattype::OutBroadcast] {

Callers 1

get_statsFunction · 0.85

Calls 2

query_map_collectMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected