Skip to content
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

Fix filename support for video, audio and image draft #2071

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions native/acter/src/api/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ impl Client {
MsgDraft::new(MsgContentDraft::Image {
source,
info: Some(info),
filename: None,
})
}

Expand All @@ -339,6 +340,7 @@ impl Client {
MsgDraft::new(MsgContentDraft::Audio {
source,
info: Some(info),
filename: None,
})
}

Expand All @@ -349,6 +351,7 @@ impl Client {
MsgDraft::new(MsgContentDraft::Video {
source,
info: Some(info),
filename: None,
})
}

Expand Down
57 changes: 54 additions & 3 deletions native/acter/src/api/stream/msg_draft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ pub(crate) enum MsgContentDraft {
Image {
source: String,
info: Option<ImageInfo>,
filename: Option<String>,
},
Audio {
source: String,
info: Option<AudioInfo>,
filename: Option<String>,
},
Video {
source: String,
info: Option<VideoInfo>,
filename: Option<String>,
},
File {
source: String,
Expand Down Expand Up @@ -181,6 +184,39 @@ impl MsgContentDraft {

fn filename(mut self, value: String) -> Self {
match self {
MsgContentDraft::Image {
source,
info,
filename: _,
} => {
return MsgContentDraft::Image {
source,
filename: Some(value),
info,
};
}
MsgContentDraft::Video {
source,
info,
filename: _,
} => {
return MsgContentDraft::Video {
source,
filename: Some(value),
info,
};
}
MsgContentDraft::Audio {
source,
info,
filename: _,
} => {
return MsgContentDraft::Audio {
source,
filename: Some(value),
info,
};
}
MsgContentDraft::File {
source,
info,
Expand Down Expand Up @@ -318,7 +354,11 @@ impl MsgDraft {
LocationMessageEventContent::new(body, geo_uri),
)),

MsgContentDraft::Image { source, info } => {
MsgContentDraft::Image {
source,
info,
filename,
} => {
let info = info.expect("image info needed");
let mimetype = info.mimetype.clone().expect("mimetype needed");
let content_type = mimetype.parse::<mime::Mime>()?;
Expand Down Expand Up @@ -350,9 +390,14 @@ impl MsgDraft {
ImageMessageEventContent::plain(body, response.content_uri)
};
image_content.info = Some(Box::new(info));
image_content.filename = filename;
RoomMessageEventContentWithoutRelation::new(MessageType::Image(image_content))
}
MsgContentDraft::Audio { source, info } => {
MsgContentDraft::Audio {
source,
info,
filename,
} => {
let info = info.expect("audio info needed");
let mimetype = info.mimetype.clone().expect("mimetype needed");
let content_type = mimetype.parse::<mime::Mime>()?;
Expand Down Expand Up @@ -384,9 +429,14 @@ impl MsgDraft {
AudioMessageEventContent::plain(body, response.content_uri)
};
audio_content.info = Some(Box::new(info));
audio_content.filename = filename;
RoomMessageEventContentWithoutRelation::new(MessageType::Audio(audio_content))
}
MsgContentDraft::Video { source, info } => {
MsgContentDraft::Video {
source,
info,
filename,
} => {
let info = info.expect("video info needed");
let mimetype = info.mimetype.clone().expect("mimetype needed");
let content_type = mimetype.parse::<mime::Mime>()?;
Expand Down Expand Up @@ -418,6 +468,7 @@ impl MsgDraft {
VideoMessageEventContent::plain(body, response.content_uri)
};
video_content.info = Some(Box::new(info));
video_content.filename = filename;
RoomMessageEventContentWithoutRelation::new(MessageType::Video(video_content))
}
MsgContentDraft::File {
Expand Down
Loading