From 54a16ae2d7d811a7f2e4454daf398ace8f97170a Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
Date: Tue, 14 Jan 2020 20:43:35 +0100
Subject: [PATCH] Fix duplicate messages in timeline after sending

---
 src/timeline/TimelineModel.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index eef4ec31d..08c29927d 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -139,6 +139,17 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
         });
         connect(this, &TimelineModel::messageSent, this, [this](QString txn_id, QString event_id) {
                 pending.removeOne(txn_id);
+
+                // we could have received the message via sync
+                if (events.contains(event_id)) {
+                        int idx = idToIndex(event_id);
+                        if (idx >= 0) {
+                                beginRemoveRows(QModelIndex(), idx, idx);
+                                eventOrder.erase(eventOrder.begin() + idx);
+                                endRemoveRows();
+                        }
+                }
+
                 int idx = idToIndex(txn_id);
                 if (idx < 0) {
                         nhlog::ui()->warn("Sent index out of range");
-- 
GitLab