diff --git a/src/models/messageeventmodel.cpp b/src/models/messageeventmodel.cpp index 1279be9a0..e854d8ff2 100644 --- a/src/models/messageeventmodel.cpp +++ b/src/models/messageeventmodel.cpp @@ -975,6 +975,9 @@ QVariant MessageEventModel::getLatestMessageFromIndex(const int baseline) for (auto it = timelineBottom; it != limit; ++it) { auto evt = it->event(); auto e = eventCast(evt); + if (!e) { + continue; + } auto content = (*it)->contentJson(); diff --git a/src/models/roomlistmodel.cpp b/src/models/roomlistmodel.cpp index d936f3276..6ccff64fb 100644 --- a/src/models/roomlistmodel.cpp +++ b/src/models/roomlistmodel.cpp @@ -229,10 +229,13 @@ void RoomListModel::handleNotifications() continue; } oldNotifications += notification["event"].toObject()["event_id"].toString(); + auto room = m_connection->room(notification["room_id"].toString()); + auto currentRoom = RoomManager::instance().currentRoom(); + bool roomIsActive = currentRoom && room->id() == currentRoom->id(); // If room exists, room is NOT active OR the application is NOT active, show notification - if (room && !(room->id() == RoomManager::instance().currentRoom()->id() && QGuiApplication::applicationState() == Qt::ApplicationActive)) { + if (room && !(roomIsActive && QGuiApplication::applicationState() == Qt::ApplicationActive)) { // The room might have been deleted (for example rejected invitation). auto sender = room->user(notification["event"].toObject()["sender"].toString());