mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-25 17:49:58 -04:00
refactor!: Rename [Sync]RoomEvent to [Sync]TimelineEvent
This commit is contained in:
committed by
Jonas Platte
parent
4be2f3aa04
commit
6ddc8ba36f
@@ -200,8 +200,8 @@ impl DecryptedRoomEvent {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<matrix_sdk_common::deserialized_responses::RoomEvent> for DecryptedRoomEvent {
|
||||
fn from(value: matrix_sdk_common::deserialized_responses::RoomEvent) -> Self {
|
||||
impl From<matrix_sdk_common::deserialized_responses::TimelineEvent> for DecryptedRoomEvent {
|
||||
fn from(value: matrix_sdk_common::deserialized_responses::TimelineEvent) -> Self {
|
||||
Self {
|
||||
event: value.event.json().get().to_owned().into(),
|
||||
encryption_info: value.encryption_info,
|
||||
|
||||
@@ -196,8 +196,8 @@ impl DecryptedRoomEvent {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<matrix_sdk_common::deserialized_responses::RoomEvent> for DecryptedRoomEvent {
|
||||
fn from(value: matrix_sdk_common::deserialized_responses::RoomEvent) -> Self {
|
||||
impl From<matrix_sdk_common::deserialized_responses::TimelineEvent> for DecryptedRoomEvent {
|
||||
fn from(value: matrix_sdk_common::deserialized_responses::TimelineEvent) -> Self {
|
||||
Self { event: value.event.json().get().to_owned(), encryption_info: value.encryption_info }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use core::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures_core::Stream;
|
||||
use matrix_sdk::{deserialized_responses::SyncRoomEvent, locks::Mutex, Result};
|
||||
use matrix_sdk::{deserialized_responses::SyncTimelineEvent, locks::Mutex, Result};
|
||||
use tokio_stream::StreamExt;
|
||||
use tracing::error;
|
||||
|
||||
@@ -11,7 +11,7 @@ use super::{
|
||||
RUNTIME,
|
||||
};
|
||||
|
||||
type MsgStream = Pin<Box<dyn Stream<Item = Result<SyncRoomEvent>> + Send>>;
|
||||
type MsgStream = Pin<Box<dyn Stream<Item = Result<SyncTimelineEvent>> + Send>>;
|
||||
|
||||
pub struct BackwardsStream {
|
||||
stream: Arc<Mutex<MsgStream>>,
|
||||
|
||||
@@ -5,7 +5,7 @@ pub use matrix_sdk::ruma::events::room::{
|
||||
message::RoomMessageEventContent as MessageEventContent, MediaSource,
|
||||
};
|
||||
use matrix_sdk::{
|
||||
deserialized_responses::SyncRoomEvent,
|
||||
deserialized_responses::SyncTimelineEvent,
|
||||
ruma::events::{
|
||||
room::{
|
||||
message::{ImageMessageEventContent, MessageFormat, MessageType},
|
||||
@@ -144,7 +144,7 @@ impl AnyMessage {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sync_event_to_message(sync_event: SyncRoomEvent) -> Option<Arc<AnyMessage>> {
|
||||
pub fn sync_event_to_message(sync_event: SyncTimelineEvent) -> Option<Arc<AnyMessage>> {
|
||||
match sync_event.event.deserialize() {
|
||||
Ok(AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
|
||||
SyncMessageLikeEvent::Original(m),
|
||||
|
||||
@@ -609,7 +609,7 @@ mod tests {
|
||||
let uri = "/_matrix/app/v1/transactions/1?access_token=hs_token";
|
||||
|
||||
let mut transaction_builder = TransactionBuilder::new();
|
||||
transaction_builder.add_room_event(TimelineTestEvent::Member);
|
||||
transaction_builder.add_timeline_event(TimelineTestEvent::Member);
|
||||
let transaction = transaction_builder.build_json_transaction();
|
||||
|
||||
let appservice = appservice(None, None).await?;
|
||||
@@ -634,7 +634,7 @@ mod tests {
|
||||
let uri = "/_matrix/app/v1/transactions/1?access_token=hs_token";
|
||||
|
||||
let mut transaction_builder = TransactionBuilder::new();
|
||||
transaction_builder.add_room_event(TimelineTestEvent::Member);
|
||||
transaction_builder.add_timeline_event(TimelineTestEvent::Member);
|
||||
let transaction = transaction_builder.build_json_transaction();
|
||||
|
||||
let appservice = appservice(None, None).await?;
|
||||
@@ -740,8 +740,9 @@ mod tests {
|
||||
let uri = "/_matrix/app/v1/transactions/1?access_token=invalid_token";
|
||||
|
||||
let mut transaction_builder = TransactionBuilder::new();
|
||||
let transaction =
|
||||
transaction_builder.add_room_event(TimelineTestEvent::Member).build_json_transaction();
|
||||
let transaction = transaction_builder
|
||||
.add_timeline_event(TimelineTestEvent::Member)
|
||||
.build_json_transaction();
|
||||
|
||||
let appservice = appservice(None, None).await?;
|
||||
|
||||
@@ -765,7 +766,7 @@ mod tests {
|
||||
let uri = "/_matrix/app/v1/transactions/1";
|
||||
|
||||
let mut transaction_builder = TransactionBuilder::new();
|
||||
transaction_builder.add_room_event(TimelineTestEvent::Member);
|
||||
transaction_builder.add_timeline_event(TimelineTestEvent::Member);
|
||||
let transaction = transaction_builder.build_json_transaction();
|
||||
|
||||
let appservice = appservice(None, None).await?;
|
||||
@@ -804,7 +805,7 @@ mod tests {
|
||||
let uri = "/_matrix/app/v1/transactions/1?access_token=hs_token";
|
||||
|
||||
let mut transaction_builder = TransactionBuilder::new();
|
||||
transaction_builder.add_room_event(TimelineTestEvent::Member);
|
||||
transaction_builder.add_timeline_event(TimelineTestEvent::Member);
|
||||
let transaction = transaction_builder.build_json_transaction();
|
||||
|
||||
warp::test::request()
|
||||
@@ -852,11 +853,11 @@ mod tests {
|
||||
let uri_2 = "/sub_path/_matrix/app/v1/transactions/2?access_token=hs_token";
|
||||
|
||||
let mut transaction_builder = TransactionBuilder::new();
|
||||
transaction_builder.add_room_event(TimelineTestEvent::Member);
|
||||
transaction_builder.add_timeline_event(TimelineTestEvent::Member);
|
||||
let transaction_1 = transaction_builder.build_json_transaction();
|
||||
|
||||
let mut transaction_builder = TransactionBuilder::new();
|
||||
transaction_builder.add_room_event(TimelineTestEvent::MemberNameChange);
|
||||
transaction_builder.add_timeline_event(TimelineTestEvent::MemberNameChange);
|
||||
let transaction_2 = transaction_builder.build_json_transaction();
|
||||
|
||||
let appservice = appservice(None, None).await?;
|
||||
|
||||
@@ -27,7 +27,7 @@ use matrix_sdk_common::deserialized_responses::TimelineSlice;
|
||||
use matrix_sdk_common::{
|
||||
deserialized_responses::{
|
||||
AmbiguityChanges, JoinedRoom, LeftRoom, MembersResponse, Rooms, SyncResponse,
|
||||
SyncRoomEvent, Timeline,
|
||||
SyncTimelineEvent, Timeline,
|
||||
},
|
||||
instant::Instant,
|
||||
};
|
||||
@@ -272,7 +272,7 @@ impl BaseClient {
|
||||
|
||||
for event in ruma_timeline.events {
|
||||
#[allow(unused_mut)]
|
||||
let mut event: SyncRoomEvent = event.into();
|
||||
let mut event: SyncTimelineEvent = event.into();
|
||||
|
||||
match event.event.deserialize() {
|
||||
Ok(e) => {
|
||||
|
||||
@@ -54,7 +54,7 @@ use crate::{
|
||||
};
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use crate::{
|
||||
deserialized_responses::{SyncRoomEvent, TimelineSlice},
|
||||
deserialized_responses::{SyncTimelineEvent, TimelineSlice},
|
||||
timeline_stream::{TimelineStreamBackward, TimelineStreamError, TimelineStreamForward},
|
||||
};
|
||||
|
||||
@@ -508,8 +508,8 @@ impl Room {
|
||||
pub async fn timeline(
|
||||
&self,
|
||||
) -> StoreResult<(
|
||||
impl Stream<Item = SyncRoomEvent>,
|
||||
impl Stream<Item = Result<SyncRoomEvent, TimelineStreamError>>,
|
||||
impl Stream<Item = SyncTimelineEvent>,
|
||||
impl Stream<Item = Result<SyncTimelineEvent, TimelineStreamError>>,
|
||||
)> {
|
||||
// We need to hold the lock while we create the stream so that we don't lose new
|
||||
// sync responses
|
||||
@@ -544,7 +544,7 @@ impl Room {
|
||||
/// If you need also a backward stream you should use
|
||||
/// [`timeline`][`crate::Room::timeline`]
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
pub async fn timeline_forward(&self) -> StoreResult<impl Stream<Item = SyncRoomEvent>> {
|
||||
pub async fn timeline_forward(&self) -> StoreResult<impl Stream<Item = SyncTimelineEvent>> {
|
||||
let mut forward_timeline_streams = self.forward_timeline_streams.lock().await;
|
||||
let event_ids = Arc::new(DashSet::new());
|
||||
|
||||
@@ -562,7 +562,7 @@ impl Room {
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
pub async fn timeline_backward(
|
||||
&self,
|
||||
) -> StoreResult<impl Stream<Item = Result<SyncRoomEvent, TimelineStreamError>>> {
|
||||
) -> StoreResult<impl Stream<Item = Result<SyncTimelineEvent, TimelineStreamError>>> {
|
||||
let mut backward_timeline_streams = self.backward_timeline_streams.lock().await;
|
||||
let sync_token = self.store.get_sync_token().await?;
|
||||
let event_ids = Arc::new(DashSet::new());
|
||||
|
||||
@@ -80,7 +80,7 @@ macro_rules! statestore_integration_tests {
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use $crate::{
|
||||
http::Response,
|
||||
deserialized_responses::{ RoomEvent, SyncRoomEvent, TimelineSlice},
|
||||
deserialized_responses::{SyncTimelineEvent, TimelineEvent, TimelineSlice},
|
||||
};
|
||||
use $crate::{
|
||||
media::{MediaFormat, MediaRequest, MediaThumbnailSize},
|
||||
@@ -642,7 +642,7 @@ macro_rules! statestore_integration_tests {
|
||||
.unwrap();
|
||||
|
||||
let timeline = &sync.rooms.join[room_id].timeline;
|
||||
let events: Vec<SyncRoomEvent> = timeline.events.iter().cloned().map(Into::into).collect();
|
||||
let events: Vec<SyncTimelineEvent> = timeline.events.iter().cloned().map(Into::into).collect();
|
||||
|
||||
stored_events.extend(events.iter().rev().cloned());
|
||||
|
||||
@@ -664,15 +664,15 @@ macro_rules! statestore_integration_tests {
|
||||
let messages = MessageResponse::try_from_http_response(
|
||||
Response::builder()
|
||||
.body(serde_json::to_vec(&*test_json::ROOM_MESSAGES_BATCH_1).expect("Parsing ROOM_MESSAGES_BATCH_1 failed"))
|
||||
.unwrap(),
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let events: Vec<SyncRoomEvent> = messages
|
||||
let events: Vec<SyncTimelineEvent> = messages
|
||||
.chunk
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|event| RoomEvent { event, encryption_info: None }.into())
|
||||
.map(|event| TimelineEvent { event, encryption_info: None }.into())
|
||||
.collect();
|
||||
|
||||
stored_events.append(&mut events.clone());
|
||||
@@ -693,11 +693,11 @@ macro_rules! statestore_integration_tests {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let events: Vec<SyncRoomEvent> = messages
|
||||
let events: Vec<SyncTimelineEvent> = messages
|
||||
.chunk
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|event| RoomEvent { event, encryption_info: None }.into())
|
||||
.map(|event| TimelineEvent { event, encryption_info: None }.into())
|
||||
.collect();
|
||||
|
||||
stored_events.append(&mut events.clone());
|
||||
@@ -719,7 +719,7 @@ macro_rules! statestore_integration_tests {
|
||||
.unwrap();
|
||||
|
||||
let timeline = &sync.rooms.join[room_id].timeline;
|
||||
let events: Vec<SyncRoomEvent> = timeline.events.iter().cloned().map(Into::into).collect();
|
||||
let events: Vec<SyncTimelineEvent> = timeline.events.iter().cloned().map(Into::into).collect();
|
||||
|
||||
let prev_stored_events = stored_events;
|
||||
stored_events = events.iter().rev().cloned().collect();
|
||||
@@ -758,14 +758,14 @@ macro_rules! statestore_integration_tests {
|
||||
async fn check_timeline_events(
|
||||
room_id: &RoomId,
|
||||
store: &dyn StateStore,
|
||||
stored_events: &[SyncRoomEvent],
|
||||
stored_events: &[SyncTimelineEvent],
|
||||
expected_end_token: Option<&str>,
|
||||
) {
|
||||
let (timeline_iter, end_token) = store.room_timeline(room_id).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(end_token.as_deref(), expected_end_token);
|
||||
|
||||
let timeline = timeline_iter.collect::<Vec<StoreResult<SyncRoomEvent>>>().await;
|
||||
let timeline = timeline_iter.collect::<Vec<StoreResult<SyncTimelineEvent>>>().await;
|
||||
|
||||
let expected: Vec<OwnedEventId> = stored_events.iter().map(|a| a.event_id().expect("event id doesn't exist")).collect();
|
||||
let found: Vec<OwnedEventId> = timeline.iter().map(|a| a.as_ref().expect("object missing").event_id().clone().expect("event id missing")).collect();
|
||||
|
||||
@@ -56,7 +56,7 @@ use crate::{
|
||||
MinimalRoomMemberEvent,
|
||||
};
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use crate::{deserialized_responses::SyncRoomEvent, StoreError};
|
||||
use crate::{deserialized_responses::SyncTimelineEvent, StoreError};
|
||||
|
||||
/// In-Memory, non-persistent implementation of the `StateStore`
|
||||
///
|
||||
@@ -671,7 +671,7 @@ impl MemoryStore {
|
||||
async fn room_timeline(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<(BoxStream<Result<SyncRoomEvent>>, Option<String>)>> {
|
||||
) -> Result<Option<(BoxStream<Result<SyncTimelineEvent>>, Option<String>)>> {
|
||||
let (events, end_token) = if let Some(data) = self.room_timeline.get(room_id) {
|
||||
(data.events.clone(), data.end.clone())
|
||||
} else {
|
||||
@@ -852,7 +852,7 @@ impl StateStore for MemoryStore {
|
||||
async fn room_timeline(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<(BoxStream<Result<SyncRoomEvent>>, Option<String>)>> {
|
||||
) -> Result<Option<(BoxStream<Result<SyncTimelineEvent>>, Option<String>)>> {
|
||||
self.room_timeline(room_id).await
|
||||
}
|
||||
}
|
||||
@@ -864,7 +864,7 @@ struct TimelineData {
|
||||
pub start_position: isize,
|
||||
pub end: Option<String>,
|
||||
pub end_position: isize,
|
||||
pub events: BTreeMap<isize, SyncRoomEvent>,
|
||||
pub events: BTreeMap<isize, SyncTimelineEvent>,
|
||||
pub event_id_to_position: HashMap<OwnedEventId, isize>,
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ use ruma::{
|
||||
pub type BoxStream<T> = Pin<Box<dyn futures_util::Stream<Item = T> + Send>>;
|
||||
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use crate::deserialized_responses::{SyncRoomEvent, TimelineSlice};
|
||||
use crate::deserialized_responses::{SyncTimelineEvent, TimelineSlice};
|
||||
use crate::{
|
||||
deserialized_responses::MemberEvent,
|
||||
media::MediaRequest,
|
||||
@@ -376,7 +376,7 @@ pub trait StateStore: AsyncTraitDeps {
|
||||
async fn room_timeline(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<(BoxStream<Result<SyncRoomEvent>>, Option<String>)>>;
|
||||
) -> Result<Option<(BoxStream<Result<SyncTimelineEvent>>, Option<String>)>>;
|
||||
}
|
||||
|
||||
/// Convenience functionality for state stores.
|
||||
|
||||
@@ -11,7 +11,7 @@ use thiserror::Error;
|
||||
use tracing::trace;
|
||||
|
||||
use crate::{
|
||||
deserialized_responses::{SyncRoomEvent, TimelineSlice},
|
||||
deserialized_responses::{SyncTimelineEvent, TimelineSlice},
|
||||
store::Result,
|
||||
};
|
||||
|
||||
@@ -35,8 +35,8 @@ pub enum TimelineStreamError {
|
||||
/// A `Stream` of timeline of a room
|
||||
pub struct TimelineStreamBackward<'a> {
|
||||
receiver: mpsc::Receiver<TimelineSlice>,
|
||||
stored_events: Option<BoxStream<'a, Result<SyncRoomEvent>>>,
|
||||
pending: Vec<SyncRoomEvent>,
|
||||
stored_events: Option<BoxStream<'a, Result<SyncTimelineEvent>>>,
|
||||
pending: Vec<SyncTimelineEvent>,
|
||||
event_ids: Arc<DashSet<OwnedEventId>>,
|
||||
token: Option<String>,
|
||||
}
|
||||
@@ -74,7 +74,7 @@ impl<'a> TimelineStreamBackward<'a> {
|
||||
pub(crate) fn new(
|
||||
event_ids: Arc<DashSet<OwnedEventId>>,
|
||||
token: Option<String>,
|
||||
stored_events: Option<BoxStream<'a, Result<SyncRoomEvent>>>,
|
||||
stored_events: Option<BoxStream<'a, Result<SyncTimelineEvent>>>,
|
||||
) -> (Self, mpsc::Sender<TimelineSlice>) {
|
||||
let (sender, receiver) = mpsc::channel(CHANNEL_LIMIT);
|
||||
let self_ = Self { event_ids, pending: Vec::new(), stored_events, token, receiver };
|
||||
@@ -85,7 +85,7 @@ impl<'a> TimelineStreamBackward<'a> {
|
||||
fn handle_new_slice(
|
||||
&mut self,
|
||||
slice: TimelineSlice,
|
||||
) -> Poll<Option<Result<SyncRoomEvent, TimelineStreamError>>> {
|
||||
) -> Poll<Option<Result<SyncTimelineEvent, TimelineStreamError>>> {
|
||||
// Check if this is the batch we are expecting
|
||||
if self.token.is_some() && self.token != Some(slice.start) {
|
||||
trace!("Store received a timeline batch that wasn't expected");
|
||||
@@ -123,7 +123,7 @@ impl<'a> TimelineStreamBackward<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Stream for TimelineStreamBackward<'a> {
|
||||
type Item = Result<SyncRoomEvent, TimelineStreamError>;
|
||||
type Item = Result<SyncTimelineEvent, TimelineStreamError>;
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
let this = self.get_mut();
|
||||
if let Some(stored_events) = &mut this.stored_events {
|
||||
@@ -168,7 +168,7 @@ impl<'a> Stream for TimelineStreamBackward<'a> {
|
||||
/// A `Stream` of timeline of a room
|
||||
pub struct TimelineStreamForward {
|
||||
receiver: mpsc::Receiver<TimelineSlice>,
|
||||
pending: Vec<SyncRoomEvent>,
|
||||
pending: Vec<SyncTimelineEvent>,
|
||||
event_ids: Arc<DashSet<OwnedEventId>>,
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ impl TimelineStreamForward {
|
||||
(self_, sender)
|
||||
}
|
||||
|
||||
fn handle_new_slice(&mut self, slice: TimelineSlice) -> Poll<Option<SyncRoomEvent>> {
|
||||
fn handle_new_slice(&mut self, slice: TimelineSlice) -> Poll<Option<SyncTimelineEvent>> {
|
||||
// There is a gap in the timeline. Therefore, terminate the stream.
|
||||
if slice.limited {
|
||||
return Poll::Ready(None);
|
||||
@@ -226,7 +226,7 @@ impl TimelineStreamForward {
|
||||
}
|
||||
|
||||
impl Stream for TimelineStreamForward {
|
||||
type Item = SyncRoomEvent;
|
||||
type Item = SyncTimelineEvent;
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
let this = self.get_mut();
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ pub struct EncryptionInfo {
|
||||
/// A customized version of a room event coming from a sync that holds optional
|
||||
/// encryption info.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct SyncRoomEvent {
|
||||
pub struct SyncTimelineEvent {
|
||||
/// The actual event.
|
||||
pub event: Raw<AnySyncTimelineEvent>,
|
||||
/// The encryption info about the event. Will be `None` if the event was not
|
||||
@@ -102,25 +102,26 @@ pub struct SyncRoomEvent {
|
||||
pub encryption_info: Option<EncryptionInfo>,
|
||||
}
|
||||
|
||||
impl SyncRoomEvent {
|
||||
/// Get the event id of this `SyncRoomEvent` if the event has any valid id.
|
||||
impl SyncTimelineEvent {
|
||||
/// Get the event id of this `SyncTimelineEvent` if the event has any valid
|
||||
/// id.
|
||||
pub fn event_id(&self) -> Option<OwnedEventId> {
|
||||
self.event.get_field::<OwnedEventId>("event_id").ok().flatten()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Raw<AnySyncTimelineEvent>> for SyncRoomEvent {
|
||||
impl From<Raw<AnySyncTimelineEvent>> for SyncTimelineEvent {
|
||||
fn from(inner: Raw<AnySyncTimelineEvent>) -> Self {
|
||||
Self { encryption_info: None, event: inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RoomEvent> for SyncRoomEvent {
|
||||
fn from(o: RoomEvent) -> Self {
|
||||
// This conversion is unproblematic since a SyncRoomEvent is just a
|
||||
// RoomEvent without the room_id. By converting the raw value in this
|
||||
// way, we simply cause the `room_id` field in the json to be ignored by
|
||||
// a subsequent deserialization.
|
||||
impl From<TimelineEvent> for SyncTimelineEvent {
|
||||
fn from(o: TimelineEvent) -> Self {
|
||||
// This conversion is unproblematic since a SyncTimelineEvent is just a
|
||||
// TimelineEvent without the room_id. By converting the raw value in
|
||||
// this way, we simply cause the `room_id` field in the json to be
|
||||
// ignored by a subsequent deserialization.
|
||||
Self { encryption_info: o.encryption_info, event: o.event.cast() }
|
||||
}
|
||||
}
|
||||
@@ -158,7 +159,7 @@ impl SyncResponse {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RoomEvent {
|
||||
pub struct TimelineEvent {
|
||||
/// The actual event.
|
||||
pub event: Raw<AnyTimelineEvent>,
|
||||
/// The encryption info about the event. Will be `None` if the event was not
|
||||
@@ -258,7 +259,7 @@ pub struct Timeline {
|
||||
pub prev_batch: Option<String>,
|
||||
|
||||
/// A list of events.
|
||||
pub events: Vec<SyncRoomEvent>,
|
||||
pub events: Vec<SyncTimelineEvent>,
|
||||
}
|
||||
|
||||
impl Timeline {
|
||||
@@ -282,7 +283,7 @@ pub struct TimelineSlice {
|
||||
pub limited: bool,
|
||||
|
||||
/// A list of events.
|
||||
pub events: Vec<SyncRoomEvent>,
|
||||
pub events: Vec<SyncTimelineEvent>,
|
||||
|
||||
/// Whether this is a timeline slice obtained from a `SyncResponse`
|
||||
pub sync: bool,
|
||||
@@ -290,7 +291,7 @@ pub struct TimelineSlice {
|
||||
|
||||
impl TimelineSlice {
|
||||
pub fn new(
|
||||
events: Vec<SyncRoomEvent>,
|
||||
events: Vec<SyncTimelineEvent>,
|
||||
start: String,
|
||||
end: Option<String>,
|
||||
limited: bool,
|
||||
@@ -379,7 +380,7 @@ mod tests {
|
||||
user_id, MilliSecondsSinceUnixEpoch,
|
||||
};
|
||||
|
||||
use super::{RoomEvent, SyncRoomEvent};
|
||||
use super::{SyncTimelineEvent, TimelineEvent};
|
||||
|
||||
#[test]
|
||||
fn room_event_to_sync_room_event() {
|
||||
@@ -395,9 +396,9 @@ mod tests {
|
||||
};
|
||||
|
||||
let room_event =
|
||||
RoomEvent { event: Raw::new(&event).unwrap().cast(), encryption_info: None };
|
||||
TimelineEvent { event: Raw::new(&event).unwrap().cast(), encryption_info: None };
|
||||
|
||||
let converted_room_event: SyncRoomEvent = room_event.into();
|
||||
let converted_room_event: SyncTimelineEvent = room_event.into();
|
||||
|
||||
let converted_event: AnySyncTimelineEvent =
|
||||
converted_room_event.event.deserialize().unwrap();
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::{
|
||||
|
||||
use dashmap::DashMap;
|
||||
use matrix_sdk_common::{
|
||||
deserialized_responses::{AlgorithmInfo, EncryptionInfo, RoomEvent, VerificationState},
|
||||
deserialized_responses::{AlgorithmInfo, EncryptionInfo, TimelineEvent, VerificationState},
|
||||
locks::Mutex,
|
||||
};
|
||||
use ruma::{
|
||||
@@ -1052,7 +1052,7 @@ impl OlmMachine {
|
||||
room_id: &RoomId,
|
||||
event: &EncryptedEvent,
|
||||
content: &SupportedEventEncryptionSchemes<'_>,
|
||||
) -> MegolmResult<RoomEvent> {
|
||||
) -> MegolmResult<TimelineEvent> {
|
||||
if let Some(session) = self
|
||||
.store
|
||||
.get_inbound_group_session(
|
||||
@@ -1105,7 +1105,7 @@ impl OlmMachine {
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(RoomEvent { encryption_info: Some(encryption_info), event: decrypted_event })
|
||||
Ok(TimelineEvent { encryption_info: Some(encryption_info), event: decrypted_event })
|
||||
} else {
|
||||
self.key_request_machine
|
||||
.create_outgoing_key_request(
|
||||
@@ -1132,7 +1132,7 @@ impl OlmMachine {
|
||||
&self,
|
||||
event: &Raw<EncryptedEvent>,
|
||||
room_id: &RoomId,
|
||||
) -> MegolmResult<RoomEvent> {
|
||||
) -> MegolmResult<TimelineEvent> {
|
||||
let event = event.deserialize()?;
|
||||
|
||||
let content = match &event.content.scheme {
|
||||
|
||||
@@ -34,7 +34,7 @@ use matrix_sdk_base::{
|
||||
MinimalStateEvent, RoomInfo,
|
||||
};
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use matrix_sdk_base::{deserialized_responses::SyncRoomEvent, store::BoxStream};
|
||||
use matrix_sdk_base::{deserialized_responses::SyncTimelineEvent, store::BoxStream};
|
||||
use matrix_sdk_store_encryption::{Error as EncryptionError, StoreCipher};
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use ruma::{
|
||||
@@ -976,7 +976,7 @@ impl IndexeddbStateStore {
|
||||
.get(&position_key)?
|
||||
.await?
|
||||
.map(|e| {
|
||||
self.deserialize_event::<SyncRoomEvent>(e)
|
||||
self.deserialize_event::<SyncTimelineEvent>(e)
|
||||
.map_err(StoreError::from)
|
||||
})
|
||||
.transpose()?
|
||||
@@ -1440,7 +1440,7 @@ impl IndexeddbStateStore {
|
||||
async fn room_timeline(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<(BoxStream<StoreResult<SyncRoomEvent>>, Option<String>)>> {
|
||||
) -> Result<Option<(BoxStream<StoreResult<SyncTimelineEvent>>, Option<String>)>> {
|
||||
let tx = self.inner.transaction_on_multi_with_mode(
|
||||
&[KEYS::ROOM_TIMELINE, KEYS::ROOM_TIMELINE_METADATA],
|
||||
IdbTransactionMode::Readonly,
|
||||
@@ -1463,7 +1463,7 @@ impl IndexeddbStateStore {
|
||||
|
||||
let end_token = tlm.end;
|
||||
#[allow(clippy::needless_collect)]
|
||||
let timeline: Vec<StoreResult<SyncRoomEvent>> = timeline
|
||||
let timeline: Vec<StoreResult<SyncTimelineEvent>> = timeline
|
||||
.get_all_with_key(&self.encode_to_range(KEYS::ROOM_TIMELINE, room_id)?)?
|
||||
.await?
|
||||
.iter()
|
||||
@@ -1644,7 +1644,7 @@ impl StateStore for IndexeddbStateStore {
|
||||
async fn room_timeline(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> StoreResult<Option<(BoxStream<StoreResult<SyncRoomEvent>>, Option<String>)>> {
|
||||
) -> StoreResult<Option<(BoxStream<StoreResult<SyncTimelineEvent>>, Option<String>)>> {
|
||||
self.room_timeline(room_id).await.map_err(|e| e.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ use matrix_sdk_base::{
|
||||
MinimalStateEvent, RoomInfo,
|
||||
};
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use matrix_sdk_base::{deserialized_responses::SyncRoomEvent, store::BoxStream};
|
||||
use matrix_sdk_base::{deserialized_responses::SyncTimelineEvent, store::BoxStream};
|
||||
use matrix_sdk_store_encryption::{Error as KeyEncryptionError, StoreCipher};
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use ruma::{
|
||||
@@ -1296,7 +1296,7 @@ impl SledStateStore {
|
||||
async fn room_timeline(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<(BoxStream<StoreResult<SyncRoomEvent>>, Option<String>)>> {
|
||||
) -> Result<Option<(BoxStream<StoreResult<SyncTimelineEvent>>, Option<String>)>> {
|
||||
let db = self.clone();
|
||||
let key = self.encode_key(TIMELINE_METADATA, room_id);
|
||||
let metadata: Option<TimelineMetadata> = db
|
||||
@@ -1469,7 +1469,7 @@ impl SledStateStore {
|
||||
.room_timeline
|
||||
.get(position_key.as_ref())?
|
||||
.map(|e| {
|
||||
self.deserialize_value::<SyncRoomEvent>(&e)
|
||||
self.deserialize_value::<SyncTimelineEvent>(&e)
|
||||
.map_err(SledStoreError::from)
|
||||
})
|
||||
.transpose()?
|
||||
@@ -1711,7 +1711,7 @@ impl StateStore for SledStateStore {
|
||||
async fn room_timeline(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> StoreResult<Option<(BoxStream<StoreResult<SyncRoomEvent>>, Option<String>)>> {
|
||||
) -> StoreResult<Option<(BoxStream<StoreResult<SyncTimelineEvent>>, Option<String>)>> {
|
||||
self.room_timeline(room_id).await.map_err(|e| e.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ use std::{
|
||||
|
||||
use anymap2::any::CloneAnySendSync;
|
||||
use matrix_sdk_base::{
|
||||
deserialized_responses::{EncryptionInfo, SyncRoomEvent},
|
||||
deserialized_responses::{EncryptionInfo, SyncTimelineEvent},
|
||||
SendOutsideWasm, SyncOutsideWasm,
|
||||
};
|
||||
use ruma::{events::AnySyncStateEvent, serde::Raw, OwnedRoomId};
|
||||
@@ -366,7 +366,7 @@ impl Client {
|
||||
pub(crate) async fn handle_sync_timeline_events(
|
||||
&self,
|
||||
room: &Option<room::Room>,
|
||||
timeline_events: &[SyncRoomEvent],
|
||||
timeline_events: &[SyncTimelineEvent],
|
||||
) -> serde_json::Result<()> {
|
||||
#[derive(Deserialize)]
|
||||
struct TimelineEventDetails<'a> {
|
||||
|
||||
@@ -5,12 +5,12 @@ use futures_channel::mpsc;
|
||||
use futures_core::stream::Stream;
|
||||
use futures_util::{SinkExt, TryStreamExt};
|
||||
use matrix_sdk_base::{
|
||||
deserialized_responses::{MembersResponse, RoomEvent},
|
||||
deserialized_responses::{MembersResponse, TimelineEvent},
|
||||
store::StateStoreExt,
|
||||
};
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use matrix_sdk_base::{
|
||||
deserialized_responses::{SyncRoomEvent, TimelineSlice},
|
||||
deserialized_responses::{SyncTimelineEvent, TimelineSlice},
|
||||
TimelineStreamError,
|
||||
};
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
@@ -87,7 +87,7 @@ pub struct Messages {
|
||||
pub end: Option<String>,
|
||||
|
||||
/// A list of room events.
|
||||
pub chunk: Vec<RoomEvent>,
|
||||
pub chunk: Vec<TimelineEvent>,
|
||||
|
||||
/// A list of state events relevant to showing the `chunk`.
|
||||
pub state: Vec<Raw<AnyStateEvent>>,
|
||||
@@ -245,7 +245,7 @@ impl Common {
|
||||
chunk: http_response
|
||||
.chunk
|
||||
.into_iter()
|
||||
.map(|event| RoomEvent { event, encryption_info: None })
|
||||
.map(|event| TimelineEvent { event, encryption_info: None })
|
||||
.collect(),
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
chunk: Vec::with_capacity(http_response.chunk.len()),
|
||||
@@ -262,10 +262,10 @@ impl Common {
|
||||
if let Ok(event) = machine.decrypt_room_event(event.cast_ref(), room_id).await {
|
||||
event
|
||||
} else {
|
||||
RoomEvent { event, encryption_info: None }
|
||||
TimelineEvent { event, encryption_info: None }
|
||||
}
|
||||
} else {
|
||||
RoomEvent { event, encryption_info: None }
|
||||
TimelineEvent { event, encryption_info: None }
|
||||
};
|
||||
|
||||
response.chunk.push(decrypted_event);
|
||||
@@ -275,7 +275,7 @@ impl Common {
|
||||
http_response
|
||||
.chunk
|
||||
.into_iter()
|
||||
.map(|event| RoomEvent { event, encryption_info: None }),
|
||||
.map(|event| TimelineEvent { event, encryption_info: None }),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -369,8 +369,10 @@ impl Common {
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
pub async fn timeline(
|
||||
&self,
|
||||
) -> Result<(impl Stream<Item = SyncRoomEvent>, impl Stream<Item = Result<SyncRoomEvent>>)>
|
||||
{
|
||||
) -> Result<(
|
||||
impl Stream<Item = SyncTimelineEvent>,
|
||||
impl Stream<Item = Result<SyncTimelineEvent>>,
|
||||
)> {
|
||||
let (forward_store, backward_store) = self.inner.timeline().await?;
|
||||
|
||||
let room = self.to_owned();
|
||||
@@ -438,7 +440,7 @@ impl Common {
|
||||
/// # });
|
||||
/// ```
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
pub async fn timeline_forward(&self) -> Result<impl Stream<Item = SyncRoomEvent>> {
|
||||
pub async fn timeline_forward(&self) -> Result<impl Stream<Item = SyncTimelineEvent>> {
|
||||
Ok(self.inner.timeline_forward().await?)
|
||||
}
|
||||
|
||||
@@ -502,7 +504,7 @@ impl Common {
|
||||
/// # });
|
||||
/// ```
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
pub async fn timeline_backward(&self) -> Result<impl Stream<Item = Result<SyncRoomEvent>>> {
|
||||
pub async fn timeline_backward(&self) -> Result<impl Stream<Item = Result<SyncTimelineEvent>>> {
|
||||
let backward_store = self.inner.timeline_backward().await?;
|
||||
|
||||
let room = self.to_owned();
|
||||
@@ -535,7 +537,7 @@ impl Common {
|
||||
});
|
||||
let messages = self.messages(options).await?;
|
||||
let timeline = TimelineSlice::new(
|
||||
messages.chunk.into_iter().map(SyncRoomEvent::from).collect(),
|
||||
messages.chunk.into_iter().map(SyncTimelineEvent::from).collect(),
|
||||
messages.start,
|
||||
messages.end,
|
||||
false,
|
||||
@@ -549,7 +551,7 @@ impl Common {
|
||||
}
|
||||
|
||||
/// Fetch the event with the given `EventId` in this room.
|
||||
pub async fn event(&self, event_id: &EventId) -> Result<RoomEvent> {
|
||||
pub async fn event(&self, event_id: &EventId) -> Result<TimelineEvent> {
|
||||
let request = get_room_event::v3::Request::new(self.room_id(), event_id);
|
||||
let event = self.client.send(request, None).await?.event;
|
||||
|
||||
@@ -563,11 +565,11 @@ impl Common {
|
||||
return Ok(event);
|
||||
}
|
||||
}
|
||||
Ok(RoomEvent { event, encryption_info: None })
|
||||
Ok(TimelineEvent { event, encryption_info: None })
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "e2e-encryption"))]
|
||||
Ok(RoomEvent { event, encryption_info: None })
|
||||
Ok(TimelineEvent { event, encryption_info: None })
|
||||
}
|
||||
|
||||
pub(crate) async fn request_members(&self) -> Result<Option<MembersResponse>> {
|
||||
@@ -1031,7 +1033,7 @@ impl Common {
|
||||
pub async fn decrypt_event(
|
||||
&self,
|
||||
event: &Raw<OriginalSyncRoomEncryptedEvent>,
|
||||
) -> Result<RoomEvent> {
|
||||
) -> Result<TimelineEvent> {
|
||||
if let Some(machine) = self.client.olm_machine() {
|
||||
Ok(machine.decrypt_room_event(event.cast_ref(), self.inner.room_id()).await?)
|
||||
} else {
|
||||
|
||||
@@ -179,7 +179,7 @@ async fn test_state_event_getting() {
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
async fn room_timeline_with_remove() {
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk::deserialized_responses::SyncRoomEvent;
|
||||
use matrix_sdk::deserialized_responses::SyncTimelineEvent;
|
||||
use wiremock::matchers::query_param;
|
||||
|
||||
let (client, server) = logged_in_client().await;
|
||||
@@ -245,8 +245,10 @@ async fn room_timeline_with_remove() {
|
||||
"$098237280074GZeOm2:localhost",
|
||||
];
|
||||
|
||||
let forward_events =
|
||||
forward_stream.take(expected_forward_events.len()).collect::<Vec<SyncRoomEvent>>().await;
|
||||
let forward_events = forward_stream
|
||||
.take(expected_forward_events.len())
|
||||
.collect::<Vec<SyncTimelineEvent>>()
|
||||
.await;
|
||||
|
||||
for (r, e) in forward_events.into_iter().zip(expected_forward_events.iter()) {
|
||||
assert_eq!(&r.event_id().unwrap().as_str(), e);
|
||||
@@ -264,7 +266,7 @@ async fn room_timeline_with_remove() {
|
||||
|
||||
let backward_events = backward_stream
|
||||
.take(expected_backwards_events.len())
|
||||
.collect::<Vec<matrix_sdk::Result<SyncRoomEvent>>>()
|
||||
.collect::<Vec<matrix_sdk::Result<SyncTimelineEvent>>>()
|
||||
.await;
|
||||
|
||||
for (r, e) in backward_events.into_iter().zip(expected_backwards_events.iter()) {
|
||||
@@ -276,7 +278,7 @@ async fn room_timeline_with_remove() {
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
async fn room_timeline() {
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk::deserialized_responses::SyncRoomEvent;
|
||||
use matrix_sdk::deserialized_responses::SyncTimelineEvent;
|
||||
use wiremock::matchers::query_param;
|
||||
|
||||
let (client, server) = logged_in_client().await;
|
||||
@@ -325,8 +327,10 @@ async fn room_timeline() {
|
||||
"$098237280074GZeOm2:localhost",
|
||||
];
|
||||
|
||||
let forward_events =
|
||||
forward_stream.take(expected_forward_events.len()).collect::<Vec<SyncRoomEvent>>().await;
|
||||
let forward_events = forward_stream
|
||||
.take(expected_forward_events.len())
|
||||
.collect::<Vec<SyncTimelineEvent>>()
|
||||
.await;
|
||||
|
||||
for (r, e) in forward_events.into_iter().zip(expected_forward_events.iter()) {
|
||||
assert_eq!(&r.event_id().unwrap().as_str(), e);
|
||||
@@ -354,7 +358,7 @@ async fn room_timeline() {
|
||||
|
||||
let backward_events = backward_stream
|
||||
.take(expected_backwards_events.len())
|
||||
.collect::<Vec<matrix_sdk::Result<SyncRoomEvent>>>()
|
||||
.collect::<Vec<matrix_sdk::Result<SyncTimelineEvent>>>()
|
||||
.await;
|
||||
|
||||
for (r, e) in backward_events.into_iter().zip(expected_backwards_events.iter()) {
|
||||
|
||||
@@ -28,7 +28,7 @@ impl TransactionBuilder {
|
||||
}
|
||||
|
||||
/// Add a room event.
|
||||
pub fn add_room_event(&mut self, event: TimelineTestEvent) -> &mut Self {
|
||||
pub fn add_timeline_event(&mut self, event: TimelineTestEvent) -> &mut Self {
|
||||
let mut val = event.into_json_value();
|
||||
value_with_room_id(&mut val);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user