summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-11-09 03:30:17 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:07:15 +0100
commit562169965ce68cadbf8214e084477c60ddfdde0b (patch)
tree554bd757f5e29d138b59c197025ad02d1e11d7be /src
parentRemove old timeline (diff)
downloadnheko-562169965ce68cadbf8214e084477c60ddfdde0b.tar.xz
Show only messages in room list
Diffstat (limited to 'src')
-rw-r--r--src/timeline/TimelineModel.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index ab7d3d47..9cae4608 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -552,17 +552,40 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
         updateLastMessage();
 }
 
+template<typename T>
+auto
+isMessage(const mtx::events::RoomEvent<T> &e)
+  -> std::enable_if_t<std::is_same<decltype(e.content.msgtype), std::string>::value, bool>
+{
+        return true;
+}
+
+template<typename T>
+auto
+isMessage(const mtx::events::Event<T> &)
+{
+        return false;
+}
+
 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;
-        }
+        for (auto it = eventOrder.rbegin(); it != eventOrder.rend(); ++it) {
+                auto event = events.value(*it);
+                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);
+                if (!boost::apply_visitor([](const auto &e) -> bool { return isMessage(e); },
+                                          event))
+                        continue;
+
+                auto description = utils::getMessageDescription(
+                  event, QString::fromStdString(http::client()->user_id().to_string()), room_id_);
+                emit manager_->updateRoomsLastMessage(room_id_, description);
+                return;
+        }
 }
 
 std::vector<QString>