summary refs log tree commit diff
path: root/src/timeline2/TimelineModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeline2/TimelineModel.cpp')
-rw-r--r--src/timeline2/TimelineModel.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp
index f9a8358f..db9ce555 100644
--- a/src/timeline2/TimelineModel.cpp
+++ b/src/timeline2/TimelineModel.cpp
@@ -9,6 +9,7 @@
 #include "Logging.h"
 #include "MainWindow.h"
 #include "Olm.h"
+#include "TimelineViewManager.h"
 #include "Utils.h"
 #include "dialogs/RawMessage.h"
 
@@ -282,9 +283,10 @@ eventPropHeight(const mtx::events::RoomEvent<T> &e)
 }
 }
 
-TimelineModel::TimelineModel(QString room_id, QObject *parent)
+TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObject *parent)
   : QAbstractListModel(parent)
   , room_id_(room_id)
+  , manager_(manager)
 {
         connect(
           this, &TimelineModel::oldMessagesRetrieved, this, &TimelineModel::addBackwardsEvents);
@@ -481,6 +483,26 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
                         static_cast<int>(this->eventOrder.size() + ids.size() - 1));
         this->eventOrder.insert(this->eventOrder.end(), ids.begin(), ids.end());
         endInsertRows();
+
+        for (auto id = ids.rbegin(); id != ids.rend(); id++) {
+                auto event = events.value(*id);
+                if (auto e = boost::get<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
+                      &event)) {
+                        event = decryptEvent(*e).event;
+                }
+
+                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;
+                }
+        }
 }
 
 std::vector<QString>