From 9d70fe10ebd537f0ff58f18a382a0a9896475925 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 29 Dec 2022 13:21:14 -0500
Subject: [PATCH] messagesadapter: protect loadMoreMessages

Change-Id: I4a8d7105ed6ea5600fc4596f62b56991631358b8
---
 src/app/messagesadapter.cpp | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/app/messagesadapter.cpp b/src/app/messagesadapter.cpp
index 837abb947..b61ad0719 100644
--- a/src/app/messagesadapter.cpp
+++ b/src/app/messagesadapter.cpp
@@ -91,27 +91,35 @@ MessagesAdapter::loadMoreMessages()
 {
     auto accountId = lrcInstance_->get_currentAccountId();
     auto convId = lrcInstance_->get_selectedConvUid();
-    const auto& convInfo = lrcInstance_->getConversationFromConvUid(convId, accountId);
-    if (convInfo.isSwarm()) {
-        auto* convModel = lrcInstance_->getCurrentConversationModel();
-        convModel->loadConversationMessages(convId, loadChunkSize_);
+    try {
+        const auto& convInfo = lrcInstance_->getConversationFromConvUid(convId, accountId);
+        if (convInfo.isSwarm()) {
+            auto* convModel = lrcInstance_->getCurrentConversationModel();
+            convModel->loadConversationMessages(convId, loadChunkSize_);
+        }
+    } catch (const std::exception& e) {
+        qWarning() << e.what();
     }
 }
 
 void
 MessagesAdapter::loadConversationUntil(const QString& to)
 {
-    if (auto* model = messageListModel_.value<MessageListModel*>()) {
-        auto idx = model->indexOfMessage(to);
-        if (idx == -1) {
-            auto accountId = lrcInstance_->get_currentAccountId();
-            auto convId = lrcInstance_->get_selectedConvUid();
-            const auto& convInfo = lrcInstance_->getConversationFromConvUid(convId, accountId);
-            if (convInfo.isSwarm()) {
-                auto* convModel = lrcInstance_->getCurrentConversationModel();
-                convModel->loadConversationUntil(convId, to);
+    try {
+        if (auto* model = messageListModel_.value<MessageListModel*>()) {
+            auto idx = model->indexOfMessage(to);
+            if (idx == -1) {
+                auto accountId = lrcInstance_->get_currentAccountId();
+                auto convId = lrcInstance_->get_selectedConvUid();
+                const auto& convInfo = lrcInstance_->getConversationFromConvUid(convId, accountId);
+                if (convInfo.isSwarm()) {
+                    auto* convModel = lrcInstance_->getCurrentConversationModel();
+                    convModel->loadConversationUntil(convId, to);
+                }
             }
         }
+    } catch (const std::exception& e) {
+        qWarning() << e.what();
     }
 }
 
-- 
GitLab