[fractal] Fix temporary widget when sending attachments



commit 2fe58bebf1335771c56336fbc51418519990e609
Author: sonjita <sonjaleaheinze gmail com>
Date:   Mon Jan 27 15:37:48 2020 +0100

    Fix temporary widget when sending attachments
    
    When sending an attachment, the temporary widget in the room history,
    that appears before the permanent widget is fully created, was created as
    follows: the local uri was added to the MessageContent. Then the
    MessageContent was treated as if it was a message coming from the server.
    That led to a temporary widget pointing to an empty uri. For example,
    in the case of audio/video, it led to a player that, when hitting play,
    wouldn't reproduce anything.
    
    With this commit, the temporary widget simply contains the information
    "Uploading [att]", where [att] is "video", "audio", "image" or "file".

 fractal-gtk/src/widgets/message.rs      | 45 +++++++++++++++++++++++++--------
 fractal-gtk/src/widgets/room_history.rs |  2 +-
 2 files changed, 36 insertions(+), 11 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/message.rs b/fractal-gtk/src/widgets/message.rs
index 8d702f5c..eec5f9a3 100644
--- a/fractal-gtk/src/widgets/message.rs
+++ b/fractal-gtk/src/widgets/message.rs
@@ -68,19 +68,44 @@ impl MessageBox {
     }
 
     /* create the message row with or without a header */
-    pub fn create(&mut self, msg: &Message, has_header: bool) {
+    pub fn create(&mut self, msg: &Message, has_header: bool, is_temp: bool) {
         self.set_msg_styles(msg, &self.row);
         self.row.set_selectable(false);
-        let w = if has_header && msg.mtype != RowType::Emote {
-            self.row.set_margin_top(12);
-            self.header = true;
-            self.widget(msg)
-        } else {
-            if let RowType::Emote = msg.mtype {
+        let upload_attachment_msg = gtk::Box::new(gtk::Orientation::Horizontal, 10);
+        let w = match msg.mtype {
+            RowType::Emote => {
                 self.row.set_margin_top(12);
+                self.header = false;
+                self.small_widget(msg)
+            }
+            RowType::Video if is_temp => {
+                upload_attachment_msg
+                    .add(&gtk::Label::new(Some(i18n("Uploading video.").as_str())));
+                upload_attachment_msg
+            }
+            RowType::Audio if is_temp => {
+                upload_attachment_msg
+                    .add(&gtk::Label::new(Some(i18n("Uploading audio.").as_str())));
+                upload_attachment_msg
+            }
+            RowType::Image if is_temp => {
+                upload_attachment_msg
+                    .add(&gtk::Label::new(Some(i18n("Uploading image.").as_str())));
+                upload_attachment_msg
+            }
+            RowType::File if is_temp => {
+                upload_attachment_msg.add(&gtk::Label::new(Some(i18n("Uploading file.").as_str())));
+                upload_attachment_msg
+            }
+            _ if has_header => {
+                self.row.set_margin_top(12);
+                self.header = true;
+                self.widget(msg)
+            }
+            _ => {
+                self.header = false;
+                self.small_widget(msg)
             }
-            self.header = false;
-            self.small_widget(msg)
         };
 
         self.eventbox.add(&w);
@@ -94,7 +119,7 @@ impl MessageBox {
     }
 
     pub fn tmpwidget(mut self, msg: &Message) -> MessageBox {
-        self.create(msg, true);
+        self.create(msg, true, true);
         {
             let w = self.get_listbox_row();
             w.get_style_context().add_class("msg-tmp");
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index 6bbb5233..12ae29bc 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -631,7 +631,7 @@ fn create_row(
     /* we need to create a message with the username, so that we don't have to pass
      * all information to the widget creating each row */
     let mut mb = widgets::MessageBox::new(backend, server_url);
-    mb.create(&row, has_header && row.mtype != RowType::Emote);
+    mb.create(&row, has_header && row.mtype != RowType::Emote, false);
 
     match row.mtype {
         RowType::Video => {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]