Browse Source

event-actions: Implement save for media files

Part-of: <https://gitlab.gnome.org/GNOME/fractal/-/merge_requests/1115>
merge-requests/1327/merge
Kirill Schmidt 4 years ago
parent
commit
f5b12387fe
  1. 20
      data/resources/ui/event-menu.ui
  2. 18
      src/session/room/event.rs
  3. 27
      src/session/room/event_actions.rs

20
data/resources/ui/event-menu.ui

@ -47,6 +47,16 @@
<attribute name="action">event.save-image</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">S_ave Video</attribute>
<attribute name="action">event.save-video</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">S_ave Audio</attribute>
<attribute name="action">event.save-audio</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Permalink</attribute>
<attribute name="action">event.permalink</attribute>
@ -78,6 +88,16 @@
<attribute name="action">event.save-image</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">S_ave Video</attribute>
<attribute name="action">event.save-video</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">S_ave Audio</attribute>
<attribute name="action">event.save-audio</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
</section>
</menu>
<menu id="state_menu_model">

18
src/session/room/event.rs

@ -615,6 +615,7 @@ impl Event {
/// - File message (`MessageType::File`).
/// - Image message (`MessageType::Image`).
/// - Video message (`MessageType::Video`).
/// - Audio message (`MessageType::Audio`).
///
/// Returns `Ok((uid, filename, binary_content))` on success, `Err` if an
/// error occurred while fetching the content. Panics on an incompatible
@ -679,6 +680,23 @@ impl Event {
let data = handle.await.unwrap()?.unwrap();
return Ok((uid, filename, data));
}
MessageType::Audio(content) => {
let uid = media_type_uid(content.source());
let filename = if content.body.is_empty() {
filename_for_mime(
content
.info
.as_ref()
.and_then(|info| info.mimetype.as_deref()),
Some(mime::AUDIO),
)
} else {
content.body.clone()
};
let handle = spawn_tokio!(async move { client.get_file(content, true).await });
let data = handle.await.unwrap()?.unwrap();
return Ok((uid, filename, data));
}
_ => {}
};
};

27
src/session/room/event_actions.rs

@ -174,6 +174,33 @@ where
})
);
}
MessageType::Image(_) => {
gtk_macros::action!(
&action_group,
"save-image",
clone!(@weak self as widget, @weak event => move |_, _| {
widget.save_event_file(event);
})
);
}
MessageType::Video(_) => {
gtk_macros::action!(
&action_group,
"save-video",
clone!(@weak self as widget, @weak event => move |_, _| {
widget.save_event_file(event);
})
);
}
MessageType::Audio(_) => {
gtk_macros::action!(
&action_group,
"save-audio",
clone!(@weak self as widget, @weak event => move |_, _| {
widget.save_event_file(event);
})
);
}
_ => {}
}
}

Loading…
Cancel
Save