diff --git a/autotests/listmessagesmodeltest.cpp b/autotests/listmessagesmodeltest.cpp index abab0c09..c9726676 100644 --- a/autotests/listmessagesmodeltest.cpp +++ b/autotests/listmessagesmodeltest.cpp @@ -1,37 +1,39 @@ /* Copyright (c) 2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "listmessagesmodeltest.h" #include "model/listmessagesmodel.h" #include QTEST_GUILESS_MAIN(ListMessagesModelTest) ListMessagesModelTest::ListMessagesModelTest(QObject *parent) : QObject(parent) { } void ListMessagesModelTest::shouldHaveDefaultValues() { ListMessagesModel w; QVERIFY(w.roomId().isEmpty()); QVERIFY(!w.loadMoreListMessagesInProgress()); + QCOMPARE(w.listMessageType(), ListMessagesModel::ListMessageType::Unknown); + QCOMPARE(w.total(), 0); } diff --git a/src/ruqolacore/model/listmessagesmodel.cpp b/src/ruqolacore/model/listmessagesmodel.cpp index fcb19f52..19896c77 100644 --- a/src/ruqolacore/model/listmessagesmodel.cpp +++ b/src/ruqolacore/model/listmessagesmodel.cpp @@ -1,102 +1,112 @@ /* Copyright (c) 2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "listmessagesmodel.h" #include "listmessages.h" ListMessagesModel::ListMessagesModel(const QString &roomID, RocketChatAccount *account, Room *room, QObject *parent) : MessageModel(roomID, account, room, parent) { } ListMessagesModel::~ListMessagesModel() { } QString ListMessagesModel::roomId() const { return mRoomId; } void ListMessagesModel::setRoomId(const QString &roomId) { mRoomId = roomId; } void ListMessagesModel::parse(const QJsonObject &obj) { ListMessages messages; messages.parseMessages(obj); mTotal = messages.total(); for (int i = 0, total = messages.count(); i < total; ++i) { addMessage(messages.at(i)); } checkFullList(); } void ListMessagesModel::parseListMessages(const QJsonObject &obj) { clear(); parse(obj); } void ListMessagesModel::loadMoreListMessages(const QJsonObject &obj) { parse(obj); } int ListMessagesModel::total() const { return mTotal; } void ListMessagesModel::setTotal(int total) { mTotal = total; } bool ListMessagesModel::loadMoreListMessagesInProgress() const { return mLoadingInProgress; } void ListMessagesModel::setLoadMoreListMessagesInProgress(bool inProgress) { mLoadingInProgress = inProgress; } void ListMessagesModel::setHasFullList(bool state) { if (mHasFullList != state) { mHasFullList = state; Q_EMIT hasFullListChanged(); } } bool ListMessagesModel::hasFullList() const { return mHasFullList; } void ListMessagesModel::checkFullList() { setHasFullList(rowCount() == total()); } + +ListMessagesModel::ListMessageType ListMessagesModel::listMessageType() const +{ + return mListMessageType; +} + +void ListMessagesModel::setListMessageType(const ListMessageType &listMessageType) +{ + mListMessageType = listMessageType; +} diff --git a/src/ruqolacore/model/listmessagesmodel.h b/src/ruqolacore/model/listmessagesmodel.h index 393974d6..5ea76603 100644 --- a/src/ruqolacore/model/listmessagesmodel.h +++ b/src/ruqolacore/model/listmessagesmodel.h @@ -1,62 +1,75 @@ /* Copyright (c) 2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef PINNEDMESSAGEMODEL_H -#define PINNEDMESSAGEMODEL_H +#ifndef LISTMESSAGESMODEL_H +#define LISTMESSAGESMODEL_H #include "libruqola_private_export.h" #include "messagemodel.h" class LIBRUQOLACORE_TESTS_EXPORT ListMessagesModel : public MessageModel { Q_OBJECT Q_PROPERTY(bool hasFullList READ hasFullList WRITE setHasFullList NOTIFY hasFullListChanged) public: + + enum ListMessageType { + Unknown = 0, + StarredMessages, + SnipperedMessages, + PinnedMessages + }; + Q_ENUM(ListMessageType) + explicit ListMessagesModel(const QString &roomID = QStringLiteral("no_room"), RocketChatAccount *account = nullptr, Room *room = nullptr, QObject *parent = nullptr); ~ListMessagesModel(); Q_REQUIRED_RESULT QString roomId() const; void setRoomId(const QString &roomId); void parseListMessages(const QJsonObject &obj); void loadMoreListMessages(const QJsonObject &obj); Q_INVOKABLE Q_REQUIRED_RESULT int total() const; void setTotal(int total); Q_REQUIRED_RESULT bool loadMoreListMessagesInProgress() const; void setLoadMoreListMessagesInProgress(bool inProgress); void setHasFullList(bool state); Q_REQUIRED_RESULT bool hasFullList() const; + Q_REQUIRED_RESULT ListMessageType listMessageType() const; + void setListMessageType(const ListMessageType &listMessageType); + Q_SIGNALS: void hasFullListChanged(); private: void parse(const QJsonObject &obj); void checkFullList(); QString mRoomId; int mTotal = 0; bool mLoadingInProgress = false; bool mHasFullList = false; + ListMessageType mListMessageType = Unknown; }; -#endif // PINNEDMESSAGEMODEL_H +#endif