From ddc0bfe78697461e9a0ff79ea40d060d3a5c9cff Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 13 Dec 2023 18:34:59 +0000 Subject: [PATCH] Make sure that a nullptr connection is not accessed in AccountEmoticonModel I don't think it possible to open settings without an account connected anymore, however just to make sure I've made sure that a nullptr connection is handled in `AccountEmoticonsModel`. BUG: 478024 --- src/models/accountemoticonmodel.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/models/accountemoticonmodel.cpp b/src/models/accountemoticonmodel.cpp index bf8c78cd1..c61c9a114 100644 --- a/src/models/accountemoticonmodel.cpp +++ b/src/models/accountemoticonmodel.cpp @@ -24,6 +24,10 @@ int AccountEmoticonModel::rowCount(const QModelIndex &index) const QVariant AccountEmoticonModel::data(const QModelIndex &index, int role) const { + if (m_connection == nullptr) { + return {}; + } + const auto &row = index.row(); const auto &image = m_images->images[row]; if (role == UrlRole) { @@ -92,6 +96,10 @@ void AccountEmoticonModel::setConnection(Connection *connection) void AccountEmoticonModel::reloadEmoticons() { + if (m_connection == nullptr) { + return; + } + QJsonObject json; if (m_connection->hasAccountData("im.ponies.user_emotes"_ls)) { json = m_connection->accountData("im.ponies.user_emotes"_ls)->contentJson(); @@ -104,6 +112,10 @@ void AccountEmoticonModel::reloadEmoticons() void AccountEmoticonModel::deleteEmoticon(int index) { + if (m_connection == nullptr) { + return; + } + QJsonObject data; m_images->images.removeAt(index); m_images->fillJson(&data); @@ -112,6 +124,10 @@ void AccountEmoticonModel::deleteEmoticon(int index) void AccountEmoticonModel::setEmoticonBody(int index, const QString &text) { + if (m_connection == nullptr) { + return; + } + m_images->images[index].body = text; QJsonObject data; m_images->fillJson(&data); @@ -120,6 +136,10 @@ void AccountEmoticonModel::setEmoticonBody(int index, const QString &text) void AccountEmoticonModel::setEmoticonShortcode(int index, const QString &shortcode) { + if (m_connection == nullptr) { + return; + } + m_images->images[index].shortcode = shortcode; QJsonObject data; m_images->fillJson(&data); @@ -128,6 +148,9 @@ void AccountEmoticonModel::setEmoticonShortcode(int index, const QString &shortc void AccountEmoticonModel::setEmoticonImage(int index, const QUrl &source) { + if (m_connection == nullptr) { + return; + } doSetEmoticonImage(index, source); } @@ -166,6 +189,9 @@ QCoro::Task AccountEmoticonModel::doAddEmoticon(QUrl source, QString short void AccountEmoticonModel::addEmoticon(const QUrl &source, const QString &shortcode, const QString &description, const QString &type) { + if (m_connection == nullptr) { + return; + } doAddEmoticon(source, shortcode, description, type); }