mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-06-21 22:58:32 -04:00
timeline: introduce new methods send/redact in the RoomDataProvider
This commit is contained in:
@@ -51,6 +51,7 @@ use ruma::{
|
||||
uint, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId, OwnedUserId,
|
||||
RoomVersionId, TransactionId, UInt, UserId,
|
||||
};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::{
|
||||
event_handler::TimelineEventKind,
|
||||
@@ -288,8 +289,21 @@ type ReadReceiptMap =
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct TestRoomDataProvider {
|
||||
/// The initial list of user receipts for that room.
|
||||
///
|
||||
/// Configurable at construction, static for the lifetime of the provider.
|
||||
initial_user_receipts: ReadReceiptMap,
|
||||
|
||||
/// Event id of the event pointed to by the fully read marker.
|
||||
///
|
||||
/// Configurable at construction, static for the lifetime of the provider.
|
||||
fully_read_marker: Option<OwnedEventId>,
|
||||
|
||||
/// Events sent with that room data provider.
|
||||
pub sent_events: Arc<RwLock<Vec<AnyMessageLikeEventContent>>>,
|
||||
|
||||
/// Events redacted with that room data providier.
|
||||
pub redacted: Arc<RwLock<Vec<OwnedEventId>>>,
|
||||
}
|
||||
|
||||
impl TestRoomDataProvider {
|
||||
@@ -400,6 +414,21 @@ impl RoomDataProvider for TestRoomDataProvider {
|
||||
async fn load_fully_read_marker(&self) -> Option<OwnedEventId> {
|
||||
self.fully_read_marker.clone()
|
||||
}
|
||||
|
||||
async fn send(&self, content: AnyMessageLikeEventContent) -> Result<(), super::Error> {
|
||||
self.sent_events.write().await.push(content);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn redact(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
_reason: Option<&str>,
|
||||
_transaction_id: Option<OwnedTransactionId>,
|
||||
) -> Result<(), super::Error> {
|
||||
self.redacted.write().await.push(event_id.to_owned());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn assert_event_is_updated(
|
||||
|
||||
@@ -24,9 +24,10 @@ use ruma::{
|
||||
events::{
|
||||
fully_read::FullyReadEventContent,
|
||||
receipt::{Receipt, ReceiptThread, ReceiptType},
|
||||
AnyMessageLikeEventContent,
|
||||
},
|
||||
push::{PushConditionRoomCtx, Ruleset},
|
||||
EventId, OwnedEventId, OwnedUserId, RoomVersionId, UserId,
|
||||
EventId, OwnedEventId, OwnedTransactionId, OwnedUserId, RoomVersionId, UserId,
|
||||
};
|
||||
use tracing::{debug, error};
|
||||
|
||||
@@ -90,6 +91,17 @@ pub(super) trait RoomDataProvider:
|
||||
async fn load_fully_read_marker(&self) -> Option<OwnedEventId>;
|
||||
|
||||
async fn push_rules_and_context(&self) -> Option<(Ruleset, PushConditionRoomCtx)>;
|
||||
|
||||
/// Send an event to that room.
|
||||
async fn send(&self, content: AnyMessageLikeEventContent) -> Result<(), super::Error>;
|
||||
|
||||
/// Redact an event from that room.
|
||||
async fn redact(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
reason: Option<&str>,
|
||||
transaction_id: Option<OwnedTransactionId>,
|
||||
) -> Result<(), super::Error>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -213,6 +225,24 @@ impl RoomDataProvider for Room {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
async fn send(&self, content: AnyMessageLikeEventContent) -> Result<(), super::Error> {
|
||||
let _ = self.send_queue().send(content).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn redact(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
reason: Option<&str>,
|
||||
transaction_id: Option<OwnedTransactionId>,
|
||||
) -> Result<(), super::Error> {
|
||||
let _ = self
|
||||
.redact(event_id, reason, transaction_id)
|
||||
.await
|
||||
.map_err(super::Error::RedactError)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// Internal helper to make most of retry_event_decryption independent of a room
|
||||
|
||||
Reference in New Issue
Block a user