Skip to main content

matrix_sdk_base/event_cache/
thread.rs

1// Copyright 2026 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Threads types related to the Event Cache.
16
17use ruma::OwnedEventId;
18use serde::{Deserialize, Serialize};
19
20use crate::read_receipts::ReadReceipts;
21
22/// All the information about a thread.
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct ThreadInfo {
25    /// The number of events in the thread.
26    ///
27    /// This doesn't include:
28    /// - the thread root event itself
29    /// - events sent by ignored users
30    /// - redacted events.
31    ///
32    /// Thus, it can be zero!
33    #[serde(default)] // For backwards compatibility.
34    pub number_of_replies: u32,
35
36    /// The ID of the latest event in the thread, if any.
37    #[serde(default)] // For backwards compatibility.
38    pub latest_event: Option<OwnedEventId>,
39
40    /// Read receipts for the current thread.
41    pub read_receipts: ReadReceipts,
42}
43
44impl ThreadInfo {
45    /// Create a new [`ThreadInfo`].
46    pub fn new() -> Self {
47        Self { number_of_replies: 0, latest_event: None, read_receipts: ReadReceipts::default() }
48    }
49}
50
51impl Default for ThreadInfo {
52    fn default() -> Self {
53        Self::new()
54    }
55}