[fractal/fractal-next] message-row: Reuse MessageFile when possible
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] message-row: Reuse MessageFile when possible
- Date: Sat, 25 Dec 2021 08:57:34 +0000 (UTC)
commit e8a44d752ec312f39d8bdcc7bd34e610e1e16733
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Sat Dec 18 11:20:27 2021 +0100
message-row: Reuse MessageFile when possible
src/session/content/room_history/message_row/file.rs | 6 +++---
src/session/content/room_history/message_row/mod.rs | 13 +++++++++++--
2 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/session/content/room_history/message_row/file.rs
b/src/session/content/room_history/message_row/file.rs
index eaa317dc..5466d4de 100644
--- a/src/session/content/room_history/message_row/file.rs
+++ b/src/session/content/room_history/message_row/file.rs
@@ -81,8 +81,8 @@ glib::wrapper! {
}
impl MessageFile {
- pub fn new(filename: Option<String>) -> Self {
- glib::Object::new(&[("filename", &filename)]).expect("Failed to create MessageFile")
+ pub fn new() -> Self {
+ glib::Object::new(&[]).expect("Failed to create MessageFile")
}
pub fn set_filename(&self, filename: Option<String>) {
@@ -106,6 +106,6 @@ impl MessageFile {
impl Default for MessageFile {
fn default() -> Self {
- Self::new(None)
+ Self::new()
}
}
diff --git a/src/session/content/room_history/message_row/mod.rs
b/src/session/content/room_history/message_row/mod.rs
index e604d8fe..d3a618b0 100644
--- a/src/session/content/room_history/message_row/mod.rs
+++ b/src/session/content/room_history/message_row/mod.rs
@@ -218,8 +218,17 @@ impl MessageRow {
}
MessageType::File(message) => {
let filename = message.filename.unwrap_or(message.body);
- let child = MessageFile::new(Some(filename));
- priv_.content.set_child(Some(&child));
+
+ let child = if let Some(Ok(child)) =
+ priv_.content.child().map(|w| w.downcast::<MessageFile>())
+ {
+ child
+ } else {
+ let child = MessageFile::new();
+ priv_.content.set_child(Some(&child));
+ child
+ };
+ child.set_filename(Some(filename));
}
MessageType::Image(message) => {
let child = MessageMedia::image(message, &event.room().session());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]