event-actions: Implement Permalink creation for Events

Part-of: <https://gitlab.gnome.org/GNOME/fractal/-/merge_requests/1146>
This commit is contained in:
Kirill Schmidt 2022-09-03 20:24:23 +02:00 committed by Marge Bot
parent 76d2de4338
commit ae2f430917
2 changed files with 34 additions and 1 deletions

View file

@ -98,6 +98,11 @@
<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>
<attribute name="hidden-when">action-missing</attribute>
</item>
</section>
</menu>
<menu id="state_menu_model">

View file

@ -10,7 +10,7 @@ use crate::{
event_source_dialog::EventSourceDialog,
room::{Event, RoomAction, SupportedEvent},
},
spawn, toast,
spawn, spawn_tokio, toast,
utils::cache_dir,
UserFacingError, Window,
};
@ -90,6 +90,34 @@ where
})
);
// Create a permalink
if event.event_id().is_some() {
gtk_macros::action!(
&action_group,
"permalink",
clone!(@weak self as widget, @weak event => move |_, _| {
let matrix_room = event.room().matrix_room();
let event_id = event.event_id().unwrap();
spawn!(clone!(@weak widget => async move {
let handle = spawn_tokio!(async move {
matrix_room.matrix_to_event_permalink(event_id).await
});
match handle.await.unwrap() {
Ok(permalink) => {
widget.clipboard().set_text(&permalink.to_string());
toast!(widget, gettext("Permalink copied to clipboard"));
},
Err(error) => {
error!("Could not get permalink: {}", error);
toast!(widget, gettext("Failed to copy the permalink"));
}
}
})
);
})
);
}
if let Some(event) = event.downcast_ref::<SupportedEvent>() {
if let Some(AnyMessageLikeEventContent::RoomMessage(message)) = event.content() {
let user_id = event