Get latest message for a room

This commit is contained in:
2025-11-24 11:20:20 +01:00
parent d23190f9d2
commit 7562a7fc61
3 changed files with 67 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
use crate::controllers::HttpResult;
use crate::controllers::matrix::matrix_event_controller::{APIEvent, get_events};
use crate::controllers::matrix::matrix_media_controller;
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
use actix_web::{HttpRequest, HttpResponse, web};
@@ -15,10 +16,13 @@ pub struct APIRoomInfo {
avatar: Option<OwnedMxcUri>,
is_space: bool,
parents: Vec<OwnedRoomId>,
number_unread_messages: u64,
latest_event: Option<APIEvent>,
}
impl APIRoomInfo {
async fn from_room(r: &Room) -> anyhow::Result<Self> {
// Get parent spaces
let parent_spaces = r
.parent_spaces()
.await?
@@ -47,6 +51,8 @@ impl APIRoomInfo {
avatar: r.avatar_url(),
is_space: r.is_space(),
parents: parent_spaces,
number_unread_messages: r.num_unread_messages(),
latest_event: get_events(r, 1).await?.messages.into_iter().next(),
})
}
}