-
Notifications
You must be signed in to change notification settings - Fork 419
feat(timeline): Expose method to send galleries in matrix-sdk-ui #5125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a5594c1
5b0b56f
7b6c0f0
793d147
2ff4345
f9f3f49
84e36c4
c960200
59b92df
434b896
f873500
2b0db6c
80e2014
8328039
e9dfb45
22f1991
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ use assert_matches::assert_matches; | |
| use assert_matches2::assert_let; | ||
| use eyeball_im::VectorDiff; | ||
| use futures_util::{FutureExt, StreamExt}; | ||
| #[cfg(feature = "unstable-msc4274")] | ||
| use matrix_sdk::attachment::{AttachmentInfo, BaseFileInfo, GalleryConfig, GalleryItemInfo}; | ||
| use matrix_sdk::{ | ||
| assert_let_timeout, | ||
| attachment::AttachmentConfig, | ||
|
|
@@ -26,6 +28,8 @@ use matrix_sdk::{ | |
| }; | ||
| use matrix_sdk_test::{async_test, event_factory::EventFactory, JoinedRoomBuilder, ALICE}; | ||
| use matrix_sdk_ui::timeline::{AttachmentSource, EventSendState, RoomExt}; | ||
| #[cfg(feature = "unstable-msc4274")] | ||
| use ruma::events::room::message::GalleryItemType; | ||
| use ruma::{ | ||
| event_id, | ||
| events::room::{ | ||
|
|
@@ -262,6 +266,128 @@ async fn test_send_attachment_from_bytes() { | |
| assert!(timeline_stream.next().now_or_never().is_none()); | ||
| } | ||
|
|
||
| #[cfg(feature = "unstable-msc4274")] | ||
| #[async_test] | ||
| async fn test_send_gallery_from_bytes() { | ||
| let mock = MatrixMockServer::new().await; | ||
| let client = mock.client_builder().build().await; | ||
|
|
||
| mock.mock_room_state_encryption().plain().mount().await; | ||
|
|
||
| let room_id = room_id!("!a98sd12bjh:example.org"); | ||
| let room = mock.sync_joined_room(&client, room_id).await; | ||
| let timeline = room.timeline().await.unwrap(); | ||
|
|
||
| let (items, mut timeline_stream) = | ||
| timeline.subscribe_filter_map(|item| item.as_event().cloned()).await; | ||
|
|
||
| assert!(items.is_empty()); | ||
|
|
||
| let f = EventFactory::new(); | ||
| mock.sync_room( | ||
| &client, | ||
| JoinedRoomBuilder::new(room_id).add_timeline_event(f.text_msg("hello").sender(&ALICE)), | ||
| ) | ||
| .await; | ||
|
|
||
| // Sanity check. | ||
| assert_let_timeout!(Some(VectorDiff::PushBack { value: item }) = timeline_stream.next()); | ||
| assert_let!(Some(msg) = item.content().as_message()); | ||
| assert_eq!(msg.body(), "hello"); | ||
|
|
||
| // No other updates. | ||
| assert!(timeline_stream.next().now_or_never().is_none()); | ||
|
Johennes marked this conversation as resolved.
Outdated
|
||
|
|
||
| // The data of the file. | ||
| let filename = "test.bin"; | ||
| let data = b"hello world".to_vec(); | ||
|
|
||
| // Set up mocks for the file upload. | ||
| mock.mock_upload() | ||
| .respond_with(ResponseTemplate::new(200).set_delay(Duration::from_secs(2)).set_body_json( | ||
| json!({ | ||
| "content_uri": "mxc://sdk.rs/media" | ||
| }), | ||
| )) | ||
| .mock_once() | ||
| .mount() | ||
| .await; | ||
|
|
||
| mock.mock_room_send().ok(event_id!("$media")).mock_once().mount().await; | ||
|
|
||
| // Queue sending of a gallery. | ||
| let gallery = | ||
| GalleryConfig::new().caption(Some("caption".to_owned())).add_item(GalleryItemInfo { | ||
| filename: filename.to_owned(), | ||
| content_type: mime::TEXT_PLAIN, | ||
| data, | ||
| attachment_info: AttachmentInfo::File(BaseFileInfo { size: None }), | ||
| caption: Some("item caption".to_owned()), | ||
| formatted_caption: None, | ||
| thumbnail: None, | ||
| }); | ||
| timeline.send_gallery(gallery).await.unwrap(); | ||
|
|
||
| { | ||
| assert_let_timeout!(Some(VectorDiff::PushBack { value: item }) = timeline_stream.next()); | ||
| assert_matches!(item.send_state(), Some(EventSendState::NotSentYet)); | ||
| assert_let!(Some(msg) = item.content().as_message()); | ||
|
|
||
| // Body matches gallery caption. | ||
| assert_eq!(msg.body(), "caption"); | ||
|
|
||
| // Message is gallery of expected length | ||
| assert_let!(MessageType::Gallery(content) = msg.msgtype()); | ||
| assert_eq!(1, content.itemtypes.len()); | ||
| assert_let!(GalleryItemType::File(file) = content.itemtypes.first().unwrap()); | ||
|
|
||
| // Item has filename and caption | ||
| assert_eq!(filename, file.filename()); | ||
| assert_eq!(Some("item caption"), file.caption()); | ||
|
|
||
| // The URI refers to the local cache. | ||
| assert_let!(MediaSource::Plain(uri) = &file.source); | ||
| assert!(uri.to_string().contains("localhost")); | ||
| } | ||
|
|
||
| // Eventually, the media is updated with the final MXC IDs… | ||
| sleep(Duration::from_secs(2)).await; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the sleep, considering that below we're using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly I have to use 3 seconds inside
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, looks like the |
||
|
|
||
| { | ||
| assert_let_timeout!( | ||
| Some(VectorDiff::Set { index: 1, value: item }) = timeline_stream.next() | ||
| ); | ||
| assert_let!(Some(msg) = item.content().as_message()); | ||
| assert_matches!(item.send_state(), Some(EventSendState::NotSentYet)); | ||
|
|
||
| // Message is gallery of expected length | ||
| assert_let!(MessageType::Gallery(content) = msg.msgtype()); | ||
| assert_eq!(1, content.itemtypes.len()); | ||
| assert_let!(GalleryItemType::File(file) = content.itemtypes.first().unwrap()); | ||
|
|
||
| // Item has filename and caption | ||
| assert_eq!(filename, file.filename()); | ||
| assert_eq!(Some("item caption"), file.caption()); | ||
|
|
||
| // The URI now refers to the final MXC URI. | ||
| assert_let!(MediaSource::Plain(uri) = &file.source); | ||
| assert_eq!(uri.to_string(), "mxc://sdk.rs/media"); | ||
| } | ||
|
|
||
| // And eventually the event itself is sent. | ||
| { | ||
| assert_let_timeout!( | ||
| Some(VectorDiff::Set { index: 1, value: item }) = timeline_stream.next() | ||
| ); | ||
| assert_matches!(item.send_state(), Some(EventSendState::Sent{ event_id }) => { | ||
| assert_eq!(event_id, event_id!("$media")); | ||
| }); | ||
| } | ||
|
|
||
| // That's all, folks! | ||
| assert!(timeline_stream.next().now_or_never().is_none()); | ||
| } | ||
|
|
||
| #[async_test] | ||
| async fn test_react_to_local_media() { | ||
| let mock = MatrixMockServer::new().await; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be true, so as to display galleries by default. Wouldn't this make the test you've added fail, since it'd filter out the gallery event from rendering into an item? Maybe that's why CI's failing now.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right! 🤦♂️
Have switched it around. It didn't seem to affect the test, however, which is mildly concerning. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is likely not running; investigating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah:
Cargo.toml, so that it's enabled workspace-wide, and included in testing. I think the latter would be great, since the FFI layer likely will want it anyways.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! 🤯
Ok, I hope I got all of this right. The test now does fail for me also locally (with the erroneous
false). When I switch back totrue, it succeeds.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it? Looks like it's the sending of the media gallery that fails, not the filtering out…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right. 🤦♂️ Ok, will have to look into what's going on there now. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the media config requests need mocking after merging in
main. Added those and switched back tofalseso the CI should now fail timing out waiting for the sent gallery.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it seems to be failing as intended now: no item is pushed, while we expected one 🥳 Good job making the test meaningful and winning over CI!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets hope it actually turns green now. 😅🤞