-
Notifications
You must be signed in to change notification settings - Fork 419
feat(send_queue): Implement sending of MSC4274 galleries #4977
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 1 commit
0c3161b
d749ebe
9a62767
58626d2
932dbf9
c6731ca
47fe934
49c9576
421f5bd
b5f4828
7149b73
0e58e50
fc4aa7e
e47706e
4028bb4
3acc0e8
7e7a38c
aaa392c
26601a4
b5b6723
9a491b6
6b2b3f0
946e05a
662d6c7
f235e56
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 |
|---|---|---|
|
|
@@ -56,6 +56,8 @@ use matrix_sdk_common::{ | |
| }; | ||
| use mime::Mime; | ||
| use reply::Reply; | ||
| #[cfg(feature = "unstable-msc4274")] | ||
| use ruma::events::room::message::GalleryItemType; | ||
| #[cfg(feature = "e2e-encryption")] | ||
| use ruma::events::{ | ||
| room::encrypted::OriginalSyncRoomEncryptedEvent, AnySyncMessageLikeEvent, AnySyncTimelineEvent, | ||
|
|
@@ -2160,7 +2162,7 @@ impl Room { | |
| } | ||
|
|
||
| let content = self | ||
| .make_attachment_event( | ||
| .make_message_event( | ||
|
bnjbvr marked this conversation as resolved.
Outdated
|
||
| self.make_attachment_type( | ||
| content_type, | ||
| filename, | ||
|
|
@@ -2276,7 +2278,7 @@ impl Room { | |
|
|
||
| /// Creates the [`RoomMessageEventContent`] based on the message type, | ||
| /// mentions and reply information. | ||
| pub(crate) async fn make_attachment_event( | ||
| pub(crate) async fn make_message_event( | ||
|
Johennes marked this conversation as resolved.
Outdated
|
||
| &self, | ||
| msg_type: MessageType, | ||
| mentions: Option<Mentions>, | ||
|
|
@@ -2294,6 +2296,99 @@ impl Room { | |
| Ok(content) | ||
| } | ||
|
|
||
| /// Creates the inner [`GalleryItemType`] for an already-uploaded media file | ||
| /// provided by its source. | ||
| #[cfg(feature = "unstable-msc4274")] | ||
| #[allow(clippy::too_many_arguments)] | ||
| pub(crate) fn make_gallery_item_type( | ||
| &self, | ||
|
Johennes marked this conversation as resolved.
Outdated
|
||
| content_type: &Mime, | ||
| filename: String, | ||
| source: MediaSource, | ||
| caption: Option<String>, | ||
| formatted_caption: Option<FormattedBody>, | ||
| info: Option<AttachmentInfo>, | ||
| thumbnail: Option<(MediaSource, Box<ThumbnailInfo>)>, | ||
| ) -> GalleryItemType { | ||
| // If caption is set, use it as body, and filename as the file name; otherwise, | ||
| // body is the filename, and the filename is not set. | ||
| // https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2530-body-as-caption.md | ||
| let (body, filename) = match caption { | ||
| Some(caption) => (caption, Some(filename)), | ||
| None => (filename, None), | ||
| }; | ||
|
|
||
| let (thumbnail_source, thumbnail_info) = thumbnail.unzip(); | ||
|
|
||
| match content_type.type_() { | ||
| mime::IMAGE => { | ||
| let info = assign!(info.map(ImageInfo::from).unwrap_or_default(), { | ||
| mimetype: Some(content_type.as_ref().to_owned()), | ||
| thumbnail_source, | ||
| thumbnail_info | ||
| }); | ||
| let content = assign!(ImageMessageEventContent::new(body, source), { | ||
| info: Some(Box::new(info)), | ||
| formatted: formatted_caption, | ||
| filename | ||
| }); | ||
|
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. These blocks could maybe share the logic with
Contributor
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. Some form of code sharing would be nice, since it's a direct copy-pasto. I think a local macro (defined with |
||
| GalleryItemType::Image(content) | ||
| } | ||
|
|
||
| mime::AUDIO => { | ||
| let mut content = assign!(AudioMessageEventContent::new(body, source), { | ||
| formatted: formatted_caption, | ||
| filename | ||
| }); | ||
|
|
||
| if let Some(AttachmentInfo::Voice { audio_info, waveform: Some(waveform_vec) }) = | ||
| &info | ||
| { | ||
| if let Some(duration) = audio_info.duration { | ||
| let waveform = waveform_vec.iter().map(|v| (*v).into()).collect(); | ||
| content.audio = | ||
| Some(UnstableAudioDetailsContentBlock::new(duration, waveform)); | ||
| } | ||
| content.voice = Some(UnstableVoiceContentBlock::new()); | ||
| } | ||
|
|
||
| let mut audio_info = info.map(AudioInfo::from).unwrap_or_default(); | ||
| audio_info.mimetype = Some(content_type.as_ref().to_owned()); | ||
| let content = content.info(Box::new(audio_info)); | ||
|
|
||
| GalleryItemType::Audio(content) | ||
| } | ||
|
|
||
| mime::VIDEO => { | ||
| let info = assign!(info.map(VideoInfo::from).unwrap_or_default(), { | ||
| mimetype: Some(content_type.as_ref().to_owned()), | ||
| thumbnail_source, | ||
| thumbnail_info | ||
| }); | ||
| let content = assign!(VideoMessageEventContent::new(body, source), { | ||
| info: Some(Box::new(info)), | ||
| formatted: formatted_caption, | ||
| filename | ||
| }); | ||
| GalleryItemType::Video(content) | ||
| } | ||
|
|
||
| _ => { | ||
| let info = assign!(info.map(FileInfo::from).unwrap_or_default(), { | ||
| mimetype: Some(content_type.as_ref().to_owned()), | ||
| thumbnail_source, | ||
| thumbnail_info | ||
| }); | ||
| let content = assign!(FileMessageEventContent::new(body, source), { | ||
| info: Some(Box::new(info)), | ||
| formatted: formatted_caption, | ||
| filename, | ||
| }); | ||
| GalleryItemType::File(content) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Update the power levels of a select set of users of this room. | ||
| /// | ||
| /// Issue a `power_levels` state event request to the server, changing the | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.