File indexing completed on 2024-02-18 15:43:51

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "listmessagesmodel.h"
0008 
0009 #include "listmessages.h"
0010 
0011 ListMessagesModel::ListMessagesModel(const QString &roomID, RocketChatAccount *account, Room *room, QObject *parent)
0012     : MessagesModel(roomID, account, room, parent)
0013 {
0014 }
0015 
0016 ListMessagesModel::~ListMessagesModel() = default;
0017 
0018 void ListMessagesModel::parse(const QJsonObject &obj)
0019 {
0020     ListMessages messages;
0021     QString parseMessageName;
0022     if (mListMessageType == MentionsMessages) {
0023         parseMessageName = QStringLiteral("messages");
0024     } else if (mListMessageType == ThreadsMessages || mListMessageType == UnreadThreadsMessages) {
0025         parseMessageName = QStringLiteral("threads");
0026     } else {
0027         parseMessageName = QStringLiteral("messages");
0028     }
0029     messages.parseMessages(obj, parseMessageName);
0030     mTotal = messages.total();
0031     addMessages(messages.listMessages(), true);
0032     setHasFullList(rowCount() == total());
0033 }
0034 
0035 void ListMessagesModel::parseListMessages(const QJsonObject &obj)
0036 {
0037     clear();
0038     parse(obj);
0039 }
0040 
0041 void ListMessagesModel::loadMoreListMessages(const QJsonObject &obj)
0042 {
0043     parse(obj);
0044 }
0045 
0046 int ListMessagesModel::total() const
0047 {
0048     return mTotal;
0049 }
0050 
0051 void ListMessagesModel::setTotal(int total)
0052 {
0053     if (mTotal != total) {
0054         mTotal = total;
0055         Q_EMIT totalChanged();
0056     }
0057 }
0058 
0059 bool ListMessagesModel::loadMoreListMessagesInProgress() const
0060 {
0061     return mLoadingInProgress;
0062 }
0063 
0064 void ListMessagesModel::setLoadMoreListMessagesInProgress(bool inProgress)
0065 {
0066     if (mLoadingInProgress != inProgress) {
0067         mLoadingInProgress = inProgress;
0068         Q_EMIT loadingInProgressChanged();
0069     }
0070 }
0071 
0072 void ListMessagesModel::setHasFullList(bool state)
0073 {
0074     if (mHasFullList != state) {
0075         mHasFullList = state;
0076         Q_EMIT hasFullListChanged();
0077     }
0078 }
0079 
0080 bool ListMessagesModel::hasFullList() const
0081 {
0082     return mHasFullList;
0083 }
0084 
0085 ListMessagesModel::ListMessageType ListMessagesModel::listMessageType() const
0086 {
0087     return mListMessageType;
0088 }
0089 
0090 void ListMessagesModel::setListMessageType(ListMessageType listMessageType)
0091 {
0092     if (mListMessageType != listMessageType) {
0093         mListMessageType = listMessageType;
0094         Q_EMIT listMessageTypeChanged();
0095     }
0096 }
0097 
0098 #include "moc_listmessagesmodel.cpp"