File indexing completed on 2024-02-25 16:44:35

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "commonmessagesmodel.h"
0008 #include "rocketchataccount.h"
0009 
0010 #include "listmessages.h"
0011 
0012 CommonMessagesModel::CommonMessagesModel(RocketChatAccount *account, QObject *parent)
0013     : MessagesModel(QStringLiteral("no_room"), account, nullptr, parent)
0014 {
0015 }
0016 
0017 CommonMessagesModel::~CommonMessagesModel() = default;
0018 
0019 void CommonMessagesModel::clearModel()
0020 {
0021     mStringNotFound = true;
0022     mLoadingInProgress = false;
0023     clear();
0024 }
0025 
0026 QVector<Message> CommonMessagesModel::extractMessages(const QJsonObject &obj)
0027 {
0028     ListMessages messages;
0029     messages.parseMessages(obj, QStringLiteral("messages"));
0030     return messages.listMessages();
0031 }
0032 
0033 void CommonMessagesModel::parse(const QJsonObject &obj)
0034 {
0035     clear();
0036     const QVector<Message> messages = extractMessages(obj);
0037     addMessages(messages);
0038     setStringNotFound(rowCount() == 0);
0039 }
0040 
0041 void CommonMessagesModel::setStringNotFound(bool stringNotFound)
0042 {
0043     if (mStringNotFound != stringNotFound) {
0044         mStringNotFound = stringNotFound;
0045         Q_EMIT stringNotFoundChanged();
0046     }
0047 }
0048 
0049 bool CommonMessagesModel::loadCommonMessagesInProgress() const
0050 {
0051     return mLoadingInProgress;
0052 }
0053 
0054 void CommonMessagesModel::setLoadCommonMessagesInProgress(bool loadSearchMessageInProgress)
0055 {
0056     if (mLoadingInProgress != loadSearchMessageInProgress) {
0057         mLoadingInProgress = loadSearchMessageInProgress;
0058         Q_EMIT loadingInProgressChanged();
0059     }
0060 }
0061 
0062 #include "moc_commonmessagesmodel.cpp"