Get latest message for a room
This commit is contained in:
@@ -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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user