matrix_sdk_base/room/
latest_event.rs

1// Copyright 2025 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
15use ruma::MilliSecondsSinceUnixEpoch;
16
17use super::Room;
18use crate::latest_event::LatestEventValue;
19
20impl Room {
21    /// Return the [`LatestEventValue`] of this room.
22    ///
23    /// Note that it clones the [`LatestEventValue`]! This can add pressure
24    /// on the memory if used in a hot path.
25    pub fn latest_event(&self) -> LatestEventValue {
26        self.info.read().latest_event_value.clone()
27    }
28
29    /// Return the value of [`LatestEventValue::timestamp`].
30    pub fn latest_event_timestamp(&self) -> Option<MilliSecondsSinceUnixEpoch> {
31        self.info.read().latest_event_value.timestamp()
32    }
33
34    /// Return the value of [`LatestEventValue::is_unsent`].
35    pub fn latest_event_is_unsent(&self) -> bool {
36        self.info.read().latest_event_value.is_unsent()
37    }
38}