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); + } } } });