chore(ui): simplify the test by using more of the TimelineItemContent helpers
This commit is contained in:
committed by
Stefan Ceriu
parent
f3baf7efd2
commit
db18e7fd74
@@ -344,6 +344,13 @@ impl TimelineItemContent {
|
||||
as_variant!(&aggregated.kind, AggregatedTimelineItemContentKind::Poll)
|
||||
}
|
||||
|
||||
pub fn as_sticker(&self) -> Option<&Sticker> {
|
||||
let aggregated = as_variant!(self, Self::Aggregated)
|
||||
.map(|f| as_variant!(&f.kind, AggregatedTimelineItemContentKind::Sticker));
|
||||
|
||||
aggregated.unwrap_or(None)
|
||||
}
|
||||
|
||||
/// If `self` is of the [`UnableToDecrypt`][Self::UnableToDecrypt] variant,
|
||||
/// return the inner [`EncryptedMessage`].
|
||||
pub fn as_unable_to_decrypt(&self) -> Option<&EncryptedMessage> {
|
||||
@@ -380,6 +387,18 @@ impl TimelineItemContent {
|
||||
)
|
||||
}
|
||||
|
||||
/// Check whether this item's content is a
|
||||
/// [`Sticker`][AggregatedTimelineItemContentKind::Sticker].
|
||||
pub fn is_sticker(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Sticker(_),
|
||||
..
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// These constructors could also be `From` implementations, but that would
|
||||
// allow users to call them directly, which should not be supported
|
||||
pub(crate) fn message(
|
||||
|
||||
@@ -429,11 +429,7 @@ impl EventTimelineItem {
|
||||
// This must be in sync with the early returns of `Timeline::send_reply`
|
||||
if self.event_id().is_none() {
|
||||
false
|
||||
} else if let TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(_),
|
||||
..
|
||||
}) = self.content()
|
||||
{
|
||||
} else if self.content.is_message() {
|
||||
true
|
||||
} else {
|
||||
self.latest_json().is_some()
|
||||
|
||||
@@ -150,13 +150,7 @@ async fn test_sticker() {
|
||||
.await;
|
||||
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_matches!(
|
||||
item.content(),
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Sticker(_),
|
||||
..
|
||||
})
|
||||
);
|
||||
assert!(item.content().is_sticker());
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
@@ -351,12 +345,7 @@ async fn test_sanitized() {
|
||||
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let event = item.as_event().unwrap();
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = event.content()
|
||||
);
|
||||
assert_let!(Some(message) = event.content().as_message());
|
||||
assert_let!(MessageType::Text(text) = message.msgtype());
|
||||
assert_eq!(
|
||||
text.formatted.as_ref().unwrap().body,
|
||||
|
||||
@@ -32,9 +32,6 @@ use ruma::{
|
||||
use stream_assert::{assert_next_matches, assert_pending};
|
||||
|
||||
use super::TestTimeline;
|
||||
use crate::timeline::{
|
||||
AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, TimelineItemContent,
|
||||
};
|
||||
|
||||
#[async_test]
|
||||
async fn test_live_redacted() {
|
||||
@@ -76,12 +73,7 @@ async fn test_live_sanitized() {
|
||||
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let first_event = item.as_event().unwrap();
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = first_event.content()
|
||||
);
|
||||
assert_let!(Some(message) = first_event.content().as_message());
|
||||
assert_let!(MessageType::Text(text) = message.msgtype());
|
||||
assert_eq!(text.body, "**original** message");
|
||||
assert_eq!(text.formatted.as_ref().unwrap().body, "<strong>original</strong> message");
|
||||
@@ -106,12 +98,7 @@ async fn test_live_sanitized() {
|
||||
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { index: 1, value } => value);
|
||||
let first_event = item.as_event().unwrap();
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = first_event.content()
|
||||
);
|
||||
assert_let!(Some(message) = first_event.content().as_message());
|
||||
assert_let!(MessageType::Text(text) = message.msgtype());
|
||||
assert_eq!(text.body, new_plain_content);
|
||||
assert_eq!(text.formatted.as_ref().unwrap().body, " <strong>better</strong> message");
|
||||
@@ -156,12 +143,7 @@ async fn test_aggregated_sanitized() {
|
||||
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let first_event = item.as_event().unwrap();
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = first_event.content()
|
||||
);
|
||||
assert_let!(Some(message) = first_event.content().as_message());
|
||||
assert_let!(MessageType::Text(text) = message.msgtype());
|
||||
assert_eq!(text.body, "!!edited!! **better** message");
|
||||
assert_eq!(text.formatted.as_ref().unwrap().body, " <strong>better</strong> message");
|
||||
@@ -213,12 +195,7 @@ async fn test_edit_updates_encryption_info() {
|
||||
VerificationState::Verified
|
||||
);
|
||||
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = first_event.content()
|
||||
);
|
||||
assert_let!(Some(message) = first_event.content().as_message());
|
||||
assert_let!(MessageType::Text(text) = message.msgtype());
|
||||
assert_eq!(text.body, "**original** message");
|
||||
|
||||
@@ -247,12 +224,7 @@ async fn test_edit_updates_encryption_info() {
|
||||
VerificationState::Unverified(VerificationLevel::UnverifiedIdentity)
|
||||
);
|
||||
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = first_event.content()
|
||||
);
|
||||
assert_let!(Some(message) = first_event.content().as_message());
|
||||
assert_let!(MessageType::Text(text) = message.msgtype());
|
||||
assert_eq!(text.body, "!!edited!! **better** message");
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ use super::TestTimeline;
|
||||
use crate::{
|
||||
timeline::{
|
||||
tests::{TestRoomDataProvider, TestTimelineBuilder},
|
||||
AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, EncryptedMessage,
|
||||
TimelineDetails, TimelineItemContent,
|
||||
EncryptedMessage, TimelineDetails, TimelineItemContent,
|
||||
},
|
||||
unable_to_decrypt_hook::{UnableToDecryptHook, UnableToDecryptInfo, UtdHookManager},
|
||||
};
|
||||
@@ -167,12 +166,7 @@ async fn test_retry_message_decryption() {
|
||||
);
|
||||
let event = item.as_event().unwrap();
|
||||
assert_matches!(event.encryption_info(), Some(_));
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = event.content()
|
||||
);
|
||||
assert_let!(Some(message) = event.content().as_message());
|
||||
assert_eq!(message.body(), "It's a secret to everybody");
|
||||
assert!(!event.is_highlighted());
|
||||
|
||||
@@ -374,12 +368,7 @@ async fn test_retry_edit_decryption() {
|
||||
|
||||
assert_matches!(item.encryption_info(), Some(_));
|
||||
assert_matches!(item.latest_edit_json(), Some(_));
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
assert!(msg.is_edited());
|
||||
assert_eq!(msg.body(), "This is Error");
|
||||
|
||||
@@ -603,12 +592,7 @@ async fn test_retry_message_decryption_highlighted() {
|
||||
assert_next_matches_with_timeout!(stream, VectorDiff::Set { index: 1, value } => value);
|
||||
let event = item.as_event().unwrap();
|
||||
assert_matches!(event.encryption_info(), Some(_));
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = event.content()
|
||||
);
|
||||
assert_let!(Some(message) = event.content().as_message());
|
||||
assert_eq!(message.body(), "A secret to everybody but Alice");
|
||||
assert!(event.is_highlighted());
|
||||
}
|
||||
@@ -905,12 +889,7 @@ async fn test_retry_decryption_updates_response() {
|
||||
{
|
||||
let event = assert_next_matches!(stream, VectorDiff::Set { index: 0, value } => value);
|
||||
assert_matches!(event.encryption_info(), Some(_));
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = event.content()
|
||||
);
|
||||
assert_let!(Some(message) = event.content().as_message());
|
||||
assert_eq!(message.body(), "It's a secret to everybody");
|
||||
assert!(!event.is_highlighted());
|
||||
}
|
||||
|
||||
@@ -59,12 +59,7 @@ async fn test_default_filter() {
|
||||
|
||||
// The edit was applied.
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { index: 1, value } => value);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = item.as_event().unwrap().content()
|
||||
);
|
||||
assert_let!(Some(message) = item.as_event().unwrap().content().as_message());
|
||||
assert_let!(MessageType::Text(text) = message.msgtype());
|
||||
assert_eq!(text.body, "The _edited_ first message");
|
||||
|
||||
|
||||
@@ -29,10 +29,7 @@ use ruma::{
|
||||
use stream_assert::{assert_next_matches, assert_pending};
|
||||
|
||||
use super::{ReadReceiptMap, TestRoomDataProvider};
|
||||
use crate::timeline::{
|
||||
controller::TimelineSettings, tests::TestTimelineBuilder, AggregatedTimelineItemContent,
|
||||
AggregatedTimelineItemContentKind,
|
||||
};
|
||||
use crate::timeline::{controller::TimelineSettings, tests::TestTimelineBuilder};
|
||||
|
||||
fn filter_notice(ev: &AnySyncTimelineEvent, _room_version: &RoomVersionId) -> bool {
|
||||
match ev {
|
||||
@@ -375,7 +372,6 @@ async fn test_read_receipts_updates_on_back_paginated_filtered_events() {
|
||||
async fn test_read_receipts_updates_on_message_decryption() {
|
||||
use std::{io::Cursor, iter};
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use assert_matches2::assert_let;
|
||||
use matrix_sdk_base::crypto::{decrypt_room_key_export, OlmMachine};
|
||||
use ruma::{
|
||||
@@ -454,13 +450,7 @@ async fn test_read_receipts_updates_on_message_decryption() {
|
||||
// The first event only has Carol's receipt.
|
||||
let clear_item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let clear_event = clear_item.as_event().unwrap();
|
||||
assert_matches!(
|
||||
clear_event.content(),
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(_),
|
||||
..
|
||||
})
|
||||
);
|
||||
assert!(clear_event.content().is_message());
|
||||
assert_eq!(clear_event.read_receipts().len(), 1);
|
||||
assert!(clear_event.read_receipts().get(*CAROL).is_some());
|
||||
|
||||
@@ -499,13 +489,7 @@ async fn test_read_receipts_updates_on_message_decryption() {
|
||||
let clear_item =
|
||||
assert_next_matches_with_timeout!(stream, VectorDiff::Set { index: 1, value } => value);
|
||||
let clear_event = clear_item.as_event().unwrap();
|
||||
assert_matches!(
|
||||
clear_event.content(),
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(_),
|
||||
..
|
||||
})
|
||||
);
|
||||
assert!(clear_event.content().is_message());
|
||||
assert_eq!(clear_event.read_receipts().len(), 2);
|
||||
assert!(clear_event.read_receipts().get(*CAROL).is_some());
|
||||
assert!(clear_event.read_receipts().get(*BOB).is_some());
|
||||
|
||||
@@ -25,8 +25,7 @@ use stream_assert::assert_next_matches;
|
||||
|
||||
use super::TestTimeline;
|
||||
use crate::timeline::{
|
||||
event_item::RemoteEventOrigin, AggregatedTimelineItemContent,
|
||||
AggregatedTimelineItemContentKind, AnyOtherFullStateEventContent, TimelineDetails,
|
||||
event_item::RemoteEventOrigin, AnyOtherFullStateEventContent, TimelineDetails,
|
||||
TimelineItemContent,
|
||||
};
|
||||
|
||||
@@ -66,13 +65,7 @@ async fn test_redact_replied_to_event() {
|
||||
timeline.handle_live_event(f.text_msg("Hello, world!").sender(&ALICE)).await;
|
||||
|
||||
let first_item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_matches!(
|
||||
first_item.content(),
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(_),
|
||||
..
|
||||
})
|
||||
);
|
||||
assert!(first_item.content().is_message());
|
||||
let first_event: OriginalSyncRoomMessageEvent =
|
||||
first_item.original_json().unwrap().deserialize_as().unwrap();
|
||||
|
||||
@@ -84,13 +77,7 @@ async fn test_redact_replied_to_event() {
|
||||
let aggregated = second_item.content().as_aggregated().unwrap();
|
||||
let in_reply_to = aggregated.in_reply_to.clone().unwrap();
|
||||
assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event);
|
||||
assert_matches!(
|
||||
replied_to_event.content(),
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(_),
|
||||
..
|
||||
})
|
||||
);
|
||||
assert!(replied_to_event.content().is_message());
|
||||
|
||||
timeline.handle_live_event(f.redaction(first_item.event_id().unwrap()).sender(&ALICE)).await;
|
||||
|
||||
|
||||
@@ -22,10 +22,7 @@ use matrix_sdk::{
|
||||
executor::spawn, ruma::MilliSecondsSinceUnixEpoch, test_utils::mocks::MatrixMockServer,
|
||||
};
|
||||
use matrix_sdk_test::{async_test, event_factory::EventFactory, JoinedRoomBuilder};
|
||||
use matrix_sdk_ui::timeline::{
|
||||
AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, EventSendState, RoomExt,
|
||||
TimelineItemContent,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{EventSendState, RoomExt};
|
||||
use ruma::{
|
||||
event_id,
|
||||
events::room::message::{MessageType, RoomMessageEventContent},
|
||||
@@ -72,12 +69,7 @@ async fn test_echo() {
|
||||
assert_let!(VectorDiff::PushBack { value: local_echo } = &timeline_updates[0]);
|
||||
let item = local_echo.as_event().unwrap();
|
||||
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
assert_let!(MessageType::Text(text) = msg.msgtype());
|
||||
assert_eq!(text.body, "Hello, World!");
|
||||
assert!(item.event_id().is_none());
|
||||
|
||||
@@ -121,13 +121,7 @@ async fn test_edit() {
|
||||
assert!(item.original_json().is_some());
|
||||
assert_eq!(item.read_receipts().len(), 1, "implicit read receipt");
|
||||
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
in_reply_to,
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
assert_matches!(item.latest_edit_json(), None);
|
||||
assert_let!(MessageType::Text(TextMessageEventContent { body, .. }) = msg.msgtype());
|
||||
assert_eq!(body, "Test");
|
||||
@@ -569,12 +563,7 @@ async fn test_send_edit_poll() {
|
||||
.await;
|
||||
|
||||
let poll_event = assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => value);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Poll(poll),
|
||||
..
|
||||
}) = poll_event.content()
|
||||
);
|
||||
assert_let!(Some(poll) = poll_event.content().as_poll());
|
||||
let poll_results = poll.results();
|
||||
assert_eq!(poll_results.question, "Test");
|
||||
assert_eq!(poll_results.answers.len(), 2);
|
||||
@@ -611,12 +600,7 @@ async fn test_send_edit_poll() {
|
||||
// a separate edit send state.
|
||||
assert_matches!(edit_item.send_state(), None);
|
||||
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Poll(edited_poll),
|
||||
..
|
||||
}) = edit_item.content()
|
||||
);
|
||||
assert_let!(Some(edited_poll) = edit_item.content().as_poll());
|
||||
let edited_poll_results = edited_poll.results();
|
||||
assert_eq!(edited_poll_results.question, "Edited Test");
|
||||
assert_eq!(edited_poll_results.answers.len(), 3);
|
||||
|
||||
@@ -22,10 +22,7 @@ use matrix_sdk::{
|
||||
assert_let_timeout, attachment::AttachmentConfig, test_utils::mocks::MatrixMockServer,
|
||||
};
|
||||
use matrix_sdk_test::{async_test, event_factory::EventFactory, JoinedRoomBuilder, ALICE};
|
||||
use matrix_sdk_ui::timeline::{
|
||||
AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, AttachmentSource,
|
||||
EventSendState, RoomExt, TimelineItemContent,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{AttachmentSource, EventSendState, RoomExt};
|
||||
use ruma::{
|
||||
event_id,
|
||||
events::room::{message::MessageType, MediaSource},
|
||||
@@ -79,12 +76,7 @@ async fn test_send_attachment_from_file() {
|
||||
|
||||
// Sanity check.
|
||||
assert_let_timeout!(Some(VectorDiff::PushBack { value: item }) = timeline_stream.next());
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
assert_eq!(msg.body(), "hello");
|
||||
|
||||
// No other updates.
|
||||
@@ -113,12 +105,7 @@ async fn test_send_attachment_from_file() {
|
||||
{
|
||||
assert_let_timeout!(Some(VectorDiff::PushBack { value: item }) = timeline_stream.next());
|
||||
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
|
||||
// Body is the caption, because there's both a caption and filename.
|
||||
assert_eq!(msg.body(), "caption");
|
||||
@@ -137,12 +124,7 @@ async fn test_send_attachment_from_file() {
|
||||
assert_let_timeout!(
|
||||
Some(VectorDiff::Set { index: 1, value: item }) = timeline_stream.next()
|
||||
);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
|
||||
assert_eq!(get_filename_and_caption(msg.msgtype()), ("test.bin", Some("caption")));
|
||||
|
||||
@@ -191,12 +173,7 @@ async fn test_send_attachment_from_bytes() {
|
||||
|
||||
// Sanity check.
|
||||
assert_let_timeout!(Some(VectorDiff::PushBack { value: item }) = timeline_stream.next());
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
assert_eq!(msg.body(), "hello");
|
||||
|
||||
// No other updates.
|
||||
@@ -227,12 +204,7 @@ async fn test_send_attachment_from_bytes() {
|
||||
{
|
||||
assert_let_timeout!(Some(VectorDiff::PushBack { value: item }) = timeline_stream.next());
|
||||
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
|
||||
// Body is the caption, because there's both a caption and filename.
|
||||
assert_eq!(msg.body(), "caption");
|
||||
@@ -251,12 +223,7 @@ async fn test_send_attachment_from_bytes() {
|
||||
assert_let_timeout!(
|
||||
Some(VectorDiff::Set { index: 1, value: item }) = timeline_stream.next()
|
||||
);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
|
||||
assert_eq!(get_filename_and_caption(msg.msgtype()), (filename, Some("caption")));
|
||||
|
||||
@@ -309,12 +276,7 @@ async fn test_react_to_local_media() {
|
||||
|
||||
let item_id = {
|
||||
assert_let_timeout!(Some(VectorDiff::PushBack { value: item }) = timeline_stream.next());
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
assert_eq!(get_filename_and_caption(msg.msgtype()), ("test.bin", None));
|
||||
|
||||
// The item starts with no reactions.
|
||||
@@ -327,12 +289,7 @@ async fn test_react_to_local_media() {
|
||||
timeline.toggle_reaction(&item_id, "🤪").await.unwrap();
|
||||
|
||||
assert_let_timeout!(Some(VectorDiff::Set { index: 0, value: item }) = timeline_stream.next());
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = item.content().as_message());
|
||||
assert_eq!(get_filename_and_caption(msg.msgtype()), ("test.bin", None));
|
||||
|
||||
// There's a reaction for the current user for the given emoji.
|
||||
|
||||
@@ -28,7 +28,6 @@ use matrix_sdk_test::{
|
||||
};
|
||||
use matrix_sdk_ui::{
|
||||
timeline::{
|
||||
AggregatedTimelineItemContent, AggregatedTimelineItemContentKind,
|
||||
AnyOtherFullStateEventContent, Error, EventSendState, RedactError, RoomExt,
|
||||
TimelineEventItemId, TimelineItemContent, VirtualTimelineItem,
|
||||
},
|
||||
@@ -100,25 +99,14 @@ async fn test_reaction() {
|
||||
// The new message starts with their author's read receipt.
|
||||
assert_let!(VectorDiff::PushBack { value: message } = &timeline_updates[0]);
|
||||
let event_item = message.as_event().unwrap();
|
||||
assert_matches!(
|
||||
event_item.content(),
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(_),
|
||||
..
|
||||
})
|
||||
);
|
||||
assert!(event_item.content().is_message());
|
||||
assert_eq!(event_item.read_receipts().len(), 1);
|
||||
|
||||
// The new message is getting the reaction, which implies an implicit read
|
||||
// receipt that's obtained first.
|
||||
assert_let!(VectorDiff::Set { index: 0, value: updated_message } = &timeline_updates[1]);
|
||||
let event_item = updated_message.as_event().unwrap();
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = event_item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = event_item.content().as_message());
|
||||
assert!(!msg.is_edited());
|
||||
assert_eq!(event_item.read_receipts().len(), 2);
|
||||
assert_eq!(event_item.content().reactions().len(), 0);
|
||||
@@ -126,12 +114,7 @@ async fn test_reaction() {
|
||||
// Then the reaction is taken into account.
|
||||
assert_let!(VectorDiff::Set { index: 0, value: updated_message } = &timeline_updates[2]);
|
||||
let event_item = updated_message.as_event().unwrap();
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = event_item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = event_item.content().as_message());
|
||||
assert!(!msg.is_edited());
|
||||
assert_eq!(event_item.read_receipts().len(), 2);
|
||||
assert_eq!(event_item.content().reactions().len(), 1);
|
||||
@@ -159,12 +142,7 @@ async fn test_reaction() {
|
||||
|
||||
assert_let!(VectorDiff::Set { index: 1, value: updated_message } = &timeline_updates[0]);
|
||||
let event_item = updated_message.as_event().unwrap();
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = event_item.content()
|
||||
);
|
||||
assert_let!(Some(msg) = event_item.content().as_message());
|
||||
assert!(!msg.is_edited());
|
||||
assert_eq!(event_item.content().reactions().len(), 0);
|
||||
|
||||
@@ -395,13 +373,7 @@ async fn test_read_marker() {
|
||||
assert_eq!(timeline_updates.len(), 2);
|
||||
|
||||
assert_let!(VectorDiff::PushBack { value: message } = &timeline_updates[0]);
|
||||
assert_matches!(
|
||||
message.as_event().unwrap().content(),
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(_),
|
||||
..
|
||||
})
|
||||
);
|
||||
assert!(message.as_event().unwrap().content().is_message());
|
||||
|
||||
assert_let!(VectorDiff::PushFront { value: date_divider } = &timeline_updates[1]);
|
||||
assert!(date_divider.is_date_divider());
|
||||
@@ -431,13 +403,7 @@ async fn test_read_marker() {
|
||||
assert_eq!(timeline_updates.len(), 2);
|
||||
|
||||
assert_let!(VectorDiff::PushBack { value: message } = &timeline_updates[0]);
|
||||
assert_matches!(
|
||||
message.as_event().unwrap().content(),
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(_),
|
||||
..
|
||||
})
|
||||
);
|
||||
assert!(message.as_event().unwrap().content().is_message());
|
||||
|
||||
assert_let!(VectorDiff::Insert { index: 2, value: marker } = &timeline_updates[1]);
|
||||
assert_matches!(marker.as_virtual().unwrap(), VirtualTimelineItem::ReadMarker);
|
||||
|
||||
@@ -33,10 +33,7 @@ use matrix_sdk_test::{
|
||||
async_test, event_factory::EventFactory, mocks::mock_encryption_state, JoinedRoomBuilder,
|
||||
StateTestEvent, SyncResponseBuilder, ALICE, BOB,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{
|
||||
AggregatedTimelineItemContent, AggregatedTimelineItemContentKind,
|
||||
AnyOtherFullStateEventContent, RoomExt, TimelineItemContent,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{AnyOtherFullStateEventContent, RoomExt, TimelineItemContent};
|
||||
use once_cell::sync::Lazy;
|
||||
use ruma::{
|
||||
events::{room::message::MessageType, FullStateEventContent},
|
||||
@@ -119,12 +116,7 @@ async fn test_back_pagination() {
|
||||
// `m.room.message`: “the world is big”
|
||||
{
|
||||
assert_let!(VectorDiff::PushBack { value: message } = &timeline_updates[2]);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = message.as_event().unwrap().content()
|
||||
);
|
||||
assert_let!(Some(msg) = message.as_event().unwrap().content().as_message());
|
||||
assert_let!(MessageType::Text(text) = msg.msgtype());
|
||||
assert_eq!(text.body, "the world is big");
|
||||
}
|
||||
@@ -132,12 +124,7 @@ async fn test_back_pagination() {
|
||||
// `m.room.message`: “hello world”
|
||||
{
|
||||
assert_let!(VectorDiff::PushBack { value: message } = &timeline_updates[3]);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = message.as_event().unwrap().content()
|
||||
);
|
||||
assert_let!(Some(msg) = message.as_event().unwrap().content().as_message());
|
||||
assert_let!(MessageType::Text(text) = msg.msgtype());
|
||||
assert_eq!(text.body, "hello world");
|
||||
}
|
||||
@@ -673,12 +660,7 @@ async fn test_empty_chunk() {
|
||||
// `m.room.message`: “the world is big”
|
||||
{
|
||||
assert_let!(VectorDiff::PushBack { value: message } = &timeline_updates[2]);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = message.as_event().unwrap().content()
|
||||
);
|
||||
assert_let!(Some(msg) = message.as_event().unwrap().content().as_message());
|
||||
assert_let!(MessageType::Text(text) = msg.msgtype());
|
||||
assert_eq!(text.body, "the world is big");
|
||||
}
|
||||
@@ -686,12 +668,7 @@ async fn test_empty_chunk() {
|
||||
// `m.room.name`: “hello world”
|
||||
{
|
||||
assert_let!(VectorDiff::PushBack { value: message } = &timeline_updates[3]);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = message.as_event().unwrap().content()
|
||||
);
|
||||
assert_let!(Some(msg) = message.as_event().unwrap().content().as_message());
|
||||
assert_let!(MessageType::Text(text) = msg.msgtype());
|
||||
assert_eq!(text.body, "hello world");
|
||||
}
|
||||
@@ -793,12 +770,7 @@ async fn test_until_num_items_with_empty_chunk() {
|
||||
// `m.room.message`: “the world is big”
|
||||
{
|
||||
assert_let!(VectorDiff::PushBack { value: message } = &timeline_updates[2]);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = message.as_event().unwrap().content()
|
||||
);
|
||||
assert_let!(Some(msg) = message.as_event().unwrap().content().as_message());
|
||||
assert_let!(MessageType::Text(text) = msg.msgtype());
|
||||
assert_eq!(text.body, "the world is big");
|
||||
}
|
||||
@@ -806,12 +778,7 @@ async fn test_until_num_items_with_empty_chunk() {
|
||||
// `m.room.name`: “hello world”
|
||||
{
|
||||
assert_let!(VectorDiff::PushBack { value: message } = &timeline_updates[3]);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = message.as_event().unwrap().content()
|
||||
);
|
||||
assert_let!(Some(msg) = message.as_event().unwrap().content().as_message());
|
||||
assert_let!(MessageType::Text(text) = msg.msgtype());
|
||||
assert_eq!(text.body, "hello world");
|
||||
}
|
||||
@@ -836,12 +803,7 @@ async fn test_until_num_items_with_empty_chunk() {
|
||||
assert_eq!(timeline_updates.len(), 1);
|
||||
|
||||
assert_let!(VectorDiff::Insert { index: 2, value: message } = &timeline_updates[0]);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = message.as_event().unwrap().content()
|
||||
);
|
||||
assert_let!(Some(msg) = message.as_event().unwrap().content().as_message());
|
||||
assert_let!(MessageType::Text(text) = msg.msgtype());
|
||||
assert_eq!(text.body, "hello room then");
|
||||
}
|
||||
|
||||
@@ -85,13 +85,7 @@ async fn test_in_reply_to_details() {
|
||||
|
||||
// We get the original message.
|
||||
assert_let!(VectorDiff::PushBack { value: first } = &timeline_updates[0]);
|
||||
assert_matches!(
|
||||
first.as_event().unwrap().content(),
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(_),
|
||||
..
|
||||
})
|
||||
);
|
||||
assert!(first.as_event().unwrap().content().is_message());
|
||||
|
||||
// We get the reply.
|
||||
assert_let!(VectorDiff::PushBack { value: second } = &timeline_updates[1]);
|
||||
@@ -459,12 +453,7 @@ async fn test_fetch_details_poll() {
|
||||
let in_reply_to = in_reply_to.clone().unwrap();
|
||||
assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event);
|
||||
assert_eq!(replied_to.sender(), *ALICE);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Poll(poll_state),
|
||||
..
|
||||
}) = replied_to.content()
|
||||
);
|
||||
assert_let!(Some(poll_state) = replied_to.content().as_poll());
|
||||
assert_eq!(
|
||||
poll_state.fallback_text().unwrap(),
|
||||
"What is the best color? A. Red, B. Blue, C. Green"
|
||||
@@ -575,12 +564,7 @@ async fn test_fetch_details_sticker() {
|
||||
let in_reply_to = in_reply_to.clone().unwrap();
|
||||
assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event);
|
||||
assert_eq!(replied_to.sender(), *ALICE);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Sticker(sticker),
|
||||
..
|
||||
}) = replied_to.content()
|
||||
);
|
||||
assert_let!(Some(sticker) = replied_to.content().as_sticker());
|
||||
assert_eq!(sticker.content().body, "sticker!");
|
||||
assert_matches!(&sticker.content().source, StickerMediaSource::Plain(src) => {
|
||||
assert_eq!(*src, media_src);
|
||||
|
||||
@@ -23,10 +23,7 @@ use matrix_sdk_test::{
|
||||
async_test, event_factory::EventFactory, mocks::mock_encryption_state, sync_timeline_event,
|
||||
GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, ALICE, BOB,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{
|
||||
AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, RoomExt, TimelineDetails,
|
||||
TimelineItemContent,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{RoomExt, TimelineDetails};
|
||||
use ruma::{
|
||||
event_id,
|
||||
events::room::{member::MembershipState, message::MessageType},
|
||||
@@ -124,12 +121,7 @@ async fn test_event_filter() {
|
||||
assert_eq!(first_event.event_id(), Some(first_event_id));
|
||||
assert_eq!(first_event.read_receipts().len(), 1, "implicit read receipt");
|
||||
assert_matches!(first_event.latest_edit_json(), None);
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = first_event.content()
|
||||
);
|
||||
assert_let!(Some(msg) = first_event.content().as_message());
|
||||
assert_matches!(msg.msgtype(), MessageType::Text(_));
|
||||
assert!(!msg.is_edited());
|
||||
|
||||
@@ -194,12 +186,7 @@ async fn test_event_filter() {
|
||||
let first_event = first.as_event().unwrap();
|
||||
assert!(first_event.read_receipts().is_empty());
|
||||
assert_matches!(first_event.latest_edit_json(), Some(_));
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(msg),
|
||||
..
|
||||
}) = first_event.content()
|
||||
);
|
||||
assert_let!(Some(msg) = first_event.content().as_message());
|
||||
assert_let!(MessageType::Text(text) = msg.msgtype());
|
||||
assert_eq!(text.body, "hi");
|
||||
assert!(msg.is_edited());
|
||||
|
||||
@@ -42,8 +42,8 @@ use matrix_sdk_ui::{
|
||||
room_list_service::RoomListLoadingState,
|
||||
sync_service::SyncService,
|
||||
timeline::{
|
||||
AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, EventSendState,
|
||||
EventTimelineItem, ReactionStatus, RoomExt, TimelineItem, TimelineItemContent,
|
||||
EventSendState, EventTimelineItem, ReactionStatus, RoomExt, TimelineItem,
|
||||
TimelineItemContent,
|
||||
},
|
||||
Timeline,
|
||||
};
|
||||
@@ -511,10 +511,7 @@ async fn test_enabling_backups_retries_decryption() {
|
||||
|
||||
// Yup it's decrypted great.
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = item.content(),
|
||||
Some(message) = item.content().as_message(),
|
||||
"The event should have been decrypted now"
|
||||
);
|
||||
|
||||
@@ -711,10 +708,7 @@ async fn test_room_keys_received_on_notification_client_trigger_redecryption() {
|
||||
|
||||
// Yup it's decrypted great.
|
||||
assert_let!(
|
||||
TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
..
|
||||
}) = item.content(),
|
||||
Some(message) = item.content().as_message(),
|
||||
"The event should have been decrypted now"
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user