[fractal] event-actions: Implement Permalink creation for Events
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] event-actions: Implement Permalink creation for Events
- Date: Sat, 3 Sep 2022 20:55:43 +0000 (UTC)
commit ae2f430917259b04e166acc56818567d498acc6f
Author: Kirill Schmidt <kirill schmidt teckids org>
Date: Sat Sep 3 20:24:23 2022 +0200
event-actions: Implement Permalink creation for Events
Part-of: <https://gitlab.gnome.org/GNOME/fractal/-/merge_requests/1146>
data/resources/ui/event-menu.ui | 5 +++++
src/session/room/event_actions.rs | 30 +++++++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 1 deletion(-)
---
diff --git a/data/resources/ui/event-menu.ui b/data/resources/ui/event-menu.ui
index d6dcb24ee..3a8cb63c3 100644
--- a/data/resources/ui/event-menu.ui
+++ b/data/resources/ui/event-menu.ui
@@ -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">
diff --git a/src/session/room/event_actions.rs b/src/session/room/event_actions.rs
index 046683b6d..e3169925a 100644
--- a/src/session/room/event_actions.rs
+++ b/src/session/room/event_actions.rs
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]