diff --git a/src/rocketchatrestapi-qt5/CMakeLists.txt b/src/rocketchatrestapi-qt5/CMakeLists.txt index a2362af5..94496ca9 100644 --- a/src/rocketchatrestapi-qt5/CMakeLists.txt +++ b/src/rocketchatrestapi-qt5/CMakeLists.txt @@ -1,160 +1,161 @@ set (RocketChatRestApiQt_SRCS restapirequest.cpp restapiutil.cpp restapimethod.cpp uploadfilejob.cpp restapiabstractjob.cpp abstractlogger.cpp spotlightjob.cpp serverinfojob.cpp misc/owninfojob.cpp misc/settingsoauthjob.cpp users/getavatarjob.cpp users/setavatarjob.cpp users/forgotpasswordjob.cpp users/usersinfojob.cpp users/userspresencejob.cpp users/getpresencejob.cpp users/resetavatarjob.cpp users/getusernamesuggestionjob.cpp users/setstatusjob.cpp authentication/logoutjob.cpp authentication/loginjob.cpp authentication/facebookauthjob.cpp authentication/googleauthjob.cpp authentication/twitterauthjob.cpp settings/privateinfojob.cpp channellistjob.cpp downloadfilejob.cpp emoji/loademojicustomjob.cpp emoji/deleteemojicustomjob.cpp chat/starmessagejob.cpp chat/syncthreadmessagesjob.cpp chat/pinmessagejob.cpp chat/postmessagejob.cpp chat/deletemessagejob.cpp chat/updatemessagejob.cpp chat/reactonmessagejob.cpp chat/searchmessagejob.cpp chat/ignoreuserjob.cpp chat/reportmessagejob.cpp chat/getmessagejob.cpp chat/followmessagejob.cpp chat/unfollowmessagejob.cpp chat/getthreadsjob.cpp chat/getthreadmessagesjob.cpp chat/sendmessagejob.cpp chat/getpinnedmessagesjob.cpp + chat/getstarredmessagesjob.cpp channels/changechanneltopicjob.cpp channels/changechannelannouncementjob.cpp channels/changechannelnamejob.cpp channels/createchanneljob.cpp channels/leavechanneljob.cpp channels/channelclosejob.cpp channels/channelhistoryjob.cpp channels/changechanneldescriptionjob.cpp channels/changechannelreadonlyjob.cpp channels/archivechanneljob.cpp channels/channelfilesjob.cpp channels/channelinvitejob.cpp channels/setjoincodechanneljob.cpp channels/channelremoveownerjob.cpp channels/setchanneltypejob.cpp channels/getchannelrolesjob.cpp channels/channeladdownerjob.cpp channels/channeladdmoderatorjob.cpp channels/channelkickjob.cpp channels/channeljoinjob.cpp channels/channelinfojob.cpp channels/channelgetallusermentionsjob.cpp channels/channelremovemoderatorjob.cpp channels/channeldeletejob.cpp channels/channelsmoderatorsjob.cpp channels/channelmembersjob.cpp channels/changechannelencryptedjob.cpp channels/channelremoveleaderjob.cpp channels/channeladdleaderjob.cpp groups/changegroupstopicjob.cpp groups/changegroupsannouncementjob.cpp groups/changegroupsnamejob.cpp groups/creategroupsjob.cpp groups/leavegroupsjob.cpp groups/changegroupsdescriptionjob.cpp groups/archivegroupsjob.cpp groups/groupsinvitejob.cpp groups/groupskickjob.cpp groups/setgrouptypejob.cpp groups/getgrouprolesjob.cpp groups/groupaddmoderatorjob.cpp groups/groupaddownerjob.cpp groups/groupsinfojob.cpp groups/groupremoveownerjob.cpp groups/groupaddleaderjob.cpp groups/groupremoveleaderjob.cpp groups/groupremovemoderatorjob.cpp groups/groupsdeletejob.cpp groups/changegroupsreadonlyjob.cpp groups/changegroupsencryptedjob.cpp directmessage/createdmjob.cpp directmessage/opendmjob.cpp directmessage/settopicdmjob.cpp rooms/savenotificationjob.cpp rooms/getroomsjob.cpp rooms/roomfavoritejob.cpp rooms/roomsinfojob.cpp rooms/roomleavejob.cpp rooms/roomstartdiscussionjob.cpp rooms/getdiscussionsjob.cpp subscriptions/markroomasreadjob.cpp subscriptions/markroomasunreadjob.cpp permissions/listpermissionsjob.cpp commands/listcommandsjob.cpp e2e/fetchmykeysjob.cpp e2e/setuserpublicandprivatekeysjob.cpp video-conference/videoconfupdatejitsitimeoutjob.cpp autotranslate/getsupportedlanguagesjob.cpp autotranslate/translatemessagejob.cpp autotranslate/translatesavesettingsjob.cpp ) ecm_qt_declare_logging_category(RocketChatRestApiQt_SRCS HEADER rocketchatqtrestapi_debug.h IDENTIFIER ROCKETCHATQTRESTAPI_LOG CATEGORY_NAME org.kde.rocketchatqtrestapi) add_library(librocketchatrestapi-qt5 ${RocketChatRestApiQt_SRCS}) generate_export_header(librocketchatrestapi-qt5 BASE_NAME librocketchatrestapi-qt5) target_link_libraries(librocketchatrestapi-qt5 Qt5::Core Qt5::Network Qt5::NetworkAuth KF5::I18n ) set_target_properties(librocketchatrestapi-qt5 PROPERTIES OUTPUT_NAME rocketchatrestapi-qt5 VERSION ${RUQOLA_LIB_VERSION} SOVERSION ${RUQOLA_LIB_SOVERSION} ) if (BUILD_TESTING) add_subdirectory(autotests) endif() install(TARGETS librocketchatrestapi-qt5 ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP) diff --git a/src/rocketchatrestapi-qt5/autotests/CMakeLists.txt b/src/rocketchatrestapi-qt5/autotests/CMakeLists.txt index 2705c87c..db3b4c7b 100644 --- a/src/rocketchatrestapi-qt5/autotests/CMakeLists.txt +++ b/src/rocketchatrestapi-qt5/autotests/CMakeLists.txt @@ -1,121 +1,122 @@ macro(add_ruqola_test _source) set( _test ${_source}) get_filename_component( _name ${_source} NAME_WE ) add_executable( ${_name} ${_test} ) add_test(NAME ${_name} COMMAND ${_name} ) ecm_mark_as_test(${_name}) target_link_libraries( ${_name} Qt5::Test librocketchatrestapi-qt5) endmacro() add_ruqola_test(restapiutiltest.cpp) add_ruqola_test(restapimethodtest.cpp) add_ruqola_test(serverinfojobtest.cpp) add_ruqola_test(uploadfilejobtest.cpp) add_ruqola_test(owninfojobtest.cpp) add_ruqola_test(getavatarjobtest.cpp) add_ruqola_test(logoutjobtest.cpp) add_ruqola_test(loginjobtest.cpp) add_ruqola_test(privateinfojobtest.cpp) add_ruqola_test(channellistjobtest.cpp) add_ruqola_test(starmessagejobtest.cpp) add_ruqola_test(downloadfilejobtest.cpp) add_ruqola_test(pinmessagejobtest.cpp) add_ruqola_test(postmessagejobtest.cpp) add_ruqola_test(changechanneltopicjobtest.cpp) add_ruqola_test(changechannelannouncementjobtest.cpp) add_ruqola_test(changegroupstopicjobtest.cpp) add_ruqola_test(changegroupsannouncementjobtest.cpp) add_ruqola_test(changechannelnamejobtest.cpp) add_ruqola_test(changegroupsnamejobtest.cpp) add_ruqola_test(deletemessagejobtest.cpp) add_ruqola_test(createchanneljobtest.cpp) add_ruqola_test(creategroupsjobtest.cpp) add_ruqola_test(leavechanneljobtest.cpp) add_ruqola_test(leavegroupsjobtest.cpp) add_ruqola_test(updatemessagejobtest.cpp) add_ruqola_test(reactonmessagejobtest.cpp) add_ruqola_test(channelclosejobtest.cpp) add_ruqola_test(createdmjobtest.cpp) add_ruqola_test(channelhistoryjobtest.cpp) add_ruqola_test(changechanneldescriptionjobtest.cpp) add_ruqola_test(changegroupsdescriptionjobtest.cpp) add_ruqola_test(changechannelreadonlyjobtest.cpp) add_ruqola_test(archivechanneljobtest.cpp) add_ruqola_test(archivegroupsjobtest.cpp) add_ruqola_test(channelfilesjobtest.cpp) add_ruqola_test(channelinvitejobtest.cpp) add_ruqola_test(groupsinvitejobtest.cpp) add_ruqola_test(loademojicustomjobtest.cpp) add_ruqola_test(spotlightjobtest.cpp) add_ruqola_test(searchmessagejobtest.cpp) add_ruqola_test(savenotificationjobtest.cpp) add_ruqola_test(markroomasreadjobtest.cpp) add_ruqola_test(settingsoauthjobtest.cpp) add_ruqola_test(facebookauthjobtest.cpp) add_ruqola_test(googleauthjobtest.cpp) add_ruqola_test(twitterauthjobtest.cpp) add_ruqola_test(roomfavoritejobtest.cpp) add_ruqola_test(setjoincodechanneljobtest.cpp) add_ruqola_test(setavatarjobtest.cpp) add_ruqola_test(markroomasunreadjobtest.cpp) add_ruqola_test(forgotpasswordjobtest.cpp) add_ruqola_test(usersinfojobtest.cpp) add_ruqola_test(userspresencejobtest.cpp) add_ruqola_test(ignoreuserjobtest.cpp) add_ruqola_test(channelremoveownerjobtest.cpp) add_ruqola_test(getpresencejobtest.cpp) add_ruqola_test(reportmessagejobtest.cpp) add_ruqola_test(resetavatarjobtest.cpp) add_ruqola_test(setgrouptypejobtest.cpp) add_ruqola_test(setchanneltypejobtest.cpp) add_ruqola_test(getchannelrolesjobtest.cpp) add_ruqola_test(getgrouprolesjobtest.cpp) add_ruqola_test(getusernamesuggestionjobtest.cpp) add_ruqola_test(listpermissionsjobtest.cpp) add_ruqola_test(listcommandsjobtest.cpp) add_ruqola_test(channeladdownerjobtest.cpp) add_ruqola_test(channeladdmoderatorjobtest.cpp) add_ruqola_test(groupaddmoderatorjobtest.cpp) add_ruqola_test(groupaddownerjobtest.cpp) add_ruqola_test(getmessagejobtest.cpp) add_ruqola_test(channelkickjobtest.cpp) add_ruqola_test(groupskickjobtest.cpp) add_ruqola_test(fetchmykeysjobtest.cpp) add_ruqola_test(setuserpublicandprivatekeysjobtest.cpp) add_ruqola_test(channeljoinjobtest.cpp) add_ruqola_test(roomleavejobtest.cpp) add_ruqola_test(getroomsjobtest.cpp) add_ruqola_test(channelinfojobtest.cpp) add_ruqola_test(groupsinfojobtest.cpp) add_ruqola_test(channelgetallusermentionsjobtest.cpp) add_ruqola_test(queryparameterstest.cpp) add_ruqola_test(videoconfupdatejitsitimeoutjobtest.cpp) add_ruqola_test(opendmjobtest.cpp) add_ruqola_test(groupremoveownerjobtest.cpp) add_ruqola_test(groupaddleaderjobtest.cpp) add_ruqola_test(groupremoveleaderjobtest.cpp) add_ruqola_test(groupremovemoderatorjobtest.cpp) add_ruqola_test(channelremovemoderatorjobtest.cpp) add_ruqola_test(channeldeletejobtest.cpp) add_ruqola_test(groupsdeletejobtest.cpp) add_ruqola_test(channelsmoderatorsjobtest.cpp) add_ruqola_test(channelmembersjobtest.cpp) add_ruqola_test(changegroupsreadonlyjobtest.cpp) add_ruqola_test(changechannelencryptedjobtest.cpp) add_ruqola_test(changegroupsencryptedjobtest.cpp) add_ruqola_test(channeladdleaderjobtest.cpp) add_ruqola_test(channelremoveleaderjobtest.cpp) add_ruqola_test(followmessagejobtest.cpp) add_ruqola_test(unfollowmessagejobtest.cpp) add_ruqola_test(roomstartdiscussionjobtest.cpp) add_ruqola_test(getdiscussionsjobtest.cpp) add_ruqola_test(getthreadsjobtest.cpp) add_ruqola_test(getthreadmessagesjobtest.cpp) add_ruqola_test(sendmessagejobtest.cpp) add_ruqola_test(deleteemojicustomjobtest.cpp) add_ruqola_test(getpinnedmessagesjobtest.cpp) add_ruqola_test(getsupportedlanguagesjobtest.cpp) add_ruqola_test(translatemessagejobtest.cpp) add_ruqola_test(syncthreadmessagesjobtest.cpp) add_ruqola_test(translatesavesettingsjobtest.cpp) add_ruqola_test(setstatusjobtest.cpp) +add_ruqola_test(getstarredmessagesjobtest.cpp) diff --git a/src/rocketchatrestapi-qt5/autotests/getstarredmessagesjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/getstarredmessagesjobtest.cpp new file mode 100644 index 00000000..d2d38d9e --- /dev/null +++ b/src/rocketchatrestapi-qt5/autotests/getstarredmessagesjobtest.cpp @@ -0,0 +1,80 @@ +/* + 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 "getstarredmessagesjobtest.h" +#include "chat/getstarredmessagesjob.h" +#include "ruqola_restapi_helper.h" +#include +QTEST_GUILESS_MAIN(GetStarredMessagesJobTest) +using namespace RocketChatRestApi; +GetStarredMessagesJobTest::GetStarredMessagesJobTest(QObject *parent) + : QObject(parent) +{ +} + +void GetStarredMessagesJobTest::shouldHaveDefaultValue() +{ + GetStarredMessagesJob job; + QVERIFY(!job.restApiMethod()); + QVERIFY(!job.networkAccessManager()); + QVERIFY(!job.start()); + QVERIFY(job.roomId().isEmpty()); + QVERIFY(job.requireHttpAuthentication()); + QVERIFY(!job.restApiLogger()); + QVERIFY(job.hasQueryParameterSupport()); +} + +void GetStarredMessagesJobTest::shouldGenerateRequest() +{ + GetStarredMessagesJob job; + RestApiMethod *method = new RestApiMethod; + method->setServerUrl(QStringLiteral("http://www.kde.org")); + job.setRestApiMethod(method); + const QString roomId = QStringLiteral("bla"); + job.setRoomId(roomId); + const QNetworkRequest request = job.request(); + QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.getStarredMessages?roomId=%1").arg(roomId))); + delete method; +} + +void GetStarredMessagesJobTest::shouldNotStarting() +{ + GetStarredMessagesJob job; + + RestApiMethod *method = new RestApiMethod; + method->setServerUrl(QStringLiteral("http://www.kde.org")); + job.setRestApiMethod(method); + + QNetworkAccessManager *mNetworkAccessManager = new QNetworkAccessManager; + job.setNetworkAccessManager(mNetworkAccessManager); + QVERIFY(!job.canStart()); + const QString auth = QStringLiteral("foo"); + const QString userId = QStringLiteral("foo"); + job.setAuthToken(auth); + QVERIFY(!job.canStart()); + job.setUserId(userId); + QVERIFY(!job.canStart()); + const QString roomId = QStringLiteral("foo1"); + job.setRoomId(roomId); + QVERIFY(job.canStart()); + + delete method; + delete mNetworkAccessManager; +} diff --git a/src/rocketchatrestapi-qt5/autotests/getstarredmessagesjobtest.h b/src/rocketchatrestapi-qt5/autotests/getstarredmessagesjobtest.h new file mode 100644 index 00000000..529903e5 --- /dev/null +++ b/src/rocketchatrestapi-qt5/autotests/getstarredmessagesjobtest.h @@ -0,0 +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. +*/ + +#ifndef GETSTARREDMESSAGESJOBTEST_H +#define GETSTARREDMESSAGESJOBTEST_H + +#include + +class GetStarredMessagesJobTest : public QObject +{ + Q_OBJECT +public: + explicit GetStarredMessagesJobTest(QObject *parent = nullptr); + ~GetStarredMessagesJobTest() = default; + +private Q_SLOTS: + void shouldGenerateRequest(); + void shouldNotStarting(); + void shouldHaveDefaultValue(); +}; + +#endif // GETSTARREDMESSAGESJOBTEST_H diff --git a/src/rocketchatrestapi-qt5/chat/getpinnedmessagesjob.cpp b/src/rocketchatrestapi-qt5/chat/getpinnedmessagesjob.cpp index f870c95f..ac3ba9bf 100644 --- a/src/rocketchatrestapi-qt5/chat/getpinnedmessagesjob.cpp +++ b/src/rocketchatrestapi-qt5/chat/getpinnedmessagesjob.cpp @@ -1,117 +1,117 @@ /* 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 "getpinnedmessagesjob.h" #include "restapimethod.h" #include "rocketchatqtrestapi_debug.h" #include #include #include #include using namespace RocketChatRestApi; GetPinnedMessagesJob::GetPinnedMessagesJob(QObject *parent) : RestApiAbstractJob(parent) { } GetPinnedMessagesJob::~GetPinnedMessagesJob() { } bool GetPinnedMessagesJob::requireHttpAuthentication() const { return true; } bool GetPinnedMessagesJob::canStart() const { if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GetPinnedMessagesJob"; return false; } if (mRoomId.isEmpty()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GetPinnedMessagesJob: mRoomId is empty"; return false; } return true; } bool GetPinnedMessagesJob::start() { if (!canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GetPinnedMessagesJob job"; deleteLater(); return false; } QNetworkReply *reply = mNetworkAccessManager->get(request()); connect(reply, &QNetworkReply::finished, this, &GetPinnedMessagesJob::slotGetPinnedMessagesFinished); - addLoggerInfo(QByteArrayLiteral("GetPinnedMessagesJob: Ask threads messages")); + addLoggerInfo(QByteArrayLiteral("GetPinnedMessagesJob: Ask pinned messages")); return true; } void GetPinnedMessagesJob::slotGetPinnedMessagesFinished() { QNetworkReply *reply = qobject_cast(sender()); if (reply) { const QByteArray data = reply->readAll(); const QJsonDocument replyJson = QJsonDocument::fromJson(data); const QJsonObject replyObject = replyJson.object(); if (replyObject[QStringLiteral("success")].toBool()) { addLoggerInfo(QByteArrayLiteral("GetPinnedMessagesJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); Q_EMIT getPinnedMessagesDone(replyObject, mRoomId); } else { emitFailedMessage(replyObject); addLoggerWarning(QByteArrayLiteral("GetPinnedMessagesJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); } reply->deleteLater(); } deleteLater(); } QString GetPinnedMessagesJob::roomId() const { return mRoomId; } void GetPinnedMessagesJob::setRoomId(const QString &roomId) { mRoomId = roomId; } QNetworkRequest GetPinnedMessagesJob::request() const { QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChatGetPinnedMessages); QUrlQuery queryUrl; queryUrl.addQueryItem(QStringLiteral("roomId"), mRoomId); addQueryParameter(queryUrl); url.setQuery(queryUrl); QNetworkRequest request(url); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); addAuthRawHeader(request); return request; } bool GetPinnedMessagesJob::hasQueryParameterSupport() const { return true; } diff --git a/src/rocketchatrestapi-qt5/chat/getpinnedmessagesjob.cpp b/src/rocketchatrestapi-qt5/chat/getstarredmessagesjob.cpp similarity index 67% copy from src/rocketchatrestapi-qt5/chat/getpinnedmessagesjob.cpp copy to src/rocketchatrestapi-qt5/chat/getstarredmessagesjob.cpp index f870c95f..d18b8243 100644 --- a/src/rocketchatrestapi-qt5/chat/getpinnedmessagesjob.cpp +++ b/src/rocketchatrestapi-qt5/chat/getstarredmessagesjob.cpp @@ -1,117 +1,117 @@ /* 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 "getpinnedmessagesjob.h" +#include "getstarredmessagesjob.h" #include "restapimethod.h" #include "rocketchatqtrestapi_debug.h" #include #include #include #include using namespace RocketChatRestApi; -GetPinnedMessagesJob::GetPinnedMessagesJob(QObject *parent) +GetStarredMessagesJob::GetStarredMessagesJob(QObject *parent) : RestApiAbstractJob(parent) { } -GetPinnedMessagesJob::~GetPinnedMessagesJob() +GetStarredMessagesJob::~GetStarredMessagesJob() { } -bool GetPinnedMessagesJob::requireHttpAuthentication() const +bool GetStarredMessagesJob::requireHttpAuthentication() const { return true; } -bool GetPinnedMessagesJob::canStart() const +bool GetStarredMessagesJob::canStart() const { if (!RestApiAbstractJob::canStart()) { - qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GetPinnedMessagesJob"; + qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GetStarredMessagesJob"; return false; } if (mRoomId.isEmpty()) { - qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GetPinnedMessagesJob: mRoomId is empty"; + qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GetStarredMessagesJob: mRoomId is empty"; return false; } return true; } -bool GetPinnedMessagesJob::start() +bool GetStarredMessagesJob::start() { if (!canStart()) { - qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GetPinnedMessagesJob job"; + qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GetStarredMessagesJob job"; deleteLater(); return false; } QNetworkReply *reply = mNetworkAccessManager->get(request()); - connect(reply, &QNetworkReply::finished, this, &GetPinnedMessagesJob::slotGetPinnedMessagesFinished); - addLoggerInfo(QByteArrayLiteral("GetPinnedMessagesJob: Ask threads messages")); + connect(reply, &QNetworkReply::finished, this, &GetStarredMessagesJob::slotGetStarredMessagesFinished); + addLoggerInfo(QByteArrayLiteral("GetStarredMessagesJob: Ask starred messages")); return true; } -void GetPinnedMessagesJob::slotGetPinnedMessagesFinished() +void GetStarredMessagesJob::slotGetStarredMessagesFinished() { QNetworkReply *reply = qobject_cast(sender()); if (reply) { const QByteArray data = reply->readAll(); const QJsonDocument replyJson = QJsonDocument::fromJson(data); const QJsonObject replyObject = replyJson.object(); if (replyObject[QStringLiteral("success")].toBool()) { - addLoggerInfo(QByteArrayLiteral("GetPinnedMessagesJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); - Q_EMIT getPinnedMessagesDone(replyObject, mRoomId); + addLoggerInfo(QByteArrayLiteral("GetStarredMessagesJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); + Q_EMIT getStarredMessagesDone(replyObject, mRoomId); } else { emitFailedMessage(replyObject); - addLoggerWarning(QByteArrayLiteral("GetPinnedMessagesJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); + addLoggerWarning(QByteArrayLiteral("GetStarredMessagesJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); } reply->deleteLater(); } deleteLater(); } -QString GetPinnedMessagesJob::roomId() const +QString GetStarredMessagesJob::roomId() const { return mRoomId; } -void GetPinnedMessagesJob::setRoomId(const QString &roomId) +void GetStarredMessagesJob::setRoomId(const QString &roomId) { mRoomId = roomId; } -QNetworkRequest GetPinnedMessagesJob::request() const +QNetworkRequest GetStarredMessagesJob::request() const { - QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChatGetPinnedMessages); + QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChatGetStarredMessages); QUrlQuery queryUrl; queryUrl.addQueryItem(QStringLiteral("roomId"), mRoomId); addQueryParameter(queryUrl); url.setQuery(queryUrl); QNetworkRequest request(url); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); addAuthRawHeader(request); return request; } -bool GetPinnedMessagesJob::hasQueryParameterSupport() const +bool GetStarredMessagesJob::hasQueryParameterSupport() const { return true; } diff --git a/src/rocketchatrestapi-qt5/chat/getstarredmessagesjob.h b/src/rocketchatrestapi-qt5/chat/getstarredmessagesjob.h new file mode 100644 index 00000000..8c9e0bbf --- /dev/null +++ b/src/rocketchatrestapi-qt5/chat/getstarredmessagesjob.h @@ -0,0 +1,58 @@ +/* + 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 GETSTARREDMESSAGESJOB_H +#define GETSTARREDMESSAGESJOB_H + +#include "restapiabstractjob.h" +#include "librestapi_private_export.h" + +#include +namespace RocketChatRestApi { +class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT GetStarredMessagesJob : public RestApiAbstractJob +{ + Q_OBJECT +public: + explicit GetStarredMessagesJob(QObject *parent = nullptr); + ~GetStarredMessagesJob() override; + + Q_REQUIRED_RESULT bool canStart() const override; + + Q_REQUIRED_RESULT bool requireHttpAuthentication() const override; + + Q_REQUIRED_RESULT bool start() override; + + Q_REQUIRED_RESULT QNetworkRequest request() const override; + + Q_REQUIRED_RESULT QString roomId() const; + void setRoomId(const QString &roomId); + + Q_REQUIRED_RESULT bool hasQueryParameterSupport() const override; + +Q_SIGNALS: + void getStarredMessagesDone(const QJsonObject &obj, const QString &roomId); + +private: + Q_DISABLE_COPY(GetStarredMessagesJob) + void slotGetStarredMessagesFinished(); + QString mRoomId; +}; +} +#endif // GETSTARREDMESSAGESJOB_H