From ae2f430917259b04e166acc56818567d498acc6f Mon Sep 17 00:00:00 2001 From: Kirill Schmidt Date: Sat, 3 Sep 2022 20:24:23 +0200 Subject: [PATCH] event-actions: Implement Permalink creation for Events Part-of: --- 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 d6dcb24e..3a8cb63c 100644 --- a/data/resources/ui/event-menu.ui +++ b/data/resources/ui/event-menu.ui @@ -98,6 +98,11 @@ event.save-audio action-missing + + _Permalink + event.permalink + action-missing + diff --git a/src/session/room/event_actions.rs b/src/session/room/event_actions.rs index 046683b6..e3169925 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::() { if let Some(AnyMessageLikeEventContent::RoomMessage(message)) = event.content() { let user_id = event