Browse Source

room-history: Do not offer to copy the thumbnail until it is loaded

pipelines/786320
Kévin Commaille 1 year ago
parent
commit
aab3a13c35
No known key found for this signature in database
GPG Key ID: C971D9DBC9D678D
  1. 26
      src/session/view/content/room_history/item_row.rs
  2. 26
      src/session/view/content/room_history/message_row/visual_media.rs

26
src/session/view/content/room_history/item_row.rs

@ -52,6 +52,32 @@ mod imp {
fn class_init(klass: &mut Self::Class) {
klass.set_css_name("room-history-row");
klass.set_accessible_role(gtk::AccessibleRole::ListItem);
klass.install_action(
"room-history-row.enable-copy-image",
Some(&bool::static_variant_type()),
|obj, _, param| {
let enable = param
.and_then(glib::Variant::get::<bool>)
.expect("The parameter should be a boolean");
let imp = obj.imp();
let Some(action_group) = imp.action_group.borrow().clone() else {
error!("Could not change state of copy-image action: no action group");
return;
};
let Some(action) = action_group.lookup_action("copy-image") else {
error!("Could not change state of copy-image action: action not found");
return;
};
tracing::debug!("Action: {action:?}");
let Some(action) = action.downcast_ref::<gio::SimpleAction>() else {
error!("Could not change state of copy-image action: not a GSimpleAction");
return;
};
action.set_enabled(enable);
},
);
}
}

26
src/session/view/content/room_history/message_row/visual_media.rs

@ -7,7 +7,7 @@ use gtk::{
};
use matrix_sdk::Client;
use ruma::api::client::media::get_content_thumbnail::v3::Method;
use tracing::warn;
use tracing::{error, warn};
use super::ContentFormat;
use crate::{
@ -324,6 +324,11 @@ mod imp {
/// Build the content for the image in the given media message.
async fn build_image(&self, media_message: &VisualMediaMessage, client: Client) {
// Disable the copy-image action while the image is loading.
if matches!(media_message, VisualMediaMessage::Image(_)) {
self.enable_copy_image_action(false);
}
let scale_factor = self.obj().scale_factor();
let settings = ThumbnailSettings {
@ -364,6 +369,25 @@ mod imp {
}
self.set_state(LoadingState::Ready);
// Enable the copy-image action now that the image is loaded.
if matches!(media_message, VisualMediaMessage::Image(_)) {
self.enable_copy_image_action(true);
}
}
/// Enable or disable the context menu action to copy the image.
fn enable_copy_image_action(&self, enable: bool) {
if self
.obj()
.activate_action(
"room-history-row.enable-copy-image",
Some(&enable.to_variant()),
)
.is_err()
{
error!("Could not change state of copy-image action: `room-history-row.enable-copy-image` action not found");
}
}
/// Build the content for the video in the given media message.

Loading…
Cancel
Save