summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-04-17 01:02:32 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-04-19 15:07:23 +0200
commiteff8af6facaaedb79b54c62437b5cc1df8a06c6d (patch)
treeee41f7270407e396883ef36930037f7f38a1d315
parentMerge pull request #167 from jevolk/master (diff)
downloadnheko-eff8af6facaaedb79b54c62437b5cc1df8a06c6d.tar.xz
Try to fix messages getting stuck by sometimes sending them twice and never failing them
-rw-r--r--src/timeline/TimelineModel.cpp27
-rw-r--r--src/timeline/TimelineModel.h5
2 files changed, 9 insertions, 23 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 80038d99..262fa10a 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -144,15 +144,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
         connect(
           this, &TimelineModel::oldMessagesRetrieved, this, &TimelineModel::addBackwardsEvents);
         connect(this, &TimelineModel::messageFailed, this, [this](QString txn_id) {
-                pending.removeOne(txn_id);
-                failed.insert(txn_id);
-                int idx = idToIndex(txn_id);
-                if (idx < 0) {
-                        nhlog::ui()->warn("Failed index out of range");
-                        return;
-                }
-                isProcessingPending = false;
-                emit dataChanged(index(idx, 0), index(idx, 0));
+                nhlog::ui()->error("Failed to send {}, retrying", txn_id.toStdString());
+
+                QTimer::singleShot(5000, this, [this]() { emit nextPendingMessage(); });
         });
         connect(this, &TimelineModel::messageSent, this, [this](QString txn_id, QString event_id) {
                 pending.removeOne(txn_id);
@@ -181,7 +175,6 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
                 // ask to be notified for read receipts
                 cache::addPendingReceipt(room_id_, event_id);
 
-                isProcessingPending = false;
                 emit dataChanged(index(idx, 0), index(idx, 0));
 
                 if (pending.size() > 0)
@@ -334,8 +327,6 @@ TimelineModel::data(const QString &id, int role) const
                 // only show read receipts for messages not from us
                 if (acc::sender(event) != http::client()->user_id().to_string())
                         return qml_mtx_events::Empty;
-                else if (failed.contains(id))
-                        return qml_mtx_events::Failed;
                 else if (pending.contains(id))
                         return qml_mtx_events::Sent;
                 else if (read.contains(id) || cache::readReceipts(id, room_id_).size() > 1)
@@ -458,10 +449,11 @@ TimelineModel::fetchMore(const QModelIndex &)
         http::client()->messages(
           opts, [this, opts](const mtx::responses::Messages &res, mtx::http::RequestErr err) {
                   if (err) {
-                          nhlog::net()->error("failed to call /messages ({}): {} - {}",
+                          nhlog::net()->error("failed to call /messages ({}): {} - {} - {}",
                                               opts.room_id,
                                               mtx::errors::to_string(err->matrix_error.errcode),
-                                              err->matrix_error.error);
+                                              err->matrix_error.error,
+                                              err->parse_error);
                           paginationInProgress = false;
                           return;
                   }
@@ -1266,11 +1258,9 @@ struct SendMessageVisitor
 void
 TimelineModel::processOnePendingMessage()
 {
-        if (isProcessingPending || pending.isEmpty())
+        if (pending.isEmpty())
                 return;
 
-        isProcessingPending = true;
-
         QString txn_id_qstr = pending.first();
 
         auto event = events.value(txn_id_qstr);
@@ -1298,8 +1288,7 @@ TimelineModel::addPendingMessage(mtx::events::collections::TimelineEvents event)
         endInsertRows();
         updateLastMessage();
 
-        if (!isProcessingPending)
-                emit nextPendingMessage();
+        emit nextPendingMessage();
 }
 
 bool
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 0b181583..bb84bcd8 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -89,8 +89,6 @@ enum EventState
         Sent,
         //! When the message is loaded from cache or backfill.
         Empty,
-        //! When the message failed to send
-        Failed,
 };
 Q_ENUM_NS(EventState)
 }
@@ -262,7 +260,7 @@ private:
         void readEvent(const std::string &id);
 
         QHash<QString, mtx::events::collections::TimelineEvents> events;
-        QSet<QString> failed, read;
+        QSet<QString> read;
         QList<QString> pending;
         std::vector<QString> eventOrder;
 
@@ -271,7 +269,6 @@ private:
 
         bool isInitialSync        = true;
         bool paginationInProgress = false;
-        bool isProcessingPending  = false;
 
         QString currentId;
         QString reply_;