diff --git a/autotests/mentionsfilterproxymodeltest.cpp b/autotests/mentionsfilterproxymodeltest.cpp index f2f1ef5a..2e6f556c 100644 --- a/autotests/mentionsfilterproxymodeltest.cpp +++ b/autotests/mentionsfilterproxymodeltest.cpp @@ -1,29 +1,28 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mentionsfilterproxymodeltest.h" #include QTEST_MAIN(MentionsFilterProxyModelTest) MentionsFilterProxyModelTest::MentionsFilterProxyModelTest(QObject *parent) : QObject(parent) { - } diff --git a/autotests/mentionsmodeltest.cpp b/autotests/mentionsmodeltest.cpp index 88c57790..5c497c78 100644 --- a/autotests/mentionsmodeltest.cpp +++ b/autotests/mentionsmodeltest.cpp @@ -1,43 +1,42 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mentionsmodeltest.h" #include "model/mentionsmodel.h" #include #include QTEST_MAIN(MentionsModelTest) MentionsModelTest::MentionsModelTest(QObject *parent) : QObject(parent) { - } void MentionsModelTest::shouldHaveDefaultValue() { MentionsModel w; QSignalSpy rowInsertedSpy(&w, &MentionsModel::rowsInserted); // (if it had 0 columns, it would have to emit column insertions, too much trouble) QCOMPARE(w.rowCount(), 0); QCOMPARE(rowInsertedSpy.count(), 0); QHash roles; //roles[FilesForRoomModel::UserName] = QByteArrayLiteral("username"); //TODO FIXME QCOMPARE(w.roleNames(), roles); } diff --git a/autotests/mentionstest.cpp b/autotests/mentionstest.cpp index 6308228b..aac089f3 100644 --- a/autotests/mentionstest.cpp +++ b/autotests/mentionstest.cpp @@ -1,27 +1,26 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mentionstest.h" #include QTEST_GUILESS_MAIN(MentionsTest) MentionsTest::MentionsTest(QObject *parent) : QObject(parent) { - } diff --git a/autotests/mentiontest.cpp b/autotests/mentiontest.cpp index 7118aab6..61822bd1 100644 --- a/autotests/mentiontest.cpp +++ b/autotests/mentiontest.cpp @@ -1,29 +1,28 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mentiontest.h" #include "mention.h" #include QTEST_GUILESS_MAIN(MentionTest) MentionTest::MentionTest(QObject *parent) : QObject(parent) { - } diff --git a/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.cpp index b0c4ff56..eacab67c 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.cpp @@ -1,82 +1,81 @@ /* 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 "channelgetallusermentionsjobtest.h" #include "channels/channelgetallusermentionsjob.h" #include "restapimethod.h" #include "ruqola_restapi_helper.h" #include QTEST_GUILESS_MAIN(ChannelGetAllUserMentionsJobTest) using namespace RocketChatRestApi; ChannelGetAllUserMentionsJobTest::ChannelGetAllUserMentionsJobTest(QObject *parent) : QObject(parent) { } void ChannelGetAllUserMentionsJobTest::shouldHaveDefaultValue() { ChannelGetAllUserMentionsJob job; QVERIFY(!job.restApiMethod()); QVERIFY(!job.networkAccessManager()); QVERIFY(!job.start()); QVERIFY(job.requireHttpAuthentication()); QVERIFY(job.roomId().isEmpty()); QVERIFY(!job.restApiLogger()); } void ChannelGetAllUserMentionsJobTest::shouldGenerateRequest() { ChannelGetAllUserMentionsJob job; RestApiMethod *method = new RestApiMethod; method->setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(method); const QString roomId = QStringLiteral("avat"); - job.setRoomId(roomId); + job.setRoomId(roomId); QNetworkRequest request = job.request(); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.getAllUserMentionsByChannel?roomId=avat"))); delete method; } void ChannelGetAllUserMentionsJobTest::shouldNotStarting() { ChannelGetAllUserMentionsJob 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/restapirequest.cpp b/src/rocketchatrestapi-qt5/restapirequest.cpp index 7f1180db..194db29e 100644 --- a/src/rocketchatrestapi-qt5/restapirequest.cpp +++ b/src/rocketchatrestapi-qt5/restapirequest.cpp @@ -1,1030 +1,1029 @@ /* Copyright (c) 2017-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 "restapimethod.h" #include "restapirequest.h" #include "rocketchatqtrestapi_debug.h" #include "serverinfojob.h" #include "uploadfilejob.h" #include "settings/privateinfojob.h" #include "channellistjob.h" #include "downloadfilejob.h" #include "spotlightjob.h" #include "users/getavatarjob.h" #include "users/setavatarjob.h" #include "users/forgotpasswordjob.h" #include "users/usersinfojob.h" #include "users/getpresencejob.h" #include "users/getusernamesuggestionjob.h" #include "misc/owninfojob.h" #include "emoji/loademojicustomjob.h" #include "authentication/logoutjob.h" #include "authentication/loginjob.h" #include "chat/starmessagejob.h" #include "chat/postmessagejob.h" #include "chat/deletemessagejob.h" #include "chat/updatemessagejob.h" #include "chat/reactonmessagejob.h" #include "chat/searchmessagejob.h" #include "chat/ignoreuserjob.h" #include "chat/reportmessagejob.h" #include "channels/changechanneltopicjob.h" #include "channels/changechannelannouncementjob.h" #include "channels/createchanneljob.h" #include "channels/leavechanneljob.h" #include "channels/channelclosejob.h" #include "channels/channelhistoryjob.h" #include "channels/changechanneldescriptionjob.h" #include "channels/archivechanneljob.h" #include "channels/channelfilesjob.h" #include "channels/channelinvitejob.h" #include "channels/setchanneltypejob.h" #include "channels/getchannelrolesjob.h" #include "channels/setjoincodechanneljob.h" #include "channels/channeljoinjob.h" #include "channels/channelinfojob.h" #include "channels/changechannelnamejob.h" #include "channels/channelgetallusermentionsjob.h" #include "groups/changegroupsannouncementjob.h" #include "groups/changegroupstopicjob.h" #include "groups/creategroupsjob.h" #include "groups/leavegroupsjob.h" #include "groups/changegroupsdescriptionjob.h" #include "groups/archivegroupsjob.h" #include "groups/groupsinvitejob.h" #include "groups/setgrouptypejob.h" #include "groups/getgrouprolesjob.h" #include "groups/changegroupsnamejob.h" #include "groups/groupsinfojob.h" #include "rooms/getroomsjob.h" #include "rooms/roomfavoritejob.h" #include "rooms/savenotificationjob.h" #include "directmessage/createdmjob.h" #include "subscriptions/markroomasreadjob.h" #include "subscriptions/markroomasunreadjob.h" #include "permissions/listpermissionsjob.h" #include "commands/listcommandsjob.h" #include "e2e/fetchmykeysjob.h" #include #include #include #include #include using namespace RocketChatRestApi; RestApiRequest::RestApiRequest(QObject *parent) : QObject(parent) { mRestApiMethod = new RestApiMethod; mCookieJar = new QNetworkCookieJar; mNetworkAccessManager = new QNetworkAccessManager(this); mNetworkAccessManager->setCookieJar(mCookieJar); connect(mNetworkAccessManager, &QNetworkAccessManager::finished, this, &RestApiRequest::slotResult); connect(mNetworkAccessManager, &QNetworkAccessManager::sslErrors, this, &RestApiRequest::slotSslErrors); } RestApiRequest::~RestApiRequest() { delete mRestApiMethod; } void RestApiRequest::setRestApiLogger(RocketChatRestApi::AbstractLogger *logger) { mRuqolaLogger = logger; } void RestApiRequest::initializeCookies() { QString url = serverUrl(); if (!url.isEmpty()) { QString host; QStringList lsthost = url.split(QStringLiteral("//")); if (lsthost.count() < 2) { host = url; } else { host = lsthost.at(1); } if (!mUserId.isEmpty()) { QNetworkCookie userIdCookie; userIdCookie.setDomain(host); userIdCookie.setName(QByteArrayLiteral("rc_uid")); userIdCookie.setValue(mUserId.toLocal8Bit()); mCookieJar->insertCookie(userIdCookie); } if (!mAuthToken.isEmpty()) { QNetworkCookie tokenCookie; tokenCookie.setDomain(host); tokenCookie.setName(QByteArrayLiteral("rc_token")); tokenCookie.setValue(mAuthToken.toLocal8Bit()); mCookieJar->insertCookie(tokenCookie); } } else { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "We can not initialize cookies as server url is empty."; } } void RestApiRequest::setAuthToken(const QString &authToken) { const bool isChanged = (mAuthToken != authToken); mAuthToken = authToken; if (isChanged) { if (!mAuthToken.isEmpty()) { initializeCookies(); } } } void RestApiRequest::setUserId(const QString &userId) { const bool isChanged = (mUserId != userId); mUserId = userId; if (isChanged) { if (!mUserId.isEmpty()) { initializeCookies(); } } } void RestApiRequest::slotResult(QNetworkReply *reply) { if (reply->error() != QNetworkReply::NoError) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << " Error reply - "<errorString(); } } void RestApiRequest::slotSslErrors(QNetworkReply *reply, const QList &error) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << " void RestApiRequest::slotSslErrors(QNetworkReply *reply, const QList &error)" << error.count(); reply->ignoreSslErrors(error); } void RestApiRequest::setPassword(const QString &password) { mPassword = password; } void RestApiRequest::setUserName(const QString &userName) { mUserName = userName; } QString RestApiRequest::serverUrl() const { return mRestApiMethod->serverUrl(); } void RestApiRequest::setServerUrl(const QString &serverUrl) { mRestApiMethod->setServerUrl(serverUrl); } QString RestApiRequest::authToken() const { return mAuthToken; } QString RestApiRequest::userId() const { return mUserId; } void RestApiRequest::login() { LoginJob *job = new LoginJob(this); connect(job, &LoginJob::loginDone, this, &RestApiRequest::slotLogin); initializeRestApiJob(job); job->setPassword(mPassword); job->setUserName(mUserName); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::slotLogin(const QString &authToken, const QString &userId) { mAuthToken = authToken; mUserId = userId; } void RestApiRequest::slotLogout() { mUserId.clear(); mAuthToken.clear(); Q_EMIT logoutDone(); } void RestApiRequest::initializeRestApiJob(RocketChatRestApi::RestApiAbstractJob *job) { job->setNetworkAccessManager(mNetworkAccessManager); job->setRestApiLogger(mRuqolaLogger); job->setRestApiMethod(mRestApiMethod); if (job->requireHttpAuthentication()) { job->setAuthToken(mAuthToken); job->setUserId(mUserId); } } void RestApiRequest::logout() { LogoutJob *job = new LogoutJob(this); connect(job, &LogoutJob::logoutDone, this, &RestApiRequest::slotLogout); initializeRestApiJob(job); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::channelList() { ChannelListJob *job = new ChannelListJob(this); connect(job, &ChannelListJob::channelListDone, this, &RestApiRequest::channelListDone); initializeRestApiJob(job); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::getAvatar(const QString &userId) { GetAvatarJob *job = new GetAvatarJob(this); connect(job, &GetAvatarJob::avatar, this, &RestApiRequest::avatar); initializeRestApiJob(job); job->setAvatarUserId(userId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::getPrivateSettings() { PrivateInfoJob *job = new PrivateInfoJob(this); connect(job, &PrivateInfoJob::privateInfoDone, this, &RestApiRequest::privateInfoDone); initializeRestApiJob(job); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::getOwnInfo() { OwnInfoJob *job = new OwnInfoJob(this); connect(job, &OwnInfoJob::ownInfoDone, this, &RestApiRequest::getOwnInfoDone); initializeRestApiJob(job); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::starMessage(const QString &messageId, bool starred) { StarMessageJob *job = new StarMessageJob(this); initializeRestApiJob(job); job->setMessageId(messageId); job->setStarMessage(starred); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::downloadFile(const QUrl &url, const QString &mimeType, bool storeInCache, const QUrl &localFileUrl) { DownloadFileJob *job = new DownloadFileJob(this); connect(job, &DownloadFileJob::downloadFileDone, this, &RestApiRequest::downloadFileDone); job->setUrl(url); job->setMimeType(mimeType); job->setLocalFileUrl(localFileUrl); job->setStoreInCache(storeInCache); initializeRestApiJob(job); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::serverInfo() { ServerInfoJob *job = new ServerInfoJob(this); initializeRestApiJob(job); connect(job, &ServerInfoJob::serverInfoDone, this, &RestApiRequest::getServerInfoDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::uploadFile(const QString &roomId, const QString &description, const QString &text, const QUrl &filename) { UploadFileJob *job = new UploadFileJob(this); initializeRestApiJob(job); job->setDescription(description); job->setMessageText(text); job->setFilenameUrl(filename); job->setRoomId(roomId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeChannelTopic(const QString &roomId, const QString &topic) { ChangeChannelTopicJob *job = new ChangeChannelTopicJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setTopic(topic); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeGroupsTopic(const QString &roomId, const QString &topic) { ChangeGroupsTopicJob *job = new ChangeGroupsTopicJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setTopic(topic); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeChannelAnnouncement(const QString &roomId, const QString &announcement) { ChangeChannelAnnouncementJob *job = new ChangeChannelAnnouncementJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setAnnouncement(announcement); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeGroupsAnnouncement(const QString &roomId, const QString &announcement) { ChangeGroupsAnnouncementJob *job = new ChangeGroupsAnnouncementJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setAnnouncement(announcement); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeChannelDescription(const QString &roomId, const QString &description) { ChangeChannelDescriptionJob *job = new ChangeChannelDescriptionJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setDescription(description); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeGroupsDescription(const QString &roomId, const QString &description) { ChangeGroupsDescriptionJob *job = new ChangeGroupsDescriptionJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setDescription(description); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::postMessage(const QString &roomId, const QString &text) { PostMessageJob *job = new PostMessageJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setText(text); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::deleteMessage(const QString &roomId, const QString &messageId) { DeleteMessageJob *job = new DeleteMessageJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setMessageId(messageId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::slotAddJoinCodeToChannel(const QString &channelId, const QString &password) { setJoinCodeChannel(channelId, password); } void RestApiRequest::createChannels(const QString &channelName, bool readOnly, const QStringList &members, const QString &password) { CreateChannelJob *job = new CreateChannelJob(this); connect(job, &CreateChannelJob::addJoinCodeToChannel, this, &RestApiRequest::slotAddJoinCodeToChannel); initializeRestApiJob(job); job->setChannelName(channelName); job->setReadOnly(readOnly); job->setMembers(members); job->setPassword(password); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::createGroups(const QString &channelName, bool readOnly, const QStringList &members) { CreateGroupsJob *job = new CreateGroupsJob(this); initializeRestApiJob(job); job->setChannelName(channelName); job->setReadOnly(readOnly); job->setMembers(members); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::leaveChannel(const QString &roomId) { LeaveChannelJob *job = new LeaveChannelJob(this); initializeRestApiJob(job); job->setRoomId(roomId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::leaveGroups(const QString &roomId) { LeaveGroupsJob *job = new LeaveGroupsJob(this); initializeRestApiJob(job); job->setRoomId(roomId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::archiveChannel(const QString &roomId) { ArchiveChannelJob *job = new ArchiveChannelJob(this); initializeRestApiJob(job); job->setRoomId(roomId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::archiveGroups(const QString &roomId) { ArchiveGroupsJob *job = new ArchiveGroupsJob(this); initializeRestApiJob(job); job->setRoomId(roomId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::updateMessage(const QString &roomId, const QString &messageId, const QString &text) { UpdateMessageJob *job = new UpdateMessageJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setMessageId(messageId); job->setUpdatedText(text); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::reactOnMessage(const QString &messageId, const QString &emoji, bool shouldReact) { ReactOnMessageJob *job = new ReactOnMessageJob(this); initializeRestApiJob(job); job->setMessageId(messageId); job->setEmoji(emoji); job->setShouldReact(shouldReact); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::closeChannel(const QString &roomId, const QString &type) { ChannelCloseJob *job = new ChannelCloseJob(this); initializeRestApiJob(job); job->setRoomId(roomId); if (type == QLatin1String("d")) { job->setChannelType(ChannelCloseJob::Direct); } else if (type == QLatin1String("p")) { job->setChannelType(ChannelCloseJob::Groups); } else if (type == QLatin1String("c")) { job->setChannelType(ChannelCloseJob::Channel); } if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::historyChannel(const QString &roomId, const QString &type) { ChannelHistoryJob *job = new ChannelHistoryJob(this); initializeRestApiJob(job); job->setRoomId(roomId); if (type == QLatin1String("d")) { job->setChannelType(ChannelHistoryJob::Direct); } else if (type == QLatin1String("p")) { job->setChannelType(ChannelHistoryJob::Groups); } else if (type == QLatin1String("c")) { job->setChannelType(ChannelHistoryJob::Channel); } if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::createDirectMessage(const QString &userName) { CreateDmJob *job = new CreateDmJob(this); initializeRestApiJob(job); job->setUserName(userName); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::filesInRoom(const QString &roomId, const QString &type) { ChannelFilesJob *job = new ChannelFilesJob(this); connect(job, &ChannelFilesJob::channelFilesDone, this, &RestApiRequest::channelFilesDone); initializeRestApiJob(job); job->setRoomId(roomId); if (type == QLatin1String("d")) { job->setChannelType(ChannelFilesJob::Direct); } else if (type == QLatin1String("p")) { job->setChannelType(ChannelFilesJob::Groups); } else if (type == QLatin1String("c")) { job->setChannelType(ChannelFilesJob::Channel); } if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::addUserInChannel(const QString &roomId, const QString &userId) { ChannelInviteJob *job = new ChannelInviteJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setInviteUserId(userId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::addUserInGroup(const QString &roomId, const QString &userId) { GroupsInviteJob *job = new GroupsInviteJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setUserId(userId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::listEmojiCustom() { LoadEmojiCustomJob *job = new LoadEmojiCustomJob(this); initializeRestApiJob(job); connect(job, &LoadEmojiCustomJob::loadEmojiCustomDone, this, &RestApiRequest::loadEmojiCustomDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::searchRoomUser(const QString &pattern) { SpotlightJob *job = new SpotlightJob(this); job->setSearchPattern(pattern); initializeRestApiJob(job); connect(job, &SpotlightJob::spotlightDone, this, &RestApiRequest::spotlightDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::searchMessages(const QString &roomId, const QString &pattern) { SearchMessageJob *job = new SearchMessageJob(this); job->setRoomId(roomId); job->setSearchText(pattern); initializeRestApiJob(job); connect(job, &SearchMessageJob::searchMessageDone, this, &RestApiRequest::searchMessageDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::markAsRead(const QString &roomId) { MarkRoomAsReadJob *job = new MarkRoomAsReadJob(this); job->setRoomId(roomId); initializeRestApiJob(job); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::markRoomAsUnRead(const QString &roomId) { MarkRoomAsUnReadJob *job = new MarkRoomAsUnReadJob(this); job->setObjectId(roomId); job->setUnReadObject(MarkRoomAsUnReadJob::Room); initializeRestApiJob(job); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::markMessageAsUnReadFrom(const QString &messageId) { MarkRoomAsUnReadJob *job = new MarkRoomAsUnReadJob(this); job->setObjectId(messageId); job->setUnReadObject(MarkRoomAsUnReadJob::FromMessage); initializeRestApiJob(job); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::getRooms() { GetRoomsJob *job = new GetRoomsJob(this); initializeRestApiJob(job); connect(job, &GetRoomsJob::getRoomsDone, this, &RestApiRequest::getRoomsDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::markAsFavorite(const QString &roomId, bool favorite) { RoomFavoriteJob *job = new RoomFavoriteJob(this); initializeRestApiJob(job); job->setFavorite(favorite); job->setRoomId(roomId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::disableNotifications(const QString &roomId, bool value) { SaveNotificationJob *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setDisableNotifications(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::muteGroupMentions(const QString &roomId, bool value) { SaveNotificationJob *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setMuteGroupMentions(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeGroupName(const QString &roomId, const QString &newName) { ChangeGroupsNameJob *job = new ChangeGroupsNameJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setName(newName); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeChannelName(const QString &roomId, const QString &newName) { ChangeChannelNameJob *job = new ChangeChannelNameJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setName(newName); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::channelInfo(const QString &roomId) { ChannelInfoJob *job = new ChannelInfoJob(this); initializeRestApiJob(job); job->setRoomId(roomId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::groupInfo(const QString &roomId) { GroupsInfoJob *job = new GroupsInfoJob(this); initializeRestApiJob(job); job->setRoomId(roomId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::hideUnreadStatus(const QString &roomId, bool value) { SaveNotificationJob *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setHideUnreadStatus(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::audioNotifications(const QString &roomId, const QString &value) { SaveNotificationJob *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setAudioNotifications(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::desktopNotifications(const QString &roomId, const QString &value) { // SaveNotificationJob *job = new SaveNotificationJob(this); // initializeRestApiJob(job); // job->setRoomId(roomId); // job->setDesktopNotificationDuration(value); // if (!job->start()) { // qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; // } } void RestApiRequest::emailNotifications(const QString &roomId, const QString &value) { SaveNotificationJob *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setEmailNotifications(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::mobilePushNotifications(const QString &roomId, const QString &value) { SaveNotificationJob *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setMobilePushNotifications(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::unreadAlert(const QString &roomId, const QString &value) { SaveNotificationJob *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setUnreadAlert(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::setAvatar(const QString &avatarUrl) { SetAvatarJob *job = new SetAvatarJob(this); initializeRestApiJob(job); job->setAvatarUrl(avatarUrl); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::forgotPassword(const QString &email) { ForgotPasswordJob *job = new ForgotPasswordJob(this); initializeRestApiJob(job); job->setEmail(email); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::userInfo(const QString &identifier, bool userName) { UsersInfoJob *job = new UsersInfoJob(this); initializeRestApiJob(job); job->setIdentifier(identifier); job->setUseUserName(userName); connect(job, &UsersInfoJob::usersInfoDone, this, &RestApiRequest::usersInfoDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::ignoreUser(const QString &roomId, const QString &userId, bool ignore) { IgnoreUserJob *job = new IgnoreUserJob(this); initializeRestApiJob(job); job->setIgnoreUserId(userId); job->setRoomId(roomId); job->setIgnore(ignore); //connect(job, &UsersInfoJob::usersInfoDone, this, &RestApiRequest::usersInfoDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::userPresence(const QString &userId) { GetPresenceJob *job = new GetPresenceJob(this); initializeRestApiJob(job); job->setPresenceUserId(userId); connect(job, &GetPresenceJob::getPresenceDone, this, &RestApiRequest::getPresenceDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::reportMessage(const QString &messageId, const QString &message) { ReportMessageJob *job = new ReportMessageJob(this); initializeRestApiJob(job); job->setMessageId(messageId); job->setReportMessage(message); //connect(job, &GetPresenceJob::getPresenceDone, this, &RestApiRequest::getPresenceDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::setGroupType(const QString &roomId, const QString &type) { SetGroupTypeJob *job = new SetGroupTypeJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setType(type == QLatin1String("c") ? SetGroupTypeJob::Private : SetGroupTypeJob::Public); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::setChannelType(const QString &roomId, const QString &type) { SetChannelTypeJob *job = new SetChannelTypeJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setType(type == QLatin1String("c") ? SetChannelTypeJob::Private : SetChannelTypeJob::Public); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::getGroupRoles(const QString &roomId) { GetGroupRolesJob *job = new GetGroupRolesJob(this); initializeRestApiJob(job); job->setRoomId(roomId); connect(job, &GetGroupRolesJob::groupRolesDone, this, &RestApiRequest::groupRolesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getGroupRoles job"; } } void RestApiRequest::getChannelRoles(const QString &roomId) { GetChannelRolesJob *job = new GetChannelRolesJob(this); initializeRestApiJob(job); job->setRoomId(roomId); connect(job, &GetChannelRolesJob::channelRolesDone, this, &RestApiRequest::channelRolesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GetChannelRolesJob job"; } } void RestApiRequest::getUsernameSuggestion() { GetUsernameSuggestionJob *job = new GetUsernameSuggestionJob(this); initializeRestApiJob(job); connect(job, &GetUsernameSuggestionJob::getUsernameSuggestionDone, this, &RestApiRequest::getUsernameSuggestionDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getUsernameSuggestion job"; } } void RestApiRequest::listPermissions() { ListPermissionsJob *job = new ListPermissionsJob(this); initializeRestApiJob(job); connect(job, &ListPermissionsJob::listPermissionDone, this, &RestApiRequest::listPermissionDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ListPermissionsJob job"; } } void RestApiRequest::listCommands() { ListCommandsJob *job = new ListCommandsJob(this); initializeRestApiJob(job); connect(job, &ListCommandsJob::listCommandsDone, this, &RestApiRequest::listCommandsDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ListPermissionsJob job"; } } void RestApiRequest::fetchMyKeys() { FetchMyKeysJob *job = new FetchMyKeysJob(this); initializeRestApiJob(job); connect(job, &FetchMyKeysJob::fetchMyKeysDone, this, &RestApiRequest::fetchMyKeysDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start fetchmykeys job"; } } void RestApiRequest::setJoinCodeChannel(const QString &roomId, const QString &joinCode) { SetJoinCodeChannelJob *job = new SetJoinCodeChannelJob(this); initializeRestApiJob(job); job->setJoinCode(joinCode); job->setRoomId(roomId); connect(job, &SetJoinCodeChannelJob::setJoinCodeDone, this, &RestApiRequest::setJoinCodeDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start setjoincode"; } } void RestApiRequest::channelJoin(const QString &roomId, const QString &joinCode) { ChannelJoinJob *job = new ChannelJoinJob(this); initializeRestApiJob(job); job->setJoinCode(joinCode); job->setRoomId(roomId); connect(job, &ChannelJoinJob::setChannelJoinDone, this, &RestApiRequest::setChannelJoinDone); connect(job, &ChannelJoinJob::missingChannelPassword, this, &RestApiRequest::missingChannelPassword); connect(job, &ChannelJoinJob::openArchivedRoom, this, &RestApiRequest::openArchivedRoom); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start setChannelJoin"; } } - void RestApiRequest::channelGetAllUserMentions(const QString &roomId) { ChannelGetAllUserMentionsJob *job = new ChannelGetAllUserMentionsJob(this); initializeRestApiJob(job); job->setRoomId(roomId); connect(job, &ChannelGetAllUserMentionsJob::channelGetAllUserMentionsDone, this, &RestApiRequest::channelGetAllUserMentionsDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start setChannelJoin"; } } diff --git a/src/ruqolacore/mention.cpp b/src/ruqolacore/mention.cpp index eef18541..3d8db5d3 100644 --- a/src/ruqolacore/mention.cpp +++ b/src/ruqolacore/mention.cpp @@ -1,37 +1,36 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mention.h" Mention::Mention() { - } QDebug operator <<(QDebug d, const Mention &t) { //TODO return d; } bool Mention::operator ==(const Mention &other) const { //return (mUserNames == other.userNames()) && (mReactionName == other.reactionName()); return true; } diff --git a/src/ruqolacore/mentions.cpp b/src/ruqolacore/mentions.cpp index 2133c286..9b98bf9d 100644 --- a/src/ruqolacore/mentions.cpp +++ b/src/ruqolacore/mentions.cpp @@ -1,134 +1,131 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mentions.h" #include #include Mentions::Mentions() { - } void Mentions::setMentions(const QVector &mentions) { mMentions = mentions; } - void Mentions::clear() { mMentions.clear(); } int Mentions::count() const { return mMentions.count(); } QVector Mentions::mentions() const { return mMentions; } void Mentions::parseMentions(const QJsonObject &reacts) { mMentions.clear(); // const QStringList lst = reacts.keys(); // QStringList users; // for (const QString &str : lst) { // users.clear(); // const QJsonObject obj = reacts.value(str).toObject(); // QJsonValue usernames = obj.value(QLatin1String("usernames")); // if (!usernames.isUndefined()) { // QJsonArray array = usernames.toArray(); // for (int i = 0; i < array.count(); ++i) { // users.append(array.at(i).toString()); // } // } // if (!users.isEmpty()) { // Mention r; // r.setMentionName(str); // r.setUserNames(users); // mMentions.append(r); // } // } } bool Mentions::operator ==(const Mentions &other) const { return mMentions == other.mentions(); } QDebug operator <<(QDebug d, const Mentions &t) { for (int i = 0, total = t.mentions().count(); i < total; ++i) { d << t.mentions().at(i); } return d; } QJsonObject Mentions::serialize(const Mentions &mentions) { QJsonObject obj; // for (int i = 0; i < mentions.mentions().count(); ++i) { // QJsonObject react; // react[QLatin1String("usernames")] = QJsonArray::fromStringList(mentions.mentions().at(i).userNames()); // obj[mentions.mentions().at(i).mentionName()] = react; // } return obj; } Mentions Mentions::fromJSon(const QJsonObject &o) { // QVector reacts; // const QStringList lst = o.keys(); // QStringList users; // for (const QString &str : lst) { // const QJsonObject obj = o.value(str).toObject(); // QJsonValue usernames = obj.value(QLatin1String("usernames")); // if (!usernames.isUndefined()) { // QJsonArray array = usernames.toArray(); // for (int i = 0; i < array.count(); ++i) { // users.append(array.at(i).toString()); // } // } // if (!users.isEmpty()) { // Mention r; // r.setMentionName(str); // r.setUserNames(users); // reacts.append(r); // } // users.clear(); // } // Mentions final; // final.setMentions(reacts); // return final; return {}; } bool Mentions::isEmpty() const { return mMentions.isEmpty(); } Mention Mentions::at(int index) const { return mMentions.at(index); } - diff --git a/src/ruqolacore/model/mentionsfilterproxymodel.h b/src/ruqolacore/model/mentionsfilterproxymodel.h index 322fa521..5d0d59f8 100644 --- a/src/ruqolacore/model/mentionsfilterproxymodel.h +++ b/src/ruqolacore/model/mentionsfilterproxymodel.h @@ -1,37 +1,36 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MENTIONSFILTERPROXYMODEL_H #define MENTIONSFILTERPROXYMODEL_H #include #include "libruqola_private_export.h" class LIBRUQOLACORE_TESTS_EXPORT MentionsFilterProxyModel : public QSortFilterProxyModel { Q_OBJECT public: explicit MentionsFilterProxyModel(QObject *parent = nullptr); ~MentionsFilterProxyModel() override; Q_REQUIRED_RESULT QHash roleNames() const override; }; - #endif // MENTIONSFILTERPROXYMODEL_H diff --git a/src/ruqolacore/model/mentionsmodel.cpp b/src/ruqolacore/model/mentionsmodel.cpp index cb7c71b5..3c2019f8 100644 --- a/src/ruqolacore/model/mentionsmodel.cpp +++ b/src/ruqolacore/model/mentionsmodel.cpp @@ -1,70 +1,67 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - #include "mentionsmodel.h" MentionsModel::MentionsModel(QObject *parent) : QAbstractListModel(parent) { - } MentionsModel::~MentionsModel() { - } int MentionsModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return mMentions.count(); } QVariant MentionsModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= mMentions.count()) { return {}; } Mention mention = mMentions.at(index.row()); //TODO return {}; } void MentionsModel::setMentions(const Mentions &mentions) { if (rowCount() != 0) { beginRemoveRows(QModelIndex(), 0, mMentions.count() - 1); mMentions.clear(); endRemoveRows(); } if (!mMentions.isEmpty()) { beginInsertRows(QModelIndex(), 0, mMentions.count() - 1); mMentions = mentions; endInsertRows(); } } QHash MentionsModel::roleNames() const { QHash roles; //TODO return roles; } diff --git a/src/ruqolacore/model/mentionsmodel.h b/src/ruqolacore/model/mentionsmodel.h index b0e500ef..5b0e77dd 100644 --- a/src/ruqolacore/model/mentionsmodel.h +++ b/src/ruqolacore/model/mentionsmodel.h @@ -1,45 +1,44 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - #ifndef MENTIONSMODEL_H #define MENTIONSMODEL_H #include "libruqola_private_export.h" #include "mentions.h" #include class LIBRUQOLACORE_TESTS_EXPORT MentionsModel : public QAbstractListModel { public: explicit MentionsModel(QObject *parent = nullptr); ~MentionsModel() override; Q_REQUIRED_RESULT Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override; Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role) const override; void setMentions(const Mentions &mentions); Q_REQUIRED_RESULT QHash roleNames() const override; private: Q_DISABLE_COPY(MentionsModel) Mentions mMentions; }; #endif // MENTIONSMODEL_H diff --git a/src/ruqolacore/rocketchatmessage.cpp b/src/ruqolacore/rocketchatmessage.cpp index cfe26183..d888d5cc 100644 --- a/src/ruqolacore/rocketchatmessage.cpp +++ b/src/ruqolacore/rocketchatmessage.cpp @@ -1,637 +1,637 @@ /* Copyright (c) 2017-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 "rocketchatmessage.h" #include "ruqola_debug.h" #include "utils.h" #include #include #include #include RocketChatMessage::RocketChatMessage() : mJsonFormat(QJsonDocument::Compact) { } void RocketChatMessage::setJsonFormat(const QJsonDocument::JsonFormat &jsonFormat) { mJsonFormat = jsonFormat; } RocketChatMessage::RocketChatMessageResult RocketChatMessage::getRoomRoles(const QString &roomID, quint64 id) { const QJsonArray params{ QJsonValue(roomID) }; return generateMethod(QStringLiteral("getRoomRoles"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setReaction(const QString &emoji, const QString &messageId, quint64 id) { const QJsonArray params{ QJsonValue(emoji), QJsonValue(messageId) }; return generateMethod(QStringLiteral("setReaction"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::messageSearch(const QString &roomId, const QString &pattern, quint64 id) { const QJsonArray params{ QJsonValue(pattern), QJsonValue(roomId) //TODO limit }; return generateMethod(QStringLiteral("messageSearch"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::openDirectChannel(const QString &username, quint64 id) { const QJsonArray params{ QJsonValue(username) }; return generateMethod(QStringLiteral("createDirectMessage"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::createChannel(const QString &roomName, const QStringList &userList, bool readOnly, quint64 id) { const QJsonArray params{ { roomName }, { QJsonArray::fromStringList(userList) }, { readOnly } }; return generateMethod(QStringLiteral("createChannel"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::createPrivateGroup(const QString &roomName, const QStringList &userList, quint64 id) { const QJsonArray params{ { roomName }, { QJsonArray::fromStringList(userList) } }; return generateMethod(QStringLiteral("createPrivateGroup"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::eraseRoom(const QString &roomID, quint64 id) { const QJsonArray params{ QJsonValue(roomID) }; return generateMethod(QStringLiteral("eraseRoom"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::archiveRoom(const QString &roomID, quint64 id) { const QJsonArray params{ QJsonValue(roomID) }; return generateMethod(QStringLiteral("archiveRoom"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::unarchiveRoom(const QString &roomID, quint64 id) { const QJsonArray params{ QJsonValue(roomID) }; return generateMethod(QStringLiteral("unarchiveRoom"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::readMessages(const QString &roomID, quint64 id) { const QJsonArray params{ QJsonValue(roomID) }; return generateMethod(QStringLiteral("readMessages"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::openRoom(const QString &roomID, quint64 id) { const QJsonArray params{ QJsonValue(roomID) }; return generateMethod(QStringLiteral("openRoom"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::leaveRoom(const QString &roomID, quint64 id) { const QJsonArray params{ QJsonValue(roomID) }; return generateMethod(QStringLiteral("leaveRoom"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::hideRoom(const QString &roomID, quint64 id) { const QJsonArray params{ QJsonValue(roomID) }; return generateMethod(QStringLiteral("hideRoom"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::toggleFavorite(const QString &roomID, bool favorite, quint64 id) { const QJsonArray params{ QJsonValue(roomID), { favorite } }; return generateMethod(QStringLiteral("toggleFavorite"), QJsonDocument(params), id); } //TODO verify RocketChatMessage::RocketChatMessageResult RocketChatMessage::listEmojiCustom(quint64 id) { const QJsonArray params; return generateMethod(QStringLiteral("listEmojiCustom"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomName(const QString &roomId, const QString &name, quint64 id) { return saveRoomSettings(QStringLiteral("roomName"), roomId, name, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomTopic(const QString &roomId, const QString &topic, quint64 id) { return saveRoomSettings(QStringLiteral("roomTopic"), roomId, topic, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomEncrypted(const QString &roomId, bool encrypted, quint64 id) { return saveRoomSettings(QStringLiteral("encrypted"), roomId, encrypted, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomDescription(const QString &roomId, const QString &description, quint64 id) { return saveRoomSettings(QStringLiteral("roomDescription"), roomId, description, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomAnnouncement(const QString &roomId, const QString &announcement, quint64 id) { return saveRoomSettings(QStringLiteral("roomAnnouncement"), roomId, announcement, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomType(const QString &roomId, bool privateChannel, quint64 id) { return saveRoomSettings(QStringLiteral("roomType"), roomId, privateChannel ? QStringLiteral("p") : QStringLiteral("c"), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomIsReadOnly(const QString &roomId, bool readOnly, quint64 id) { return saveRoomSettings(QStringLiteral("readOnly"), roomId, readOnly, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomHasSystemMessages(const QString &roomId, bool systemMessages, quint64 id) { return saveRoomSettings(QStringLiteral("systemMessages"), roomId, systemMessages, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomIsDefault(const QString &roomId, bool isDefault, quint64 id) { return saveRoomSettings(QStringLiteral("default"), roomId, isDefault, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setRoomJoinCode(const QString &roomId, const QString &joinCode, quint64 id) { return saveRoomSettings(QStringLiteral("joinCode"), roomId, joinCode, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::blockUser(const QString &rid, const QString &userId, quint64 id) { QJsonObject obj{ { QStringLiteral("rid"), rid }, { QStringLiteral("blocked"), userId }, }; const QJsonArray params{{ - obj - }}; + obj + }}; return generateMethod(QStringLiteral("blockUser"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::ignoreUser(const QString &roomId, const QString &userId, bool ignore, quint64 id) { QJsonObject obj{ { QStringLiteral("userId"), userId }, { QStringLiteral("rid"), roomId }, { QStringLiteral("ignore"), ignore } }; const QJsonArray params{{ - obj - }}; + obj + }}; return generateMethod(QStringLiteral("ignoreUser"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::unblockUser(const QString &rid, const QString &userId, quint64 id) { QJsonObject obj{ { QStringLiteral("rid"), rid }, { QStringLiteral("blocked"), userId }, }; const QJsonArray params{{ - obj - }}; + obj + }}; return generateMethod(QStringLiteral("unblockUser"), QJsonDocument(params), id); } //TODO verify RocketChatMessage::RocketChatMessageResult RocketChatMessage::saveNotificationsSettings(const QString &key, const QString &roomId, const QJsonValue &value, quint64 id) { const QJsonArray params{{ - roomId - }, { - key - }, { - value - }}; + roomId + }, { + key + }, { + value + }}; return generateMethod(QStringLiteral("saveNotificationSettings"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::disableNotifications(const QString &roomId, bool disabled, quint64 id) { return saveNotificationsSettings(QStringLiteral("disableNotifications"), roomId, QJsonValue(disabled ? QLatin1String("1") : QLatin1String("0")), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::hideUnreadStatus(const QString &roomId, bool disabled, quint64 id) { return saveNotificationsSettings(QStringLiteral("hideUnreadStatus"), roomId, QJsonValue(disabled ? QLatin1String("1") : QLatin1String("0")), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::audioNotifications(const QString &roomId, const QString &value, quint64 id) { return saveNotificationsSettings(QStringLiteral("audioNotifications"), roomId, value, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::desktopNotifications(const QString &roomId, const QString &value, quint64 id) { return saveNotificationsSettings(QStringLiteral("desktopNotifications"), roomId, value, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::mobilePushNotifications(const QString &roomId, const QString &value, quint64 id) { return saveNotificationsSettings(QStringLiteral("mobilePushNotifications"), roomId, value, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::emailNotifications(const QString &roomId, const QString &value, quint64 id) { return saveNotificationsSettings(QStringLiteral("emailNotifications"), roomId, value, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::unreadAlert(const QString &roomId, const QString &value, quint64 id) { return saveNotificationsSettings(QStringLiteral("unreadAlert"), roomId, value, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::saveRoomSettings(const QString &key, const QString &roomId, const QJsonValue &value, quint64 id) { const QJsonArray params{{ - roomId - }, { - key - }, { - value - }}; + roomId + }, { + key + }, { + value + }}; return generateMethod(QStringLiteral("saveRoomSettings"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::joinRoom(const QString &roomId, const QString &accessCode, quint64 id) { const QJsonArray params{{ - roomId - }, { - accessCode - }}; + roomId + }, { + accessCode + }}; return generateMethod(QStringLiteral("joinRoom"), QJsonDocument(params), id); } //Verify RocketChatMessage::RocketChatMessageResult RocketChatMessage::deleteFileMessage(const QString &fileId, quint64 id) { const QJsonArray params{{ - fileId - }}; + fileId + }}; return generateMethod(QStringLiteral("deleteFileMessage"), QJsonDocument(params), id); } //Verify RocketChatMessage::RocketChatMessageResult RocketChatMessage::updateMessage(quint64 id) { const QJsonArray params; return generateMethod(QStringLiteral("updateMessage"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::deleteMessage(const QString &messageId, quint64 id) { QJsonObject obj{{ - QStringLiteral("_id"), messageId - }}; + QStringLiteral("_id"), messageId + }}; const QJsonArray params{{ - obj - }}; + obj + }}; return generateMethod(QStringLiteral("deleteMessage"), QJsonDocument(params), id); } //TODO verify RocketChatMessage::RocketChatMessageResult RocketChatMessage::starMessage(const QString &_id, const QString &rid, bool starred, quint64 id) { QJsonObject obj{ { QStringLiteral("_id"), _id }, { QStringLiteral("rid"), rid }, { QStringLiteral("starred"), starred } }; const QJsonArray params{{ - obj - }}; + obj + }}; return generateMethod(QStringLiteral("starMessage"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::informTypingStatus(const QString &roomId, const QString &userId, bool typingStatus, quint64 id) { const QString eventName = roomId + QStringLiteral("/typing"); const QJsonArray params{{ - eventName - }, { - userId - }, { - typingStatus - }}; + eventName + }, { + userId + }, { + typingStatus + }}; return generateMethod(QStringLiteral("stream-notify-room"), QJsonDocument(params), id); } QJsonValue RocketChatMessage::toJsonDateTime(const QDateTime &dateTime) { if (dateTime.isNull()) { return {}; } return QJsonObject{{ - QStringLiteral("$date"), dateTime.toMSecsSinceEpoch() - }}; + QStringLiteral("$date"), dateTime.toMSecsSinceEpoch() + }}; } RocketChatMessage::RocketChatMessageResult RocketChatMessage::getSubscriptions(const QDateTime &lastUpdate, quint64 id) { const QJsonArray params{ toJsonDateTime(lastUpdate) }; return generateMethod(QStringLiteral("subscriptions/get"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setDefaultStatus(User::PresenceStatus status, quint64 id) { const QString strPresence = Utils::presenceStatusToString(status); const QJsonArray params{{ - strPresence - }}; + strPresence + }}; return generateMethod(QStringLiteral("UserPresence:setDefaultStatus"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::setTemporaryStatus(User::PresenceStatus status, quint64 id) { const QString strPresence = Utils::presenceStatusToString(status); const QJsonArray params{{}}; return generateMethod((QStringLiteral("UserPresence:") + strPresence), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::getUsersOfRoom(const QString &roomId, bool showAll, quint64 id) { const QJsonArray params{{ - QJsonValue(roomId), showAll - }}; + QJsonValue(roomId), showAll + }}; return generateMethod(QStringLiteral("getUsersOfRoom"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::createJitsiConfCall(const QString &roomId, quint64 id) { const QJsonArray params{{ - QJsonValue(roomId) - }}; + QJsonValue(roomId) + }}; return generateMethod(QStringLiteral("jitsi:updateTimeout"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::roomFiles(const QString &roomId, quint64 id) { const QJsonArray params{{ - QJsonValue(roomId) - }}; + QJsonValue(roomId) + }}; return subscribe(QStringLiteral("roomFiles"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::login(const QString &username, const QString &password, quint64 id) { QJsonObject user; user[QStringLiteral("username")] = username; QByteArray passwordAsArray = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Sha256); const QString hash = QString::fromLatin1(passwordAsArray.toHex()); QJsonObject passwordObject; passwordObject[QStringLiteral("digest")] = hash; passwordObject[QStringLiteral("algorithm")] = QStringLiteral("sha-256"); QJsonObject params; params[QStringLiteral("password")] = passwordObject; params[QStringLiteral("user")] = user; return generateMethod(QStringLiteral("login"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::loginProvider(const QString &credentialToken, const QString &credentialSecretd, quint64 id) { QJsonObject params; QJsonObject authKeys; authKeys[QStringLiteral("credentialToken")] = credentialToken; authKeys[QStringLiteral("credentialSecret")] = credentialSecretd; params[QStringLiteral("oauth")] = authKeys; return generateMethod(QStringLiteral("login"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::addUserToRoom(const QString &username, const QString &roomId, quint64 id) { //This method use multiusers const QJsonArray users = QJsonArray::fromStringList(QStringList() << username); QJsonArray params; QJsonObject param; param[QStringLiteral("rid")] = roomId; param[QStringLiteral("username")] = users.first(); params.append(param); return generateMethod(QStringLiteral("addUserToRoom"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::logout(const QString &name, quint64 id) { Q_UNUSED(name); //TODO add name const QJsonArray params{{}}; return generateMethod(QStringLiteral("logout"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::userAutocomplete(const QString &searchText, const QString &exception, quint64 id) { QJsonArray params; QJsonObject firstParam; const QStringList users = exception.split(QLatin1Char(',')); QJsonArray exceptionEntries; for (const QString &entry: users) { exceptionEntries.append(entry); } firstParam[QStringLiteral("exceptions")] = exceptionEntries; firstParam[QStringLiteral("term")] = searchText; params.append(firstParam); return subscribe(QStringLiteral("userAutocomplete"), QJsonDocument(params), id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::channelAndPrivateAutocomplete(const QString &pattern, const QString &exceptions, quint64 id) { return searchRoomUsers(pattern, exceptions, true, true, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::inputChannelAutocomplete(const QString &pattern, const QString &exceptions, quint64 id) { return searchRoomUsers(pattern, exceptions, false, true, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::inputUserAutocomplete(const QString &pattern, const QString &exceptions, quint64 id) { return searchRoomUsers(pattern, exceptions, true, false, id); } RocketChatMessage::RocketChatMessageResult RocketChatMessage::searchRoomUsers(const QString &pattern, const QString &exceptions, bool searchUser, bool searchRoom, quint64 id) { QJsonArray params; params.append(pattern); const QJsonArray exceptionJson = QJsonArray::fromStringList(exceptions.split(QLatin1Char(','))); params.append(exceptionJson); QJsonObject secondParams; secondParams[QStringLiteral("rooms")] = searchRoom; secondParams[QStringLiteral("users")] = searchUser; params.append(secondParams); return generateMethod(QStringLiteral("spotlight"), QJsonDocument(params), id); } //We need to be able to send file for audio/video RocketChatMessage::RocketChatMessageResult RocketChatMessage::sendFileMessage(const QJsonObject &result, const QString &serviceUploadType, const QString &roomId, quint64 id) { const QJsonArray obj = {roomId, serviceUploadType, result}; const QJsonArray params{{ - obj - }}; + obj + }}; return generateMethod(QStringLiteral("sendFileMessage"), QJsonDocument(params), id); } //Verify RocketChatMessage::RocketChatMessageResult RocketChatMessage::unsubscribe(quint64 id) { QJsonObject json; json[QStringLiteral("msg")] = QStringLiteral("unsub"); json[QStringLiteral("id")] = QString::number(id); const QString generatedJsonDoc = QString::fromUtf8(QJsonDocument(json).toJson(mJsonFormat)); RocketChatMessageResult result; result.result = generatedJsonDoc; return result; } RocketChatMessage::RocketChatMessageResult RocketChatMessage::subscribe(const QString &name, const QJsonDocument ¶ms, quint64 id) { //TODO fixme. QJsonObject json; json[QStringLiteral("msg")] = QStringLiteral("sub"); json[QStringLiteral("id")] = QString::number(id); json[QStringLiteral("name")] = name; if (params.isArray()) { json[QStringLiteral("params")] = params.array(); } else if (params.isObject()) { QJsonArray arr; arr.append(params.object()); json[QStringLiteral("params")] = arr; } const QString generatedJsonDoc = QString::fromUtf8(QJsonDocument(json).toJson(mJsonFormat)); RocketChatMessageResult result; result.jsonDocument = params; result.method = name; result.result = generatedJsonDoc; return result; } RocketChatMessage::RocketChatMessageResult RocketChatMessage::generateMethod(const QString &method, const QJsonDocument ¶ms, quint64 id) { QJsonObject json; json[QStringLiteral("msg")] = QStringLiteral("method"); json[QStringLiteral("method")] = method; json[QStringLiteral("id")] = QString::number(id); if (!params.isEmpty()) { if (params.isArray()) { json[QStringLiteral("params")] = params.array(); } else if (params.isObject()) { QJsonArray arr; arr.append(params.object()); json[QStringLiteral("params")] = arr; } } const QString generatedJsonDoc = QString::fromUtf8(QJsonDocument(json).toJson(mJsonFormat)); RocketChatMessageResult result; result.jsonDocument = params; result.method = method; result.result = generatedJsonDoc; return result; }