From 78138bf39b2da8e11983f4c4e36e808ec9ebeda4 Mon Sep 17 00:00:00 2001
From: fiaxh <git@lightrise.org>
Date: Sun, 11 Oct 2020 12:16:38 +0200
Subject: [PATCH] Unregister handlers related to displaying messages as pending

---
 .../src/ui/conversation_content_view/message_widget.vala | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/main/src/ui/conversation_content_view/message_widget.vala b/main/src/ui/conversation_content_view/message_widget.vala
index 8e164857..3186cfbb 100644
--- a/main/src/ui/conversation_content_view/message_widget.vala
+++ b/main/src/ui/conversation_content_view/message_widget.vala
@@ -87,6 +87,7 @@ public class MessageItemWidget : SizeRequestBin {
 
     ulong realize_id = -1;
     ulong style_updated_id = -1;
+    ulong marked_notify_handler_id = -1;
 
     construct {
         this.add(label);
@@ -186,12 +187,16 @@ public class MessageItemWidget : SizeRequestBin {
             theme_dependent = true;
         }
 
+        // Append "pending..." iff message has not been sent yet
         if (message.direction == Message.DIRECTION_SENT && (message.marked == Message.Marked.SENDING || message.marked == Message.Marked.UNSENT)) {
             if (message.local_time.compare(new DateTime.now_utc().add_seconds(-10)) < 0) {
                 markup_text += " <span size='small' color='%s'>%s</span>".printf(gray_color, "pending…");
 
-                message.bind_property("marked", this, "marked");
-                this.notify["marked"].connect(() => {
+                // Update the label as soon as the sent state changes
+                var binding = message.bind_property("marked", this, "marked");
+                marked_notify_handler_id = this.notify["marked"].connect(() => {
+                    binding.unbind();
+                    this.disconnect(marked_notify_handler_id);
                     update_label();
                 });
             } else {