diff --git a/src/apps/qml/MainComponent.qml b/src/apps/qml/MainComponent.qml index ce7c2594..5b66ee5f 100644 --- a/src/apps/qml/MainComponent.qml +++ b/src/apps/qml/MainComponent.qml @@ -1,481 +1,490 @@ /* * Copyright 2016 Riccardo Iaconelli * Copyright (C) 2017-2019 Laurent Montel * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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. If not, see . * */ import QtQuick 2.9 import QtQuick.Controls 1.4 import QtQuick.Window 2.2 import QtQuick.Dialogs 1.2 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.5 as QQC2 import KDE.Ruqola.RuqolaUtils 1.0 import KDE.Ruqola.Ruqola 1.0 import KDE.Ruqola.Clipboard 1.0 import KDE.Ruqola.RoomFilterProxyModel 1.0 import org.kde.kirigami 2.4 as Kirigami import KDE.Ruqola.DebugCategory 1.0 import KDE.Ruqola.ReceiveTypingNotificationManager 1.0 import KDE.Ruqola.DebugCategory 1.0 Component { id: mainComponent Kirigami.Page { id: mainWidget leftPadding: Kirigami.Units.smallSpacing rightPadding: Kirigami.Units.smallSpacing topPadding: Kirigami.Units.smallSpacing bottomPadding: Kirigami.Units.smallSpacing actions { contextualActions: [ Kirigami.Action { id: editAction iconName: "list-add" text: i18n("Open room"); onTriggered: { searchChannelDialog.initializeAndOpen(); } }, Kirigami.Action { iconName: "edit-symbolic" text: i18n("Edit room"); checkable: true onToggled: { appid.rocketChatAccount.switchEditingMode(checked); // do stuff } }, Kirigami.Action { text: i18n("Create New Channel") onTriggered: { createNewChannelDialog.encryptedRoomEnabled = appid.rocketChatAccount.encryptedEnabled() createNewChannelDialog.initializeAndOpen() } }, Kirigami.Action { separator: true }, Kirigami.Action { text: i18n("Server Info") onTriggered: { serverinfodialog.rcAccount = appid.rocketChatAccount serverinfodialog.open(); } } ] } header: Column { RowLayout { anchors.left: parent.left anchors.right: parent.right anchors.leftMargin: 2*Kirigami.Units.smallSpacing visible: appid.selectedRoom ToolButton { iconName: "favorite" checkable: true Binding on checked { value: appid.selectedRoom && appid.selectedRoom.favorite } onCheckedChanged: { appid.rocketChatAccount.changeFavorite(appid.selectedRoomID, checked) } } Kirigami.Icon { source: "encrypted" //FIXME height: 22 width: 22 visible: appid.selectedRoom && appid.selectedRoom.encrypted } Kirigami.Heading { text: "#" + (appid.selectedRoom ? appid.selectedRoom.name : "") level: 3 font.bold: true } Item { Layout.fillWidth: true } ToolButton { id: showNotification iconName: "preferences-desktop-notification" onClicked: { notificationsDialog.roomInfo = appid.selectedRoom notificationsDialog.open() } } ToolButton { id: showUsersButton iconName: "system-users" checkable: true } ToolButton { id: searchMessage iconName: "edit-find" onClicked: { searchMessageDialog.roomId = appid.selectedRoomID searchMessageDialog.initializeAndOpen(); } } ToolButton { iconName: "settings-configure" onClicked: menu.open(); QQC2.Menu { id: menu y: parent.height QQC2.MenuItem { text: i18n("Channel Info") onTriggered: { var channelType = appid.selectedRoom.channelType; if (channelType === "c" || channelType === "p") { //Only for debug // if (channelType === "c") { // appid.rocketChatAccount.channelInfo(appid.selectedRoom.rid); // } else { // appid.rocketChatAccount.groupInfo(appid.selectedRoom.rid); // } channelInfoDialog.roomInfo = appid.selectedRoom channelInfoDialog.initializeAndOpen() } else if (channelType === "d") { privateChannelInfoDialog.roomInfo = appid.selectedRoom privateChannelInfoDialog.initializeAndOpen() } else { console.log(RuqolaDebugCategorySingleton.category,"channel type " + appid.selectedRoom.channelType) } } } + //Hide it if direct channel + RuqolaMenuSeparator { + } + QQC2.MenuItem { + text: i18n("Mentions") + onTriggered: { + appid.rocketChatAccount.channelGetAllUserMentions(appid.selectedRoomID); + } + } RuqolaMenuSeparator { } QQC2.MenuItem { text: i18n("Video Chat") onTriggered: { appid.rocketChatAccount.createJitsiConfCall(appid.selectedRoomID); } } RuqolaMenuSeparator { } QQC2.MenuItem { text: i18n("Add User In Room") visible: appid.selectedRoom ? appid.selectedRoom.canBeModify : true onTriggered: { var channelType = appid.selectedRoom.channelType; if (channelType === "c" || channelType === "p") { addUserDialog.roomInfo = appid.selectedRoom addUserDialog.roomId = appid.selectedRoomID addUserDialog.initializeAndOpen() } } } RuqolaMenuSeparator { visible: appid.selectedRoom ? appid.selectedRoom.canBeModify : true } QQC2.MenuItem { text: i18n("Take a Video Message") onTriggered: { takeVideoMessage.open(); } } RuqolaMenuSeparator {} QQC2.MenuItem { text: i18n("Load Recent History") onTriggered: { appid.rocketChatAccount.loadHistory(appid.selectedRoomID); } } RuqolaMenuSeparator { } QQC2.MenuItem { text: i18n("Show Files Attachment In Room") onTriggered: { appid.rocketChatAccount.roomFiles(appid.selectedRoomID, appid.selectedRoom.channelType); showFilesInRoomDialog.initializeAndOpen() } } } } } QQC2.Label { visible: appid.selectedRoom && (appid.selectedRoom.topic !== "") text: appid.selectedRoom ? appid.selectedRoom.topic : "" font.italic: true anchors.right: parent.right anchors.left: parent.left anchors.margins: 2*Kirigami.Units.smallSpacing wrapMode: QQC2.Label.Wrap } QQC2.Label { visible: appid.selectedRoom && (appid.selectedRoom.announcement !== "") text: appid.selectedRoom ? appid.selectedRoom.announcement : "" anchors.right: parent.right anchors.left: parent.left anchors.margins: 2*Kirigami.Units.smallSpacing wrapMode: QQC2.Label.Wrap onLinkActivated: { RuqolaUtils.openUrl(link); } } Rectangle { color: Kirigami.Theme.textColor height:1 anchors.right: parent.right anchors.left: parent.left opacity: .5 visible: appid.selectedRoom } Flow { id: topBarUserList readonly property bool isActive: showUsersButton.checked anchors { left: parent.left right: parent.right margins: Kirigami.Units.smallSpacing } opacity: topBarUserList.isActive ? 1 : 0 Behavior on opacity { NumberAnimation { duration: 650; easing.type: Easing.InOutQuad } } Repeater { model: parent.opacity > 0.5 ? appid.userModel : 0 RowLayout { Kirigami.Icon { source: model.iconstatus //FIXME height: 22 width: 22 } QQC2.Label { text: model.displayname onLinkActivated: { openDirectChannelDialog.username = link; openDirectChannelDialog.open() } } } } Item { width: parent.width height: topBarUserList.isActive ? 1 : 0 Rectangle { height: parent.height width: height > 0 ? parent.width : 0 anchors.centerIn: parent Behavior on width { NumberAnimation { duration: 650; easing.type: Easing.InOutQuad } } color: Kirigami.Theme.textColor } } } } Clipboard { id: clipboard } ActiveChat { id: activeChat model: appid.messageModel rcAccount: appid.rocketChatAccount roomId: appid.selectedRoomID anchors.fill: parent clip: true QQC2.ScrollBar.vertical: QQC2.ScrollBar { } onEditMessage: { userInputMessage.messageId = messageId; userInputMessage.setOriginalMessage(messageStr) //console.log(RuqolaDebugCategorySingleton.category, "edit! messageId : " + messageId + " messageStr " + messageStr) } onCopyMessage: { clipboard.text = messageStr //console.log(RuqolaDebugCategorySingleton.category, "copy! messageId : " + messageId + " messageStr " + messageStr) } onReplyMessage: { //console.log(RuqolaDebugCategorySingleton.category, "Not implemented reply message : " + messageId) } onSetFavoriteMessage: { appid.rocketChatAccount.starMessage(messageId, roomId, starred) } onIgnoreUser: { appid.rocketChatAccount.ignoreUser(roomId, userId, ignored) } onOpenChannel: { openChannelDialog.channelName = channel openChannelDialog.open() } onOpenDirectChannel: { openDirectChannelDialog.username = userName; openDirectChannelDialog.open() } onJitsiCallConfActivated: { appid.rocketChatAccount.joinJitsiConfCall(roomId) } onDeleteMessage: { deleteMessageDialog.msgId = messageId deleteMessageDialog.open() } onDownloadAttachment: { downloadFileDialog.fileToSaveUrl = url downloadFileDialog.open() } onDisplayImage: { displayImageDialog.iUrl = imageUrl displayImageDialog.title = title displayImageDialog.isAnimatedImage = isAnimatedImage displayImageDialog.clearScaleAndOpen(); } onDeleteReaction: { appid.rocketChatAccount.reactOnMessage(messageId, emoji, false) } OpenChannelDialog { id: openChannelDialog onOpenChannel: { appid.rocketChatAccount.openChannel(channelName); } } OpenDirectChannelDialog { id: openDirectChannelDialog onOpenDirectChannel: { if (appid.rocketChatAccount.userName !== userName) { appid.rocketChatAccount.openDirectChannel(userName); } } } DeleteMessageDialog { id: deleteMessageDialog onDeleteMessage: { appid.rocketChatAccount.deleteMessage(messageId, appid.selectedRoomID) } } DownloadFileDialog { id: downloadFileDialog onAccepted: { if (fileUrl != "") { console.log(RuqolaDebugCategorySingleton.category, "You chose: " + fileUrl) appid.rocketChatAccount.downloadFile(fileToSaveUrl, fileUrl) } else { console.log(RuqolaDebugCategorySingleton.category, "No file selected"); } } } DisplayImageDialog { id: displayImageDialog } UploadFileDialog { id: uploadFileDialog onUploadFile: { appid.rocketChatAccount.uploadFile(appid.selectedRoomID, description, messageText, filename) } } ShowFilesInRoomDialog { id: showFilesInRoomDialog filesModel: appid.filesModel onDownloadFile: { downloadFileDialog.fileToSaveUrl = file downloadFileDialog.open() } onDeleteFile: { appid.rocketChatAccount.deleteFileMessage(appid.selectedRoomID, fileid, appid.selectedRoom.channelType) } } CreateNewChannelDialog { id: createNewChannelDialog onCreateNewChannel: { rocketChatAccount.createNewChannel(name, readOnly, privateRoom, usernames, encryptedRoom, password); } } ServerInfoDialog { id: serverinfodialog } } Keys.onEscapePressed: { appid.rocketChatAccount.clearUnreadMessages(appid.selectedRoomID); } footer: ColumnLayout { anchors.bottom: mainWidget.bottom //anchors.margins: Kirigami.Units.smallSpacing QQC2.Label { id: channelInfo font.bold: true anchors { margins: Kirigami.Units.smallSpacing } Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft visible: appid.selectedRoom && ((appid.selectedRoom.readOnly === true) || (appid.selectedRoom.blocker === true) || (appid.selectedRoom.blocked === true)) text: appid.selectedRoom ? appid.selectedRoom.roomMessageInfo : "" } UserInput { id: userInputMessage rcAccount: appid.rocketChatAccount visible: appid.selectedRoom && (appid.selectedRoom.readOnly === false) && (appid.selectedRoom.blocker === false) && (appid.selectedRoom.blocked === false) messageLineText: rcAccount.getUserCurrentMessage(appid.selectedRoomID) onTextEditing: { rcAccount.textEditing(appid.selectedRoomID, str) appid.userInputMessageText = str; } onClearUnreadMessages: { rcAccount.clearUnreadMessages(appid.selectedRoomID) } onUploadFile: { uploadFileDialog.initializeAndOpen() } } QQC2.Label { id: typingInfo anchors.margins: 2*Kirigami.Units.smallSpacing text: "" } Connections { target: appid.rocketChatAccount.receiveTypingNotificationManager() onNotificationChanged: { //console.log(RuqolaDebugCategorySingleton.category, "Typing in roomId: " + roomId + " str " + notificationStr); if (appid.selectedRoomID === roomId) { typingInfo.text = notificationStr; } } } } }// mainWidget Item } diff --git a/src/rocketchatrestapi-qt5/CMakeLists.txt b/src/rocketchatrestapi-qt5/CMakeLists.txt index 578aa9f4..fad5d4df 100644 --- a/src/rocketchatrestapi-qt5/CMakeLists.txt +++ b/src/rocketchatrestapi-qt5/CMakeLists.txt @@ -1,125 +1,126 @@ set (RocketChatRestApiQt_SRCS restapirequest.cpp restapiutil.cpp restapimethod.cpp uploadfilejob.cpp restapiabstractjob.cpp abstractlogger.cpp # job. spotlightjob.cpp serverinfojob.cpp misc/owninfojob.cpp misc/settingsoauthjob.cpp users/getavatarjob.cpp users/setavatarjob.cpp users/forgotpasswordjob.cpp users/usersinfojob.cpp users/getpresencejob.cpp users/resetavatarjob.cpp users/getusernamesuggestionjob.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 chat/starmessagejob.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 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 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 directmessage/createdmjob.cpp rooms/savenotificationjob.cpp rooms/getroomsjob.cpp rooms/roomfavoritejob.cpp rooms/roomsinfojob.cpp rooms/roomleavejob.cpp subscriptions/markroomasreadjob.cpp subscriptions/markroomasunreadjob.cpp permissions/listpermissionsjob.cpp commands/listcommandsjob.cpp e2e/fetchmykeysjob.cpp e2e/setuserpublicandprivatekeysjob.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 ) 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 e0358f9e..daf91d9c 100644 --- a/src/rocketchatrestapi-qt5/autotests/CMakeLists.txt +++ b/src/rocketchatrestapi-qt5/autotests/CMakeLists.txt @@ -1,88 +1,89 @@ 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(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) diff --git a/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.cpp new file mode 100644 index 00000000..393b4b10 --- /dev/null +++ b/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.cpp @@ -0,0 +1,54 @@ +/* + 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 +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); + const QNetworkRequest request = job.request(); + QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.getAllUserMentionsByChannel?roomId=avat"))); + delete method; +} diff --git a/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.h b/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.h new file mode 100644 index 00000000..d02cbace --- /dev/null +++ b/src/rocketchatrestapi-qt5/autotests/channelgetallusermentionsjobtest.h @@ -0,0 +1,37 @@ +/* + 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 CHANNELGETALLUSERMENTIONSJOBTEST_H +#define CHANNELGETALLUSERMENTIONSJOBTEST_H + +#include + +class ChannelGetAllUserMentionsJobTest : public QObject +{ + Q_OBJECT +public: + explicit ChannelGetAllUserMentionsJobTest(QObject *parent = nullptr); + ~ChannelGetAllUserMentionsJobTest() = default; +private Q_SLOTS: + void shouldHaveDefaultValue(); + void shouldGenerateRequest(); +}; + +#endif // CHANNELGETALLUSERMENTIONSJOBTEST_H diff --git a/src/rocketchatrestapi-qt5/autotests/restapimethodtest.cpp b/src/rocketchatrestapi-qt5/autotests/restapimethodtest.cpp index f84c01ca..ecbc3c65 100644 --- a/src/rocketchatrestapi-qt5/autotests/restapimethodtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/restapimethodtest.cpp @@ -1,171 +1,172 @@ /* Copyright (c) 2018-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 "restapimethodtest.h" #include "restapimethod.h" #include QTEST_GUILESS_MAIN(RestApiMethodTest) using namespace RocketChatRestApi; RestApiMethodTest::RestApiMethodTest(QObject *parent) : QObject(parent) { } void RestApiMethodTest::shouldHaveDefaultValue() { RestApiMethod rest; QVERIFY(rest.serverUrl().isEmpty()); } void RestApiMethodTest::shouldAssignDefaultValue() { RestApiMethod rest; QString newUrl = QStringLiteral("http://www.kde.org"); rest.setServerUrl(newUrl); QCOMPARE(rest.serverUrl(), newUrl); } void RestApiMethodTest::shouldGenerateUrl() { RestApiMethod rest; //If server url is empty return null url QVERIFY(!rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsList).isValid()); rest.setServerUrl(QStringLiteral("http://www.kde.org")); QVERIFY(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsList).isValid()); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::Login), QUrl(QStringLiteral("http://www.kde.org/api/v1/login"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::Logout), QUrl(QStringLiteral("http://www.kde.org/api/v1/logout"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::Me), QUrl(QStringLiteral("http://www.kde.org/api/v1/me"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersCreate), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.create"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersCreateToken), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.createToken"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersGetPresence), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.getPresence"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersInfo), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.info"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersList), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.list"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersDelete), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.delete"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersRegister), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.register"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersGetAvatar), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.getAvatar"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersResetAvatar), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.resetAvatar"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersSetAvatar), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.setAvatar"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersUpdate), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.update"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::UsersGetUsernameSuggestion), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.getUsernameSuggestion"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatDelete), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.delete"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatGetMessage), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.getMessage"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatPinMessage), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.pinMessage"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatPostMessage), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.postMessage"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatReact), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.react"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatIgnoreUser), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.ignoreUser"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatStarMessage), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.starMessage"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatUnPinMessage), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.unPinMessage"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatUnStarMessage), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.unStarMessage"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatUpdate), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.update"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatSearch), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.search"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChatReportMessage), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.reportMessage"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsAddAll), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.addAll"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsAddModerator), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.addModerator"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsAddOwner), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.addOwner"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsArchive), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.archive"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsCleanHistory), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.cleanHistory"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsClose), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.close"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsCreate), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.create"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsGetIntegrations), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.getIntegrations"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsHistory), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.history"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsInfo), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.info"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsInvite), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.invite"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsKick), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.kick"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsLeave), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.leave"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsList), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.list"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsListJoined), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.list.joined"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsOpen), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.open"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsJoin), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.join"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsRemoveModerator), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.removeModerator"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsRemoveOwner), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.removeOwner"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsRename), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.rename"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsSetDescription), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setDescription"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsSetJoinCode), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setJoinCode"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsRoles), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.roles"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsSetPurpose), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setPurpose"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsSetReadOnly), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setReadOnly"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsSetTopic), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setTopic"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsSetType), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setType"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsUnarchive), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.unarchive"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsSetAnnouncement), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setAnnouncement"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsFiles), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.files"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsMembers), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.members"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsCounters), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.counters"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsDelete), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.delete"))); + QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ChannelsGetAllUserMentionsByChannel), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.getAllUserMentionsByChannel"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsAddAll), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.addAll"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsAddModerator), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.addModerator"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsAddOwner), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.addOwner"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsArchive), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.archive"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsClose), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.close"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsCreate), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.create"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsGetIntegrations), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.getIntegrations"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsHistory), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.history"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsInfo), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.info"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsInvite), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.invite"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsKick), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.kick"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsLeave), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.leave"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsList), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.list"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsOpen), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.open"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsRemoveModerator), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.removeModerator"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupRemoveOwner), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.removeOwner"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsRename), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.rename"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsSetDescription), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.setDescription"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsSetPurpose), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.setPurpose"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsSetReadOnly), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.setReadOnly"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsSetTopic), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.setTopic"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsSetType), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.setType"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsUnarchive), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.unarchive"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsSetAnnouncement), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.setAnnouncement"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsRoles), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.roles"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::GroupsCounters), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.counters"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ServerInfo), QUrl(QStringLiteral("http://www.kde.org/api/v1/info"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::Settings), QUrl(QStringLiteral("http://www.kde.org/api/v1/settings"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::SettingsPublic), QUrl(QStringLiteral("http://www.kde.org/api/v1/settings.public"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RoomsUpload), QUrl(QStringLiteral("http://www.kde.org/api/v1/rooms.upload"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::Spotlight), QUrl(QStringLiteral("http://www.kde.org/api/v1/spotlight"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ImClose), QUrl(QStringLiteral("http://www.kde.org/api/v1/im.close"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ImCreate), QUrl(QStringLiteral("http://www.kde.org/api/v1/im.create"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ImHistory), QUrl(QStringLiteral("http://www.kde.org/api/v1/im.history"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::LoadEmojiCustom), QUrl(QStringLiteral("http://www.kde.org/api/v1/emoji-custom"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RoomsSaveNotification), QUrl(QStringLiteral("http://www.kde.org/api/v1/rooms.saveNotification"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::SubscriptionsRead), QUrl(QStringLiteral("http://www.kde.org/api/v1/subscriptions.read"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::SubscriptionsUnRead), QUrl(QStringLiteral("http://www.kde.org/api/v1/subscriptions.unread"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::SettingsOauth), QUrl(QStringLiteral("http://www.kde.org/api/v1/settings.oauth"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RoomsGet), QUrl(QStringLiteral("http://www.kde.org/api/v1/rooms.get"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RoomsFavorite), QUrl(QStringLiteral("http://www.kde.org/api/v1/rooms.favorite"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RoomscleanHistory), QUrl(QStringLiteral("http://www.kde.org/api/v1/rooms.cleanHistory"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RoomsInfo), QUrl(QStringLiteral("http://www.kde.org/api/v1/rooms.info"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RoomsLeave), QUrl(QStringLiteral("http://www.kde.org/api/v1/rooms.leave"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::ForgotPassword), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.forgotPassword"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::PermissionsList), QUrl(QStringLiteral("http://www.kde.org/api/v1/permissions.list"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::CommandsList), QUrl(QStringLiteral("http://www.kde.org/api/v1/commands.list"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::E2EfetchMyKeys), QUrl(QStringLiteral("http://www.kde.org/api/v1/e2e.fetchMyKeys"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::E2EupdateGroupKey), QUrl(QStringLiteral("http://www.kde.org/api/v1/e2e.updateGroupKey"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::E2ESetRoomKeyID), QUrl(QStringLiteral("http://www.kde.org/api/v1/e2e.setRoomKeyID"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::E2ESetUserPublicAndPrivateKeys), QUrl(QStringLiteral("http://www.kde.org/api/v1/e2e.setUserPublicAndPivateKeys"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::E2ERequestSubscriptionKeys), QUrl(QStringLiteral("http://www.kde.org/api/v1/e2e.requestSubscriptionKeys"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RolesList), QUrl(QStringLiteral("http://www.kde.org/api/v1/roles.list"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RolesCreate), QUrl(QStringLiteral("http://www.kde.org/api/v1/roles.create"))); QCOMPARE(rest.generateUrl(RestApiUtil::RestApiUrlType::RolesAddUserToRole), QUrl(QStringLiteral("http://www.kde.org/api/v1/roles.addUserToRole"))); } diff --git a/src/rocketchatrestapi-qt5/e2e/fetchmykeysjob.cpp b/src/rocketchatrestapi-qt5/channels/channelgetallusermentionsjob.cpp similarity index 51% copy from src/rocketchatrestapi-qt5/e2e/fetchmykeysjob.cpp copy to src/rocketchatrestapi-qt5/channels/channelgetallusermentionsjob.cpp index 7ff20874..0a983ecc 100644 --- a/src/rocketchatrestapi-qt5/e2e/fetchmykeysjob.cpp +++ b/src/rocketchatrestapi-qt5/channels/channelgetallusermentionsjob.cpp @@ -1,88 +1,104 @@ /* - Copyright (c) 2018-2019 Montel Laurent + 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 "fetchmykeysjob.h" +#include "channelgetallusermentionsjob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" -#include -#include #include +#include #include +#include using namespace RocketChatRestApi; -FetchMyKeysJob::FetchMyKeysJob(QObject *parent) +ChannelGetAllUserMentionsJob::ChannelGetAllUserMentionsJob(QObject *parent) : RestApiAbstractJob(parent) { } -FetchMyKeysJob::~FetchMyKeysJob() +ChannelGetAllUserMentionsJob::~ChannelGetAllUserMentionsJob() { } -bool FetchMyKeysJob::canStart() const +bool ChannelGetAllUserMentionsJob::canStart() const { + if (mRoomId.isEmpty()) { + qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelGetAllUserMentionsJob: RoomId is empty"; + return false; + } if (!RestApiAbstractJob::canStart()) { - qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start FetchKeyChain job"; + qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelGetAllUserMentionsJob job"; return false; } return true; } -bool FetchMyKeysJob::start() +bool ChannelGetAllUserMentionsJob::start() { if (!canStart()) { + qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start server info job"; deleteLater(); return false; } + QNetworkReply *reply = mNetworkAccessManager->get(request()); - connect(reply, &QNetworkReply::finished, this, &FetchMyKeysJob::slotFetchMyKeys); - addLoggerInfo("Start FetchMyKeysJob"); + addLoggerInfo("ChannelGetAllUserMentionsJob::start"); + connect(reply, &QNetworkReply::finished, this, &ChannelGetAllUserMentionsJob::slotChannelGetAllUserMentionsFinished); + + return true; +} +QNetworkRequest ChannelGetAllUserMentionsJob::request() const +{ + QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsGetAllUserMentionsByChannel); + QUrlQuery queryUrl; + queryUrl.addQueryItem(QStringLiteral("roomId"), mRoomId); + url.setQuery(queryUrl); + QNetworkRequest request(url); + request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); + request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); + return request; +} + +bool ChannelGetAllUserMentionsJob::requireHttpAuthentication() const +{ return true; } -void FetchMyKeysJob::slotFetchMyKeys() +void ChannelGetAllUserMentionsJob::slotChannelGetAllUserMentionsFinished() { 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("FetchMyKeysJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); - Q_EMIT fetchMyKeysDone(); - } else { - addLoggerWarning(QByteArrayLiteral("FetchMyKeysJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); - } + addLoggerInfo(QByteArrayLiteral("ChannelGetAllUserMentionsJob: finished: ") + replyJson.toJson(QJsonDocument::Indented)); + Q_EMIT channelGetAllUserMentionsDone(replyObject); } deleteLater(); } -QNetworkRequest FetchMyKeysJob::request() const +QString ChannelGetAllUserMentionsJob::roomId() const { - const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::E2EfetchMyKeys); - QNetworkRequest request(url); - return request; + return mRoomId; } -bool FetchMyKeysJob::requireHttpAuthentication() const +void ChannelGetAllUserMentionsJob::setRoomId(const QString &roomId) { - return true; + mRoomId = roomId; } diff --git a/src/rocketchatrestapi-qt5/groups/archivegroupsjob.h b/src/rocketchatrestapi-qt5/channels/channelgetallusermentionsjob.h similarity index 70% copy from src/rocketchatrestapi-qt5/groups/archivegroupsjob.h copy to src/rocketchatrestapi-qt5/channels/channelgetallusermentionsjob.h index 50e61ab8..91f07922 100644 --- a/src/rocketchatrestapi-qt5/groups/archivegroupsjob.h +++ b/src/rocketchatrestapi-qt5/channels/channelgetallusermentionsjob.h @@ -1,58 +1,55 @@ /* - Copyright (c) 2018-2019 Montel Laurent + 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 ARCHIVEGROUPSJOB_H -#define ARCHIVEGROUPSJOB_H +#ifndef CHANNELGETALLUSERMENTIONSJOB_H +#define CHANNELGETALLUSERMENTIONSJOB_H #include "restapiabstractjob.h" #include "librestapi_private_export.h" +class QNetworkRequest; namespace RocketChatRestApi { -class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT ArchiveGroupsJob : public RestApiAbstractJob +class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT ChannelGetAllUserMentionsJob : public RestApiAbstractJob { Q_OBJECT public: - explicit ArchiveGroupsJob(QObject *parent = nullptr); - ~ArchiveGroupsJob() override; + explicit ChannelGetAllUserMentionsJob(QObject *parent = nullptr); + ~ChannelGetAllUserMentionsJob() override; Q_REQUIRED_RESULT bool start() override; - Q_REQUIRED_RESULT bool requireHttpAuthentication() const override; + Q_REQUIRED_RESULT bool canStart() const override; Q_REQUIRED_RESULT QNetworkRequest request() const override; - Q_REQUIRED_RESULT QJsonDocument json() const; + Q_REQUIRED_RESULT bool requireHttpAuthentication() const override; Q_REQUIRED_RESULT QString roomId() const; void setRoomId(const QString &roomId); - Q_REQUIRED_RESULT bool archive() const; - void setArchive(bool archive); - Q_SIGNALS: - void archiveGroupsDone(); + void channelGetAllUserMentionsDone(const QJsonObject &obj); private: - Q_DISABLE_COPY(ArchiveGroupsJob) - void slotArchiveGroupsFinished(); + Q_DISABLE_COPY(ChannelGetAllUserMentionsJob) + void slotChannelGetAllUserMentionsFinished(); QString mRoomId; - bool mArchive = true; }; } -#endif // ARCHIVEGROUPSJOB_H +#endif // CHANNELGETALLUSERMENTIONSJOB_H diff --git a/src/rocketchatrestapi-qt5/e2e/fetchmykeysjob.cpp b/src/rocketchatrestapi-qt5/e2e/fetchmykeysjob.cpp index 7ff20874..e546cc67 100644 --- a/src/rocketchatrestapi-qt5/e2e/fetchmykeysjob.cpp +++ b/src/rocketchatrestapi-qt5/e2e/fetchmykeysjob.cpp @@ -1,88 +1,88 @@ /* Copyright (c) 2018-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 "fetchmykeysjob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" #include #include #include #include using namespace RocketChatRestApi; FetchMyKeysJob::FetchMyKeysJob(QObject *parent) : RestApiAbstractJob(parent) { } FetchMyKeysJob::~FetchMyKeysJob() { } bool FetchMyKeysJob::canStart() const { if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start FetchKeyChain job"; return false; } return true; } bool FetchMyKeysJob::start() { if (!canStart()) { deleteLater(); return false; } QNetworkReply *reply = mNetworkAccessManager->get(request()); connect(reply, &QNetworkReply::finished, this, &FetchMyKeysJob::slotFetchMyKeys); addLoggerInfo("Start FetchMyKeysJob"); return true; } void FetchMyKeysJob::slotFetchMyKeys() { 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("FetchMyKeysJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); Q_EMIT fetchMyKeysDone(); } else { - addLoggerWarning(QByteArrayLiteral("FetchMyKeysJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); + addLoggerWarning(QByteArrayLiteral("FetchMyKeysJob: problem: ") + replyJson.toJson(QJsonDocument::Indented)); } } deleteLater(); } QNetworkRequest FetchMyKeysJob::request() const { const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::E2EfetchMyKeys); QNetworkRequest request(url); return request; } bool FetchMyKeysJob::requireHttpAuthentication() const { return true; } diff --git a/src/rocketchatrestapi-qt5/groups/archivegroupsjob.cpp b/src/rocketchatrestapi-qt5/groups/archivegroupsjob.cpp index dc95012d..b8f44f6f 100644 --- a/src/rocketchatrestapi-qt5/groups/archivegroupsjob.cpp +++ b/src/rocketchatrestapi-qt5/groups/archivegroupsjob.cpp @@ -1,125 +1,127 @@ /* Copyright (c) 2018-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 "archivegroupsjob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" #include #include #include using namespace RocketChatRestApi; ArchiveGroupsJob::ArchiveGroupsJob(QObject *parent) : RestApiAbstractJob(parent) { } ArchiveGroupsJob::~ArchiveGroupsJob() { } bool ArchiveGroupsJob::start() { if (!canStart()) { deleteLater(); return false; } const QByteArray baPostData = json().toJson(QJsonDocument::Compact); addLoggerInfo("ArchiveGroupsJob::start: " + baPostData); QNetworkReply *reply = mNetworkAccessManager->post(request(), baPostData); connect(reply, &QNetworkReply::finished, this, &ArchiveGroupsJob::slotArchiveGroupsFinished); return true; } void ArchiveGroupsJob::slotArchiveGroupsFinished() { 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("ArchiveGroupsJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); Q_EMIT archiveGroupsDone(); } else { - addLoggerWarning(QByteArrayLiteral("ArchiveGroupsJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); + addLoggerWarning(QByteArrayLiteral("ArchiveGroupsJob: problem: ") + replyJson.toJson(QJsonDocument::Indented)); + //FIXME report error + Q_EMIT archiveGroupsError(QString()); } } deleteLater(); } bool ArchiveGroupsJob::archive() const { return mArchive; } void ArchiveGroupsJob::setArchive(bool archive) { mArchive = archive; } bool ArchiveGroupsJob::requireHttpAuthentication() const { return true; } bool ArchiveGroupsJob::canStart() const { if (mRoomId.isEmpty()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ArchiveGroupsJob: RoomId is empty"; return false; } if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ArchiveGroupsJob job"; return false; } return true; } QJsonDocument ArchiveGroupsJob::json() const { QJsonObject jsonObj; jsonObj[QLatin1String("roomId")] = roomId(); const QJsonDocument postData = QJsonDocument(jsonObj); return postData; } QString ArchiveGroupsJob::roomId() const { return mRoomId; } void ArchiveGroupsJob::setRoomId(const QString &roomId) { mRoomId = roomId; } QNetworkRequest ArchiveGroupsJob::request() const { const QUrl url = mRestApiMethod->generateUrl(mArchive ? RestApiUtil::RestApiUrlType::GroupsArchive : RestApiUtil::RestApiUrlType::GroupsUnarchive); QNetworkRequest request(url); addAuthRawHeader(request); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/json")); return request; } diff --git a/src/rocketchatrestapi-qt5/groups/archivegroupsjob.h b/src/rocketchatrestapi-qt5/groups/archivegroupsjob.h index 50e61ab8..f31cce2f 100644 --- a/src/rocketchatrestapi-qt5/groups/archivegroupsjob.h +++ b/src/rocketchatrestapi-qt5/groups/archivegroupsjob.h @@ -1,58 +1,59 @@ /* Copyright (c) 2018-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 ARCHIVEGROUPSJOB_H #define ARCHIVEGROUPSJOB_H #include "restapiabstractjob.h" #include "librestapi_private_export.h" namespace RocketChatRestApi { class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT ArchiveGroupsJob : public RestApiAbstractJob { Q_OBJECT public: explicit ArchiveGroupsJob(QObject *parent = nullptr); ~ArchiveGroupsJob() override; Q_REQUIRED_RESULT bool start() override; Q_REQUIRED_RESULT bool requireHttpAuthentication() const override; Q_REQUIRED_RESULT bool canStart() const override; Q_REQUIRED_RESULT QNetworkRequest request() const override; Q_REQUIRED_RESULT QJsonDocument json() const; Q_REQUIRED_RESULT QString roomId() const; void setRoomId(const QString &roomId); Q_REQUIRED_RESULT bool archive() const; void setArchive(bool archive); Q_SIGNALS: void archiveGroupsDone(); + void archiveGroupsError(const QString &); private: Q_DISABLE_COPY(ArchiveGroupsJob) void slotArchiveGroupsFinished(); QString mRoomId; bool mArchive = true; }; } #endif // ARCHIVEGROUPSJOB_H diff --git a/src/rocketchatrestapi-qt5/groups/groupskickjob.cpp b/src/rocketchatrestapi-qt5/groups/groupskickjob.cpp index 0bd29b0f..6308206a 100644 --- a/src/rocketchatrestapi-qt5/groups/groupskickjob.cpp +++ b/src/rocketchatrestapi-qt5/groups/groupskickjob.cpp @@ -1,130 +1,130 @@ /* Copyright (c) 2018-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 "groupskickjob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" #include #include #include using namespace RocketChatRestApi; GroupsKickJob::GroupsKickJob(QObject *parent) : RestApiAbstractJob(parent) { } GroupsKickJob::~GroupsKickJob() { } bool GroupsKickJob::start() { if (!canStart()) { deleteLater(); return false; } const QByteArray baPostData = json().toJson(QJsonDocument::Compact); addLoggerInfo("GroupsKickJob::start: " + baPostData); QNetworkReply *reply = mNetworkAccessManager->post(request(), baPostData); connect(reply, &QNetworkReply::finished, this, &GroupsKickJob::slotKickUsersFinished); return true; } void GroupsKickJob::slotKickUsersFinished() { 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("GroupsKickJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); Q_EMIT kickUserDone(replyObject); } else { - addLoggerWarning(QByteArrayLiteral("GroupsKickJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); + addLoggerWarning(QByteArrayLiteral("GroupsKickJob: problem: ") + replyJson.toJson(QJsonDocument::Indented)); } } deleteLater(); } bool GroupsKickJob::requireHttpAuthentication() const { return true; } bool GroupsKickJob::canStart() const { if (mKickUserId.isEmpty()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GroupsKickJob: mKickUserId is empty"; return false; } if (mRoomId.isEmpty()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GroupsKickJob: RoomId is empty"; return false; } if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GroupsKickJob job"; return false; } return true; } QJsonDocument GroupsKickJob::json() const { QJsonObject jsonObj; jsonObj[QLatin1String("roomId")] = roomId(); jsonObj[QLatin1String("userId")] = kickUserId(); const QJsonDocument postData = QJsonDocument(jsonObj); return postData; } QString GroupsKickJob::roomId() const { return mRoomId; } void GroupsKickJob::setRoomId(const QString &roomId) { mRoomId = roomId; } QNetworkRequest GroupsKickJob::request() const { const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::GroupsKick); QNetworkRequest request(url); addAuthRawHeader(request); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/json")); return request; } QString GroupsKickJob::kickUserId() const { return mKickUserId; } void GroupsKickJob::setKickUserId(const QString &kickUserId) { mKickUserId = kickUserId; } diff --git a/src/rocketchatrestapi-qt5/restapirequest.cpp b/src/rocketchatrestapi-qt5/restapirequest.cpp index 00ee9d06..7f1180db 100644 --- a/src/rocketchatrestapi-qt5/restapirequest.cpp +++ b/src/rocketchatrestapi-qt5/restapirequest.cpp @@ -1,1017 +1,1030 @@ /* 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/rocketchatrestapi-qt5/restapirequest.h b/src/rocketchatrestapi-qt5/restapirequest.h index 0d844c98..081589e2 100644 --- a/src/rocketchatrestapi-qt5/restapirequest.h +++ b/src/rocketchatrestapi-qt5/restapirequest.h @@ -1,178 +1,180 @@ /* 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. */ #ifndef RESTAPIREQUEST_H #define RESTAPIREQUEST_H #include #include #include #include "restapiutil.h" #include "librocketchatrestapi-qt5_export.h" class QNetworkAccessManager; class QNetworkReply; class QNetworkCookieJar; class RestApiMethod; namespace RocketChatRestApi { class RestApiAbstractJob; class AbstractLogger; class LIBROCKETCHATRESTAPI_QT5_EXPORT RestApiRequest : public QObject { Q_OBJECT public: explicit RestApiRequest(QObject *parent = nullptr); ~RestApiRequest(); void setRestApiLogger(RocketChatRestApi::AbstractLogger *logger); Q_REQUIRED_RESULT QString userId() const; Q_REQUIRED_RESULT QString authToken() const; void setUserId(const QString &userId); void setAuthToken(const QString &authToken); //Assign/get server url QString serverUrl() const; void setServerUrl(const QString &serverUrl); void setUserName(const QString &userName); void setPassword(const QString &password); void login(); void logout(); void channelList(); void getAvatar(const QString &userId); void serverInfo(); void getPrivateSettings(); void getOwnInfo(); void starMessage(const QString &messageId, bool starred); void uploadFile(const QString &roomId, const QString &description, const QString &text, const QUrl &filename); void downloadFile(const QUrl &url, const QString &mimeType = QStringLiteral("text/plain"), bool storeInCache = true, const QUrl &localFileUrl = QUrl()); void changeChannelTopic(const QString &roomId, const QString &topic); void changeGroupsTopic(const QString &roomId, const QString &topic); void changeChannelAnnouncement(const QString &roomId, const QString &announcement); void changeGroupsAnnouncement(const QString &roomId, const QString &announcement); void postMessage(const QString &roomId, const QString &text); void deleteMessage(const QString &roomId, const QString &messageId); void createChannels(const QString &channelName, bool readOnly, const QStringList &members, const QString &password); void createGroups(const QString &channelName, bool readOnly, const QStringList &members); void leaveChannel(const QString &roomId); void leaveGroups(const QString &roomId); void updateMessage(const QString &roomId, const QString &messageId, const QString &text); void reactOnMessage(const QString &messageId, const QString &emoji, bool shouldReact); void closeChannel(const QString &roomId, const QString &type); void createDirectMessage(const QString &userName); void historyChannel(const QString &roomId, const QString &type); void changeChannelDescription(const QString &roomId, const QString &description); void changeGroupsDescription(const QString &roomId, const QString &description); void archiveChannel(const QString &roomId); void archiveGroups(const QString &roomId); void filesInRoom(const QString &roomId, const QString &type); void addUserInChannel(const QString &roomId, const QString &userId); void listEmojiCustom(); void searchRoomUser(const QString &pattern); void searchMessages(const QString &roomId, const QString &pattern); void markAsRead(const QString &roomId); void getRooms(); void markAsFavorite(const QString &roomId, bool favorite); void addUserInGroup(const QString &roomId, const QString &userId); void disableNotifications(const QString &roomId, bool value); void hideUnreadStatus(const QString &roomId, bool value); void audioNotifications(const QString &roomId, const QString &value); void desktopNotifications(const QString &roomId, const QString &value); void emailNotifications(const QString &roomId, const QString &value); void mobilePushNotifications(const QString &roomId, const QString &value); void unreadAlert(const QString &roomId, const QString &value); void setAvatar(const QString &avatarUrl); void markRoomAsUnRead(const QString &roomId); void markMessageAsUnReadFrom(const QString &messageId); void forgotPassword(const QString &email); void userInfo(const QString &identifier, bool userName = false); void ignoreUser(const QString &roomId, const QString &userId, bool ignore); void userPresence(const QString &userId); void reportMessage(const QString &messageId, const QString &message); void setGroupType(const QString &roomId, const QString &type); void setChannelType(const QString &roomId, const QString &type); void getGroupRoles(const QString &roomId); void getChannelRoles(const QString &roomId); void getUsernameSuggestion(); void listPermissions(); void listCommands(); void fetchMyKeys(); void setJoinCodeChannel(const QString &roomId, const QString &joinCode); void channelJoin(const QString &roomId, const QString &joinCode); void muteGroupMentions(const QString &roomId, bool value); void channelInfo(const QString &roomId); void changeChannelName(const QString &roomId, const QString &newName); void changeGroupName(const QString &roomId, const QString &newName); void groupInfo(const QString &roomId); + void channelGetAllUserMentions(const QString &roomId); Q_SIGNALS: void avatar(const QString &userId, const QString &url); void logoutDone(); void loginDone(const QString &authToken, const QString &userId); void downloadFileDone(const QByteArray &data, const QUrl &url, bool useCache, const QUrl &localFileUrl); void getServerInfoDone(const QString &version); void getOwnInfoDone(const QJsonObject &data); void privateInfoDone(const QByteArray &data); void channelFilesDone(const QJsonObject &obj, const QString &roomId); void loadEmojiCustomDone(const QJsonObject &obj); void spotlightDone(const QJsonObject &obj); void channelListDone(const QJsonObject &obj); void searchMessageDone(const QJsonObject &obj); void getRoomsDone(const QJsonObject &obj); void usersInfoDone(const QJsonObject &obj); void groupRolesDone(const QJsonObject &obj); void channelRolesDone(const QJsonObject &obj); void getUsernameSuggestionDone(const QString &username); void getPresenceDone(const QString &presence); void listPermissionDone(const QJsonObject &obj); void listCommandsDone(const QJsonObject &obj); void fetchMyKeysDone(); void setJoinCodeDone(); void setChannelJoinDone(const QString &roomId); void missingChannelPassword(const QString &roomId); void openArchivedRoom(const QString &roomId); + void channelGetAllUserMentionsDone(const QJsonObject &obj); private: Q_DISABLE_COPY(RestApiRequest) void initializeCookies(); void slotResult(QNetworkReply *reply); void slotSslErrors(QNetworkReply *reply, const QList &error); void slotLogout(); void slotLogin(const QString &authToken, const QString &userId); void slotAddJoinCodeToChannel(const QString &channelId, const QString &password); void initializeRestApiJob(RocketChatRestApi::RestApiAbstractJob *job); QNetworkAccessManager *mNetworkAccessManager = nullptr; QNetworkCookieJar *mCookieJar = nullptr; RestApiMethod *mRestApiMethod = nullptr; RocketChatRestApi::AbstractLogger *mRuqolaLogger = nullptr; QString mUserId; QString mAuthToken; QString mUserName; QString mPassword; }; } #endif // RESTAPIREQUEST_H diff --git a/src/rocketchatrestapi-qt5/restapiutil.cpp b/src/rocketchatrestapi-qt5/restapiutil.cpp index bcf62666..c1ed2ed1 100644 --- a/src/rocketchatrestapi-qt5/restapiutil.cpp +++ b/src/rocketchatrestapi-qt5/restapiutil.cpp @@ -1,290 +1,292 @@ /* 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 "restapiutil.h" #include "rocketchatqtrestapi_debug.h" QString RestApiUtil::adaptUrl(const QString &url) { if (url.isEmpty()) { return url; } //Avoid to add more https:// :) if (url.startsWith(QLatin1String("https://")) || url.startsWith(QLatin1String("http://"))) { return url; } else { //Default to https return QStringLiteral("https://") + url; } } QString RestApiUtil::apiUri() { return QStringLiteral("/api/v1/"); } QString RestApiUtil::restUrl(RestApiUtil::RestApiUrlType type) { switch (type) { case RestApiUtil::RestApiUrlType::Login: return QStringLiteral("login"); case RestApiUtil::RestApiUrlType::Logout: return QStringLiteral("logout"); case RestApiUtil::RestApiUrlType::Me: return QStringLiteral("me"); case RestApiUtil::RestApiUrlType::UsersGetAvatar: return QStringLiteral("users.getAvatar"); case RestApiUtil::RestApiUrlType::UsersDelete: return QStringLiteral("users.delete"); case RestApiUtil::RestApiUrlType::UsersCreate: return QStringLiteral("users.create"); case RestApiUtil::RestApiUrlType::UsersCreateToken: return QStringLiteral("users.createToken"); case RestApiUtil::RestApiUrlType::UsersGetPresence: return QStringLiteral("users.getPresence"); case RestApiUtil::RestApiUrlType::UsersInfo: return QStringLiteral("users.info"); case RestApiUtil::RestApiUrlType::UsersList: return QStringLiteral("users.list"); case RestApiUtil::RestApiUrlType::UsersRegister: return QStringLiteral("users.register"); case RestApiUtil::RestApiUrlType::UsersResetAvatar: return QStringLiteral("users.resetAvatar"); case RestApiUtil::RestApiUrlType::UsersSetAvatar: return QStringLiteral("users.setAvatar"); case RestApiUtil::RestApiUrlType::UsersUpdate: return QStringLiteral("users.update"); case RestApiUtil::RestApiUrlType::UsersGetUsernameSuggestion: return QStringLiteral("users.getUsernameSuggestion"); case RestApiUtil::RestApiUrlType::ChatDelete: return QStringLiteral("chat.delete"); case RestApiUtil::RestApiUrlType::ChatGetMessage: return QStringLiteral("chat.getMessage"); case RestApiUtil::RestApiUrlType::ChatPinMessage: return QStringLiteral("chat.pinMessage"); case RestApiUtil::RestApiUrlType::ChatPostMessage: return QStringLiteral("chat.postMessage"); case RestApiUtil::RestApiUrlType::ChatReact: return QStringLiteral("chat.react"); case RestApiUtil::RestApiUrlType::ChatStarMessage: return QStringLiteral("chat.starMessage"); case RestApiUtil::RestApiUrlType::ChatUnPinMessage: return QStringLiteral("chat.unPinMessage"); case RestApiUtil::RestApiUrlType::ChatUnStarMessage: return QStringLiteral("chat.unStarMessage"); case RestApiUtil::RestApiUrlType::ChatUpdate: return QStringLiteral("chat.update"); case RestApiUtil::RestApiUrlType::ChatSearch: return QStringLiteral("chat.search"); case RestApiUtil::RestApiUrlType::ChatIgnoreUser: return QStringLiteral("chat.ignoreUser"); case RestApiUtil::RestApiUrlType::ChatReportMessage: return QStringLiteral("chat.reportMessage"); case RestApiUtil::RestApiUrlType::ChannelsAddAll: return QStringLiteral("channels.addAll"); case RestApiUtil::RestApiUrlType::ChannelsAddModerator: return QStringLiteral("channels.addModerator"); case RestApiUtil::RestApiUrlType::ChannelsAddOwner: return QStringLiteral("channels.addOwner"); case RestApiUtil::RestApiUrlType::ChannelsArchive: return QStringLiteral("channels.archive"); case RestApiUtil::RestApiUrlType::ChannelsCleanHistory: return QStringLiteral("channels.cleanHistory"); case RestApiUtil::RestApiUrlType::ChannelsClose: return QStringLiteral("channels.close"); case RestApiUtil::RestApiUrlType::ChannelsCreate: return QStringLiteral("channels.create"); case RestApiUtil::RestApiUrlType::ChannelsGetIntegrations: return QStringLiteral("channels.getIntegrations"); case RestApiUtil::RestApiUrlType::ChannelsHistory: return QStringLiteral("channels.history"); case RestApiUtil::RestApiUrlType::ChannelsInfo: return QStringLiteral("channels.info"); case RestApiUtil::RestApiUrlType::ChannelsInvite: return QStringLiteral("channels.invite"); case RestApiUtil::RestApiUrlType::ChannelsKick: return QStringLiteral("channels.kick"); case RestApiUtil::RestApiUrlType::ChannelsLeave: return QStringLiteral("channels.leave"); case RestApiUtil::RestApiUrlType::ChannelsList: return QStringLiteral("channels.list"); case RestApiUtil::RestApiUrlType::ChannelsListJoined: return QStringLiteral("channels.list.joined"); case RestApiUtil::RestApiUrlType::ChannelsOpen: return QStringLiteral("channels.open"); case RestApiUtil::RestApiUrlType::ChannelsRemoveModerator: return QStringLiteral("channels.removeModerator"); case RestApiUtil::RestApiUrlType::ChannelsRemoveOwner: return QStringLiteral("channels.removeOwner"); case RestApiUtil::RestApiUrlType::ChannelsRename: return QStringLiteral("channels.rename"); case RestApiUtil::RestApiUrlType::ChannelsSetDescription: return QStringLiteral("channels.setDescription"); case RestApiUtil::RestApiUrlType::ChannelsSetJoinCode: return QStringLiteral("channels.setJoinCode"); case RestApiUtil::RestApiUrlType::ChannelsSetPurpose: return QStringLiteral("channels.setPurpose"); case RestApiUtil::RestApiUrlType::ChannelsSetReadOnly: return QStringLiteral("channels.setReadOnly"); case RestApiUtil::RestApiUrlType::ChannelsSetTopic: return QStringLiteral("channels.setTopic"); case RestApiUtil::RestApiUrlType::ChannelsSetAnnouncement: return QStringLiteral("channels.setAnnouncement"); case RestApiUtil::RestApiUrlType::ChannelsFiles: return QStringLiteral("channels.files"); case RestApiUtil::RestApiUrlType::ChannelsSetType: return QStringLiteral("channels.setType"); case RestApiUtil::RestApiUrlType::ChannelsUnarchive: return QStringLiteral("channels.unarchive"); case RestApiUtil::RestApiUrlType::ChannelsRoles: return QStringLiteral("channels.roles"); case RestApiUtil::RestApiUrlType::ChannelsCounters: return QStringLiteral("channels.counters"); case RestApiUtil::RestApiUrlType::ChannelsJoin: return QStringLiteral("channels.join"); case RestApiUtil::RestApiUrlType::ChannelsMembers: return QStringLiteral("channels.members"); case RestApiUtil::RestApiUrlType::ChannelsDelete: return QStringLiteral("channels.delete"); + case RestApiUtil::RestApiUrlType::ChannelsGetAllUserMentionsByChannel: + return QStringLiteral("channels.getAllUserMentionsByChannel"); case RestApiUtil::RestApiUrlType::GroupsAddAll: return QStringLiteral("groups.addAll"); case RestApiUtil::RestApiUrlType::GroupsAddModerator: return QStringLiteral("groups.addModerator"); case RestApiUtil::RestApiUrlType::GroupsAddOwner: return QStringLiteral("groups.addOwner"); case RestApiUtil::RestApiUrlType::GroupsArchive: return QStringLiteral("groups.archive"); case RestApiUtil::RestApiUrlType::GroupsClose: return QStringLiteral("groups.close"); case RestApiUtil::RestApiUrlType::GroupsCreate: return QStringLiteral("groups.create"); case RestApiUtil::RestApiUrlType::GroupsGetIntegrations: return QStringLiteral("groups.getIntegrations"); case RestApiUtil::RestApiUrlType::GroupsHistory: return QStringLiteral("groups.history"); case RestApiUtil::RestApiUrlType::GroupsInfo: return QStringLiteral("groups.info"); case RestApiUtil::RestApiUrlType::GroupsInvite: return QStringLiteral("groups.invite"); case RestApiUtil::RestApiUrlType::GroupsKick: return QStringLiteral("groups.kick"); case RestApiUtil::RestApiUrlType::GroupsLeave: return QStringLiteral("groups.leave"); case RestApiUtil::RestApiUrlType::GroupsList: return QStringLiteral("groups.list"); case RestApiUtil::RestApiUrlType::GroupsOpen: return QStringLiteral("groups.open"); case RestApiUtil::RestApiUrlType::GroupsRemoveModerator: return QStringLiteral("groups.removeModerator"); case RestApiUtil::RestApiUrlType::GroupRemoveOwner: return QStringLiteral("groups.removeOwner"); case RestApiUtil::RestApiUrlType::GroupsRename: return QStringLiteral("groups.rename"); case RestApiUtil::RestApiUrlType::GroupsSetDescription: return QStringLiteral("groups.setDescription"); case RestApiUtil::RestApiUrlType::GroupsSetPurpose: return QStringLiteral("groups.setPurpose"); case RestApiUtil::RestApiUrlType::GroupsSetReadOnly: return QStringLiteral("groups.setReadOnly"); case RestApiUtil::RestApiUrlType::GroupsSetTopic: return QStringLiteral("groups.setTopic"); case RestApiUtil::RestApiUrlType::GroupsSetType: return QStringLiteral("groups.setType"); case RestApiUtil::RestApiUrlType::GroupsUnarchive: return QStringLiteral("groups.unarchive"); case RestApiUtil::RestApiUrlType::GroupsSetAnnouncement: return QStringLiteral("groups.setAnnouncement"); case RestApiUtil::RestApiUrlType::GroupsFiles: return QStringLiteral("groups.files"); case RestApiUtil::RestApiUrlType::GroupsRoles: return QStringLiteral("groups.roles"); case RestApiUtil::RestApiUrlType::GroupsCounters: return QStringLiteral("groups.counters"); case RestApiUtil::RestApiUrlType::ServerInfo: return QStringLiteral("info"); case RestApiUtil::RestApiUrlType::Settings: return QStringLiteral("settings"); case RestApiUtil::RestApiUrlType::SettingsPublic: return QStringLiteral("settings.public"); case RestApiUtil::RestApiUrlType::RoomsUpload: return QStringLiteral("rooms.upload"); case RestApiUtil::RestApiUrlType::RoomsSaveNotification: return QStringLiteral("rooms.saveNotification"); case RestApiUtil::RestApiUrlType::Spotlight: return QStringLiteral("spotlight"); case RestApiUtil::RestApiUrlType::ImClose: return QStringLiteral("im.close"); case RestApiUtil::RestApiUrlType::ImCreate: return QStringLiteral("im.create"); case RestApiUtil::RestApiUrlType::ImHistory: return QStringLiteral("im.history"); case RestApiUtil::RestApiUrlType::ImFiles: return QStringLiteral("im.files"); case RestApiUtil::RestApiUrlType::LoadEmojiCustom: return QStringLiteral("emoji-custom"); case RestApiUtil::RestApiUrlType::SubscriptionsRead: return QStringLiteral("subscriptions.read"); case RestApiUtil::RestApiUrlType::SubscriptionsUnRead: return QStringLiteral("subscriptions.unread"); case RestApiUtil::RestApiUrlType::SettingsOauth: return QStringLiteral("settings.oauth"); case RestApiUtil::RestApiUrlType::RoomsGet: return QStringLiteral("rooms.get"); case RestApiUtil::RestApiUrlType::RoomsFavorite: return QStringLiteral("rooms.favorite"); case RestApiUtil::RestApiUrlType::RoomscleanHistory: return QStringLiteral("rooms.cleanHistory"); //since 0.72 ? Need to implement it case RestApiUtil::RestApiUrlType::RoomsInfo: return QStringLiteral("rooms.info"); case RestApiUtil::RestApiUrlType::RoomsLeave: return QStringLiteral("rooms.leave"); // case RestApiUtil::RestApiUrlType::ForgotPassword: return QStringLiteral("users.forgotPassword"); case RestApiUtil::RestApiUrlType::PermissionsList: return QStringLiteral("permissions.list"); case RestApiUtil::RestApiUrlType::CommandsList: return QStringLiteral("commands.list"); case RestApiUtil::RestApiUrlType::E2EfetchMyKeys: return QStringLiteral("e2e.fetchMyKeys"); case RestApiUtil::RestApiUrlType::E2EupdateGroupKey: return QStringLiteral("e2e.updateGroupKey"); case RestApiUtil::RestApiUrlType::E2ESetRoomKeyID: return QStringLiteral("e2e.setRoomKeyID"); case RestApiUtil::RestApiUrlType::E2ESetUserPublicAndPrivateKeys: return QStringLiteral("e2e.setUserPublicAndPivateKeys"); case RestApiUtil::RestApiUrlType::E2EGetUsersOfRoomWithoutKey: return QStringLiteral("e2e.getUsersOfRoomWithoutKey"); case RestApiUtil::RestApiUrlType::E2ERequestSubscriptionKeys: return QStringLiteral("e2e.requestSubscriptionKeys"); case RestApiUtil::RestApiUrlType::RolesList: return QStringLiteral("roles.list"); case RestApiUtil::RestApiUrlType::RolesCreate: return QStringLiteral("roles.create"); case RestApiUtil::RestApiUrlType::RolesAddUserToRole: return QStringLiteral("roles.addUserToRole"); } qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Unknown RestApiUtil::RestApiUrlType " << static_cast(type); return {}; } diff --git a/src/rocketchatrestapi-qt5/restapiutil.h b/src/rocketchatrestapi-qt5/restapiutil.h index 71506bf6..3f26898f 100644 --- a/src/rocketchatrestapi-qt5/restapiutil.h +++ b/src/rocketchatrestapi-qt5/restapiutil.h @@ -1,158 +1,160 @@ /* 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. */ #ifndef RESTAPIUTIL_H #define RESTAPIUTIL_H #include #include "librestapi_private_export.h" namespace RestApiUtil { enum class RestApiUrlType { Login, Logout, Me, UsersCreate, UsersDelete, UsersCreateToken, UsersGetPresence, UsersInfo, UsersList, UsersRegister, UsersGetAvatar, UsersResetAvatar, UsersSetAvatar, UsersUpdate, UsersGetUsernameSuggestion, ChatDelete, ChatGetMessage, ChatPinMessage, ChatPostMessage, ChatReact, ChatSearch, ChatStarMessage, ChatUnPinMessage, ChatUnStarMessage, ChatUpdate, ChatIgnoreUser, ChatReportMessage, ChannelsAddAll, ChannelsAddModerator, ChannelsAddOwner, ChannelsArchive, ChannelsCleanHistory, ChannelsClose, ChannelsCreate, ChannelsGetIntegrations, ChannelsHistory, ChannelsInfo, ChannelsInvite, ChannelsKick, ChannelsLeave, ChannelsList, ChannelsListJoined, ChannelsOpen, ChannelsRemoveModerator, ChannelsRemoveOwner, ChannelsRename, ChannelsSetDescription, ChannelsSetJoinCode, ChannelsSetPurpose, ChannelsSetReadOnly, ChannelsSetTopic, ChannelsSetType, ChannelsSetAnnouncement, ChannelsFiles, ChannelsUnarchive, ChannelsCounters, ChannelsMembers, ChannelsJoin, //Since 0.71 ChannelsDelete, //since 0.65 ChannelsRoles, + //since 0.63 + ChannelsGetAllUserMentionsByChannel, GroupsAddAll, GroupsAddModerator, GroupsAddOwner, GroupsArchive, GroupsClose, GroupsCreate, GroupsGetIntegrations, GroupsHistory, GroupsInfo, GroupsInvite, GroupsKick, GroupsLeave, GroupsList, GroupsOpen, GroupsRemoveModerator, GroupRemoveOwner, GroupsRename, GroupsSetDescription, GroupsSetPurpose, GroupsSetReadOnly, GroupsSetTopic, GroupsSetType, GroupsUnarchive, GroupsSetAnnouncement, GroupsFiles, //Since 0.65 GroupsRoles, GroupsCounters, ServerInfo, Settings, SettingsPublic, Spotlight, LoadEmojiCustom, RoomsUpload, RoomsSaveNotification, ImClose, ImCreate, ImHistory, ImFiles, SubscriptionsRead, SubscriptionsUnRead, SettingsOauth, RoomsGet, RoomsFavorite, RoomscleanHistory, RoomsInfo, RoomsLeave, ForgotPassword, PermissionsList, CommandsList, //since 0.70 E2ESetRoomKeyID, E2EfetchMyKeys, E2EupdateGroupKey, E2ESetUserPublicAndPrivateKeys, E2EGetUsersOfRoomWithoutKey, E2ERequestSubscriptionKeys, RolesList, RolesCreate, RolesAddUserToRole, }; LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT QString adaptUrl(const QString &url); LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT QString restUrl(RestApiUtil::RestApiUrlType type); LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT QString apiUri(); } #endif // RESTAPIUTIL_H diff --git a/src/ruqolacore/rocketchataccount.cpp b/src/ruqolacore/rocketchataccount.cpp index 3ef007aa..bf4a0768 100644 --- a/src/ruqolacore/rocketchataccount.cpp +++ b/src/ruqolacore/rocketchataccount.cpp @@ -1,1272 +1,1277 @@ /* 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 "model/messagemodel.h" #include "rocketchataccount.h" #include "model/roommodel.h" #include "roomwrapper.h" #include "typingnotification.h" #include "model/usersmodel.h" #include "ruqola_debug.h" #include "ruqola.h" #include "messagequeue.h" #include "rocketchatbackend.h" #include "model/roomfilterproxymodel.h" #include "ruqolalogger.h" #include "ruqolaserverconfig.h" #include "model/usercompletermodel.h" #include "model/usercompleterfilterproxymodel.h" #include "model/statusmodel.h" #include "utils.h" #include "rocketchatcache.h" #include "emojimanager.h" #include "otrmanager.h" #include "inputtextmanager.h" #include "model/usersforroommodel.h" #include "model/filesforroommodel.h" #include "model/searchchannelfilterproxymodel.h" #include "model/searchchannelmodel.h" #include "model/loginmethodmodel.h" #include "model/inputcompletermodel.h" #include "model/searchmessagemodel.h" #include "model/searchmessagefilterproxymodel.h" #include "managerdatapaths.h" #include "authenticationmanager.h" #include "ddpapi/ddpclient.h" #include "receivetypingnotificationmanager.h" #include "restapirequest.h" #include "serverconfiginfo.h" #include #include #include #include #include #define USE_REASTAPI_JOB 1 RocketChatAccount::RocketChatAccount(const QString &accountFileName, QObject *parent) : QObject(parent) { qCDebug(RUQOLA_LOG) << " RocketChatAccount::RocketChatAccount(const QString &accountFileName, QObject *parent)"<setServerUrl(mSettings->serverUrl()); mOtrManager = new OtrManager(this); mRoomFilterProxyModel = new RoomFilterProxyModel(this); mUserCompleterModel = new UserCompleterModel(this); mUserCompleterFilterModelProxy = new UserCompleterFilterProxyModel(this); mUserCompleterFilterModelProxy->setSourceModel(mUserCompleterModel); mSearchChannelModel = new SearchChannelModel(this); mSearchChannelFilterProxyModel = new SearchChannelFilterProxyModel(this); mSearchChannelFilterProxyModel->setSourceModel(mSearchChannelModel); mSearchMessageModel = new SearchMessageModel(this); mSearchMessageFilterProxyModel = new SearchMessageFilterProxyModel(this); mSearchMessageFilterProxyModel->setSourceModel(mSearchMessageModel); mStatusModel = new StatusModel(this); mRoomModel = new RoomModel(this, this); connect(mRoomModel, &RoomModel::needToUpdateNotification, this, &RocketChatAccount::slotNeedToUpdateNotification); mRoomFilterProxyModel->setSourceModel(mRoomModel); mUserModel = new UsersModel(this); connect(mUserModel, &UsersModel::userStatusChanged, this, &RocketChatAccount::userStatusChanged); mMessageQueue = new MessageQueue(this, this); //TODO fix mem leak ! mTypingNotification = new TypingNotification(this); mCache = new RocketChatCache(this, this); connect(mCache, &RocketChatCache::fileDownloaded, this, &RocketChatAccount::fileDownloaded); connect(mTypingNotification, &TypingNotification::informTypingStatus, this, &RocketChatAccount::slotInformTypingStatus); QTimer::singleShot(0, this, &RocketChatAccount::clearModels); } RocketChatAccount::~RocketChatAccount() { delete mCache; mCache = nullptr; delete mRuqolaServerConfig; delete mRuqolaLogger; } void RocketChatAccount::removeSettings() { mSettings->removeSettings(); } void RocketChatAccount::loadSettings(const QString &accountFileName) { delete mSettings; mSettings = new RocketChatAccountSettings(accountFileName, this); connect(mSettings, &RocketChatAccountSettings::serverURLChanged, this, &RocketChatAccount::serverUrlChanged); connect(mSettings, &RocketChatAccountSettings::userIDChanged, this, &RocketChatAccount::userIDChanged); connect(mSettings, &RocketChatAccountSettings::userNameChanged, this, &RocketChatAccount::userNameChanged); connect(mSettings, &RocketChatAccountSettings::passwordChanged, this, &RocketChatAccount::passwordChanged); } void RocketChatAccount::slotNeedToUpdateNotification() { bool hasAlert = false; int nbUnread = 0; mRoomModel->getUnreadAlertFromAccount(hasAlert, nbUnread); Q_EMIT updateNotification(hasAlert, nbUnread, accountName()); } void RocketChatAccount::clearModels() { // Clear rooms data and refill it with data in the cache, if there is mRoomModel->reset(); mMessageQueue->loadCache(); //Try to send queue message mMessageQueue->processQueue(); } SearchChannelFilterProxyModel *RocketChatAccount::searchChannelFilterProxyModel() const { return mSearchChannelFilterProxyModel; } SearchChannelModel *RocketChatAccount::searchChannelModel() const { return mSearchChannelModel; } UserCompleterModel *RocketChatAccount::userCompleterModel() const { return mUserCompleterModel; } UserCompleterFilterProxyModel *RocketChatAccount::userCompleterFilterModelProxy() const { return mUserCompleterFilterModelProxy; } EmojiManager *RocketChatAccount::emojiManager() const { return mEmojiManager; } QString RocketChatAccount::userStatusIconFileName(const QString &name) { return mUserModel->userStatusIconFileName(name); } StatusModel *RocketChatAccount::statusModel() const { return mStatusModel; } RuqolaServerConfig *RocketChatAccount::ruqolaServerConfig() const { return mRuqolaServerConfig; } RuqolaLogger *RocketChatAccount::ruqolaLogger() const { return mRuqolaLogger; } RoomFilterProxyModel *RocketChatAccount::roomFilterProxyModel() const { return mRoomFilterProxyModel; } UsersForRoomFilterProxyModel *RocketChatAccount::usersForRoomFilterProxyModel(const QString &roomId) const { return mRoomModel->usersForRoomFilterProxyModel(roomId); } FilesForRoomFilterProxyModel *RocketChatAccount::filesForRoomFilterProxyModel(const QString &roomId) const { return mRoomModel->filesForRoomFilterProxyModel(roomId); } RocketChatBackend *RocketChatAccount::rocketChatBackend() const { return mRocketChatBackend; } MessageQueue *RocketChatAccount::messageQueue() const { return mMessageQueue; } RocketChatAccountSettings *RocketChatAccount::settings() const { return mSettings; } void RocketChatAccount::slotInformTypingStatus(const QString &room, bool typing) { ddp()->informTypingStatus(room, typing, mSettings->userName()); } RoomModel *RocketChatAccount::roomModel() const { return mRoomModel; } UsersModel *RocketChatAccount::usersModel() const { return mUserModel; } Room *RocketChatAccount::getRoom(const QString &roomId) { return mRoomModel->findRoom(roomId); } RoomWrapper *RocketChatAccount::getRoomWrapper(const QString &roomId) { return mRoomModel->findRoomWrapper(roomId); } MessageModel *RocketChatAccount::messageModelForRoom(const QString &roomID) { return mRoomModel->messageModel(roomID); } QString RocketChatAccount::getUserCurrentMessage(const QString &roomId) { return mRoomModel->inputMessage(roomId); } void RocketChatAccount::setUserCurrentMessage(const QString &message, const QString &roomId) { mRoomModel->setInputMessage(roomId, message); } void RocketChatAccount::setInputTextChanged(const QString &str, int position) { mInputTextManager->setInputTextChanged(str, position); } QString RocketChatAccount::replaceWord(const QString &newWord, const QString &str, int position) { return mInputTextManager->replaceWord(newWord, str, position); } void RocketChatAccount::textEditing(const QString &roomId, const QString &str) { mTypingNotification->setText(roomId, str); } void RocketChatAccount::reactOnMessage(const QString &messageId, const QString &emoji, bool shouldReact) { restApi()->reactOnMessage(messageId, emoji, shouldReact); } void RocketChatAccount::sendMessage(const QString &roomID, const QString &message) { #ifdef USE_REASTAPI_JOB restApi()->postMessage(roomID, message); #else QJsonObject json; json[QStringLiteral("rid")] = roomID; json[QStringLiteral("msg")] = message; ddp()->method(QStringLiteral("sendMessage"), QJsonDocument(json), DDPClient::Persistent); #endif } void RocketChatAccount::updateMessage(const QString &roomID, const QString &messageId, const QString &message) { #ifdef USE_REASTAPI_JOB restApi()->updateMessage(roomID, messageId, message); #else QJsonObject json; json[QStringLiteral("rid")] = roomID; json[QStringLiteral("msg")] = message; json[QStringLiteral("_id")] = messageId; ddp()->method(QStringLiteral("updateMessage"), QJsonDocument(json), DDPClient::Persistent); #endif } QString RocketChatAccount::avatarUrlFromDirectChannel(const QString &rid) { return mCache->avatarUrl(Utils::userIdFromDirectChannel(rid, userID())); } void RocketChatAccount::deleteFileMessage(const QString &roomId, const QString &fileId, const QString &channelType) { ddp()->deleteFileMessage(roomId, fileId, channelType); } QString RocketChatAccount::avatarUrl(const QString &userId) { return mCache->avatarUrl(userId); } void RocketChatAccount::insertAvatarUrl(const QString &userId, const QString &url) { mCache->insertAvatarUrl(userId, url); } RocketChatRestApi::RestApiRequest *RocketChatAccount::restApi() { if (!mRestApi) { mRestApi = new RocketChatRestApi::RestApiRequest(this); connect(mRestApi, &RocketChatRestApi::RestApiRequest::setChannelJoinDone, this, &RocketChatAccount::setChannelJoinDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::missingChannelPassword, this, &RocketChatAccount::missingChannelPassword); connect(mRestApi, &RocketChatRestApi::RestApiRequest::openArchivedRoom, this, &RocketChatAccount::openArchivedRoom); mRestApi->setServerUrl(mSettings->serverUrl()); mRestApi->setRestApiLogger(mRuqolaLogger); } return mRestApi; } void RocketChatAccount::leaveRoom(const QString &roomId, const QString &channelType) { #ifdef USE_REASTAPI_JOB if (channelType == QStringLiteral("c")) { restApi()->leaveChannel(roomId); } else if (channelType == QStringLiteral("p")) { restApi()->leaveGroups(roomId); } else { qCWarning(RUQOLA_LOG) << " unsupport leave room for type " << channelType; } #else Q_UNUSED(channelType) ddp()->leaveRoom(roomId); #endif } void RocketChatAccount::hideRoom(const QString &roomId, const QString &channelType) { #ifdef USE_REASTAPI_JOB restApi()->closeChannel(roomId, channelType); #else Q_UNUSED(channelType) ddp()->hideRoom(roomId); #endif } DDPClient *RocketChatAccount::ddp() { if (!mDdp) { mDdp = new DDPClient(this, this); connect(mDdp, &DDPClient::loginStatusChanged, this, &RocketChatAccount::loginStatusChanged); connect(mDdp, &DDPClient::connectedChanged, this, &RocketChatAccount::connectedChanged); connect(mDdp, &DDPClient::changed, this, &RocketChatAccount::changed); connect(mDdp, &DDPClient::added, this, &RocketChatAccount::added); connect(mDdp, &DDPClient::removed, this, &RocketChatAccount::removed); if (mSettings) { mDdp->setServerUrl(mSettings->serverUrl()); } mDdp->start(); } return mDdp; } bool RocketChatAccount::editingMode() const { return mEditingMode; } DDPClient::LoginStatus RocketChatAccount::loginStatus() { if (mDdp) { return ddp()->loginStatus(); } else { return DDPClient::LoggedOut; } } void RocketChatAccount::tryLogin() { qCDebug(RUQOLA_LOG) << "Attempting login" << mSettings->userName() << "on" << mSettings->serverUrl(); delete mDdp; mDdp = nullptr; // This creates a new ddp() object. // DDP will automatically try to connect and login. ddp(); // In the meantime, load cache... mRoomModel->reset(); } void RocketChatAccount::logOut() { mSettings->logout(); mRoomModel->clear(); #ifdef USE_REASTAPI_JOB restApi()->logout(); #else QJsonObject user; user[QStringLiteral("username")] = mSettings->userName(); QJsonObject json; json[QStringLiteral("user")] = user; ddp()->method(QStringLiteral("logout"), QJsonDocument(json)); #endif delete mDdp; mDdp = nullptr; Q_EMIT logoutDone(accountName()); Q_EMIT loginStatusChanged(); qCDebug(RUQOLA_LOG) << "Successfully logged out!"; } void RocketChatAccount::clearUnreadMessages(const QString &roomId) { restApi()->markAsRead(roomId); } void RocketChatAccount::changeFavorite(const QString &roomId, bool checked) { if (mRuqolaServerConfig->hasAtLeastVersion(0, 64, 0)) { restApi()->markAsFavorite(roomId, checked); } else { ddp()->toggleFavorite(roomId, checked); } } void RocketChatAccount::openChannel(const QString &url) { //TODO use restapi qCDebug(RUQOLA_LOG) << " void RocketChatAccount::openChannel(const QString &url)"<channelJoin(url, QString()); #else ddp()->joinRoom(url, QString()); #endif //TODO search correct room + select it. } void RocketChatAccount::setChannelJoinDone(const QString &roomId) { ddp()->subscribeRoomMessage(roomId); } void RocketChatAccount::openArchivedRoom(const QString &roomId) { //TODO } void RocketChatAccount::joinJitsiConfCall(const QString &roomId) { qCDebug(RUQOLA_LOG) << " void RocketChatAccount::joinJitsiConfCall(const QString &roomId)"<uniqueId() + roomId).toUtf8(), QCryptographicHash::Md5).toHex()); #if defined(Q_OS_IOS) || defined(Q_OS_ANDROID) const QString scheme = "org.jitsi.meet://"; #else const QString scheme = QStringLiteral("https://"); #endif const QString url = scheme + mRuqolaServerConfig->jitsiMeetUrl() + QLatin1Char('/') + mRuqolaServerConfig->jitsiMeetPrefix() + hash; const QUrl clickedUrl = QUrl::fromUserInput(url); QDesktopServices::openUrl(clickedUrl); } void RocketChatAccount::eraseRoom(const QString &roomId, const QString &channelType) { #ifdef USE_REASTAPI_JOB_NOT_SUPPORTED_YET //Leave ! or close for direct channel. //restApi()->closeChannel(roomId, channelType); #else Q_UNUSED(channelType); ddp()->eraseRoom(roomId); #endif } void RocketChatAccount::openDirectChannel(const QString &username) { #ifdef USE_REASTAPI_JOB restApi()->createDirectMessage(username); #else ddp()->openDirectChannel(username); #endif } void RocketChatAccount::createNewChannel(const QString &name, bool readOnly, bool privateRoom, const QString &userNames, bool encryptedRoom, const QString &password) { //TODO use encryted room if (!name.trimmed().isEmpty()) { const QStringList lstUsers = userNames.split(QLatin1Char(','), QString::SkipEmptyParts); #ifdef USE_REASTAPI_JOB if (privateRoom) { restApi()->createGroups(name, readOnly, lstUsers); } else { restApi()->createChannels(name, readOnly, lstUsers, password); } #else if (privateRoom) { ddp()->createPrivateGroup(name, lstUsers); } else { ddp()->createChannel(name, lstUsers, readOnly); } #endif } else { qCDebug(RUQOLA_LOG) << "Channel name can't be empty"; } } void RocketChatAccount::joinRoom(const QString &roomId, const QString &joinCode) { #ifdef USE_REASTAPI_JOB restApi()->channelJoin(roomId, joinCode); #else //TODO use restapi ddp()->joinRoom(roomId, joinCode); #endif } void RocketChatAccount::channelAndPrivateAutocomplete(const QString &pattern) { //TODO use restapi if (pattern.isEmpty()) { searchChannelModel()->clear(); } else { //Avoid to show own user const QString addUserNameToException = userName(); ddp()->channelAndPrivateAutocomplete(pattern, addUserNameToException); } } void RocketChatAccount::listEmojiCustom() { #ifdef USE_REASTAPI_JOB if (mRuqolaServerConfig->hasAtLeastVersion(0, 63, 0)) { restApi()->listEmojiCustom(); connect(restApi(), &RocketChatRestApi::RestApiRequest::loadEmojiCustomDone, this, &RocketChatAccount::loadEmojiRestApi, Qt::UniqueConnection); } else { ddp()->listEmojiCustom(); } #else ddp()->listEmojiCustom(); #endif } void RocketChatAccount::setDefaultStatus(User::PresenceStatus status) { //Not implemented yet //TODO use restapi ddp()->setDefaultStatus(status); } void RocketChatAccount::changeDefaultStatus(int index) { setDefaultStatus(mStatusModel->status(index)); } void RocketChatAccount::loadEmojiRestApi(const QJsonObject &obj) { mEmojiManager->loadEmoji(obj, true); } void RocketChatAccount::loadEmoji(const QJsonObject &obj) { mEmojiManager->loadEmoji(obj, false); } void RocketChatAccount::deleteMessage(const QString &messageId, const QString &roomId) { #ifdef USE_REASTAPI_JOB restApi()->deleteMessage(roomId, messageId); #else Q_UNUSED(roomId); ddp()->deleteMessage(messageId); #endif } void RocketChatAccount::insertFilesList(const QString &roomId) { FilesForRoomModel *filesForRoomModel = roomModel()->filesModelForRoom(roomId); if (filesForRoomModel) { filesForRoomModel->setFiles(rocketChatBackend()->files()); } else { qCWarning(RUQOLA_LOG) << " Impossible to find room " << roomId; } } void RocketChatAccount::insertCompleterUsers() { userCompleterModel()->insertUsers(rocketChatBackend()->users()); } void RocketChatAccount::userAutocomplete(const QString &searchText, const QString &exception) { //Clear before to create new search userCompleterModel()->clear(); rocketChatBackend()->clearUsersList(); if (!searchText.isEmpty()) { //Avoid to show own user QString addUserNameToException; if (exception.isEmpty()) { addUserNameToException = userName(); } else { addUserNameToException = exception + QLatin1Char(',') + userName(); } //TODO use restapi ddp()->userAutocomplete(searchText, addUserNameToException); } } void RocketChatAccount::getUsersOfRoom(const QString &roomId) { //TODO use restapi ddp()->getUsersOfRoom(roomId, true); } void RocketChatAccount::parseUsersForRooms(const QString &roomId, const QJsonObject &root) { UsersForRoomModel *usersModelForRoom = roomModel()->usersModelForRoom(roomId); if (usersModelForRoom) { usersModelForRoom->parseUsersForRooms(root, mUserModel); } else { qCWarning(RUQOLA_LOG) << " Impossible to find room " << roomId; } } void RocketChatAccount::loadAutoCompleteChannel(const QJsonObject &obj) { mSearchChannelModel->parseChannels(obj); } UsersForRoomModel *RocketChatAccount::usersModelForRoom(const QString &roomId) const { return mRoomModel->usersModelForRoom(roomId); } void RocketChatAccount::roomFiles(const QString &roomId, const QString &channelType) { #ifdef USE_REASTAPI_JOB connect(restApi(), &RocketChatRestApi::RestApiRequest::channelFilesDone, this, &RocketChatAccount::slotChannelFilesDone, Qt::UniqueConnection); restApi()->filesInRoom(roomId, channelType); #else Q_UNUSED(channelType); rocketChatBackend()->clearFilesList(); ddp()->roomFiles(roomId); #endif } QVector RocketChatAccount::parseFilesInChannel(const QJsonObject &obj) { //TODO add autotests QVector files; const QJsonArray filesArray = obj.value(QLatin1String("files")).toArray(); files.reserve(filesArray.count()); for (int i = 0; i < filesArray.count(); ++i) { QJsonObject fileObj = filesArray.at(i).toObject(); File f; f.parseFile(fileObj, true); files.append(f); } return files; } ReceiveTypingNotificationManager *RocketChatAccount::receiveTypingNotificationManager() const { return mReceiveTypingNotificationManager; } void RocketChatAccount::slotChannelFilesDone(const QJsonObject &obj, const QString &roomId) { const QVector files = parseFilesInChannel(obj); FilesForRoomModel *filesForRoomModel = roomModel()->filesModelForRoom(roomId); if (filesForRoomModel) { filesForRoomModel->setFiles(files); } else { qCWarning(RUQOLA_LOG) << " Impossible to find room " << roomId; } } void RocketChatAccount::createJitsiConfCall(const QString &roomId) { //TODO use restapi ddp()->createJitsiConfCall(roomId); joinJitsiConfCall(roomId); } void RocketChatAccount::addUserToRoom(const QString &username, const QString &roomId, const QString &channelType) { #ifdef USE_REASTAPI_JOB if (channelType == QStringLiteral("c")) { restApi()->addUserInChannel(roomId, username); } else if (channelType == QStringLiteral("p")) { restApi()->addUserInGroup(roomId, username); } #else Q_UNUSED(channelType); ddp()->addUserToRoom(username, roomId); #endif } void RocketChatAccount::clearSearchModel() { mSearchMessageModel->clear(); } void RocketChatAccount::messageSearch(const QString &pattern, const QString &rid) { if (pattern.isEmpty()) { clearSearchModel(); } else { #ifdef USE_REASTAPI_JOB connect(restApi(), &RocketChatRestApi::RestApiRequest::searchMessageDone, this, &RocketChatAccount::slotSearchMessages); restApi()->searchMessages(rid, pattern); #else ddp()->messageSearch(rid, pattern); #endif } } void RocketChatAccount::slotSearchMessages(const QJsonObject &obj) { mSearchMessageModel->parseResult(obj, true); } void RocketChatAccount::starMessage(const QString &messageId, const QString &rid, bool starred) { #ifdef USE_REASTAPI_JOB Q_UNUSED(rid); restApi()->starMessage(messageId, starred); #else ddp()->starMessage(messageId, rid, starred); #endif } void RocketChatAccount::uploadFile(const QString &roomId, const QString &description, const QString &messageText, const QUrl &fileUrl) { restApi()->uploadFile(roomId, description, messageText, fileUrl); } void RocketChatAccount::changeChannelSettings(const QString &roomId, RocketChatAccount::RoomInfoType infoType, const QVariant &newValue, const QString &channelType) { switch (infoType) { case Announcement: if (channelType == QStringLiteral("c")) { restApi()->changeChannelAnnouncement(roomId, newValue.toString()); } else if (channelType == QStringLiteral("p")) { //FOR the moment we can't change group announcement with restapi if (mRuqolaServerConfig->hasAtLeastVersion(0, 70, 0)) { restApi()->changeGroupsAnnouncement(roomId, newValue.toString()); } else { ddp()->setRoomAnnouncement(roomId, newValue.toString()); } } else { qCWarning(RUQOLA_LOG) << " unsupport change announcement for type " << channelType; } break; case Description: if (channelType == QStringLiteral("c")) { restApi()->changeChannelDescription(roomId, newValue.toString()); } else if (channelType == QStringLiteral("p")) { restApi()->changeGroupsDescription(roomId, newValue.toString()); } else { qCWarning(RUQOLA_LOG) << " unsupport change description for type " << channelType; } break; case Name: if (channelType == QStringLiteral("c")) { restApi()->changeChannelName(roomId, newValue.toString()); } else if (channelType == QStringLiteral("p")) { restApi()->changeGroupName(roomId, newValue.toString()); } else { qCWarning(RUQOLA_LOG) << " unsupport change name for type " << channelType; } break; case Topic: if (channelType == QStringLiteral("c")) { restApi()->changeChannelTopic(roomId, newValue.toString()); } else if (channelType == QStringLiteral("p")) { restApi()->changeGroupsTopic(roomId, newValue.toString()); } else { qCWarning(RUQOLA_LOG) << " unsupport change topic for type " << channelType; } break; case ReadOnly: ddp()->setRoomIsReadOnly(roomId, newValue.toBool()); break; case Archive: if (channelType == QStringLiteral("c")) { restApi()->archiveChannel(roomId); } else if (channelType == QStringLiteral("p")) { restApi()->archiveGroups(roomId); } else { qCWarning(RUQOLA_LOG) << " unsupport archiving for type " << channelType; } break; case RoomType: ddp()->setRoomType(roomId, newValue.toBool()); break; case Encrypted: //TODO use restApi when there is some api ddp()->setRoomEncrypted(roomId, newValue.toBool()); break; } } void RocketChatAccount::changeNotificationsSettings(const QString &roomId, RocketChatAccount::NotificationOptionsType notificationsType, const QVariant &newValue) { switch (notificationsType) { case DisableNotifications: restApi()->disableNotifications(roomId, newValue.toBool()); break; case HideUnreadStatus: restApi()->hideUnreadStatus(roomId, newValue.toBool()); break; case AudioNotifications: restApi()->audioNotifications(roomId, newValue.toString()); break; case DesktopNotifications: restApi()->desktopNotifications(roomId, newValue.toString()); break; case EmailNotifications: restApi()->emailNotifications(roomId, newValue.toString()); break; case MobilePushNotifications: restApi()->mobilePushNotifications(roomId, newValue.toString()); break; case UnreadAlert: restApi()->unreadAlert(roomId, newValue.toString()); break; case MuteGroupMentions: restApi()->muteGroupMentions(roomId, newValue.toBool()); break; } } void RocketChatAccount::parsePublicSettings(const QJsonObject &obj) { QJsonArray configs = obj.value(QLatin1String("result")).toArray(); for (QJsonValueRef currentConfig : configs) { QJsonObject currentConfObject = currentConfig.toObject(); const QString id = currentConfObject[QStringLiteral("_id")].toString(); const QVariant value = currentConfObject[QStringLiteral("value")].toVariant(); if (id == QLatin1String("uniqueID")) { mRuqolaServerConfig->setUniqueId(value.toString()); } else if (id == QLatin1String("Jitsi_Domain")) { mRuqolaServerConfig->setJitsiMeetUrl(value.toString()); } else if (id == QLatin1String("Jitsi_URL_Room_Prefix")) { mRuqolaServerConfig->setJitsiMeetPrefix(value.toString()); } else if (id == QLatin1String("FileUpload_Storage_Type")) { mRuqolaServerConfig->setFileUploadStorageType(value.toString()); } else if (id == QLatin1String("Message_AllowEditing")) { mRuqolaServerConfig->setAllowMessageEditing(value.toBool()); } else if (id == QLatin1String("Message_AllowEditing_BlockEditInMinutes")) { mRuqolaServerConfig->setBlockEditingMessageInMinutes(value.toInt()); } else if (id == QLatin1String("OTR_Enable")) { mRuqolaServerConfig->setOtrEnabled(value.toBool()); } else if (id.contains(QRegularExpression(QStringLiteral("^Accounts_OAuth_\\w+")))) { if (value.toBool()) { mRuqolaServerConfig->addOauthService(id); } } else if (id == QLatin1String("Site_Url")) { mRuqolaServerConfig->setSiteUrl(value.toString()); } else if (id == QLatin1String("Site_Name")) { mRuqolaServerConfig->setSiteName(value.toString()); } else if (id == QLatin1String("E2E_Enable")) { mRuqolaServerConfig->setEncryptionEnabled(value.toBool()); } else { qCDebug(RUQOLA_LOG) << "Other public settings id " << id << value; } } fillOauthModel(); } void RocketChatAccount::fillOauthModel() { QVector fillModel; for (int i = 0, total = mLstInfos.count(); i < total; ++i) { if (mRuqolaServerConfig->canShowOauthService(mLstInfos.at(i).oauthType())) { fillModel.append(mLstInfos.at(i)); } } mLoginMethodModel->setAuthenticationInfos(fillModel); } void RocketChatAccount::changeDefaultAuthentication(int index) { setDefaultAuthentication(mLoginMethodModel->loginType(index)); } void RocketChatAccount::setDefaultAuthentication(AuthenticationManager::OauthType type) { PluginAuthenticationInterface *interface = mLstPluginAuthenticationInterface.value(type); if (interface) { mDefaultAuthenticationInterface = interface; } else { qCWarning(RUQOLA_LOG) << "No interface defined for " << type; } } SearchMessageFilterProxyModel *RocketChatAccount::searchMessageFilterProxyModel() const { return mSearchMessageFilterProxyModel; } SearchMessageModel *RocketChatAccount::searchMessageModel() const { return mSearchMessageModel; } void RocketChatAccount::initializeAuthenticationPlugins() { //TODO change it when we change server //Clean up at the end. const QVector lstPlugins = AuthenticationManager::self()->pluginsList(); qCDebug(RUQOLA_LOG) <<" void RocketChatAccount::initializeAuthenticationPlugins()" << lstPlugins.count(); mLstPluginAuthenticationInterface.clear(); mLstInfos.clear(); for (PluginAuthentication *abstractPlugin : lstPlugins) { AuthenticationInfo info; info.setIconName(abstractPlugin->iconName()); info.setName(abstractPlugin->name()); info.setOauthType(abstractPlugin->type()); if (info.isValid()) { mLstInfos.append(info); } PluginAuthenticationInterface *interface = abstractPlugin->createInterface(this); interface->setAccount(this); mRuqolaServerConfig->addRuqolaAuthenticationSupport(abstractPlugin->type()); mLstPluginAuthenticationInterface.insert(abstractPlugin->type(), interface); //For the moment initialize default interface if (abstractPlugin->type() == AuthenticationManager::OauthType::Password) { mDefaultAuthenticationInterface = interface; } qCDebug(RUQOLA_LOG) << " plugin type " << abstractPlugin->type(); } //TODO fill ??? or store QVector } PluginAuthenticationInterface *RocketChatAccount::defaultAuthenticationInterface() const { return mDefaultAuthenticationInterface; } InputCompleterModel *RocketChatAccount::inputCompleterModel() const { return mInputTextManager->inputCompleterModel(); } LoginMethodModel *RocketChatAccount::loginMethodModel() const { return mLoginMethodModel; } QString RocketChatAccount::authToken() const { return settings()->authToken(); } QString RocketChatAccount::userName() const { return settings()->userName(); } void RocketChatAccount::setAccountName(const QString &accountname) { //Initialize new account room ManagerDataPaths::self()->initializeAccountPath(accountname); //qDebug() << "void RocketChatAccount::setAccountName(const QString &servername)"<accountConfigFileName(accountname)); settings()->setAccountName(accountname); } QString RocketChatAccount::accountName() const { return settings()->accountName(); } QString RocketChatAccount::userID() const { return settings()->userId(); } QString RocketChatAccount::password() const { return settings()->password(); } void RocketChatAccount::setAuthToken(const QString &token) { settings()->setAuthToken(token); } void RocketChatAccount::setPassword(const QString &password) { settings()->setPassword(password); } void RocketChatAccount::setUserName(const QString &username) { settings()->setUserName(username); } void RocketChatAccount::setUserID(const QString &userID) { settings()->setUserId(userID); } QString RocketChatAccount::serverUrl() const { return settings()->serverUrl(); } void RocketChatAccount::setServerUrl(const QString &serverURL) { settings()->setServerUrl(serverURL); restApi()->setServerUrl(serverURL); mEmojiManager->setServerUrl(serverURL); } QString RocketChatAccount::recordingVideoPath() const { return mCache->recordingVideoPath(accountName()); } QString RocketChatAccount::recordingImagePath() const { return mCache->recordingImagePath(accountName()); } void RocketChatAccount::downloadFile(const QString &downloadFileUrl, const QUrl &localFile) { mCache->downloadFile(downloadFileUrl, localFile, false); } QUrl RocketChatAccount::attachmentUrl(const QString &url) { return mCache->attachmentUrl(url); } void RocketChatAccount::loadHistory(const QString &roomID, const QString &channelType, bool initial) { //TODO port to restapi Q_UNUSED(channelType); MessageModel *roomModel = messageModelForRoom(roomID); if (roomModel) { //TODO add autotest for it ! QJsonArray params; params.append(QJsonValue(roomID)); // Load history const qint64 endDateTime = roomModel->lastTimestamp(); if (initial || roomModel->isEmpty()) { params.append(QJsonValue(QJsonValue::Null)); params.append(QJsonValue(50)); // Max number of messages to load; QJsonObject dateObject; //qDebug() << "roomModel->lastTimestamp()" << roomModel->lastTimestamp() << " ROOMID " << roomID; dateObject[QStringLiteral("$date")] = QJsonValue(endDateTime); params.append(dateObject); } else { const qint64 startDateTime = roomModel->generateNewStartTimeStamp(endDateTime); QJsonObject dateObjectEnd; dateObjectEnd[QStringLiteral("$date")] = QJsonValue(endDateTime); //qDebug() << " QDATE TIME END" << QDateTime::fromMSecsSinceEpoch(endDateTime) << " START " << QDateTime::fromMSecsSinceEpoch(startDateTime) << " ROOMID" << roomID; params.append(dateObjectEnd); params.append(QJsonValue(50)); // Max number of messages to load; QJsonObject dateObjectStart; //qDebug() << "roomModel->lastTimestamp()" << roomModel->lastTimestamp() << " ROOMID " << roomID; dateObjectStart[QStringLiteral("$date")] = QJsonValue(startDateTime); params.append(dateObjectStart); } ddp()->loadHistory(params); } else { qCWarning(RUQOLA_LOG) << "Room is not found " << roomID; } } void RocketChatAccount::setServerVersion(const QString &version) { qCDebug(RUQOLA_LOG) << " void RocketChatAccount::setServerVersion(const QString &version)" << version; mRuqolaServerConfig->setServerVersion(version); } bool RocketChatAccount::needAdaptNewSubscriptionRC60() const { return mRuqolaServerConfig->needAdaptNewSubscriptionRC60(); } bool RocketChatAccount::otrEnabled() const { return mRuqolaServerConfig->otrEnabled(); } bool RocketChatAccount::encryptedEnabled() const { return mRuqolaServerConfig->encryptionEnabled(); } QString RocketChatAccount::serverVersionStr() const { return mRuqolaServerConfig->serverVersionStr(); } ServerConfigInfo *RocketChatAccount::serverConfigInfo() const { return mServerConfigInfo; } void RocketChatAccount::groupInfo(const QString &roomId) { restApi()->groupInfo(roomId); } void RocketChatAccount::switchEditingMode(bool b) { if (mEditingMode != b) { mEditingMode = b; Q_EMIT editingModeChanged(); } } void RocketChatAccount::channelInfo(const QString &roomId) { restApi()->channelInfo(roomId); } bool RocketChatAccount::allowEditingMessages() const { return mRuqolaServerConfig->allowMessageEditing(); } void RocketChatAccount::parseOtr(const QJsonArray &contents) { const Otr t = mOtrManager->parseOtr(contents); qDebug() << " void RocketChatAccount::parseOtr(const QJsonArray &contents)"<avatarUrlFromCacheOnly(sender); //qDebug() << " iconFileName"<inputChannelAutocomplete(pattern, exceptions); } void RocketChatAccount::inputUserAutocomplete(const QString &pattern, const QString &exceptions) { ddp()->inputUserAutocomplete(pattern, exceptions); } void RocketChatAccount::inputTextCompleter(const QJsonObject &obj) { mInputTextManager->inputTextCompleter(obj); } void RocketChatAccount::displaySearchedMessage(const QJsonObject &obj) { mSearchMessageModel->parseResult(obj); } void RocketChatAccount::updateUser(const QJsonObject &object) { mUserModel->updateUser(object); } void RocketChatAccount::userStatusChanged(const User &user) { //qDebug() << " void RocketChatAccount::userStatusChanged(const User &user)"<setCurrentPresenceStatus(Utils::presenceStatusFromString(user.status())); } mRoomModel->userStatusChanged(user); } void RocketChatAccount::ignoreUser(const QString &rid, const QString &userId, bool ignore) { ddp()->ignoreUser(rid, userId, ignore); } void RocketChatAccount::blockUser(const QString &rid, bool block) { //TODO use restapi if (rid.isEmpty()) { qCWarning(RUQOLA_LOG) << " void RocketChatAccount::blockUser EMPTY rid ! block " << block; } else { //qDebug() << " void RocketChatAccount::blockUser userId " << userId << " block " << block << " rid " << rid << " own userdId" << userID(); const QString userId = Utils::userIdFromDirectChannel(rid, userID()); if (block) { ddp()->blockUser(rid, userId); } else { ddp()->unBlockUser(rid, userId); } } } void RocketChatAccount::initializeRoom(const QString &roomId, bool loadInitialHistory) { ddp()->subscribeRoomMessage(roomId); getUsersOfRoom(roomId); if (loadInitialHistory) { //Load history //TODO fix me use channeltype! loadHistory(roomId, QString(), true /*initial loading*/); } } void RocketChatAccount::openDocumentation() { QDesktopServices::openUrl(QUrl(QStringLiteral("help:/"))); } + +void RocketChatAccount::channelGetAllUserMentions(const QString &roomId) +{ + restApi()->channelGetAllUserMentions(roomId); +} diff --git a/src/ruqolacore/rocketchataccount.h b/src/ruqolacore/rocketchataccount.h index 8d50f056..f5cc994c 100644 --- a/src/ruqolacore/rocketchataccount.h +++ b/src/ruqolacore/rocketchataccount.h @@ -1,332 +1,333 @@ /* 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. */ #ifndef ROCKETCHATACCOUNT_H #define ROCKETCHATACCOUNT_H #include #include #include #include "rocketchataccountsettings.h" #include "libruqola_private_export.h" #include "authenticationinfo.h" #include "file.h" class TypingNotification; class UsersModel; class RoomModel; class RoomWrapper; class MessageModel; class DDPClient; class MessageQueue; class RocketChatBackend; class RoomFilterProxyModel; class RuqolaLogger; class RuqolaServerConfig; class UserCompleterModel; class UserCompleterFilterProxyModel; class StatusModel; class RocketChatCache; class EmojiManager; class OtrManager; class UsersForRoomFilterProxyModel; class UsersForRoomModel; class FilesForRoomFilterProxyModel; class SearchChannelModel; class SearchChannelFilterProxyModel; class LoginMethodModel; class InputCompleterModel; class InputTextManager; class PluginAuthenticationInterface; class Room; class SearchMessageModel; class SearchMessageFilterProxyModel; class ServerConfigInfo; class ReceiveTypingNotificationManager; namespace RocketChatRestApi { class RestApiRequest; } class LIBRUQOLACORE_EXPORT RocketChatAccount : public QObject { Q_OBJECT Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged) Q_PROPERTY(QString userID READ userID WRITE setUserID NOTIFY userIDChanged) Q_PROPERTY(QString serverUrl READ serverUrl WRITE setServerUrl NOTIFY serverUrlChanged) Q_PROPERTY(QString accountName READ accountName WRITE setAccountName NOTIFY accountNameChanged) Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) Q_PROPERTY(DDPClient::LoginStatus loginStatus READ loginStatus NOTIFY loginStatusChanged) Q_PROPERTY(bool editingMode READ editingMode NOTIFY editingModeChanged) public: explicit RocketChatAccount(const QString &accountName = QString(), QObject *parent = nullptr); ~RocketChatAccount(); enum RoomInfoType { Announcement, Description, Name, Topic, ReadOnly, Archive, RoomType, Encrypted, }; Q_ENUM(RoomInfoType) enum NotificationOptionsType { DisableNotifications, HideUnreadStatus, AudioNotifications, DesktopNotifications, EmailNotifications, MobilePushNotifications, UnreadAlert, MuteGroupMentions }; Q_ENUM(NotificationOptionsType) Q_INVOKABLE UsersModel *usersModel() const; Q_INVOKABLE RoomModel *roomModel() const; Q_INVOKABLE RoomFilterProxyModel *roomFilterProxyModel() const; Q_INVOKABLE UsersForRoomFilterProxyModel *usersForRoomFilterProxyModel(const QString &roomId) const; Q_INVOKABLE UsersForRoomModel *usersModelForRoom(const QString &roomId) const; Q_INVOKABLE RoomWrapper *getRoomWrapper(const QString &roomId); Q_INVOKABLE MessageModel *messageModelForRoom(const QString &roomID); Q_INVOKABLE QString getUserCurrentMessage(const QString &roomId); Q_INVOKABLE void setUserCurrentMessage(const QString &message, const QString &roomId); Q_INVOKABLE void textEditing(const QString &roomId, const QString &str); Q_INVOKABLE void leaveRoom(const QString &roomId, const QString &channelType); Q_INVOKABLE void hideRoom(const QString &roomId, const QString &channelType = QString()); Q_INVOKABLE void tryLogin(); Q_INVOKABLE void logOut(); Q_INVOKABLE void clearUnreadMessages(const QString &roomId); Q_INVOKABLE void changeFavorite(const QString &roomId, bool checked); Q_INVOKABLE void sendMessage(const QString &roomID, const QString &message); Q_INVOKABLE void updateMessage(const QString &roomID, const QString &messageId, const QString &message); Q_INVOKABLE void openChannel(const QString &url); Q_INVOKABLE void joinJitsiConfCall(const QString &roomId); Q_INVOKABLE void createNewChannel(const QString &name, bool readOnly, bool privateRoom, const QString &userNames, bool encryptedRoom, const QString &password); Q_INVOKABLE void joinRoom(const QString &roomId, const QString &joinCode = QString()); Q_INVOKABLE void openDirectChannel(const QString &username); Q_INVOKABLE void listEmojiCustom(); Q_INVOKABLE void setDefaultStatus(User::PresenceStatus status); Q_INVOKABLE void changeDefaultStatus(int index); Q_INVOKABLE void createJitsiConfCall(const QString &roomId); Q_INVOKABLE void deleteMessage(const QString &messageId, const QString &roomId); Q_INVOKABLE void userAutocomplete(const QString &searchText, const QString &exception); Q_INVOKABLE void eraseRoom(const QString &roomId, const QString &channelType = QString()); Q_INVOKABLE void changeChannelSettings(const QString &roomId, RocketChatAccount::RoomInfoType infoType, const QVariant &newValue, const QString &channelType = QString()); Q_INVOKABLE void changeNotificationsSettings(const QString &roomId, RocketChatAccount::NotificationOptionsType notificationsType, const QVariant &newValue); Q_INVOKABLE QString recordingVideoPath() const; Q_INVOKABLE QString recordingImagePath() const; Q_INVOKABLE void downloadFile(const QString &downloadFileUrl, const QUrl &localFile); Q_INVOKABLE void starMessage(const QString &messageId, const QString &rid, bool starred); Q_INVOKABLE void uploadFile(const QString &roomId, const QString &description, const QString &messageText, const QUrl &fileUrl); Q_INVOKABLE QString serverUrl() const; Q_INVOKABLE QString avatarUrl(const QString &userId); Q_INVOKABLE StatusModel *statusModel() const; Q_INVOKABLE Q_REQUIRED_RESULT QUrl attachmentUrl(const QString &url); Q_INVOKABLE void loadHistory(const QString &roomID, const QString &channelType = QString(), bool initial = false); Q_INVOKABLE Q_REQUIRED_RESULT bool allowEditingMessages() const; Q_INVOKABLE Q_REQUIRED_RESULT bool otrEnabled() const; Q_INVOKABLE void channelAndPrivateAutocomplete(const QString &pattern); Q_INVOKABLE UserCompleterFilterProxyModel *userCompleterFilterModelProxy() const; Q_INVOKABLE void roomFiles(const QString &roomId, const QString &channelType = QString()); Q_INVOKABLE FilesForRoomFilterProxyModel *filesForRoomFilterProxyModel(const QString &roomId) const; Q_INVOKABLE void addUserToRoom(const QString &username, const QString &roomId, const QString &channelType); Q_INVOKABLE SearchChannelFilterProxyModel *searchChannelFilterProxyModel() const; Q_INVOKABLE InputCompleterModel *inputCompleterModel() const; Q_INVOKABLE LoginMethodModel *loginMethodModel() const; Q_INVOKABLE Room *getRoom(const QString &roomId); Q_INVOKABLE void changeDefaultAuthentication(int index); Q_INVOKABLE void messageSearch(const QString &pattern, const QString &rid); Q_INVOKABLE SearchMessageFilterProxyModel *searchMessageFilterProxyModel() const; Q_INVOKABLE void setInputTextChanged(const QString &str, int position); Q_INVOKABLE QString replaceWord(const QString &newWord, const QString &str, int position); Q_INVOKABLE void blockUser(const QString &userId, bool block); Q_INVOKABLE QString avatarUrlFromDirectChannel(const QString &rid); Q_INVOKABLE void deleteFileMessage(const QString &roomId, const QString &fileId, const QString &channelType); Q_INVOKABLE void openDocumentation(); Q_INVOKABLE void clearSearchModel(); Q_INVOKABLE void reactOnMessage(const QString &messageId, const QString &emoji, bool shouldReact); Q_INVOKABLE void ignoreUser(const QString &rid, const QString &userId, bool ignore); Q_INVOKABLE ReceiveTypingNotificationManager *receiveTypingNotificationManager() const; Q_INVOKABLE Q_REQUIRED_RESULT bool encryptedEnabled() const; Q_INVOKABLE Q_REQUIRED_RESULT QString serverVersionStr() const; Q_INVOKABLE Q_REQUIRED_RESULT ServerConfigInfo *serverConfigInfo() const; Q_INVOKABLE void channelInfo(const QString &roomId); Q_INVOKABLE void groupInfo(const QString &roomId); + Q_INVOKABLE void channelGetAllUserMentions(const QString &roomId); Q_INVOKABLE void switchEditingMode(bool b); SearchChannelModel *searchChannelModel() const; UserCompleterModel *userCompleterModel() const; RocketChatAccountSettings *settings() const; DDPClient *ddp(); bool editingMode() const; DDPClient::LoginStatus loginStatus(); RocketChatRestApi::RestApiRequest *restApi(); //Make it private in future void slotInformTypingStatus(const QString &room, bool typing); MessageQueue *messageQueue() const; RocketChatBackend *rocketChatBackend() const; RuqolaLogger *ruqolaLogger() const; void loadEmoji(const QJsonObject &obj); void parsePublicSettings(const QJsonObject &obj); RuqolaServerConfig *ruqolaServerConfig() const; void setUserName(const QString &username); Q_REQUIRED_RESULT QString userName() const; void setAccountName(const QString &servername); Q_REQUIRED_RESULT QString accountName() const; void setUserID(const QString &userID); Q_REQUIRED_RESULT QString userID() const; void setPassword(const QString &password); Q_REQUIRED_RESULT QString password() const; void setAuthToken(const QString &token); Q_REQUIRED_RESULT QString authToken() const; void setServerUrl(const QString &serverUrl); void sendNotification(const QJsonArray &contents); void parseOtr(const QJsonArray &contents); void setServerVersion(const QString &version); Q_REQUIRED_RESULT bool needAdaptNewSubscriptionRC60() const; EmojiManager *emojiManager() const; Q_REQUIRED_RESULT QString userStatusIconFileName(const QString &id); void getUsersOfRoom(const QString &roomId); void parseUsersForRooms(const QString &roomId, const QJsonObject &root); void loadAutoCompleteChannel(const QJsonObject &obj); void insertCompleterUsers(); void insertFilesList(const QString &roomId); void inputChannelAutocomplete(const QString &pattern, const QString &exceptions); void inputUserAutocomplete(const QString &pattern, const QString &exceptions); void inputTextCompleter(const QJsonObject &obj); PluginAuthenticationInterface *defaultAuthenticationInterface() const; SearchMessageModel *searchMessageModel() const; void displaySearchedMessage(const QJsonObject &obj); void updateUser(const QJsonObject &object); void initializeRoom(const QString &roomId, bool loadInitialHistory = true); void removeSettings(); Q_SIGNALS: void connectedChanged(); void accountNameChanged(); void userNameChanged(); void userIDChanged(); void passwordChanged(); void serverUrlChanged(); void loginStatusChanged(); void logoutDone(const QString &accountname); void added(const QJsonObject &item); void changed(const QJsonObject &item); void removed(const QJsonObject &item); void notification(const QString &title, const QString &message, const QPixmap &pixmap); void fileDownloaded(const QString &filePath, const QUrl &cacheImageUrl); void updateNotification(bool hasAlert, int nbUnread, const QString &accountName); void missingChannelPassword(const QString &roomId); void editingModeChanged(); private: Q_DISABLE_COPY(RocketChatAccount) void slotChannelFilesDone(const QJsonObject &obj, const QString &roomId); void loadEmojiRestApi(const QJsonObject &obj); void slotSearchMessages(const QJsonObject &obj); void slotNeedToUpdateNotification(); void insertAvatarUrl(const QString &userId, const QString &url); void loadSettings(const QString &accountFileName); void clearModels(); void fillOauthModel(); void initializeAuthenticationPlugins(); void setDefaultAuthentication(AuthenticationManager::OauthType type); void userStatusChanged(const User &user); void setChannelJoinDone(const QString &roomId); void openArchivedRoom(const QString &roomId); QVector parseFilesInChannel(const QJsonObject &obj); PluginAuthenticationInterface *mDefaultAuthenticationInterface = nullptr; QHash mLstPluginAuthenticationInterface; QVector mLstInfos; RocketChatAccountSettings *mSettings = nullptr; EmojiManager *mEmojiManager = nullptr; TypingNotification *mTypingNotification = nullptr; UsersModel *mUserModel = nullptr; RoomModel *mRoomModel = nullptr; RoomFilterProxyModel *mRoomFilterProxyModel = nullptr; DDPClient *mDdp = nullptr; RocketChatRestApi::RestApiRequest *mRestApi = nullptr; MessageQueue *mMessageQueue = nullptr; RocketChatBackend *mRocketChatBackend = nullptr; RuqolaLogger *mRuqolaLogger = nullptr; RuqolaServerConfig *mRuqolaServerConfig = nullptr; UserCompleterModel *mUserCompleterModel = nullptr; UserCompleterFilterProxyModel *mUserCompleterFilterModelProxy = nullptr; StatusModel *mStatusModel = nullptr; RocketChatCache *mCache = nullptr; OtrManager *mOtrManager = nullptr; SearchChannelModel *mSearchChannelModel = nullptr; SearchChannelFilterProxyModel *mSearchChannelFilterProxyModel = nullptr; LoginMethodModel *mLoginMethodModel = nullptr; InputTextManager *mInputTextManager = nullptr; SearchMessageModel *mSearchMessageModel = nullptr; SearchMessageFilterProxyModel *mSearchMessageFilterProxyModel = nullptr; ReceiveTypingNotificationManager *mReceiveTypingNotificationManager = nullptr; ServerConfigInfo *mServerConfigInfo = nullptr; bool mEditingMode = false; }; #endif // ROCKETCHATACCOUNT_H