Can get read receipts
This commit is contained in:
@@ -8,7 +8,10 @@ use matrix_sdk::notification_settings::{
|
||||
IsEncrypted, IsOneToOne, NotificationSettings, RoomNotificationMode,
|
||||
};
|
||||
use matrix_sdk::room::ParentSpace;
|
||||
use matrix_sdk::ruma::{OwnedMxcUri, OwnedRoomId, OwnedUserId};
|
||||
use matrix_sdk::ruma::events::receipt::{ReceiptThread, ReceiptType};
|
||||
use matrix_sdk::ruma::{
|
||||
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedMxcUri, OwnedRoomId, OwnedUserId,
|
||||
};
|
||||
use matrix_sdk::{Room, RoomMemberships};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
@@ -71,7 +74,11 @@ impl APIRoomInfo {
|
||||
parents: parent_spaces,
|
||||
number_unread_messages: r.unread_notification_counts().notification_count,
|
||||
notifications,
|
||||
latest_event: get_events(r, 1, None).await?.events.into_iter().next(),
|
||||
latest_event: get_events(r, 1, None, None)
|
||||
.await?
|
||||
.events
|
||||
.into_iter()
|
||||
.next(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -137,3 +144,37 @@ pub async fn room_avatar(
|
||||
|
||||
matrix_media_controller::serve_mxc_file(req, uri).await
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct UserReceipt {
|
||||
user: OwnedUserId,
|
||||
event_id: OwnedEventId,
|
||||
ts: Option<MilliSecondsSinceUnixEpoch>,
|
||||
}
|
||||
|
||||
/// Get room receipts
|
||||
pub async fn receipts(client: MatrixClientExtractor, path: web::Path<RoomIdInPath>) -> HttpResult {
|
||||
let Some(room) = client.client.client.get_room(&path.room_id) else {
|
||||
return Ok(HttpResponse::NotFound().json("Room not found"));
|
||||
};
|
||||
|
||||
let members = room.members(RoomMemberships::ACTIVE).await?;
|
||||
|
||||
let mut receipts = Vec::new();
|
||||
for m in members {
|
||||
let Some((event_id, receipt)) = room
|
||||
.load_user_receipt(ReceiptType::Read, ReceiptThread::Main, m.user_id())
|
||||
.await?
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
|
||||
receipts.push(UserReceipt {
|
||||
user: m.user_id().to_owned(),
|
||||
event_id,
|
||||
ts: receipt.ts,
|
||||
})
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().json(receipts))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user