From 9b65ae1e667341e3924cc3819d87d66c05a00f7e Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Fri, 29 Aug 2025 17:41:53 +0200 Subject: [PATCH] Cleanup LocationsModel Use libQuotient's event properties instead of accessing data from raw json --- src/libneochat/models/locationsmodel.cpp | 30 ++++++++++-------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/libneochat/models/locationsmodel.cpp b/src/libneochat/models/locationsmodel.cpp index ed8e1b842..4970f030e 100644 --- a/src/libneochat/models/locationsmodel.cpp +++ b/src/libneochat/models/locationsmodel.cpp @@ -12,33 +12,27 @@ LocationsModel::LocationsModel(QObject *parent) { connect(this, &LocationsModel::roomChanged, this, [this]() { for (const auto &event : m_room->messageEvents()) { - if (!is(*event)) { - continue; - } - if (event->contentJson()["msgtype"_L1] == "m.location"_L1) { - const auto &e = *event; - addLocation(eventCast(&e)); + if (const auto &roomMessageEvent = event.viewAs()) { + if (roomMessageEvent->msgtype() == RoomMessageEvent::MsgType::Location) { + addLocation(roomMessageEvent); + } } } connect(m_room, &NeoChatRoom::aboutToAddHistoricalMessages, this, [this](const auto &events) { for (const auto &event : events) { - if (!is(*event)) { - continue; - } - if (event->contentJson()["msgtype"_L1] == "m.location"_L1) { - const auto &e = *event; - addLocation(eventCast(&e)); + if (const auto &roomMessageEvent = eventCast(event)) { + if (roomMessageEvent->msgtype() == RoomMessageEvent::MsgType::Location) { + addLocation(roomMessageEvent); + } } } }); connect(m_room, &NeoChatRoom::aboutToAddNewMessages, this, [this](const auto &events) { for (const auto &event : events) { - if (!is(*event)) { - continue; - } - if (event->contentJson()["msgtype"_L1] == "m.location"_L1) { - const auto &e = *event; - addLocation(eventCast(&e)); + if (const auto &roomMessageEvent = eventCast(event)) { + if (roomMessageEvent->msgtype() == RoomMessageEvent::MsgType::Location) { + addLocation(roomMessageEvent); + } } } });