summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-10-31 14:09:51 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:06:15 +0100
commit6b6085b270bcdffe56e19de1cd1171a73fe5fba1 (patch)
tree361425a90d30c73f4d0ebf4f1bf97951c522c698 /src
parentbreak height binding loop (diff)
downloadnheko-6b6085b270bcdffe56e19de1cd1171a73fe5fba1.tar.xz
Actually fix updating roomlist on new messages
Diffstat (limited to 'src')
-rw-r--r--src/Logging.cpp1
-rw-r--r--src/timeline2/TimelineModel.cpp57
-rw-r--r--src/timeline2/TimelineModel.h3
3 files changed, 32 insertions, 29 deletions
diff --git a/src/Logging.cpp b/src/Logging.cpp
index b5952aeb..126b3781 100644
--- a/src/Logging.cpp
+++ b/src/Logging.cpp
@@ -105,4 +105,3 @@ qml()
         return qml_logger;
 }
 }
-
diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp
index 45126b36..2428ddb6 100644
--- a/src/timeline2/TimelineModel.cpp
+++ b/src/timeline2/TimelineModel.cpp
@@ -348,6 +348,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
                 events.remove(txn_id);
                 events.insert(event_id, ev);
 
+                // mark our messages as read
+                readEvent(event_id.toStdString());
+
                 // ask to be notified for read receipts
                 cache::client()->addPendingReceipt(room_id_, event_id);
 
@@ -525,25 +528,20 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
         this->eventOrder.insert(this->eventOrder.end(), ids.begin(), ids.end());
         endInsertRows();
 
-        for (auto id = eventOrder.rbegin(); id != eventOrder.rend(); id++) {
-                auto event = events.value(*id);
-                if (auto e = boost::get<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
-                      &event)) {
-                        event = decryptEvent(*e).event;
-                }
+        updateLastMessage();
+}
 
-                auto type = boost::apply_visitor(
-                  [](const auto &e) -> mtx::events::EventType { return e.type; }, event);
-                if (type == mtx::events::EventType::RoomMessage ||
-                    type == mtx::events::EventType::Sticker) {
-                        auto description = utils::getMessageDescription(
-                          event,
-                          QString::fromStdString(http::client()->user_id().to_string()),
-                          room_id_);
-                        emit manager_->updateRoomsLastMessage(room_id_, description);
-                        break;
-                }
+void
+TimelineModel::updateLastMessage()
+{
+        auto event = events.value(eventOrder.back());
+        if (auto e = boost::get<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(&event)) {
+                event = decryptEvent(*e).event;
         }
+
+        auto description = utils::getMessageDescription(
+          event, QString::fromStdString(http::client()->user_id().to_string()), room_id_);
+        emit manager_->updateRoomsLastMessage(room_id_, description);
 }
 
 std::vector<QString>
@@ -634,21 +632,24 @@ TimelineModel::setCurrentIndex(int index)
         currentId     = indexToId(index);
         emit currentIndexChanged(index);
 
-        if (oldIndex < index) {
-                http::client()->read_event(room_id_.toStdString(),
-                                           currentId.toStdString(),
-                                           [this](mtx::http::RequestErr err) {
-                                                   if (err) {
-                                                           nhlog::net()->warn(
-                                                             "failed to read_event ({}, {})",
-                                                             room_id_.toStdString(),
-                                                             currentId.toStdString());
-                                                   }
-                                           });
+        if (oldIndex < index && !pending.contains(currentId)) {
+                readEvent(currentId.toStdString());
         }
 }
 
 void
+TimelineModel::readEvent(const std::string &id)
+{
+        http::client()->read_event(room_id_.toStdString(), id, [this](mtx::http::RequestErr err) {
+                if (err) {
+                        nhlog::net()->warn("failed to read_event ({}, {})",
+                                           room_id_.toStdString(),
+                                           currentId.toStdString());
+                }
+        });
+}
+
+void
 TimelineModel::addBackwardsEvents(const mtx::responses::Messages &msgs)
 {
         std::vector<QString> ids = internalAddEvents(msgs.chunk);
diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h
index b7ff546b..6a1f3438 100644
--- a/src/timeline2/TimelineModel.h
+++ b/src/timeline2/TimelineModel.h
@@ -192,6 +192,8 @@ private:
                                const std::string &user_id,
                                const mtx::responses::ClaimKeys &res,
                                mtx::http::RequestErr err);
+        void updateLastMessage();
+        void readEvent(const std::string &id);
 
         QHash<QString, mtx::events::collections::TimelineEvents> events;
         QSet<QString> pending, failed, read;
@@ -229,6 +231,7 @@ TimelineModel::sendMessage(const T &msg)
         pending.insert(txn_id_qstr);
         this->eventOrder.insert(this->eventOrder.end(), txn_id_qstr);
         endInsertRows();
+        updateLastMessage();
 
         if (cache::client()->isRoomEncrypted(room_id_.toStdString()))
                 sendEncryptedMessage(txn_id, nlohmann::json(msg));