Make various models more robust against deleted rooms
This commit is contained in:
@@ -80,6 +80,7 @@ QString ActionsHandler::handleMentions(QString handledText, QList<Mention> *ment
|
|||||||
|
|
||||||
void ActionsHandler::handleMessage(const QString &text, QString handledText, ChatBarCache *chatBarCache)
|
void ActionsHandler::handleMessage(const QString &text, QString handledText, ChatBarCache *chatBarCache)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(m_room);
|
||||||
if (NeoChatConfig::allowQuickEdit()) {
|
if (NeoChatConfig::allowQuickEdit()) {
|
||||||
QRegularExpression sed(QStringLiteral("^s/([^/]*)/([^/]*)(/g)?$"));
|
QRegularExpression sed(QStringLiteral("^s/([^/]*)/([^/]*)(/g)?$"));
|
||||||
auto match = sed.match(text);
|
auto match = sed.match(text);
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public Q_SLOTS:
|
|||||||
void handleMessageEvent(ChatBarCache *chatBarCache);
|
void handleMessageEvent(ChatBarCache *chatBarCache);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NeoChatRoom *m_room = nullptr;
|
QPointer<NeoChatRoom> m_room;
|
||||||
void checkEffects(const QString &text);
|
void checkEffects(const QString &text);
|
||||||
|
|
||||||
QString handleMentions(QString handledText, QList<Mention> *mentions);
|
QString handleMentions(QString handledText, QList<Mention> *mentions);
|
||||||
|
|||||||
@@ -91,7 +91,9 @@ QVariant CompletionModel::data(const QModelIndex &index, int role) const
|
|||||||
if (mediaId.isEmpty()) {
|
if (mediaId.isEmpty()) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
return m_room->connection()->makeMediaUrl(QUrl(QStringLiteral("mxc://%1").arg(mediaId)));
|
if (m_room) {
|
||||||
|
return m_room->connection()->makeMediaUrl(QUrl(QStringLiteral("mxc://%1").arg(mediaId)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_autoCompletionType == Emoji) {
|
if (m_autoCompletionType == Emoji) {
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ private:
|
|||||||
QString m_text;
|
QString m_text;
|
||||||
QString m_fullText;
|
QString m_fullText;
|
||||||
CompletionProxyModel *m_filterModel;
|
CompletionProxyModel *m_filterModel;
|
||||||
NeoChatRoom *m_room = nullptr;
|
QPointer<NeoChatRoom> m_room;
|
||||||
AutoCompletionType m_autoCompletionType = None;
|
AutoCompletionType m_autoCompletionType = None;
|
||||||
|
|
||||||
void updateCompletion();
|
void updateCompletion();
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public:
|
|||||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NeoChatRoom *m_room = nullptr;
|
QPointer<NeoChatRoom> m_room;
|
||||||
const Quotient::RoomEvent *m_event = nullptr;
|
const Quotient::RoomEvent *m_event = nullptr;
|
||||||
|
|
||||||
QList<MessageComponent> m_components;
|
QList<MessageComponent> m_components;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include <Quotient/user.h>
|
#include <Quotient/user.h>
|
||||||
|
|
||||||
ReactionModel::ReactionModel(const Quotient::RoomMessageEvent *event, const NeoChatRoom *room)
|
ReactionModel::ReactionModel(const Quotient::RoomMessageEvent *event, NeoChatRoom *room)
|
||||||
: QAbstractListModel(nullptr)
|
: QAbstractListModel(nullptr)
|
||||||
, m_room(room)
|
, m_room(room)
|
||||||
, m_event(event)
|
, m_event(event)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
HasLocalUser, /**< Whether the local user is in the list of authors. */
|
HasLocalUser, /**< Whether the local user is in the list of authors. */
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ReactionModel(const Quotient::RoomMessageEvent *event, const NeoChatRoom *room);
|
explicit ReactionModel(const Quotient::RoomMessageEvent *event, NeoChatRoom *room);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the given role value at the given index.
|
* @brief Get the given role value at the given index.
|
||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const NeoChatRoom *m_room;
|
QPointer<NeoChatRoom> m_room;
|
||||||
const Quotient::RoomMessageEvent *m_event;
|
const Quotient::RoomMessageEvent *m_event;
|
||||||
QList<Reaction> m_reactions;
|
QList<Reaction> m_reactions;
|
||||||
QMap<QString, QString> m_shortcodes;
|
QMap<QString, QString> m_shortcodes;
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ private:
|
|||||||
void setSearching(bool searching);
|
void setSearching(bool searching);
|
||||||
|
|
||||||
QString m_searchText;
|
QString m_searchText;
|
||||||
NeoChatRoom *m_room = nullptr;
|
QPointer<NeoChatRoom> m_room;
|
||||||
Quotient::Omittable<Quotient::SearchJob::ResultRoomEvents> m_result = Quotient::none;
|
Quotient::Omittable<Quotient::SearchJob::ResultRoomEvents> m_result = Quotient::none;
|
||||||
Quotient::SearchJob *m_job = nullptr;
|
Quotient::SearchJob *m_job = nullptr;
|
||||||
bool m_searching = false;
|
bool m_searching = false;
|
||||||
|
|||||||
@@ -55,11 +55,14 @@ void StateKeysModel::setRoom(NeoChatRoom *room)
|
|||||||
|
|
||||||
m_room = room;
|
m_room = room;
|
||||||
Q_EMIT roomChanged();
|
Q_EMIT roomChanged();
|
||||||
loadState();
|
|
||||||
|
|
||||||
connect(room, &NeoChatRoom::changed, this, [this] {
|
if (room) {
|
||||||
loadState();
|
loadState();
|
||||||
});
|
|
||||||
|
connect(room, &NeoChatRoom::changed, this, [this] {
|
||||||
|
loadState();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString StateKeysModel::eventType() const
|
QString StateKeysModel::eventType() const
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ Q_SIGNALS:
|
|||||||
void eventTypeChanged();
|
void eventTypeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NeoChatRoom *m_room = nullptr;
|
QPointer<NeoChatRoom> m_room;
|
||||||
QString m_eventType;
|
QString m_eventType;
|
||||||
QVector<const Quotient::StateEvent *> m_stateKeys;
|
QVector<const Quotient::StateEvent *> m_stateKeys;
|
||||||
void loadState();
|
void loadState();
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ QVariant StickerModel::data(const QModelIndex &index, int role) const
|
|||||||
const auto &row = index.row();
|
const auto &row = index.row();
|
||||||
const auto &image = m_images[row];
|
const auto &image = m_images[row];
|
||||||
if (role == UrlRole) {
|
if (role == UrlRole) {
|
||||||
return m_room->connection()->makeMediaUrl(image.url);
|
if (m_room) {
|
||||||
|
return m_room->connection()->makeMediaUrl(image.url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (role == BodyRole) {
|
if (role == BodyRole) {
|
||||||
if (image.body) {
|
if (image.body) {
|
||||||
@@ -108,6 +110,10 @@ void StickerModel::setRoom(NeoChatRoom *room)
|
|||||||
|
|
||||||
void StickerModel::postSticker(int index)
|
void StickerModel::postSticker(int index)
|
||||||
{
|
{
|
||||||
|
if (!m_room) {
|
||||||
|
qWarning() << "No room";
|
||||||
|
}
|
||||||
|
|
||||||
const auto &image = m_images[index];
|
const auto &image = m_images[index];
|
||||||
const auto &body = image.body ? *image.body : image.shortcode;
|
const auto &body = image.body ? *image.body : image.shortcode;
|
||||||
QJsonObject infoJson;
|
QJsonObject infoJson;
|
||||||
|
|||||||
@@ -101,6 +101,6 @@ private:
|
|||||||
ImagePacksModel *m_model = nullptr;
|
ImagePacksModel *m_model = nullptr;
|
||||||
int m_index = 0;
|
int m_index = 0;
|
||||||
QList<Quotient::ImagePackEventContent::ImagePackImage> m_images;
|
QList<Quotient::ImagePackEventContent::ImagePackImage> m_images;
|
||||||
NeoChatRoom *m_room;
|
QPointer<NeoChatRoom> m_room;
|
||||||
void reloadImages();
|
void reloadImages();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user