[fractal] room-history: Implement Permalink creation for rooms
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] room-history: Implement Permalink creation for rooms
- Date: Sat, 3 Sep 2022 20:55:43 +0000 (UTC)
commit 425891310fc3737978f72c2ba3b93fbe4dbba055
Author: Kirill Schmidt <kirill schmidt teckids org>
Date: Sat Sep 3 20:25:12 2022 +0200
room-history: Implement Permalink creation for rooms
Enhances #891
Part-of: <https://gitlab.gnome.org/GNOME/fractal/-/merge_requests/1146>
data/resources/ui/content-room-history.ui | 4 ++++
src/session/content/room_history/mod.rs | 27 +++++++++++++++++++++++++--
src/session/room/mod.rs | 2 +-
3 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/data/resources/ui/content-room-history.ui b/data/resources/ui/content-room-history.ui
index 90cd23d48..8be8f7541 100644
--- a/data/resources/ui/content-room-history.ui
+++ b/data/resources/ui/content-room-history.ui
@@ -12,6 +12,10 @@
<attribute name="action">room-history.invite-members</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
+ <item>
+ <attribute name="label" translatable="yes">Room _Permalink</attribute>
+ <attribute name="action">room-history.permalink</attribute>
+ </item>
</section>
<section>
<item>
diff --git a/src/session/content/room_history/mod.rs b/src/session/content/room_history/mod.rs
index a4e72a43e..b21860d90 100644
--- a/src/session/content/room_history/mod.rs
+++ b/src/session/content/room_history/mod.rs
@@ -20,7 +20,7 @@ use gtk::{
prelude::*,
CompositeTemplate,
};
-use log::warn;
+use log::{error, warn};
use matrix_sdk::ruma::events::room::message::{
EmoteMessageEventContent, FormattedBody, MessageType, RoomMessageEventContent,
TextMessageEventContent,
@@ -40,7 +40,7 @@ use crate::{
room::{Room, RoomType, SupportedEvent, Timeline, TimelineItem, TimelineState},
user::UserExt,
},
- spawn, toast,
+ spawn, spawn_tokio, toast,
utils::filename_for_mime,
};
@@ -126,6 +126,12 @@ mod imp {
widget.try_again();
});
+ klass.install_action("room-history.permalink", None, move |widget, _, _| {
+ spawn!(clone!(@weak widget => async move {
+ widget.permalink().await;
+ }));
+ });
+
klass.install_action("room-history.details", None, move |widget, _, _| {
widget.open_room_details("general");
});
@@ -558,6 +564,23 @@ impl RoomHistory {
}
}
+ pub async fn permalink(&self) {
+ if let Some(room) = self.room() {
+ let room = room.matrix_room();
+ let handle = spawn_tokio!(async move { room.matrix_to_permalink().await });
+ match handle.await.unwrap() {
+ Ok(permalink) => {
+ self.clipboard().set_text(&permalink.to_string());
+ toast!(self, gettext("Permalink copied to clipboard"));
+ }
+ Err(error) => {
+ error!("Could not get permalink: {}", error);
+ toast!(self, gettext("Failed to copy the permalink"));
+ }
+ }
+ }
+ }
+
/// Opens the room details on the page with the given name.
pub fn open_room_details(&self, page_name: &str) {
if let Some(room) = self.room() {
diff --git a/src/session/room/mod.rs b/src/session/room/mod.rs
index b1faba8c9..1bd7e9e51 100644
--- a/src/session/room/mod.rs
+++ b/src/session/room/mod.rs
@@ -399,7 +399,7 @@ impl Room {
.is_direct()
}
- fn matrix_room(&self) -> MatrixRoom {
+ pub fn matrix_room(&self) -> MatrixRoom {
self.imp().matrix_room.borrow().as_ref().unwrap().clone()
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]