diff --git a/src/core/ddpapi/ddpclient.cpp b/src/core/ddpapi/ddpclient.cpp index ebcbe143..9da09771 100644 --- a/src/core/ddpapi/ddpclient.cpp +++ b/src/core/ddpapi/ddpclient.cpp @@ -1,951 +1,955 @@ /* * Copyright 2016 Riccardo Iaconelli * Copyright (C) 2017-2020 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 . * */ #include "ddpclient.h" #include "restapirequest.h" #include "utils.h" #include "ruqola_ddpapi_debug.h" #include "ruqola_ddpapi_command_debug.h" #include "rocketchatmessage.h" #include "ruqolawebsocket.h" #include "rocketchataccount.h" #include "messagequeue.h" #include "ruqolalogger.h" #include "rocketchatbackend.h" #include "plugins/pluginauthenticationinterface.h" #include #include #include #include namespace RuqolaTestWebSocket { LIBRUQOLACORE_EXPORT AbstractWebSocket *_k_ruqola_webSocket = nullptr; } void user_ignore(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("User Ignore:") + QJsonDocument(root).toJson()); } } void block_user(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Block User:") + QJsonDocument(root).toJson()); } } void unblock_user(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("UnBlock User:") + QJsonDocument(root).toJson()); } } void input_user_channel_autocomplete(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Input channel/User autocomplete:") + QJsonDocument(root).toJson()); } const QJsonObject obj = root.value(QLatin1String("result")).toObject(); account->inputTextManager()->inputTextCompleter(obj); } void process_backlog(const QJsonObject &root, RocketChatAccount *account) { const QJsonObject obj = root.value(QLatin1String("result")).toObject(); //qCDebug(RUQOLA_DDPAPI_LOG) << obj.value(QLatin1String("messages")).toArray().size(); account->rocketChatBackend()->processIncomingMessages(obj.value(QLatin1String("messages")).toArray()); } void add_user_to_room(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Add User To Room:") + QJsonDocument(root).toJson()); } } void star_message(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Star message:") + QJsonDocument(root).toJson()); } } void change_notifications_settings(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Change Notifications Settings:") + QJsonDocument(root).toJson()); } } void change_room_settings(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Change Room Settings:") + QJsonDocument(root).toJson()); } } void erase_room(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Delete Room:") + QJsonDocument(root).toJson()); } qDebug()<< "void erase_room(const QJsonObject &root, RocketChatAccount *account)"<ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Delete Message:") + QJsonDocument(root).toJson()); } } void channel_and_private_autocomplete(const QJsonObject &root, RocketChatAccount *account) { const QJsonObject obj = root.value(QLatin1String("result")).toObject(); account->loadAutoCompleteChannel(obj); if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Channel And Private AutoComplete:") + QJsonDocument(root).toJson()); } } void create_jitsi_conf_call(const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Create Jitsi Conf Call:") + QJsonDocument(root).toJson()); } } void open_direct_channel(const QJsonObject &root, RocketChatAccount *account) { const QJsonObject obj = root.value(QLatin1String("result")).toObject(); if (!obj.isEmpty()) { const QString rid = obj.value(QLatin1String("rid")).toString(); if (!rid.isEmpty()) { account->ddp()->subscribeRoomMessage(rid); } } if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Open Direct channel:") + QJsonDocument(root).toJson()); } } void join_room(const QJsonObject &obj, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Join Room :") + QJsonDocument(obj).toJson()); } } void change_default_status(const QJsonObject &obj, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Change Default Status :") + QJsonDocument(obj).toJson()); } } void empty_callback(const QJsonObject &obj, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Empty call back :") + QJsonDocument(obj).toJson()); } else { qCWarning(RUQOLA_DDPAPI_LOG) << "empty_callback "<< obj; } } void login_result(const QJsonObject &obj, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Login result: ") + QJsonDocument(obj).toJson()); } else { qCWarning(RUQOLA_DDPAPI_LOG) << "Login result: "<< obj; } const QJsonObject result = obj.value(QLatin1String("result")).toObject(); //qDebug() << " result token " << result[QStringLiteral("token")].toString(); const qint64 tokenExpires = Utils::parseDate(QStringLiteral("tokenExpires"), result); //qDebug() << " result tokenExpires " << tokenExpires; account->settings()->setExpireToken(tokenExpires); } void create_channel(const QJsonObject &root, RocketChatAccount *account) { const QJsonObject obj = root.value(QLatin1String("result")).toObject(); if (!obj.isEmpty()) { const QString rid = obj.value(QLatin1String("rid")).toString(); if (!rid.isEmpty()) { account->joinRoom(rid); } if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("create Channel :") + QJsonDocument(root).toJson()); } } } DDPClient::DDPClient(RocketChatAccount *account, QObject *parent) : QObject(parent) , m_uid(1) , m_loginStatus(NotConnected) , mRocketChatMessage(new RocketChatMessage) , mRocketChatAccount(account) { } DDPClient::~DDPClient() { mWebSocket->close(); //Don't delete socket when we use specific socket. if (!RuqolaTestWebSocket::_k_ruqola_webSocket) { delete mWebSocket; mWebSocket = nullptr; } delete mRocketChatMessage; mRocketChatMessage = nullptr; } void DDPClient::setServerUrl(const QString &url) { mUrl = url; } void DDPClient::initializeWebSocket() { mWebSocket->ignoreSslErrors(); connect(mWebSocket, &AbstractWebSocket::connected, this, &DDPClient::onWSConnected); connect(mWebSocket, &AbstractWebSocket::textMessageReceived, this, &DDPClient::onTextMessageReceived); connect(mWebSocket, &AbstractWebSocket::disconnected, this, &DDPClient::onWSclosed); connect(mWebSocket, &AbstractWebSocket::socketError, this, &DDPClient::socketError); connect(mWebSocket, &AbstractWebSocket::sslErrors, this, &DDPClient::onSslErrors); } void DDPClient::start() { if (!mWebSocket) { if (!RuqolaTestWebSocket::_k_ruqola_webSocket) { mWebSocket = new RuqolaWebSocket(mRocketChatAccount->ruqolaLogger(), this); } else { mWebSocket = RuqolaTestWebSocket::_k_ruqola_webSocket; } initializeWebSocket(); } connect(mRocketChatAccount, &RocketChatAccount::serverUrlChanged, this, &DDPClient::onServerURLChange); if (!mUrl.isEmpty()) { const QUrl serverUrl = adaptUrl(mUrl); if (!serverUrl.isValid()) { setLoginStatus(LoginFailed); } else { mWebSocket->openUrl(serverUrl); qCDebug(RUQOLA_DDPAPI_LOG) << "Trying to connect to URL" << serverUrl; } } else { qCDebug(RUQOLA_DDPAPI_LOG) << "url is empty"; } } void DDPClient::setLoginJobId(quint64 jobid) { m_loginJob = jobid; } QUrl DDPClient::adaptUrl(const QString &url) { return Utils::generateServerUrl(url); } void DDPClient::onServerURLChange() { if (mRocketChatAccount->settings()->serverUrl() != mUrl || !mWebSocket->isValid()) { if (mWebSocket->isValid()) { mWebSocket->flush(); mWebSocket->close(); } mUrl = mRocketChatAccount->settings()->serverUrl(); mWebSocket->openUrl(adaptUrl(mUrl)); connect(mWebSocket, &AbstractWebSocket::connected, this, &DDPClient::onWSConnected); qCDebug(RUQOLA_DDPAPI_LOG) << "Reconnecting" << mUrl; } } DDPClient::LoginStatus DDPClient::loginStatus() const { return m_loginStatus; } void DDPClient::setLoginStatus(DDPClient::LoginStatus l) { qCDebug(RUQOLA_DDPAPI_LOG) << "Setting login status to" << l; m_loginStatus = l; Q_EMIT loginStatusChanged(); // reset flags if (l == LoginFailed) { m_attemptedPasswordLogin = false; } } bool DDPClient::isConnected() const { return m_connected; } bool DDPClient::isLoggedIn() const { return m_loginStatus == LoggedIn; } QString DDPClient::cachePath() const { return QStandardPaths::writableLocation(QStandardPaths::CacheLocation); } QQueue > DDPClient::messageQueue() const { return m_messageQueue; } quint64 DDPClient::leaveRoom(const QString &roomID) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->leaveRoom(roomID, m_uid); return method(result, empty_callback, DDPClient::Persistent); } quint64 DDPClient::hideRoom(const QString &roomID) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->hideRoom(roomID, m_uid); return method(result, empty_callback, DDPClient::Persistent); } quint64 DDPClient::toggleFavorite(const QString &roomID, bool favorite) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->toggleFavorite(roomID, favorite, m_uid); return method(result, empty_callback, DDPClient::Persistent); } quint64 DDPClient::createChannel(const QString &name, const QStringList &userList, bool readOnly) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->createChannel(name, userList, readOnly, m_uid); return method(result, create_channel, DDPClient::Persistent); } quint64 DDPClient::setRoomName(const QString &roomId, const QString &name) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->setRoomName(roomId, name, m_uid); return method(result, change_room_settings, DDPClient::Persistent); } quint64 DDPClient::setRoomTopic(const QString &roomId, const QString &topic) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->setRoomTopic(roomId, topic, m_uid); return method(result, change_room_settings, DDPClient::Persistent); } quint64 DDPClient::setRoomType(const QString &roomId, bool privateChannel) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->setRoomType(roomId, privateChannel, m_uid); return method(result, change_room_settings, DDPClient::Persistent); } quint64 DDPClient::setRoomEncrypted(const QString &roomId, bool encrypted) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->setRoomEncrypted(roomId, encrypted, m_uid); return method(result, change_room_settings, DDPClient::Persistent); } quint64 DDPClient::setRoomDescription(const QString &roomId, const QString &description) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->setRoomDescription(roomId, description, m_uid); return method(result, change_room_settings, DDPClient::Persistent); } quint64 DDPClient::archiveRoom(const QString &roomId) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->archiveRoom(roomId, m_uid); return method(result, change_room_settings, DDPClient::Persistent); } quint64 DDPClient::setRoomIsReadOnly(const QString &roomId, bool readOnly) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->setRoomIsReadOnly(roomId, readOnly, m_uid); return method(result, change_room_settings, DDPClient::Persistent); } quint64 DDPClient::setRoomAnnouncement(const QString &roomId, const QString &announcement) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->setRoomAnnouncement(roomId, announcement, m_uid); return method(result, change_room_settings, DDPClient::Persistent); } quint64 DDPClient::disableNotifications(const QString &roomId, bool disabled) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->disableNotifications(roomId, disabled, m_uid); return method(result, change_notifications_settings, DDPClient::Persistent); } quint64 DDPClient::hideUnreadStatus(const QString &roomId, bool disabled) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->hideUnreadStatus(roomId, disabled, m_uid); return method(result, change_notifications_settings, DDPClient::Persistent); } quint64 DDPClient::audioNotifications(const QString &roomId, const QString &value) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->audioNotifications(roomId, value, m_uid); return method(result, change_notifications_settings, DDPClient::Persistent); } quint64 DDPClient::mobilePushNotifications(const QString &roomId, const QString &value) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->mobilePushNotifications(roomId, value, m_uid); return method(result, change_notifications_settings, DDPClient::Persistent); } quint64 DDPClient::desktopNotifications(const QString &roomId, const QString &value) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->desktopNotifications(roomId, value, m_uid); return method(result, change_notifications_settings, DDPClient::Persistent); } quint64 DDPClient::emailNotifications(const QString &roomId, const QString &value) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->emailNotifications(roomId, value, m_uid); return method(result, change_notifications_settings, DDPClient::Persistent); } quint64 DDPClient::unreadAlert(const QString &roomId, const QString &value) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->unreadAlert(roomId, value, m_uid); return method(result, change_notifications_settings, DDPClient::Persistent); } void DDPClient::subscribeRoomMessage(const QString &roomId) { QJsonArray params; params.append(QJsonValue(roomId)); subscribe(QStringLiteral("stream-room-messages"), params); const QJsonArray params2{ QJsonValue(QStringLiteral("%1/%2").arg(roomId).arg(QStringLiteral("deleteMessage"))), true }; subscribe(QStringLiteral("stream-notify-room"), params2); const QJsonArray params3{ QJsonValue(QStringLiteral("%1/%2").arg(roomId).arg(QStringLiteral("typing"))), true }; subscribe(QStringLiteral("stream-notify-room"), params3); } quint64 DDPClient::eraseRoom(const QString &roomID) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->eraseRoom(roomID, m_uid); return method(result, erase_room, DDPClient::Persistent); } quint64 DDPClient::openDirectChannel(const QString &userId) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->openDirectChannel(userId, m_uid); return method(result, open_direct_channel, DDPClient::Persistent); } quint64 DDPClient::setReaction(const QString &emoji, const QString &messageId) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->setReaction(emoji, messageId, m_uid); return method(result, empty_callback, DDPClient::Persistent); } quint64 DDPClient::createPrivateGroup(const QString &name, const QStringList &userList) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->createPrivateGroup(name, userList, m_uid); return method(result, empty_callback, DDPClient::Persistent); } quint64 DDPClient::deleteMessage(const QString &messageId) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->deleteMessage(messageId, m_uid); return method(result, delete_message, DDPClient::Persistent); } quint64 DDPClient::deleteFileMessage(const QString &roomId, const QString &fileid, const QString &channelType) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->deleteFileMessage(fileid, m_uid); std::function callback = [ roomId, channelType ](const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Delete Attachment File:") + QJsonDocument(root).toJson()); } else { qCDebug(RUQOLA_DDPAPI_LOG) << " parse users for room" << roomId; } account->roomFiles(roomId, channelType); }; return method(result, callback, DDPClient::Persistent); } quint64 DDPClient::joinRoom(const QString &roomId, const QString &joinCode) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->joinRoom(roomId, joinCode, m_uid); return method(result, join_room, DDPClient::Persistent); } quint64 DDPClient::setDefaultStatus(User::PresenceStatus status) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->setDefaultStatus(status, m_uid); return method(result, change_default_status, DDPClient::Persistent); } quint64 DDPClient::userAutocomplete(const QString &pattern, const QString &exception) { const quint64 subscribeId = m_uid; const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->userAutocomplete(pattern, exception, subscribeId); std::function callback = [=](const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("User AutoComplete:") + QJsonDocument(root).toJson()); } else { qCDebug(RUQOLA_DDPAPI_LOG) << " User AutoComplete" << root; } account->insertCompleterUsers(); const RocketChatMessage::RocketChatMessageResult resultUnsubscribe = mRocketChatMessage->unsubscribe(subscribeId); std::function callbackUnsubscribeAutoComplete = [=](const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()-> dataReceived(QByteArrayLiteral( "Unsubscribe AutoComplete:") + QJsonDocument(root).toJson()); } else { qDebug() << " Unsubscribe AutoComplete" << root; qCDebug(RUQOLA_DDPAPI_LOG) << " Unsubscribe AutoComplete" << root; } }; method(resultUnsubscribe, callbackUnsubscribeAutoComplete, DDPClient::Persistent); }; return method(result, callback, DDPClient::Persistent); } quint64 DDPClient::channelAndPrivateAutocomplete(const QString &pattern, const QString &exception) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->channelAndPrivateAutocomplete(pattern, exception, m_uid); return method(result, channel_and_private_autocomplete, DDPClient::Persistent); } quint64 DDPClient::getUsersOfRoom(const QString &roomId, bool showAll) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->getUsersOfRoom(roomId, showAll, m_uid); std::function callback = [ roomId ](const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Get Users of Room:") + QJsonDocument(root).toJson()); } else { qCDebug(RUQOLA_DDPAPI_LOG) << " parse users for room" << roomId; } - account->parseUsersForRooms(root, roomId); + RocketChatRestApi::ChannelBaseJob::ChannelInfo info; + info.channelInfoType = RocketChatRestApi::ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + + account->parseUsersForRooms(root, info); }; return method(result, callback, DDPClient::Persistent); } #if 0 quint64 DDPClient::roomFiles(const QString &roomId) { const quint64 subscribeId = m_uid; const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->roomFiles(roomId, subscribeId); std::function callback = [=](const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()->dataReceived(QByteArrayLiteral("Room File done:") + QJsonDocument(root).toJson()); } else { qDebug() << "Room Files " << root; qCDebug(RUQOLA_DDPAPI_LOG) << " Room Files" << root; } account->insertFilesList(roomId); const RocketChatMessage::RocketChatMessageResult resultUnsubscribe = mRocketChatMessage->unsubscribe(subscribeId); std::function callbackUnsubscribeAutoComplete = [=](const QJsonObject &root, RocketChatAccount *account) { if (account->ruqolaLogger()) { account->ruqolaLogger()-> dataReceived(QByteArrayLiteral( "Unsubscribe room files:") + QJsonDocument(root).toJson()); } else { qDebug() << " Unsubscribe room files" << root; qCDebug(RUQOLA_DDPAPI_LOG) << " Unsubscribe room files" << root; } }; method(resultUnsubscribe, callbackUnsubscribeAutoComplete, DDPClient::Persistent); }; return method(result, callback, DDPClient::Persistent); } #endif quint64 DDPClient::createJitsiConfCall(const QString &roomId) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->createJitsiConfCall(roomId, m_uid); return method(result, create_jitsi_conf_call, DDPClient::Persistent); } quint64 DDPClient::clearUnreadMessages(const QString &roomID) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->readMessages(roomID, m_uid); return method(result, empty_callback, DDPClient::Persistent); } quint64 DDPClient::inputChannelAutocomplete(const QString &pattern, const QString &exceptions) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->inputChannelAutocomplete(pattern, exceptions, m_uid); return method(result, input_user_channel_autocomplete, DDPClient::Persistent); } quint64 DDPClient::inputUserAutocomplete(const QString &pattern, const QString &exceptions) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->inputUserAutocomplete(pattern, exceptions, m_uid); return method(result, input_user_channel_autocomplete, DDPClient::Persistent); } quint64 DDPClient::loginProvider(const QString &credentialToken, const QString &credentialSecret) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->loginProvider(credentialToken, credentialSecret, m_uid); return method(result, empty_callback, DDPClient::Ephemeral); } quint64 DDPClient::login(const QString &username, const QString &password) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->login(username, password, mRocketChatAccount->settings()->twoFactorAuthenticationCode(), m_uid); return method(result, login_result, DDPClient::Ephemeral); } quint64 DDPClient::addUserToRoom(const QString &username, const QString &roomId) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->addUserToRoom(username, roomId, m_uid); return method(result, add_user_to_room, DDPClient::Persistent); } quint64 DDPClient::starMessage(const QString &messageId, const QString &rid, bool starred) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->starMessage(messageId, rid, starred, m_uid); return method(result, star_message, DDPClient::Persistent); } quint64 DDPClient::unBlockUser(const QString &rid, const QString &userId) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->unblockUser(rid, userId, m_uid); return method(result, unblock_user, DDPClient::Persistent); } quint64 DDPClient::blockUser(const QString &rid, const QString &userId) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->blockUser(rid, userId, m_uid); return method(result, block_user, DDPClient::Persistent); } quint64 DDPClient::informTypingStatus(const QString &roomId, bool typing, const QString &userName) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->informTypingStatus(roomId, userName, typing, m_uid); qint64 bytes = mWebSocket->sendTextMessage(result.result); if (bytes < result.result.length()) { qCDebug(RUQOLA_DDPAPI_LOG) << "ERROR! I couldn't send all of my message. This is a bug! (try again)"; qCDebug(RUQOLA_DDPAPI_LOG) << mWebSocket->isValid() << mWebSocket->error() << mWebSocket->requestUrl(); } else { qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << "Successfully sent " << result.result; } const quint64 value = m_uid; m_uid++; return value; } quint64 DDPClient::ignoreUser(const QString &roomId, const QString &userId, bool ignore) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->ignoreUser(roomId, userId, ignore, m_uid); return method(result, user_ignore, DDPClient::Persistent); } quint64 DDPClient::method(const RocketChatMessage::RocketChatMessageResult &result, std::function callback, DDPClient::MessageType messageType) { qint64 bytes = mWebSocket->sendTextMessage(result.result); if (bytes < result.result.length()) { qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << "ERROR! I couldn't send all of my message. This is a bug! (try again)"; qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << mWebSocket->isValid() << mWebSocket->error() << mWebSocket->requestUrl(); if (messageType == DDPClient::Persistent) { m_messageQueue.enqueue(qMakePair(result.method, result.jsonDocument)); mRocketChatAccount->messageQueue()->processQueue(); } } else { qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << "Successfully sent " << result.result; } m_callbackHash[m_uid] = callback; const quint64 value = m_uid; m_uid++; return value; } quint64 DDPClient::method(const QString &m, const QJsonDocument ¶ms, DDPClient::MessageType messageType) { return method(m, params, empty_callback, messageType); } quint64 DDPClient::method(const QString &method, const QJsonDocument ¶ms, std::function callback, DDPClient::MessageType messageType) { const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->generateMethod(method, params, m_uid); qint64 bytes = mWebSocket->sendTextMessage(result.result); if (bytes < result.result.length()) { qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << "ERROR! I couldn't send all of my message. This is a bug! (try again)"; qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << mWebSocket->isValid() << mWebSocket->error() << mWebSocket->requestUrl(); if (messageType == DDPClient::Persistent) { m_messageQueue.enqueue(qMakePair(result.method, result.jsonDocument)); mRocketChatAccount->messageQueue()->processQueue(); } } else { qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << "Successfully sent " << result.result; } m_callbackHash[m_uid] = callback; const quint64 uidCurrent = m_uid; m_uid++; return uidCurrent; } void DDPClient::subscribe(const QString &collection, const QJsonArray ¶ms) { QJsonObject json; json[QStringLiteral("msg")] = QStringLiteral("sub"); json[QStringLiteral("id")] = QString::number(m_uid); json[QStringLiteral("name")] = collection; QJsonArray newParams = params; if (mRocketChatAccount->needAdaptNewSubscriptionRC60()) { QJsonArray args; QJsonObject obj; obj[QStringLiteral("useCollection")] = false; obj[QStringLiteral("args")] = args; newParams.append(obj); } json[QStringLiteral("params")] = newParams; qint64 bytes = mWebSocket->sendTextMessage(QString::fromUtf8(QJsonDocument(json).toJson(QJsonDocument::Compact))); if (bytes < json.length()) { qCDebug(RUQOLA_DDPAPI_LOG) << "ERROR! I couldn't send all of my message. This is a bug! (try again)"; qCDebug(RUQOLA_DDPAPI_LOG) << mWebSocket->isValid() << mWebSocket->error() << mWebSocket->requestUrl(); } else { qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << "Successfully sent " << json; } m_uid++; } void DDPClient::onTextMessageReceived(const QString &message) { QJsonDocument response = QJsonDocument::fromJson(message.toUtf8()); if (!response.isNull() && response.isObject()) { QJsonObject root = response.object(); const QString messageType = root.value(QLatin1String("msg")).toString(); if (messageType == QLatin1String("updated")) { //nothing to do. qCDebug(RUQOLA_DDPAPI_LOG) << mRocketChatAccount->accountName() << " message updated ! not implemented yet" << response; } else if (messageType == QLatin1String("result")) { quint64 id = root.value(QLatin1String("id")).toString().toULongLong(); if (m_callbackHash.contains(id)) { std::function callback = m_callbackHash.take(id); callback(root, mRocketChatAccount); } Q_EMIT result(id, QJsonDocument(root.value(QLatin1String("result")).toObject())); if (id == m_loginJob) { const QJsonObject error(root.value(QLatin1String("error")).toObject()); const QJsonValue errorValue(error.value(QLatin1String("error"))); if (errorValue.toInt() == 403) { qCDebug(RUQOLA_DDPAPI_LOG) << mRocketChatAccount->accountName() << "Wrong password or token expired"; login(); // Let's keep trying to log in } else if (errorValue.toString() == QLatin1String("totp-required") || errorValue.toString() == QLatin1String("totp-invalid")) { qCDebug(RUQOLA_DDPAPI_LOG) << mRocketChatAccount->accountName() << "A 2FA code or backup code is required to login"; setLoginStatus(LoginCodeRequired); } else if (!error.isEmpty()) { qCDebug(RUQOLA_DDPAPI_LOG) << mRocketChatAccount->accountName() << error.value(QLatin1String("message")).toString(); setLoginStatus(LoginFailed); } else { const QString token = root.value(QLatin1String("result")).toObject().value(QLatin1String("token")).toString(); mRocketChatAccount->settings()->setAuthToken(token); mRocketChatAccount->restApi()->setAuthToken(token); mRocketChatAccount->restApi()->setUserId(root.value(QLatin1String("id")).toString()); setLoginStatus(DDPClient::LoggedIn); } } } else if (messageType == QLatin1String("connected")) { qCDebug(RUQOLA_DDPAPI_LOG) << mRocketChatAccount->accountName() << " Connected!"; m_connected = true; setLoginStatus(DDPClient::LoggingIn); Q_EMIT connectedChanged(); } else if (messageType == QLatin1String("error")) { qWarning() << mRocketChatAccount->accountName() << " ERROR!!" << message; } else if (messageType == QLatin1String("ping")) { qCDebug(RUQOLA_DDPAPI_LOG) << mRocketChatAccount->accountName() << "Ping - Pong"; pong(); } else if (messageType == QLatin1String("added")) { qCDebug(RUQOLA_DDPAPI_LOG) << mRocketChatAccount->accountName() << "ADDING element" <accountName() << "Changed element" <accountName() << "READY element" <accountName() << "REMOVED element" <accountName() << "Unsubscribe element" <accountName() << "Error unsubscribing from" << id; qWarning() << mRocketChatAccount->accountName() << "ERROR: " << errorObj[QStringLiteral("error")].toString(); qWarning() << mRocketChatAccount->accountName() << "Message: " << errorObj[QStringLiteral("message")].toString(); qWarning() << mRocketChatAccount->accountName() << "Reason: " << errorObj[QStringLiteral("reason")].toString(); qWarning() << mRocketChatAccount->accountName() << "-- Error found END --"; } } else { // The very first message we receive is {"server_id":"0"}, can't find it in the spec, just ignore it. if (messageType.isEmpty() && !root.value(QStringLiteral("server_id")).isUndefined()) { return; } qWarning() << mRocketChatAccount->accountName() << "received something unhandled:" << messageType << message; } } else { qWarning() << mRocketChatAccount->accountName() << "received something unhandled unknown " << message; } } quint64 DDPClient::loadHistory(const QJsonArray ¶ms) { return method(QStringLiteral("loadHistory"), QJsonDocument(params), process_backlog); } void DDPClient::login() { if (!mRocketChatAccount->settings()->authToken().isEmpty() && !mRocketChatAccount->settings()->tokenExpired()) { m_attemptedPasswordLogin = true; QJsonObject json; json[QStringLiteral("resume")] = mRocketChatAccount->settings()->authToken(); m_loginJob = method(QStringLiteral("login"), QJsonDocument(json)); } else if (!mRocketChatAccount->settings()->password().isEmpty()) { // If we have a password and we couldn't log in, let's stop here if (m_attemptedPasswordLogin) { setLoginStatus(LoginFailed); return; } m_attemptedPasswordLogin = true; //m_loginJob = login(mRocketChatAccount->settings()->userName(), mRocketChatAccount->settings()->password()); if (mRocketChatAccount->defaultAuthenticationInterface()) { mRocketChatAccount->defaultAuthenticationInterface()->login(); } else { qCWarning(RUQOLA_DDPAPI_LOG) <<"No plugins loaded. Please verify your installation."; setLoginStatus(FailedToLoginPluginProblem); } } else { setLoginStatus(LoginFailed); } } void DDPClient::onWSConnected() { qCDebug(RUQOLA_DDPAPI_LOG) << "Websocket connected at URL" << mUrl; QJsonArray supportedVersions; supportedVersions.append(QLatin1String("1")); QJsonObject protocol; protocol[QStringLiteral("msg")] = QStringLiteral("connect"); protocol[QStringLiteral("version")] = QStringLiteral("1"); protocol[QStringLiteral("support")] = supportedVersions; QByteArray serialize = QJsonDocument(protocol).toJson(QJsonDocument::Compact); qint64 bytes = mWebSocket->sendTextMessage(QString::fromUtf8(serialize)); if (bytes < serialize.length()) { qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << "onWSConnected: ERROR! I couldn't send all of my message. This is a bug! (try again)"; qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << mWebSocket->isValid() << mWebSocket->error() << mWebSocket->requestUrl(); } else { qCDebug(RUQOLA_DDPAPI_COMMAND_LOG) << "Successfully sent " << serialize; } } void DDPClient::onSslErrors(const QList &errors) { qCDebug(RUQOLA_DDPAPI_LOG) << "SSL error" << errors.count(); for (const QSslError &err : errors) { qCDebug(RUQOLA_DDPAPI_LOG) << "error ssl type:" << err.errorString(); } mWebSocket->ignoreSslErrors(); } void DDPClient::onWSclosed() { const bool normalClose = mWebSocket->closeCode() == QWebSocketProtocol::CloseCodeNormal; if (!normalClose) { qCWarning(RUQOLA_DDPAPI_LOG) << "WebSocket CLOSED" << mWebSocket->closeReason() << mWebSocket->error() << mWebSocket->closeCode(); } setLoginStatus(NotConnected); if (normalClose) { Q_EMIT disconnectedByServer(); } } void DDPClient::pong() { QJsonObject pong; pong[QStringLiteral("msg")] = QStringLiteral("pong"); mWebSocket->sendBinaryMessage(QJsonDocument(pong).toJson(QJsonDocument::Compact)); } void DDPClient::executeSubsCallBack(const QJsonObject &root) { const QJsonArray subs = root[QStringLiteral("subs")].toArray(); if (!subs.isEmpty()) { const quint64 id = subs.at(0).toString().toULongLong(); if (m_callbackHash.contains(id)) { std::function callback = m_callbackHash.take(id); callback(root, mRocketChatAccount); } } else { qCWarning(RUQOLA_DDPAPI_LOG) << "Problem with subs json " << root; } } diff --git a/src/core/rocketchataccount.cpp b/src/core/rocketchataccount.cpp index 057c9db6..212beea4 100644 --- a/src/core/rocketchataccount.cpp +++ b/src/core/rocketchataccount.cpp @@ -1,1954 +1,1956 @@ /* Copyright (c) 2017-2020 Laurent Montel 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 "fileattachments.h" #include "emoticons/emojimanager.h" #include "model/emoticonmodel.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 "model/discussionsmodel.h" #include "model/threadsmodel.h" #include "model/filesforroomfilterproxymodel.h" #include "model/discussionsfilterproxymodel.h" #include "model/threadsfilterproxymodel.h" #include "model/listmessagesmodel.h" #include "model/threadmessagemodel.h" #include "model/listmessagesmodelfilterproxymodel.h" #include "model/autotranslatelanguagesmodel.h" #include "managerdatapaths.h" #include "authenticationmanager.h" #include "ddpapi/ddpclient.h" #include "discussions.h" #include "receivetypingnotificationmanager.h" #include "restapirequest.h" #include "serverconfiginfo.h" #include "listmessages.h" #include "threads.h" #include #include #include #include #include #include "users/setstatusjob.h" #include "users/usersautocompletejob.h" #define USE_REASTAPI_JOB 1 RocketChatAccount::RocketChatAccount(const QString &accountFileName, QObject *parent) : QObject(parent) { mAccountRoomSettings = new AccountRoomSettings; qCDebug(RUQOLA_LOG) << " RocketChatAccount::RocketChatAccount(const QString &accountFileName, QObject *parent)"<accountName()); } mServerConfigInfo = new ServerConfigInfo(this, this); //Create it before loading settings mLoginMethodModel = new LoginMethodModel(this); mInputTextManager = new InputTextManager(this); connect(mInputTextManager, &InputTextManager::inputCompleter, this, &RocketChatAccount::inputAutocomplete); mInputThreadMessageTextManager = new InputTextManager(this); connect(mInputThreadMessageTextManager, &InputTextManager::inputCompleter, this, &RocketChatAccount::inputThreadMessageAutocomplete); mRuqolaServerConfig = new RuqolaServerConfig; mReceiveTypingNotificationManager = new ReceiveTypingNotificationManager(this); initializeAuthenticationPlugins(); mRocketChatBackend = new RocketChatBackend(this, this); mEmoticonModel = new EmoticonModel(this); //After loadSettings mEmojiManager = new EmojiManager(this); mEmojiManager->setServerUrl(mSettings->serverUrl()); mEmoticonModel->setEmoticons(mEmojiManager->unicodeEmojiList()); 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(QString(), this, nullptr, this); mSearchMessageFilterProxyModel = new SearchMessageFilterProxyModel(mSearchMessageModel, this); mFilesModelForRoom = new FilesForRoomModel(this, this); mFilesModelForRoom->setObjectName(QStringLiteral("filesmodelforrooms")); mFilesForRoomFilterProxyModel = new FilesForRoomFilterProxyModel(mFilesModelForRoom, this); mFilesForRoomFilterProxyModel->setObjectName(QStringLiteral("filesforroomfiltermodelproxy")); mDiscussionsModel = new DiscussionsModel(this); mDiscussionsModel->setObjectName(QStringLiteral("discussionsmodel")); mDiscussionsFilterProxyModel = new DiscussionsFilterProxyModel(mDiscussionsModel, this); mDiscussionsFilterProxyModel->setObjectName(QStringLiteral("discussionsfilterproxymodel")); mThreadsModel = new ThreadsModel(this); mThreadsModel->setObjectName(QStringLiteral("threadsmodel")); mThreadsFilterProxyModel = new ThreadsFilterProxyModel(mThreadsModel, this); mThreadsFilterProxyModel->setObjectName(QStringLiteral("threadsfiltermodelproxy")); mThreadMessageModel = new ThreadMessageModel(QString(), this, nullptr, this); mThreadMessageModel->setObjectName(QStringLiteral("threadmessagemodel")); mListMessageModel = new ListMessagesModel(QString(), this, nullptr, this); mListMessageModel->setObjectName(QStringLiteral("listmessagemodel")); mListMessagesFilterProxyModel = new ListMessagesModelFilterProxyModel(mListMessageModel, this); mListMessagesFilterProxyModel->setObjectName(QStringLiteral("listmessagesfiltermodelproxy")); mAutoTranslateLanguagesModel = new AutotranslateLanguagesModel(this); mAutoTranslateLanguagesModel->setObjectName(QStringLiteral("autotranslatelanguagesmodel")); 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; delete mAccountRoomSettings; } 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 { return mFilesForRoomFilterProxyModel; } 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); } DiscussionsFilterProxyModel *RocketChatAccount::discussionsFilterProxyModel() const { return mDiscussionsFilterProxyModel; } ThreadsFilterProxyModel *RocketChatAccount::threadsFilterProxyModel() const { return mThreadsFilterProxyModel; } RoomWrapper *RocketChatAccount::roomWrapper(const QString &roomId) { return mRoomModel->findRoomWrapper(roomId); } MessageModel *RocketChatAccount::messageModelForRoom(const QString &roomID) { return mRoomModel->messageModel(roomID); } void RocketChatAccount::changeDisplayAttachment(const QString &roomId, const QString &messageId, bool displayAttachment) { MessageModel *model = mRoomModel->messageModel(roomId); if (model) { model->changeDisplayAttachment(messageId, displayAttachment); } else { qCWarning(RUQOLA_LOG) << "impossible to find room: " << roomId; } //TODO } void RocketChatAccount::changeShowOriginalMessage(const QString &roomId, const QString &messageId, bool showOriginal) { MessageModel *model = mRoomModel->messageModel(roomId); if (model) { model->changeShowOriginalMessage(messageId, showOriginal); } else { qCWarning(RUQOLA_LOG) << "impossible to find room: " << roomId; } //TODO } 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::textEditing(const QString &roomId, bool clearNotification) { mTypingNotification->textNotificationChanged(roomId, clearNotification); } void RocketChatAccount::reactOnMessage(const QString &messageId, const QString &emoji, bool shouldReact) { restApi()->reactOnMessage(messageId, emoji, shouldReact); } void RocketChatAccount::replyToMessage(const QString &roomID, const QString &message, const QString &messageId) { restApi()->postMessage(roomID, message); } void RocketChatAccount::sendMessage(const QString &roomID, const QString &message) { restApi()->postMessage(roomID, message); } void RocketChatAccount::updateMessage(const QString &roomID, const QString &messageId, const QString &message) { restApi()->updateMessage(roomID, messageId, message); } void RocketChatAccount::replyOnThread(const QString &roomID, const QString &threadMessageId, const QString &message) { restApi()->sendMessage(roomID, message, QString(), threadMessageId); } 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 QUrl &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::loadEmojiCustomDone, this, &RocketChatAccount::loadEmoji); connect(mRestApi, &RocketChatRestApi::RestApiRequest::openArchivedRoom, this, &RocketChatAccount::openArchivedRoom); connect(mRestApi, &RocketChatRestApi::RestApiRequest::channelMembersDone, this, &RocketChatAccount::parseUsersForRooms); connect(mRestApi, &RocketChatRestApi::RestApiRequest::channelFilesDone, this, &RocketChatAccount::slotChannelFilesDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::channelRolesDone, this, &RocketChatAccount::slotChannelRolesDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::searchMessageDone, this, &RocketChatAccount::slotSearchMessages); connect(mRestApi, &RocketChatRestApi::RestApiRequest::failed, this, &RocketChatAccount::jobFailed); connect(mRestApi, &RocketChatRestApi::RestApiRequest::spotlightDone, this, &RocketChatAccount::slotSplotLightDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::getThreadMessagesDone, this, &RocketChatAccount::slotGetThreadMessagesDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::getThreadsDone, this, &RocketChatAccount::slotGetThreadsListDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::getDiscussionsDone, this, &RocketChatAccount::slotGetDiscussionsListDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::channelGetAllUserMentionsDone, this, [this](const QJsonObject &obj, const QString &roomId) { slotGetListMessagesDone(obj, roomId, ListMessagesModel::ListMessageType::MentionsMessages); }); connect(mRestApi, &RocketChatRestApi::RestApiRequest::getPinnedMessagesDone, this, [this](const QJsonObject &obj, const QString &roomId) { slotGetListMessagesDone(obj, roomId, ListMessagesModel::ListMessageType::PinnedMessages); }); connect(mRestApi, &RocketChatRestApi::RestApiRequest::getSnippetedMessagesDone, this, [this](const QJsonObject &obj, const QString &roomId) { slotGetListMessagesDone(obj, roomId, ListMessagesModel::ListMessageType::SnipperedMessages); }); connect(mRestApi, &RocketChatRestApi::RestApiRequest::getStarredMessagesDone, this, [this](const QJsonObject &obj, const QString &roomId) { slotGetListMessagesDone(obj, roomId, ListMessagesModel::ListMessageType::StarredMessages); }); connect(mRestApi, &RocketChatRestApi::RestApiRequest::getSupportedLanguagesDone, this, &RocketChatAccount::slotGetSupportedLanguagesDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::usersPresenceDone, this, &RocketChatAccount::slotUsersPresenceDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::usersAutocompleteDone, this, &RocketChatAccount::slotUserAutoCompleterDone); connect(mRestApi, &RocketChatRestApi::RestApiRequest::roomsAutoCompleteChannelAndPrivateDone, this, &RocketChatAccount::slotRoomsAutoCompleteChannelAndPrivateDone); mRestApi->setServerUrl(mSettings->serverUrl()); mRestApi->setRestApiLogger(mRuqolaLogger); } return mRestApi; } void RocketChatAccount::leaveRoom(const QString &roomId, const QString &channelType) { if (channelType == QLatin1Char('c')) { restApi()->leaveChannel(roomId); } else if (channelType == QLatin1Char('p')) { restApi()->leaveGroups(roomId); } else { qCWarning(RUQOLA_LOG) << " unsupport leave room for type " << channelType; } } void RocketChatAccount::hideRoom(const QString &roomId, const QString &channelType) { restApi()->closeChannel(roomId, channelType); } 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); connect(mDdp, &DDPClient::socketError, this, &RocketChatAccount::socketError); connect(mDdp, &DDPClient::disconnectedByServer, this, &RocketChatAccount::slotDisconnectedByServer); 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::clearAllUnreadMessages() { for (int roomIdx = 0, nRooms = mRoomModel->rowCount(); roomIdx < nRooms; ++roomIdx) { const auto roomModelIndex = mRoomModel->index(roomIdx); const auto roomId = roomModelIndex.data(RoomModel::RoomID).toString(); const bool roomHasAlert = roomModelIndex.data(RoomModel::RoomAlert).toBool(); if (roomHasAlert) { clearUnreadMessages(roomId); } } } void RocketChatAccount::clearUnreadMessages(const QString &roomId) { restApi()->markAsRead(roomId); } void RocketChatAccount::changeFavorite(const QString &roomId, bool checked) { restApi()->markAsFavorite(roomId, checked); } void RocketChatAccount::openChannel(const QString &url) { qCDebug(RUQOLA_LOG) << "opening channel" << url; restApi()->channelJoin(url, QString()); //TODO search correct room + select it. } -void RocketChatAccount::setChannelJoinDone(const QString &roomId) +void RocketChatAccount::setChannelJoinDone(const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo) { - ddp()->subscribeRoomMessage(roomId); + //FIXME type of identifier + ddp()->subscribeRoomMessage(channelInfo.channelInfoIdentifier); } -void RocketChatAccount::openArchivedRoom(const QString &roomId) +void RocketChatAccount::openArchivedRoom(const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo) { //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 = QStringLiteral("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) { if (channelType == QLatin1Char('c')) { restApi()->channelDelete(roomId); } else if (channelType == QLatin1Char('p')) { restApi()->groupDelete(roomId); } else { qCWarning(RUQOLA_LOG) << " unsupport delete for type " << channelType; } } void RocketChatAccount::openDirectChannel(const QString &username) { //Laurent for the moment I didn't find a restapi method for it //TODO verify username vs userId //#ifdef USE_REASTAPI_JOB // restApi()->openDirectMessage(username); //#else qDebug() << "Open direct conversation channel with" << username; ddp()->openDirectChannel(username); //#endif } void RocketChatAccount::createNewChannel(const QString &name, bool readOnly, bool privateRoom, const QString &userNames, bool encryptedRoom, const QString &password, bool broadcast) { //TODO use encrypted room //TODO use broadcast if (!name.trimmed().isEmpty()) { const QStringList lstUsers = userNames.split(QLatin1Char(','), QString::SkipEmptyParts); if (privateRoom) { //TODO add password ??? restApi()->createGroups(name, readOnly, lstUsers); } else { restApi()->createChannels(name, readOnly, lstUsers, password); } } else { qCDebug(RUQOLA_LOG) << "Channel name can't be empty"; } } void RocketChatAccount::joinRoom(const QString &roomId, const QString &joinCode) { restApi()->channelJoin(roomId, joinCode); } void RocketChatAccount::channelAndPrivateAutocomplete(const QString &pattern) { - //TODO use restapi if (pattern.isEmpty()) { searchChannelModel()->clear(); } else { //Use restapi //Avoid to show own user #ifdef USE_REASTAPI_JOB restApi()->searchRoomUser(pattern); #else const QString addUserNameToException = userName(); ddp()->channelAndPrivateAutocomplete(pattern, addUserNameToException); #endif } } void RocketChatAccount::listEmojiCustom() { restApi()->listEmojiCustom(); } void RocketChatAccount::setDefaultStatus(User::PresenceStatus status, const QString &messageStatus) { #ifdef USE_REASTAPI_JOB RocketChatRestApi::SetStatusJob::StatusType type = RocketChatRestApi::SetStatusJob::Unknown; switch (status) { case User::PresenceStatus::PresenceOnline: type = RocketChatRestApi::SetStatusJob::OnLine; break; case User::PresenceStatus::PresenceBusy: type = RocketChatRestApi::SetStatusJob::Busy; break; case User::PresenceStatus::PresenceAway: type = RocketChatRestApi::SetStatusJob::Away; break; case User::PresenceStatus::PresenceOffline: type = RocketChatRestApi::SetStatusJob::Offline; break; case User::PresenceStatus::Unknown: type = RocketChatRestApi::SetStatusJob::Unknown; break; } restApi()->setUserStatus(userID(), type, messageStatus); #else Q_UNUSED(messageStatus); ddp()->setDefaultStatus(status); #endif } void RocketChatAccount::changeDefaultStatus(int index, const QString &messageStatus) { setDefaultStatus(mStatusModel->status(index), messageStatus); } void RocketChatAccount::loadEmoji(const QJsonObject &obj) { mEmojiManager->loadCustomEmoji(obj); } void RocketChatAccount::deleteMessage(const QString &messageId, const QString &roomId) { restApi()->deleteMessage(roomId, messageId); } void RocketChatAccount::insertCompleterUsers() { userCompleterModel()->insertUsers(rocketChatBackend()->users()); } void RocketChatAccount::userAutocomplete(const QString &searchText, const QString &exception) { userCompleterModel()->clear(); if (mRuqolaServerConfig->hasAtLeastVersion(2, 4, 0)) { if (!searchText.isEmpty()) { RocketChatRestApi::UsersAutocompleteJob::UsersAutocompleterInfo info; info.pattern = searchText; info.exception = exception; restApi()->usersAutocomplete(info); } } else { //Clear before to create new search rocketChatBackend()->clearUsersList(); if (!searchText.isEmpty()) { //Avoid to show own user QString addUserNameToException; if (exception.isEmpty()) { addUserNameToException = userName(); } else { addUserNameToException = exception + QLatin1Char(',') + userName(); } ddp()->userAutocomplete(searchText, addUserNameToException); } } } void RocketChatAccount::membersInRoom(const QString &roomId, const QString &roomType) { restApi()->membersInRoom(roomId, roomType); } -void RocketChatAccount::parseUsersForRooms(const QJsonObject &obj, const QString &roomId) +void RocketChatAccount::parseUsersForRooms(const QJsonObject &obj, const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo) { - UsersForRoomModel *usersModelForRoom = roomModel()->usersModelForRoom(roomId); + //FIXME channelInfo + UsersForRoomModel *usersModelForRoom = roomModel()->usersModelForRoom(channelInfo.channelInfoIdentifier); if (usersModelForRoom) { usersModelForRoom->parseUsersForRooms(obj, mUserModel, true); } else { - qCWarning(RUQOLA_LOG) << " Impossible to find room " << roomId; + qCWarning(RUQOLA_LOG) << " Impossible to find room " << channelInfo.channelInfoIdentifier; } } void RocketChatAccount::loadAutoCompleteChannel(const QJsonObject &obj) { mSearchChannelModel->parseChannels(obj); } void RocketChatAccount::roomFiles(const QString &roomId, const QString &channelType) { mFilesModelForRoom->initialize(); restApi()->filesInRoom(roomId, channelType); } MessageModel *RocketChatAccount::threadMessageModel() const { return mThreadMessageModel; } ThreadsModel *RocketChatAccount::threadsModel() const { return mThreadsModel; } DiscussionsModel *RocketChatAccount::discussionsModel() const { return mDiscussionsModel; } FilesForRoomModel *RocketChatAccount::filesModelForRoom() const { return mFilesModelForRoom; } EmoticonModel *RocketChatAccount::emoticonModel() const { return mEmoticonModel; } ReceiveTypingNotificationManager *RocketChatAccount::receiveTypingNotificationManager() const { return mReceiveTypingNotificationManager; } -void RocketChatAccount::slotChannelRolesDone(const QJsonObject &obj, const QString &roomId) +void RocketChatAccount::slotChannelRolesDone(const QJsonObject &obj, const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo) { - Room *room = mRoomModel->findRoom(roomId); + Room *room = mRoomModel->findRoom(channelInfo.channelInfoIdentifier); if (room) { Roles r; r.parseRole(obj); room->setRolesForRooms(r); } else { - qCWarning(RUQOLA_LOG) << " Impossible to find room " << roomId; + qCWarning(RUQOLA_LOG) << " Impossible to find room " << channelInfo.channelInfoIdentifier; } } void RocketChatAccount::slotGetThreadMessagesDone(const QJsonObject &obj, const QString &threadMessageId) { if (mThreadMessageModel->threadMessageId() != threadMessageId) { mThreadMessageModel->setThreadMessageId(threadMessageId); mThreadMessageModel->parseThreadMessages(obj); } else { mThreadMessageModel->loadMoreThreadMessages(obj); } } void RocketChatAccount::slotGetDiscussionsListDone(const QJsonObject &obj, const QString &roomId) { if (mDiscussionsModel->roomId() != roomId) { mDiscussionsModel->parseDiscussions(obj, roomId); } else { mDiscussionsModel->addMoreDiscussions(obj); } mDiscussionsModel->setLoadMoreDiscussionsInProgress(false); } void RocketChatAccount::slotGetListMessagesDone(const QJsonObject &obj, const QString &roomId, ListMessagesModel::ListMessageType type) { if (mListMessageModel->roomId() != roomId || mListMessageModel->listMessageType() != type) { mListMessageModel->setRoomId(roomId); mListMessageModel->setListMessageType(type); mListMessageModel->parseListMessages(obj); } else { mListMessageModel->loadMoreListMessages(obj); } mListMessageModel->setLoadMoreListMessagesInProgress(false); } void RocketChatAccount::slotUserAutoCompleterDone(const QJsonObject &obj) { const QVector users = User::parseUsersList(obj); mUserCompleterModel->insertUsers(users); } void RocketChatAccount::slotRoomsAutoCompleteChannelAndPrivateDone(const QJsonObject &obj) { //TODO } AccountRoomSettings *RocketChatAccount::accountRoomSettings() const { return mAccountRoomSettings; } ListMessagesModelFilterProxyModel *RocketChatAccount::listMessagesFilterProxyModel() const { return mListMessagesFilterProxyModel; } ListMessagesModel *RocketChatAccount::listMessageModel() const { return mListMessageModel; } void RocketChatAccount::slotGetThreadsListDone(const QJsonObject &obj, const QString &roomId) { if (mThreadsModel->roomId() != roomId) { mThreadsModel->parseThreads(obj, roomId); } else { mThreadsModel->addMoreThreads(obj); } mThreadsModel->setLoadMoreThreadsInProgress(false); } void RocketChatAccount::slotSplotLightDone(const QJsonObject &obj) { //qDebug() << " void RocketChatAccount::slotSplotLightDone(const QJsonObject &obj)"<roomId() != roomId) { - mFilesModelForRoom->parseFileAttachments(obj, roomId); + if (mFilesModelForRoom->roomId() != channelInfo.channelInfoIdentifier) { + mFilesModelForRoom->parseFileAttachments(obj, channelInfo.channelInfoIdentifier); } else { mFilesModelForRoom->addMoreFileAttachments(obj); } mFilesModelForRoom->setLoadMoreFilesInProgress(false); } void RocketChatAccount::loadMoreUsersInRoom(const QString &roomId, const QString &channelType) { UsersForRoomModel *usersModelForRoom = roomModel()->usersModelForRoom(roomId); const int offset = usersModelForRoom->usersCount(); if (offset < usersModelForRoom->total()) { restApi()->membersInRoom(roomId, channelType, offset, qMin(50, usersModelForRoom->total() - offset)); } } void RocketChatAccount::getMentionsMessages(const QString &roomId) { mListMessageModel->clear(); mListMessageModel->setRoomId(roomId); restApi()->channelGetAllUserMentions(roomId); } void RocketChatAccount::getPinnedMessages(const QString &roomId) { if (hasPinnedMessagesSupport()) { mListMessageModel->clear(); mListMessageModel->setRoomId(roomId); restApi()->getPinnedMessages(roomId); } else { qCWarning(RUQOLA_LOG) << " RocketChatAccount::getPinnedMessages is not supported before server 2.0.0"; } } bool RocketChatAccount::hasPinnedMessagesSupport() const { return mRuqolaServerConfig->hasAtLeastVersion(1, 4, 0); } bool RocketChatAccount::hasStarredMessagesSupport() const { return mRuqolaServerConfig->hasAtLeastVersion(2, 3, 0); } void RocketChatAccount::getStarredMessages(const QString &roomId) { if (hasStarredMessagesSupport()) { mListMessageModel->clear(); mListMessageModel->setRoomId(roomId); restApi()->getStarredMessages(roomId); } else { qCWarning(RUQOLA_LOG) << " RocketChatAccount::getStarredMessages is not supported before server 2.3.0"; } } bool RocketChatAccount::hasSnippetedMessagesSupport() const { return mRuqolaServerConfig->hasAtLeastVersion(2, 3, 0); } void RocketChatAccount::getSnippetedMessages(const QString &roomId) { if (hasSnippetedMessagesSupport()) { mListMessageModel->clear(); mListMessageModel->setRoomId(roomId); restApi()->getSnippetedMessages(roomId); } else { qCWarning(RUQOLA_LOG) << " RocketChatAccount::getSnippetedMessages is not supported before server 2.3.0"; } } void RocketChatAccount::loadMoreFileAttachments(const QString &roomId, const QString &channelType) { if (!mFilesModelForRoom->loadMoreFilesInProgress()) { const int offset = mFilesModelForRoom->fileAttachments()->filesCount(); if (offset < mFilesModelForRoom->fileAttachments()->total()) { mFilesModelForRoom->setLoadMoreFilesInProgress(true); restApi()->filesInRoom(roomId, channelType, offset, qMin(50, mFilesModelForRoom->fileAttachments()->total() - offset)); } } } void RocketChatAccount::loadMoreDiscussions(const QString &roomId) { if (!mDiscussionsModel->loadMoreDiscussionsInProgress()) { const int offset = mDiscussionsModel->discussions()->discussionsCount(); if (offset < mDiscussionsModel->discussions()->total()) { mDiscussionsModel->setLoadMoreDiscussionsInProgress(true); restApi()->getDiscussions(roomId, offset, qMin(50, mDiscussionsModel->discussions()->total() - offset)); } } } void RocketChatAccount::updateThreadMessageList(const Message &m) { if (mThreadMessageModel->threadMessageId() == m.threadMessageId()) { mThreadMessageModel->addMessage(m); } } void RocketChatAccount::loadMoreThreads(const QString &roomId) { if (!mThreadsModel->loadMoreThreadsInProgress()) { const int offset = mThreadsModel->threads()->threadsCount(); if (offset < mThreadsModel->threads()->total()) { restApi()->getThreadsList(roomId, offset, qMin(50, mThreadsModel->threads()->total() - offset)); } } } void RocketChatAccount::getListMessages(const QString &roomId, ListMessagesModel::ListMessageType type) { mListMessageModel->setListMessageType(type); switch (type) { case ListMessagesModel::Unknown: qCWarning(RUQOLA_LOG) << " Error when using getListMessages"; break; case ListMessagesModel::StarredMessages: if (hasStarredMessagesSupport()) { getStarredMessages(roomId); } break; case ListMessagesModel::SnipperedMessages: if (hasSnippetedMessagesSupport()) { getSnippetedMessages(roomId); } break; case ListMessagesModel::PinnedMessages: getPinnedMessages(roomId); break; case ListMessagesModel::MentionsMessages: getMentionsMessages(roomId); break; } } QUrl RocketChatAccount::urlForLink(const QString &link) const { return mCache->urlForLink(link); } void RocketChatAccount::loadMoreListMessages(const QString &roomId) { if (!mListMessageModel->loadMoreListMessagesInProgress()) { const int offset = mListMessageModel->rowCount(); if (offset < mListMessageModel->total()) { switch (mListMessageModel->listMessageType()) { case ListMessagesModel::Unknown: qCWarning(RUQOLA_LOG) << " Error when using loadMoreListMessages"; break; case ListMessagesModel::StarredMessages: if (hasStarredMessagesSupport()) { restApi()->getStarredMessages(roomId, offset, qMin(50, mListMessageModel->total() - offset)); } break; case ListMessagesModel::SnipperedMessages: if (hasSnippetedMessagesSupport()) { restApi()->getSnippetedMessages(roomId, offset, qMin(50, mListMessageModel->total() - offset)); } break; case ListMessagesModel::PinnedMessages: restApi()->getPinnedMessages(roomId, offset, qMin(50, mListMessageModel->total() - offset)); break; case ListMessagesModel::MentionsMessages: restApi()->channelGetAllUserMentions(roomId, offset, qMin(50, mListMessageModel->total() - offset)); break; } } } } void RocketChatAccount::loadThreadMessagesHistory(const QString &threadMessageId) { restApi()->getThreadMessages(threadMessageId); } void RocketChatAccount::createJitsiConfCall(const QString &roomId) { //TODO use restapi ddp()->createJitsiConfCall(roomId); joinJitsiConfCall(roomId); } void RocketChatAccount::addUserToRoom(const QString &userId, const QString &roomId, const QString &channelType) { if (channelType == QLatin1Char('c')) { restApi()->addUserInChannel(roomId, userId); } else if (channelType == QLatin1Char('p')) { restApi()->addUserInGroup(roomId, userId); } } void RocketChatAccount::clearSearchModel() { mSearchMessageModel->clear(); } void RocketChatAccount::messageSearch(const QString &pattern, const QString &rid) { if (pattern.isEmpty()) { clearSearchModel(); } else { restApi()->searchMessages(rid, pattern); } } void RocketChatAccount::slotSearchMessages(const QJsonObject &obj) { mSearchMessageModel->parse(obj); } void RocketChatAccount::starMessage(const QString &messageId, bool starred) { restApi()->starMessage(messageId, starred); } void RocketChatAccount::pinMessage(const QString &messageId, bool pinned) { restApi()->pinMessage(messageId, pinned); } 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 == QLatin1Char('c')) { restApi()->changeChannelAnnouncement(roomId, newValue.toString()); } else if (channelType == QLatin1Char('p')) { restApi()->changeGroupsAnnouncement(roomId, newValue.toString()); } else { qCWarning(RUQOLA_LOG) << " unsupport change announcement for type " << channelType; } break; case Description: if (channelType == QLatin1Char('c')) { restApi()->changeChannelDescription(roomId, newValue.toString()); } else if (channelType == QLatin1Char('p')) { restApi()->changeGroupsDescription(roomId, newValue.toString()); } else { qCWarning(RUQOLA_LOG) << " unsupport change description for type " << channelType; } break; case Name: if (channelType == QLatin1Char('c')) { restApi()->changeChannelName(roomId, newValue.toString()); } else if (channelType == QLatin1Char('p')) { restApi()->changeGroupName(roomId, newValue.toString()); } else { qCWarning(RUQOLA_LOG) << " unsupport change name for type " << channelType; } break; case Topic: if (channelType == QLatin1Char('c')) { restApi()->changeChannelTopic(roomId, newValue.toString()); } else if (channelType == QLatin1Char('p')) { restApi()->changeGroupsTopic(roomId, newValue.toString()); } else { //TODO : change topic in direct channel qCWarning(RUQOLA_LOG) << " unsupport change topic for type " << channelType; } break; case ReadOnly: if (channelType == QLatin1Char('c')) { restApi()->changeChannelReadOnly(roomId, newValue.toBool()); } else if (channelType == QLatin1Char('p')) { restApi()->changeGroupsReadOnly(roomId, newValue.toBool()); } else { qCWarning(RUQOLA_LOG) << " unsupport change readonly for type " << channelType; } break; case Archive: if (channelType == QLatin1Char('c')) { restApi()->archiveChannel(roomId, newValue.toBool()); } else if (channelType == QLatin1Char('p')) { restApi()->archiveGroups(roomId, newValue.toBool()); } else { qCWarning(RUQOLA_LOG) << " unsupport archiving for type " << channelType; } break; case RoomType: if (channelType == QLatin1Char('c')) { restApi()->setChannelType(roomId, newValue.toBool()); } else if (channelType == QLatin1Char('p')) { restApi()->setGroupType(roomId, newValue.toBool()); } else { qCWarning(RUQOLA_LOG) << " unsupport roomtype for type " << channelType; } break; case Encrypted: if (channelType == QLatin1Char('c')) { restApi()->changeChannelEncrypted(roomId, newValue.toBool()); } else if (channelType == QLatin1Char('p')) { restApi()->changeGroupsEncrypted(roomId, newValue.toBool()); } else { qCWarning(RUQOLA_LOG) << " unsupport encrypted mode for type " << channelType; } break; case Password: //FIXME channel type ??? //restApi()->setJoinCodeChannel(roomId, newValue.toString()); break; } } void RocketChatAccount::reportMessage(const QString &messageId, const QString &message) { restApi()->reportMessage(messageId, message); } void RocketChatAccount::getThreadMessages(const QString &threadMessageId) { mThreadMessageModel->clear(); restApi()->getThreadMessages(threadMessageId); } 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; case DesktopDurationNotifications: restApi()->desktopDurationNotifications(roomId, newValue.toInt()); break; case DesktopSoundNotifications: restApi()->desktopSoundNotifications(roomId, newValue.toString()); 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_Enabled")) { mRuqolaServerConfig->setJitsiEnabled(value.toBool()); } 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 if (id == QLatin1String("Message_AllowPinning")) { mRuqolaServerConfig->setAllowMessagePinningEnabled(value.toBool()); } else if (id == QLatin1String("Message_AllowSnippeting")) { mRuqolaServerConfig->setAllowMessageSnippetingEnabled(value.toBool()); } else if (id == QLatin1String("Message_AllowStarring")) { mRuqolaServerConfig->setAllowMessageStarringEnabled(value.toBool()); } else if (id == QLatin1String("Message_AllowDeleting")) { mRuqolaServerConfig->setAllowMessageDeletingEnabled(value.toBool()); } else if (id == QLatin1String("Threads_enabled")) { mRuqolaServerConfig->setThreadsEnabled(value.toBool()); } else if (id == QLatin1String("Discussion_enabled")) { mRuqolaServerConfig->setDiscussionEnabled(value.toBool()); } else if (id == QLatin1String("AutoTranslate_Enabled")) { mRuqolaServerConfig->setAutoTranslateEnabled(value.toBool()); } else if (id == QLatin1String("AutoTranslate_GoogleAPIKey")) { mRuqolaServerConfig->setAutoTranslateGoogleKey(value.toString()); } else { qCDebug(RUQOLA_LOG) << "Other public settings id " << id << value; } //TODO add Accounts_AllowUserStatusMessageChange when we will have a RestAPI method for it. } fillOauthModel(); Q_EMIT publicSettingChanged(); } 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(); if (lstPlugins.isEmpty()) { qCWarning(RUQOLA_LOG) <<" No plugins loaded. Please verify your installation."; } 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; } 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(); } QString RocketChatAccount::twoFactorAuthenticationCode() const { return settings()->twoFactorAuthenticationCode(); } void RocketChatAccount::setAuthToken(const QString &token) { settings()->setAuthToken(token); } void RocketChatAccount::setPassword(const QString &password) { settings()->setPassword(password); } void RocketChatAccount::setTwoFactorAuthenticationCode(const QString &twoFactorAuthenticationCode) { settings()->setTwoFactorAuthenticationCode(twoFactorAuthenticationCode); } void RocketChatAccount::setAccountEnabled(bool enabled) { settings()->setAccountEnabled(enabled); } void RocketChatAccount::setUserName(const QString &username) { settings()->setUserName(username); } bool RocketChatAccount::accountEnabled() const { return settings()->accountEnabled(); } 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); Q_EMIT serverVersionChanged(); } bool RocketChatAccount::needAdaptNewSubscriptionRC60() const { return mRuqolaServerConfig->needAdaptNewSubscriptionRC60(); } bool RocketChatAccount::otrEnabled() const { return mRuqolaServerConfig->otrEnabled(); } bool RocketChatAccount::encryptedEnabled() const { return mRuqolaServerConfig->encryptionEnabled(); } bool RocketChatAccount::allowMessagePinningEnabled() const { return mRuqolaServerConfig->allowMessagePinningEnabled(); } bool RocketChatAccount::allowMessageSnippetingEnabled() const { return mRuqolaServerConfig->allowMessageSnippetingEnabled(); } bool RocketChatAccount::allowMessageStarringEnabled() const { return mRuqolaServerConfig->allowMessageStarringEnabled(); } bool RocketChatAccount::allowMessageDeletingEnabled() const { return mRuqolaServerConfig->allowMessageDeletingEnabled(); } bool RocketChatAccount::threadsEnabled() const { return mRuqolaServerConfig->threadsEnabled(); } bool RocketChatAccount::autoTranslateEnabled() const { return mRuqolaServerConfig->autoTranslateEnabled(); } bool RocketChatAccount::discussionEnabled() const { return mRuqolaServerConfig->discussionEnabled(); } QString RocketChatAccount::serverVersionStr() const { return mRuqolaServerConfig->serverVersionStr(); } ServerConfigInfo *RocketChatAccount::serverConfigInfo() const { return mServerConfigInfo; } bool RocketChatAccount::jitsiEnabled() const { return mRuqolaServerConfig->jitsiEnabled(); } void RocketChatAccount::groupInfo(const QString &roomId) { restApi()->groupInfo(roomId); } void RocketChatAccount::switchEditingMode(bool b) { if (mEditingMode != b) { mEditingMode = b; Q_EMIT editingModeChanged(); } } void RocketChatAccount::setSortUnreadOnTop(bool b) { if (settings()->setShowUnreadOnTop(b)) { mRoomFilterProxyModel->invalidate(); Q_EMIT sortUnreadOnTopChanged(); } } bool RocketChatAccount::sortUnreadOnTop() const { return settings()->showUnreadOnTop(); } void RocketChatAccount::kickUser(const QString &roomId, const QString &userId, const QString &channelType) { if (channelType == QLatin1Char('c')) { restApi()->channelKick(roomId, userId); } else if (channelType == QLatin1Char('p')) { restApi()->groupKick(roomId, userId); } else { qCWarning(RUQOLA_LOG) << " unsupport kickUser room for type " << channelType; } } void RocketChatAccount::rolesInRoom(const QString &roomId, const QString &channelType) { if (channelType == QLatin1Char('c')) { restApi()->getChannelRoles(roomId); } else if (channelType == QLatin1Char('p')) { restApi()->getGroupRoles(roomId); } else if (channelType == QLatin1Char('d')) { //No a problem here. } else { qCWarning(RUQOLA_LOG) << " unsupport get roles room for type " << channelType; } } void RocketChatAccount::switchingToRoom(const QString &roomID) { clearTypingNotification(); checkInitializedRoom(roomID); } void RocketChatAccount::changeRoles(const QString &roomId, const QString &userId, const QString &channelType, RocketChatAccount::RoleType roleType) { if (channelType == QLatin1Char('c')) { switch (roleType) { case RocketChatAccount::AddOwner: restApi()->channelAddOwner(roomId, userId); break; case RocketChatAccount::AddLeader: restApi()->channelAddLeader(roomId, userId); break; case RocketChatAccount::AddModerator: restApi()->channelAddModerator(roomId, userId); break; case RocketChatAccount::RemoveOwner: restApi()->channelRemoveOwner(roomId, userId); break; case RocketChatAccount::RemoveLeader: restApi()->channelRemoveLeader(roomId, userId); break; case RocketChatAccount::RemoveModerator: restApi()->channelRemoveModerator(roomId, userId); break; } } else if (channelType == QLatin1Char('p')) { switch (roleType) { case RocketChatAccount::AddOwner: restApi()->groupAddOwner(roomId, userId); break; case RocketChatAccount::AddLeader: restApi()->groupAddLeader(roomId, userId); break; case RocketChatAccount::AddModerator: restApi()->groupAddModerator(roomId, userId); break; case RocketChatAccount::RemoveOwner: restApi()->groupRemoveOwner(roomId, userId); break; case RocketChatAccount::RemoveLeader: restApi()->groupRemoveLeader(roomId, userId); break; case RocketChatAccount::RemoveModerator: restApi()->groupRemoveModerator(roomId, userId); break; } } else { qCWarning(RUQOLA_LOG) << " unsupport changeRoles room for type " << channelType; } } void RocketChatAccount::channelInfo(const QString &roomId) { restApi()->channelInfo(roomId); } bool RocketChatAccount::allowEditingMessages() const { return mRuqolaServerConfig->allowMessageEditing(); } void RocketChatAccount::parseOtr(const QJsonArray &contents) { qCWarning(RUQOLA_LOG) << " NOT IMPLEMENTED YET"; //const Otr t = mOtrManager->parseOtr(contents); //qDebug() << " void RocketChatAccount::parseOtr(const QJsonArray &contents)"<avatarUrlFromCacheOnly(sender); //qDebug() << " iconFileName"<inputChannelAutocomplete(pattern, exceptions); break; case InputTextManager::CompletionForType::User: ddp()->inputUserAutocomplete(pattern, exceptions); break; } } void RocketChatAccount::inputThreadMessageAutocomplete(const QString &pattern, const QString &exceptions, InputTextManager::CompletionForType type) { //qDebug() << " void RocketChatAccount::inputThreadMessageAutocomplete(const QString &pattern, const QString &exceptions, InputTextManager::CompletionForType type)" << pattern; switch (type) { case InputTextManager::CompletionForType::Channel: ddp()->inputChannelAutocomplete(pattern, exceptions); break; case InputTextManager::CompletionForType::User: ddp()->inputUserAutocomplete(pattern, exceptions); break; } } AutotranslateLanguagesModel *RocketChatAccount::autoTranslateLanguagesModel() const { return mAutoTranslateLanguagesModel; } void RocketChatAccount::updateUser(const QJsonObject &object) { mUserModel->updateUser(object); } void RocketChatAccount::userStatusChanged(User *user) { if (user->userId() == userID()) { const User::PresenceStatus status = Utils::presenceStatusFromString(user->status()); statusModel()->setCurrentPresenceStatus(status); Q_EMIT userStatusUpdated(status); } mRoomModel->userStatusChanged(user); } void RocketChatAccount::ignoreUser(const QString &rid, const QString &userId, bool ignore) { restApi()->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::clearTypingNotification() { mReceiveTypingNotificationManager->clearTypingNotification(); } void RocketChatAccount::checkInitializedRoom(const QString &roomId) { Room *r = mRoomModel->findRoom(roomId); if (r && !r->wasInitialized()) { r->setWasInitialized(true); ddp()->subscribeRoomMessage(roomId); if (!r->archived()) { membersInRoom(r->roomId(), r->channelType()); rolesInRoom(r->roomId(), r->channelType()); } loadHistory(r->roomId(), QString(), true /*initial loading*/); } else if (!r) { qWarning() << " Room " << roomId << " was no found! Need to open it"; //openDirectChannel(roomId); } QMetaObject::invokeMethod(this, &RocketChatAccount::switchedRooms, Qt::QueuedConnection); } void RocketChatAccount::openDocumentation() { QDesktopServices::openUrl(QUrl(QStringLiteral("help:/"))); } void RocketChatAccount::rolesChanged(const QJsonArray &contents) { for (int i = 0; i < contents.count(); ++i) { const QJsonObject obj = contents.at(i).toObject(); const QString scope = obj[QLatin1String("scope")].toString(); Room *room = mRoomModel->findRoom(scope); if (room) { room->updateRoles(obj); } } } void RocketChatAccount::createDiscussion(const QString &parentRoomId, const QString &discussionName, const QString &replyMessage, const QString &messageId, const QStringList &users) { restApi()->createDiscussion(parentRoomId, discussionName, replyMessage, messageId, users); } void RocketChatAccount::threadsInRoom(const QString &roomId) { mThreadsModel->initialize(); restApi()->getThreadsList(roomId); } void RocketChatAccount::discussionsInRoom(const QString &roomId) { mDiscussionsModel->initialize(); restApi()->getDiscussions(roomId); } void RocketChatAccount::followMessage(const QString &messageId, bool follow) { if (follow) { restApi()->followMessage(messageId); } else { restApi()->unFollowMessage(messageId); } } void RocketChatAccount::getSupportedLanguages() { if (mRuqolaServerConfig->hasAtLeastVersion(1, 99, 0) && autoTranslateEnabled()) { restApi()->getSupportedLanguagesMessages(); } else { qCWarning(RUQOLA_LOG) << " RocketChatAccount::getSupportedLanguages is not supported before server 2.0.0"; } } void RocketChatAccount::slotGetSupportedLanguagesDone(const QJsonObject &obj) { mAutoTranslateLanguagesModel->parseLanguages(obj); } void RocketChatAccount::autoTranslateSaveLanguageSettings(const QString &roomId, const QString &language) { if (mRuqolaServerConfig->hasAtLeastVersion(1, 99, 0)) { restApi()->autoTranslateSaveLanguageSettings(roomId, language); } else { qCWarning(RUQOLA_LOG) << " RocketChatAccount::autoTranslateSaveLanguageSettings is not supported before server 2.0.0"; } } void RocketChatAccount::autoTranslateSaveAutoTranslateSettings(const QString &roomId, bool autoTranslate) { if (mRuqolaServerConfig->hasAtLeastVersion(1, 99, 0)) { restApi()->autoTranslateSaveAutoTranslateSettings(roomId, autoTranslate); } else { qCWarning(RUQOLA_LOG) << " RocketChatAccount::autoTranslateSaveLanguageSettings is not supported before server 2.0.0"; } } void RocketChatAccount::slotUsersPresenceDone(const QJsonObject &obj) { qDebug() << " void RocketChatAccount::slotUsersPresenceDone(const QJsonObject &obj)" << obj; } void RocketChatAccount::slotDisconnectedByServer() { //Laurent: disable it for the moment otherwise when we logout we are unable to add password in login page. Need to improve it first :) return; // This happens when we didn't react to pings for a while // (e.g. while stopped in gdb, or if network went down for a bit) // Let's try connecting in again // TODO: delay this more and more like RC+ ? QTimer::singleShot(100, this, [this]() { qCDebug(RUQOLA_LOG) << "Attempting to reconnect after the server disconnected us"; // Do the parts of logOut() that don't actually try talking to the server mRoomModel->clear(); delete mDdp; mDdp = nullptr; tryLogin(); }); } void RocketChatAccount::usersPresence() { restApi()->usersPresence(); } void RocketChatAccount::customUsersStatus() { if (mRuqolaServerConfig->hasAtLeastVersion(2, 4, 0)) { restApi()->customUserStatus(); } else { qCWarning(RUQOLA_LOG) << " RocketChatAccount::customUserStatus is not supported before server 2.4.0"; } } void RocketChatAccount::initializeAccount() { listEmojiCustom(); //load when necessary //account->usersPresence(); if (mRuqolaServerConfig->autoTranslateEnabled()) { getSupportedLanguages(); } //Force set online. //TODO don't reset message status ! ddp()->setDefaultStatus(User::PresenceStatus::PresenceOnline); //customUsersStatus(); Only for test } diff --git a/src/core/rocketchataccount.h b/src/core/rocketchataccount.h index c713b802..239a0095 100644 --- a/src/core/rocketchataccount.h +++ b/src/core/rocketchataccount.h @@ -1,509 +1,510 @@ /* Copyright (c) 2017-2020 Laurent Montel 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 #include #include "messages/message.h" #include "rocketchataccountsettings.h" #include "libruqolacore_export.h" #include "authenticationinfo.h" #include "file.h" #include "inputtextmanager.h" #include "accountroomsettings.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 FilesForRoomFilterProxyModel; class FilesForRoomModel; class SearchChannelModel; class SearchChannelFilterProxyModel; class LoginMethodModel; class InputTextManager; class PluginAuthenticationInterface; class Room; class SearchMessageModel; class SearchMessageFilterProxyModel; class ThreadsFilterProxyModel; class ServerConfigInfo; class ReceiveTypingNotificationManager; class EmoticonModel; class DiscussionsFilterProxyModel; class DiscussionsModel; class ThreadsModel; class ThreadMessageModel; class ListMessagesModel; class ListMessagesModelFilterProxyModel; class AutotranslateLanguagesModel; 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(QString twoFactorAuthenticationCode READ twoFactorAuthenticationCode WRITE setTwoFactorAuthenticationCode NOTIFY twoFactorAuthenticationCodeChanged) Q_PROPERTY(DDPClient::LoginStatus loginStatus READ loginStatus NOTIFY loginStatusChanged) Q_PROPERTY(bool editingMode READ editingMode NOTIFY editingModeChanged) Q_PROPERTY(bool sortUnreadOnTop READ sortUnreadOnTop NOTIFY sortUnreadOnTopChanged) Q_PROPERTY(bool autoTranslateEnabled READ autoTranslateEnabled CONSTANT) Q_PROPERTY(bool jitsiEnabled READ jitsiEnabled CONSTANT) Q_PROPERTY(bool encryptedEnabled READ encryptedEnabled CONSTANT) Q_PROPERTY(bool allowMessagePinningEnabled READ allowMessagePinningEnabled CONSTANT) Q_PROPERTY(bool allowMessageSnippetingEnabled READ allowMessageSnippetingEnabled CONSTANT) Q_PROPERTY(bool allowMessageStarringEnabled READ allowMessageStarringEnabled CONSTANT) Q_PROPERTY(bool allowMessageDeletingEnabled READ allowMessageDeletingEnabled CONSTANT) Q_PROPERTY(bool threadsEnabled READ threadsEnabled CONSTANT) Q_PROPERTY(bool discussionEnabled READ discussionEnabled CONSTANT) Q_PROPERTY(bool hasPinnedMessagesSupport READ hasPinnedMessagesSupport CONSTANT) Q_PROPERTY(bool hasSnippetedMessagesSupport READ hasSnippetedMessagesSupport CONSTANT) Q_PROPERTY(bool hasStarredMessagesSupport READ hasStarredMessagesSupport CONSTANT) Q_PROPERTY(bool allowEditingMessages READ allowEditingMessages CONSTANT) Q_PROPERTY(bool otrEnabled READ otrEnabled CONSTANT) Q_PROPERTY(ServerConfigInfo* serverConfigInfo READ serverConfigInfo CONSTANT) Q_PROPERTY(AutotranslateLanguagesModel* autoTranslateLanguagesModel READ autoTranslateLanguagesModel CONSTANT) Q_PROPERTY(QString recordingVideoPath READ recordingVideoPath CONSTANT) Q_PROPERTY(QString recordingImagePath READ recordingImagePath CONSTANT) Q_PROPERTY(LoginMethodModel* loginMethodModel READ loginMethodModel CONSTANT) Q_PROPERTY(StatusModel* statusModel READ statusModel CONSTANT) Q_PROPERTY(DiscussionsFilterProxyModel* discussionsFilterProxyModel READ discussionsFilterProxyModel CONSTANT) Q_PROPERTY(SearchChannelFilterProxyModel* searchChannelFilterProxyModel READ searchChannelFilterProxyModel CONSTANT) Q_PROPERTY(InputTextManager* inputTextManager READ inputTextManager CONSTANT) Q_PROPERTY(InputTextManager* inputThreadMessageTextManager READ inputThreadMessageTextManager CONSTANT) Q_PROPERTY(ThreadsFilterProxyModel* threadsFilterProxyModel READ threadsFilterProxyModel CONSTANT) Q_PROPERTY(MessageModel* threadMessageModel READ threadMessageModel CONSTANT) Q_PROPERTY(EmoticonModel* emoticonModel READ emoticonModel CONSTANT) Q_PROPERTY(FilesForRoomFilterProxyModel* filesForRoomFilterProxyModel READ filesForRoomFilterProxyModel CONSTANT) Q_PROPERTY(SearchMessageFilterProxyModel* searchMessageFilterProxyModel READ searchMessageFilterProxyModel CONSTANT) Q_PROPERTY(ListMessagesModelFilterProxyModel* listMessagesFilterProxyModel READ listMessagesFilterProxyModel CONSTANT) Q_PROPERTY(RoomFilterProxyModel* roomFilterProxyModel READ roomFilterProxyModel CONSTANT) Q_PROPERTY(UsersModel* usersModel READ usersModel CONSTANT) Q_PROPERTY(ReceiveTypingNotificationManager* receiveTypingNotificationManager READ receiveTypingNotificationManager CONSTANT) Q_PROPERTY(UserCompleterFilterProxyModel* userCompleterFilterModelProxy READ userCompleterFilterModelProxy CONSTANT) public: explicit RocketChatAccount(const QString &accountName = QString(), QObject *parent = nullptr); ~RocketChatAccount() override; enum RoomInfoType { Announcement, Description, Name, Topic, ReadOnly, Archive, RoomType, Encrypted, Password }; Q_ENUM(RoomInfoType) enum NotificationOptionsType { DisableNotifications, HideUnreadStatus, AudioNotifications, DesktopNotifications, DesktopDurationNotifications, DesktopSoundNotifications, EmailNotifications, MobilePushNotifications, UnreadAlert, MuteGroupMentions }; Q_ENUM(NotificationOptionsType) enum RoleType { AddOwner, AddLeader, AddModerator, RemoveOwner, RemoveLeader, RemoveModerator }; Q_ENUM(RoleType) Q_INVOKABLE Q_REQUIRED_RESULT QString getUserCurrentMessage(const QString &roomId); Q_INVOKABLE void setUserCurrentMessage(const QString &message, const QString &roomId); Q_INVOKABLE void textEditing(const QString &roomId, bool clearNotification); 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 clearAllUnreadMessages(); 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 replyOnThread(const QString &roomID, const QString &threadMessageId, 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, bool broadcast); Q_INVOKABLE void joinRoom(const QString &roomId, const QString &joinCode = QString()); Q_INVOKABLE void openDirectChannel(const QString &username); Q_INVOKABLE void setDefaultStatus(User::PresenceStatus status, const QString &messageStatus); //Move to private no ? Q_INVOKABLE void changeDefaultStatus(int index, const QString &messageStatus); 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); 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 void downloadFile(const QString &downloadFileUrl, const QUrl &localFile); Q_INVOKABLE void starMessage(const QString &messageId, bool starred); Q_INVOKABLE void pinMessage(const QString &messageId, bool pinned); Q_INVOKABLE void uploadFile(const QString &roomId, const QString &description, const QString &messageText, const QUrl &fileUrl); Q_INVOKABLE Q_REQUIRED_RESULT QString avatarUrl(const QString &userId); 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 void channelAndPrivateAutocomplete(const QString &pattern); Q_INVOKABLE void roomFiles(const QString &roomId, const QString &channelType = QString()); Q_INVOKABLE void addUserToRoom(const QString &username, const QString &roomId, const QString &channelType); Q_INVOKABLE void changeDefaultAuthentication(int index); Q_INVOKABLE void messageSearch(const QString &pattern, const QString &rid); InputTextManager *inputTextManager() const { return mInputTextManager; } InputTextManager *inputThreadMessageTextManager() const { return mInputThreadMessageTextManager; } Q_INVOKABLE void blockUser(const QString &userId, bool block); Q_INVOKABLE Q_REQUIRED_RESULT 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 void channelInfo(const QString &roomId); Q_INVOKABLE void groupInfo(const QString &roomId); Q_INVOKABLE void switchEditingMode(bool b); Q_INVOKABLE void setSortUnreadOnTop(bool b); Q_INVOKABLE void kickUser(const QString &rid, const QString &userId, const QString &channelType); Q_INVOKABLE void changeRoles(const QString &rid, const QString &userId, const QString &channelType, RocketChatAccount::RoleType roleType); Q_INVOKABLE void rolesInRoom(const QString &roomId, const QString &channelType); Q_INVOKABLE void switchingToRoom(const QString &roomID); Q_INVOKABLE void reportMessage(const QString &messageId, const QString &message); Q_INVOKABLE void getThreadMessages(const QString &threadMessageId); Q_INVOKABLE void createDiscussion(const QString &parentRoomName, const QString &discussionName, const QString &replyMessage, const QString &messageId, const QStringList &users = QStringList()); Q_INVOKABLE void threadsInRoom(const QString &roomId); Q_INVOKABLE void discussionsInRoom(const QString &roomId); Q_INVOKABLE void followMessage(const QString &messageId, bool follow); Q_INVOKABLE void replyToMessage(const QString &roomID, const QString &message, const QString &messageId); Q_INVOKABLE void loadMoreFileAttachments(const QString &roomId, const QString &channelType); Q_INVOKABLE void loadMoreDiscussions(const QString &roomId); Q_INVOKABLE void loadMoreThreads(const QString &roomId); Q_INVOKABLE void loadThreadMessagesHistory(const QString &roomId); Q_INVOKABLE void loadMoreUsersInRoom(const QString &roomId, const QString &channelType); Q_INVOKABLE void getPinnedMessages(const QString &roomId); Q_INVOKABLE void getStarredMessages(const QString &roomId); Q_INVOKABLE void getSnippetedMessages(const QString &roomId); Q_INVOKABLE void getMentionsMessages(const QString &roomId); Q_INVOKABLE void autoTranslateSaveLanguageSettings(const QString &roomId, const QString &language); Q_INVOKABLE void autoTranslateSaveAutoTranslateSettings(const QString &roomId, bool autoTranslate); Q_INVOKABLE UsersForRoomFilterProxyModel *usersForRoomFilterProxyModel(const QString &roomId) const; Q_INVOKABLE RoomWrapper *roomWrapper(const QString &roomId); Q_INVOKABLE MessageModel *messageModelForRoom(const QString &roomID); Q_INVOKABLE void changeDisplayAttachment(const QString &roomId, const QString &messageId, bool displayAttachment); Q_INVOKABLE void changeShowOriginalMessage(const QString &roomId, const QString &messageId, bool showOriginal); Q_INVOKABLE void loadMoreListMessages(const QString &roomId); Q_INVOKABLE void getListMessages(const QString &roomId, ListMessagesModel::ListMessageType type); QUrl urlForLink(const QString &link) const; SearchMessageFilterProxyModel *searchMessageFilterProxyModel() const; FilesForRoomFilterProxyModel *filesForRoomFilterProxyModel() const; ReceiveTypingNotificationManager *receiveTypingNotificationManager() const; UserCompleterFilterProxyModel *userCompleterFilterModelProxy() const; UsersModel *usersModel() const; RoomFilterProxyModel *roomFilterProxyModel() const; MessageModel *threadMessageModel() const; EmoticonModel *emoticonModel() const; SearchChannelFilterProxyModel *searchChannelFilterProxyModel() const; AutotranslateLanguagesModel *autoTranslateLanguagesModel() const; DiscussionsFilterProxyModel *discussionsFilterProxyModel() const; SearchChannelModel *searchChannelModel() const; UserCompleterModel *userCompleterModel() const; RocketChatAccountSettings *settings() const; ThreadsFilterProxyModel *threadsFilterProxyModel() const; DDPClient *ddp(); RoomModel *roomModel() const; LoginMethodModel *loginMethodModel() const; Q_REQUIRED_RESULT bool editingMode() const; Q_REQUIRED_RESULT QString serverVersionStr() const; Q_REQUIRED_RESULT bool sortUnreadOnTop() const; Q_REQUIRED_RESULT 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 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 setTwoFactorAuthenticationCode(const QString &twoFactorAuthenticationCode); Q_REQUIRED_RESULT QString twoFactorAuthenticationCode() 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 membersInRoom(const QString &roomId, const QString &roomType); - void parseUsersForRooms(const QJsonObject &obj, const QString &roomId); + void parseUsersForRooms(const QJsonObject &obj, const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo); void loadAutoCompleteChannel(const QJsonObject &obj); void insertCompleterUsers(); PluginAuthenticationInterface *defaultAuthenticationInterface() const; SearchMessageModel *searchMessageModel() const; void updateUser(const QJsonObject &object); void removeSettings(); void rolesChanged(const QJsonArray &contents); FilesForRoomModel *filesModelForRoom() const; DiscussionsModel *discussionsModel() const; ThreadsModel *threadsModel() const; Q_REQUIRED_RESULT bool encryptedEnabled() const; void updateThreadMessageList(const Message &m); void initializeAccount(); Q_REQUIRED_RESULT bool allowEditingMessages() const; Q_REQUIRED_RESULT bool otrEnabled() const; ListMessagesModel *listMessageModel() const; ListMessagesModelFilterProxyModel *listMessagesFilterProxyModel() const; Q_REQUIRED_RESULT ServerConfigInfo *serverConfigInfo() const; Q_REQUIRED_RESULT QString serverUrl() const; Q_REQUIRED_RESULT StatusModel *statusModel() const; void customUsersStatus(); Q_REQUIRED_RESULT bool jitsiEnabled() const; Q_REQUIRED_RESULT bool allowMessagePinningEnabled() const; Q_REQUIRED_RESULT bool allowMessageSnippetingEnabled() const; Q_REQUIRED_RESULT bool allowMessageStarringEnabled() const; Q_REQUIRED_RESULT bool allowMessageDeletingEnabled() const; Q_REQUIRED_RESULT bool hasPinnedMessagesSupport() const; Q_REQUIRED_RESULT bool hasStarredMessagesSupport() const; Q_REQUIRED_RESULT bool hasSnippetedMessagesSupport() const; Q_REQUIRED_RESULT bool autoTranslateEnabled() const; Q_REQUIRED_RESULT bool threadsEnabled() const; Q_REQUIRED_RESULT bool discussionEnabled() const; Q_REQUIRED_RESULT QString recordingVideoPath() const; Q_REQUIRED_RESULT QString recordingImagePath() const; void setAccountEnabled(bool enabled); Q_REQUIRED_RESULT bool accountEnabled() const; void insertAvatarUrl(const QString &userId, const QUrl &url); Q_REQUIRED_RESULT AccountRoomSettings *accountRoomSettings() const; Q_SIGNALS: void connectedChanged(); void accountNameChanged(); void userNameChanged(); void userIDChanged(); void passwordChanged(); void twoFactorAuthenticationCodeChanged(); void serverUrlChanged(); void loginStatusChanged(); void socketError(QAbstractSocket::SocketError error, const QString &errorString); 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 missingChannelPassword(const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo); void editingModeChanged(); void sortUnreadOnTopChanged(); void jobFailed(const QString &message); void switchedRooms(); void userStatusUpdated(User::PresenceStatus status); void publicSettingChanged(); void serverVersionChanged(); void openLinkRequested(const QString &link); private: Q_DISABLE_COPY(RocketChatAccount) Room *getRoom(const QString &roomId); - void slotChannelFilesDone(const QJsonObject &obj, const QString &roomId); - void slotChannelRolesDone(const QJsonObject &obj, const QString &roomId); + void slotChannelFilesDone(const QJsonObject &obj, const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo); + void slotChannelRolesDone(const QJsonObject &obj, const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo); void slotSplotLightDone(const QJsonObject &obj); void slotGetThreadMessagesDone(const QJsonObject &obj, const QString &threadMessageId); void slotGetThreadsListDone(const QJsonObject &obj, const QString &roomId); void slotGetDiscussionsListDone(const QJsonObject &obj, const QString &roomId); void slotGetSupportedLanguagesDone(const QJsonObject &obj); void slotUsersPresenceDone(const QJsonObject &obj); void slotSocketError(QAbstractSocket::SocketError error, const QString &errorString); void slotDisconnectedByServer(); void loadEmoji(const QJsonObject &obj); void slotSearchMessages(const QJsonObject &obj); void slotNeedToUpdateNotification(); void loadSettings(const QString &accountFileName); void clearModels(); void fillOauthModel(); void initializeAuthenticationPlugins(); void setDefaultAuthentication(AuthenticationManager::OauthType type); void userStatusChanged(User *user); - void setChannelJoinDone(const QString &roomId); - void openArchivedRoom(const QString &roomId); + void setChannelJoinDone(const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo); + void openArchivedRoom(const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo); void getSupportedLanguages(); void usersPresence(); void listEmojiCustom(); void checkInitializedRoom(const QString &roomId); void clearTypingNotification(); void inputAutocomplete(const QString &pattern, const QString &exceptions, InputTextManager::CompletionForType type); void inputThreadMessageAutocomplete(const QString &pattern, const QString &exceptions, InputTextManager::CompletionForType type); void slotGetListMessagesDone(const QJsonObject &obj, const QString &roomId, ListMessagesModel::ListMessageType type); void slotUserAutoCompleterDone(const QJsonObject &obj); void slotRoomsAutoCompleteChannelAndPrivateDone(const QJsonObject &obj); AccountRoomSettings *mAccountRoomSettings = nullptr; 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; InputTextManager *mInputThreadMessageTextManager = nullptr; SearchMessageModel *mSearchMessageModel = nullptr; SearchMessageFilterProxyModel *mSearchMessageFilterProxyModel = nullptr; ReceiveTypingNotificationManager *mReceiveTypingNotificationManager = nullptr; ServerConfigInfo *mServerConfigInfo = nullptr; FilesForRoomModel *mFilesModelForRoom = nullptr; FilesForRoomFilterProxyModel *mFilesForRoomFilterProxyModel = nullptr; DiscussionsFilterProxyModel *mDiscussionsFilterProxyModel = nullptr; DiscussionsModel *mDiscussionsModel = nullptr; ThreadsModel *mThreadsModel = nullptr; ThreadsFilterProxyModel *mThreadsFilterProxyModel = nullptr; EmoticonModel *mEmoticonModel = nullptr; ThreadMessageModel *mThreadMessageModel = nullptr; ListMessagesModel *mListMessageModel = nullptr; ListMessagesModelFilterProxyModel *mListMessagesFilterProxyModel = nullptr; AutotranslateLanguagesModel *mAutoTranslateLanguagesModel = nullptr; bool mEditingMode = false; }; #endif // ROCKETCHATACCOUNT_H diff --git a/src/rocketchatrestapi-qt5/autotests/channeladdleaderjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channeladdleaderjobtest.cpp index ca7ad58e..77fe7914 100644 --- a/src/rocketchatrestapi-qt5/autotests/channeladdleaderjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channeladdleaderjobtest.cpp @@ -1,59 +1,62 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 "channeladdleaderjobtest.h" #include "channels/channeladdleaderjob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelAddLeaderJobTest) using namespace RocketChatRestApi; ChannelAddLeaderJobTest::ChannelAddLeaderJobTest(QObject *parent) : QObject(parent) { } void ChannelAddLeaderJobTest::shouldHaveDefaultValue() { ChannelAddLeaderJob job; verifyDefaultValue(&job); QVERIFY(job.addLeaderUserId().isEmpty()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelAddLeaderJobTest::shouldGenerateRequest() { ChannelAddLeaderJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.addLeader"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelAddLeaderJobTest::shouldGenerateJson() { ChannelAddLeaderJob job; const QString roomId = QStringLiteral("foo1"); const QString removeUserId = QStringLiteral("topic1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); job.setAddLeaderUserId(removeUserId); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%2\",\"userId\":\"%1\"}").arg(removeUserId, roomId).toLatin1()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channeladdmoderatorjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channeladdmoderatorjobtest.cpp index 1e4f75c2..07645b0d 100644 --- a/src/rocketchatrestapi-qt5/autotests/channeladdmoderatorjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channeladdmoderatorjobtest.cpp @@ -1,59 +1,62 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channeladdmoderatorjobtest.h" #include "channels/channeladdmoderatorjob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelAddModeratorJobTest) using namespace RocketChatRestApi; ChannelAddModeratorJobTest::ChannelAddModeratorJobTest(QObject *parent) : QObject(parent) { } void ChannelAddModeratorJobTest::shouldHaveDefaultValue() { ChannelAddModeratorJob job; verifyDefaultValue(&job); QVERIFY(job.addModeratorUserId().isEmpty()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelAddModeratorJobTest::shouldGenerateRequest() { ChannelAddModeratorJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.addModerator"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelAddModeratorJobTest::shouldGenerateJson() { ChannelAddModeratorJob job; const QString roomId = QStringLiteral("foo1"); const QString addUsedId = QStringLiteral("topic1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); job.setAddModeratorUserId(addUsedId); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%2\",\"userId\":\"%1\"}").arg(addUsedId, roomId).toLatin1()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channeladdownerjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channeladdownerjobtest.cpp index 35783f8a..e7959eb7 100644 --- a/src/rocketchatrestapi-qt5/autotests/channeladdownerjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channeladdownerjobtest.cpp @@ -1,59 +1,62 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channeladdownerjobtest.h" #include "channels/channeladdownerjob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelAddOwnerJobTest) using namespace RocketChatRestApi; ChannelAddOwnerJobTest::ChannelAddOwnerJobTest(QObject *parent) : QObject(parent) { } void ChannelAddOwnerJobTest::shouldHaveDefaultValue() { ChannelAddOwnerJob job; verifyDefaultValue(&job); QVERIFY(job.addownerUserId().isEmpty()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelAddOwnerJobTest::shouldGenerateRequest() { ChannelAddOwnerJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.addOwner"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelAddOwnerJobTest::shouldGenerateJson() { ChannelAddOwnerJob job; const QString roomId = QStringLiteral("foo1"); const QString addUsedId = QStringLiteral("topic1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); job.setAddownerUserId(addUsedId); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%2\",\"userId\":\"%1\"}").arg(addUsedId, roomId).toLatin1()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelclosejobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelclosejobtest.cpp index 414d6d32..ffecc4ed 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelclosejobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelclosejobtest.cpp @@ -1,95 +1,102 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channelclosejobtest.h" #include "channels/channelclosejob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelCloseJobTest) using namespace RocketChatRestApi; ChannelCloseJobTest::ChannelCloseJobTest(QObject *parent) : QObject(parent) { } void ChannelCloseJobTest::shouldHaveDefaultValue() { ChannelCloseJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QCOMPARE(job.channelType(), ChannelCloseJob::ChannelType::Unknown); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelCloseJobTest::shouldGenerateRequest() { ChannelCloseJob job; job.setChannelType(ChannelCloseJob::Channel); QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.close"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); job.setChannelType(ChannelCloseJob::Direct); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/im.close"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); job.setChannelType(ChannelCloseJob::Groups); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.close"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelCloseJobTest::shouldGenerateJson() { ChannelCloseJob job; const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%1\"}") .arg(roomId).toLatin1()); } void ChannelCloseJobTest::shouldNotStarting() { ChannelCloseJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); + QVERIFY(!job.canStart()); job.setChannelType(ChannelCloseJob::ChannelType::Channel); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channeldeletejobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channeldeletejobtest.cpp index 61e12b99..0294b72a 100644 --- a/src/rocketchatrestapi-qt5/autotests/channeldeletejobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channeldeletejobtest.cpp @@ -1,64 +1,70 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channeldeletejobtest.h" #include "channels/channeldeletejob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelDeleteJobTest) using namespace RocketChatRestApi; ChannelDeleteJobTest::ChannelDeleteJobTest(QObject *parent) : QObject(parent) { } void ChannelDeleteJobTest::shouldHaveDefaultValue() { ChannelDeleteJob job; verifyDefaultValue(&job); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelDeleteJobTest::shouldGenerateRequest() { ChannelDeleteJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.delete"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelDeleteJobTest::shouldGenerateUserIdJson() { ChannelDeleteJob job; const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%1\"}").arg(roomId).toLatin1()); } void ChannelDeleteJobTest::shouldGenerateUserNameJson() { ChannelDeleteJob job; const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%1\"}").arg(roomId).toLatin1()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelfilesjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelfilesjobtest.cpp index 132ac6a5..261754c2 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelfilesjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelfilesjobtest.cpp @@ -1,82 +1,89 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channelfilesjobtest.h" #include "channels/channelfilesjob.h" #include "ruqola_restapi_helper.h" #include QTEST_GUILESS_MAIN(ChannelFilesJobTest) using namespace RocketChatRestApi; ChannelFilesJobTest::ChannelFilesJobTest(QObject *parent) : QObject(parent) { } void ChannelFilesJobTest::shouldHaveDefaultValue() { ChannelFilesJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QCOMPARE(job.channelType(), ChannelFilesJob::ChannelType::Unknown); QVERIFY(job.hasQueryParameterSupport()); } void ChannelFilesJobTest::shouldGenerateRequest() { ChannelFilesJob job; job.setChannelType(ChannelFilesJob::Channel); - job.setRoomId(QStringLiteral("foo")); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = QStringLiteral("foo"); + job.setChannelInfo(info); + QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.files?roomId=foo"))); job.setChannelType(ChannelFilesJob::Direct); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/im.files?roomId=foo"))); job.setChannelType(ChannelFilesJob::Groups); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.files?roomId=foo"))); } void ChannelFilesJobTest::shouldNotStarting() { ChannelFilesJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(!job.canStart()); job.setChannelType(ChannelFilesJob::ChannelType::Channel); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelhistoryjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelhistoryjobtest.cpp index d42c7d23..2ad8acc1 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelhistoryjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelhistoryjobtest.cpp @@ -1,96 +1,102 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channelhistoryjobtest.h" #include "channels/channelhistoryjob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelHistoryJobTest) using namespace RocketChatRestApi; ChannelHistoryJobTest::ChannelHistoryJobTest(QObject *parent) : QObject(parent) { } void ChannelHistoryJobTest::shouldHaveDefaultValue() { ChannelHistoryJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QCOMPARE(job.channelType(), ChannelHistoryJob::ChannelType::Unknown); QCOMPARE(job.count(), -1); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelHistoryJobTest::shouldGenerateRequest() { ChannelHistoryJob job; job.setChannelType(ChannelHistoryJob::Channel); QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.history"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); job.setChannelType(ChannelHistoryJob::Direct); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/im.history"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); job.setChannelType(ChannelHistoryJob::Groups); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.history"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelHistoryJobTest::shouldGenerateJson() { ChannelHistoryJob job; const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%1\"}") .arg(roomId).toLatin1()); } void ChannelHistoryJobTest::shouldNotStarting() { ChannelHistoryJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(!job.canStart()); job.setChannelType(ChannelHistoryJob::ChannelType::Channel); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelinfojobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelinfojobtest.cpp index 5be931ce..70628a45 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelinfojobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelinfojobtest.cpp @@ -1,70 +1,77 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 "channelinfojobtest.h" #include "channels/channelinfojob.h" #include "ruqola_restapi_helper.h" #include QTEST_GUILESS_MAIN(ChannelInfoJobTest) using namespace RocketChatRestApi; ChannelInfoJobTest::ChannelInfoJobTest(QObject *parent) : QObject(parent) { } void ChannelInfoJobTest::shouldHaveDefaultValue() { ChannelInfoJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelInfoJobTest::shouldGenerateRequest() { ChannelInfoJob job; - job.setRoomId(QStringLiteral("foo")); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = QStringLiteral("foo"); + job.setChannelInfo(info); + QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.info?roomId=foo"))); } void ChannelInfoJobTest::shouldNotStarting() { ChannelInfoJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelinvitejobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelinvitejobtest.cpp index 63826b93..e29bf49d 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelinvitejobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelinvitejobtest.cpp @@ -1,70 +1,76 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channelinvitejobtest.h" #include "channels/channelinvitejob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelInviteJobTest) using namespace RocketChatRestApi; ChannelInviteJobTest::ChannelInviteJobTest(QObject *parent) : QObject(parent) { } void ChannelInviteJobTest::shouldHaveDefaultValue() { ChannelInviteJob job; verifyDefaultValue(&job); QVERIFY(job.inviteUserId().isEmpty()); QVERIFY(job.inviteUserName().isEmpty()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelInviteJobTest::shouldGenerateRequest() { ChannelInviteJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.invite"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelInviteJobTest::shouldGenerateUserIdJson() { ChannelInviteJob job; const QString roomId = QStringLiteral("foo1"); const QString userId = QStringLiteral("topic1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); job.setInviteUserId(userId); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%2\",\"userId\":\"%1\"}").arg(userId, roomId).toLatin1()); } void ChannelInviteJobTest::shouldGenerateUserNameJson() { ChannelInviteJob job; const QString roomId = QStringLiteral("foo1"); const QString userName = QStringLiteral("topic1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); job.setInviteUserName(userName); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%2\",\"userName\":\"%1\"}").arg(userName, roomId).toLatin1()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channeljoinjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channeljoinjobtest.cpp index 81bc1b42..c82639c1 100644 --- a/src/rocketchatrestapi-qt5/autotests/channeljoinjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channeljoinjobtest.cpp @@ -1,86 +1,92 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channeljoinjobtest.h" #include "channels/channeljoinjob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelJoinJobTest) using namespace RocketChatRestApi; ChannelJoinJobTest::ChannelJoinJobTest(QObject *parent) : QObject(parent) { } void ChannelJoinJobTest::shouldHaveDefaultValue() { ChannelJoinJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelJoinJobTest::shouldGenerateRequest() { ChannelJoinJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.join"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelJoinJobTest::shouldGenerateJson() { ChannelJoinJob job; const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); const QString joinCode = QStringLiteral("bli"); job.setJoinCode(joinCode); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"joinCode\":\"%2\",\"roomId\":\"%1\"}").arg(roomId, joinCode).toLatin1()); } void ChannelJoinJobTest::shouldNotStarting() { ChannelJoinJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(job.canStart()); //Join code is optional const QString joinCode = QStringLiteral("fd1"); job.setJoinCode(joinCode); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelkickjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelkickjobtest.cpp index 17f80238..775bc2ef 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelkickjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelkickjobtest.cpp @@ -1,86 +1,93 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channelkickjobtest.h" #include "channels/channelkickjob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelKickJobTest) using namespace RocketChatRestApi; ChannelKickJobTest::ChannelKickJobTest(QObject *parent) : QObject(parent) { } void ChannelKickJobTest::shouldHaveDefaultValue() { ChannelKickJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(job.kickUserId().isEmpty()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelKickJobTest::shouldGenerateRequest() { ChannelKickJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.kick"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelKickJobTest::shouldGenerateJson() { ChannelKickJob job; const QString channelname = QStringLiteral("foo1"); - job.setRoomId(channelname); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = channelname; + job.setChannelInfo(info); + const QString userkick = QStringLiteral("bla"); job.setKickUserId(userkick); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%1\",\"userId\":\"%2\"}").arg(channelname, userkick).toLatin1()); } void ChannelKickJobTest::shouldNotStarting() { ChannelKickJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(!job.canStart()); const QString kickuser = QStringLiteral("bla"); job.setKickUserId(kickuser); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelmembersjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelmembersjobtest.cpp index 2e8ce6b8..c75b795b 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelmembersjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelmembersjobtest.cpp @@ -1,82 +1,89 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 "channelmembersjobtest.h" #include "channels/channelmembersjob.h" #include "ruqola_restapi_helper.h" #include QTEST_GUILESS_MAIN(ChannelMembersJobTest) using namespace RocketChatRestApi; ChannelMembersJobTest::ChannelMembersJobTest(QObject *parent) : QObject(parent) { } void ChannelMembersJobTest::shouldHaveDefaultValue() { ChannelMembersJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QCOMPARE(job.channelType(), ChannelMembersJob::ChannelType::Unknown); QVERIFY(job.hasQueryParameterSupport()); } void ChannelMembersJobTest::shouldGenerateRequest() { ChannelMembersJob job; job.setChannelType(ChannelMembersJob::Channel); - job.setRoomId(QStringLiteral("foo")); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = QStringLiteral("foo"); + job.setChannelInfo(info); + QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.members?roomId=foo"))); job.setChannelType(ChannelMembersJob::Direct); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/im.members?roomId=foo"))); job.setChannelType(ChannelMembersJob::Groups); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.members?roomId=foo"))); } void ChannelMembersJobTest::shouldNotStarting() { ChannelMembersJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(!job.canStart()); job.setChannelType(ChannelMembersJob::ChannelType::Channel); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelremoveleaderjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelremoveleaderjobtest.cpp index 59e884eb..7b21ccbc 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelremoveleaderjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelremoveleaderjobtest.cpp @@ -1,59 +1,62 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 "channelremoveleaderjobtest.h" #include "channels/channelremoveleaderjob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelRemoveLeaderJobTest) using namespace RocketChatRestApi; ChannelRemoveLeaderJobTest::ChannelRemoveLeaderJobTest(QObject *parent) : QObject(parent) { } void ChannelRemoveLeaderJobTest::shouldHaveDefaultValue() { ChannelRemoveLeaderJob job; verifyDefaultValue(&job); QVERIFY(job.removeUserId().isEmpty()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelRemoveLeaderJobTest::shouldGenerateRequest() { ChannelRemoveLeaderJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.removeLeader"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelRemoveLeaderJobTest::shouldGenerateJson() { ChannelRemoveLeaderJob job; const QString roomId = QStringLiteral("foo1"); const QString removeUserId = QStringLiteral("topic1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); job.setRemoveUserId(removeUserId); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%2\",\"userId\":\"%1\"}").arg(removeUserId, roomId).toLatin1()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelremovemoderatorjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelremovemoderatorjobtest.cpp index d9ea8221..75caa605 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelremovemoderatorjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelremovemoderatorjobtest.cpp @@ -1,59 +1,62 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 "channelremovemoderatorjobtest.h" #include "channels/channelremovemoderatorjob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelRemoveModeratorJobTest) using namespace RocketChatRestApi; ChannelRemoveModeratorJobTest::ChannelRemoveModeratorJobTest(QObject *parent) : QObject(parent) { } void ChannelRemoveModeratorJobTest::shouldHaveDefaultValue() { ChannelRemoveModeratorJob job; verifyDefaultValue(&job); QVERIFY(job.removeUserId().isEmpty()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelRemoveModeratorJobTest::shouldGenerateRequest() { ChannelRemoveModeratorJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.removeModerator"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelRemoveModeratorJobTest::shouldGenerateJson() { ChannelRemoveModeratorJob job; const QString roomId = QStringLiteral("foo1"); const QString removeUserId = QStringLiteral("topic1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); job.setRemoveUserId(removeUserId); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%2\",\"userId\":\"%1\"}").arg(removeUserId, roomId).toLatin1()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelremoveownerjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelremoveownerjobtest.cpp index dd6946e6..076da269 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelremoveownerjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelremoveownerjobtest.cpp @@ -1,59 +1,62 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channelremoveownerjobtest.h" #include "channels/channelremoveownerjob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(ChannelRemoveOwnerJobTest) using namespace RocketChatRestApi; ChannelRemoveOwnerJobTest::ChannelRemoveOwnerJobTest(QObject *parent) : QObject(parent) { } void ChannelRemoveOwnerJobTest::shouldHaveDefaultValue() { ChannelRemoveOwnerJob job; verifyDefaultValue(&job); QVERIFY(job.removeUserId().isEmpty()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelRemoveOwnerJobTest::shouldGenerateRequest() { ChannelRemoveOwnerJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.removeOwner"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void ChannelRemoveOwnerJobTest::shouldGenerateJson() { ChannelRemoveOwnerJob job; const QString roomId = QStringLiteral("foo1"); const QString removeUserId = QStringLiteral("topic1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); job.setRemoveUserId(removeUserId); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%2\",\"userId\":\"%1\"}").arg(removeUserId, roomId).toLatin1()); } diff --git a/src/rocketchatrestapi-qt5/autotests/channelsmoderatorsjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/channelsmoderatorsjobtest.cpp index c1eaaadf..32df61c3 100644 --- a/src/rocketchatrestapi-qt5/autotests/channelsmoderatorsjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/channelsmoderatorsjobtest.cpp @@ -1,70 +1,76 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 "channelsmoderatorsjobtest.h" #include "channels/channelsmoderatorsjob.h" #include "ruqola_restapi_helper.h" #include QTEST_GUILESS_MAIN(ChannelsModeratorsJobTest) using namespace RocketChatRestApi; ChannelsModeratorsJobTest::ChannelsModeratorsJobTest(QObject *parent) : QObject(parent) { } void ChannelsModeratorsJobTest::shouldHaveDefaultValue() { ChannelsModeratorsJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void ChannelsModeratorsJobTest::shouldGenerateRequest() { ChannelsModeratorsJob job; - job.setRoomId(QStringLiteral("foo")); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = QStringLiteral("foo"); + job.setChannelInfo(info); QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.moderators?roomId=foo"))); } void ChannelsModeratorsJobTest::shouldNotStarting() { ChannelsModeratorsJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/getchannelrolesjobtest.cpp b/src/rocketchatrestapi-qt5/autotests/getchannelrolesjobtest.cpp index 4c909f62..89bc6913 100644 --- a/src/rocketchatrestapi-qt5/autotests/getchannelrolesjobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/getchannelrolesjobtest.cpp @@ -1,54 +1,57 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "getchannelrolesjobtest.h" #include "channels/getchannelrolesjob.h" #include "restapimethod.h" #include QTEST_GUILESS_MAIN(GetChannelRolesJobTest) using namespace RocketChatRestApi; GetChannelRolesJobTest::GetChannelRolesJobTest(QObject *parent) : QObject(parent) { } void GetChannelRolesJobTest::shouldHaveDefaultValue() { GetChannelRolesJob job; QVERIFY(!job.restApiMethod()); QVERIFY(!job.networkAccessManager()); QVERIFY(!job.start()); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.restApiLogger()); QVERIFY(!job.hasQueryParameterSupport()); } void GetChannelRolesJobTest::shouldGenerateRequest() { GetChannelRolesJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); const QString roomId = QStringLiteral("avat"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); const QNetworkRequest request = job.request(); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.roles?roomId=avat"))); } diff --git a/src/rocketchatrestapi-qt5/autotests/leavechanneljobtest.cpp b/src/rocketchatrestapi-qt5/autotests/leavechanneljobtest.cpp index 2b18044a..580c512f 100644 --- a/src/rocketchatrestapi-qt5/autotests/leavechanneljobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/leavechanneljobtest.cpp @@ -1,79 +1,85 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "leavechanneljobtest.h" #include "channels/leavechanneljob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(LeaveChannelJobTest) using namespace RocketChatRestApi; LeaveChannelJobTest::LeaveChannelJobTest(QObject *parent) : QObject(parent) { } void LeaveChannelJobTest::shouldHaveDefaultValue() { LeaveChannelJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void LeaveChannelJobTest::shouldGenerateRequest() { LeaveChannelJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.leave"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void LeaveChannelJobTest::shouldGenerateJson() { LeaveChannelJob job; const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%1\"}").arg(roomId).toLatin1()); } void LeaveChannelJobTest::shouldNotStarting() { LeaveChannelJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/setchanneltypejobtest.cpp b/src/rocketchatrestapi-qt5/autotests/setchanneltypejobtest.cpp index 9a37bd1b..5dc5fe1b 100644 --- a/src/rocketchatrestapi-qt5/autotests/setchanneltypejobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/setchanneltypejobtest.cpp @@ -1,86 +1,92 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "setchanneltypejobtest.h" #include "channels/setchanneltypejob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(SetChannelTypeJobTest) using namespace RocketChatRestApi; SetChannelTypeJobTest::SetChannelTypeJobTest(QObject *parent) : QObject(parent) { } void SetChannelTypeJobTest::shouldHaveDefaultValue() { SetChannelTypeJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QCOMPARE(job.type(), SetChannelTypeJob::Unknown); QVERIFY(!job.hasQueryParameterSupport()); } void SetChannelTypeJobTest::shouldGenerateRequest() { SetChannelTypeJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setType"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void SetChannelTypeJobTest::shouldGenerateJson() { SetChannelTypeJob job; const QString channelname = QStringLiteral("foo1"); - job.setRoomId(channelname); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = channelname; + job.setChannelInfo(info); job.setType(SetChannelTypeJob::Private); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%1\",\"type\":\"p\"}").arg(channelname).toLatin1()); job.setType(SetChannelTypeJob::Public); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%1\",\"type\":\"c\"}").arg(channelname).toLatin1()); } void SetChannelTypeJobTest::shouldNotStarting() { SetChannelTypeJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(!job.canStart()); job.setType(SetChannelTypeJob::Private); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/autotests/setjoincodechanneljobtest.cpp b/src/rocketchatrestapi-qt5/autotests/setjoincodechanneljobtest.cpp index 7aa60b6d..494dd544 100644 --- a/src/rocketchatrestapi-qt5/autotests/setjoincodechanneljobtest.cpp +++ b/src/rocketchatrestapi-qt5/autotests/setjoincodechanneljobtest.cpp @@ -1,85 +1,92 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "setjoincodechanneljobtest.h" #include "channels/setjoincodechanneljob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(SetJoinCodeChannelJobTest) using namespace RocketChatRestApi; SetJoinCodeChannelJobTest::SetJoinCodeChannelJobTest(QObject *parent) : QObject(parent) { } void SetJoinCodeChannelJobTest::shouldHaveDefaultValue() { SetJoinCodeChannelJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); - QVERIFY(job.roomId().isEmpty()); + QVERIFY(!job.hasRoomIdentifier()); QVERIFY(!job.hasQueryParameterSupport()); } void SetJoinCodeChannelJobTest::shouldGenerateRequest() { SetJoinCodeChannelJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setJoinCode"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void SetJoinCodeChannelJobTest::shouldGenerateJson() { SetJoinCodeChannelJob job; const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); const QString joinCode = QStringLiteral("bli"); job.setJoinCode(joinCode); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"joinCode\":\"%2\",\"roomId\":\"%1\"}").arg(roomId, joinCode).toLatin1()); } void SetJoinCodeChannelJobTest::shouldNotStarting() { SetJoinCodeChannelJob job; RestApiMethod method; method.setServerUrl(QStringLiteral("http://www.kde.org")); job.setRestApiMethod(&method); QNetworkAccessManager mNetworkAccessManager; job.setNetworkAccessManager(&mNetworkAccessManager); QVERIFY(!job.canStart()); const QString auth = QStringLiteral("foo"); const QString userId = QStringLiteral("foo"); job.setAuthToken(auth); QVERIFY(!job.canStart()); job.setUserId(userId); + QVERIFY(!job.canStart()); const QString roomId = QStringLiteral("foo1"); - job.setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job.setChannelInfo(info); QVERIFY(!job.canStart()); const QString joinCode = QStringLiteral("fd1"); job.setJoinCode(joinCode); QVERIFY(job.canStart()); } diff --git a/src/rocketchatrestapi-qt5/channels/channelbasejob.cpp b/src/rocketchatrestapi-qt5/channels/channelbasejob.cpp index b2e2de8a..97ae4487 100644 --- a/src/rocketchatrestapi-qt5/channels/channelbasejob.cpp +++ b/src/rocketchatrestapi-qt5/channels/channelbasejob.cpp @@ -1,115 +1,76 @@ /* Copyright (c) 2020 Laurent Montel 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 "channelbasejob.h" #include "rocketchatqtrestapi_debug.h" using namespace RocketChatRestApi; ChannelBaseJob::ChannelBaseJob(QObject *parent) : RestApiAbstractJob(parent) { } ChannelBaseJob::~ChannelBaseJob() { } -QString ChannelBaseJob::roomId() const -{ - return mRoomId; -} - -void ChannelBaseJob::setRoomId(const QString &roomId) -{ - mRoomId = roomId; -} - -QString ChannelBaseJob::roomName() const -{ - return mRoomName; -} - -void ChannelBaseJob::setRoomName(const QString &roomName) -{ - mRoomName = roomName; -} - bool ChannelBaseJob::hasRoomIdentifier() const { - //return !mChannelInfo.channelInfoIdentifier.isEmpty() && (mChannelInfo.channelInfoType != ChannelBaseJob::ChannelInfoType::Unknown); - return !mRoomId.isEmpty() || !mRoomName.isEmpty(); + return !mChannelInfo.channelInfoIdentifier.isEmpty() && (mChannelInfo.channelInfoType != ChannelBaseJob::ChannelInfoType::Unknown); } void ChannelBaseJob::generateJSon(QJsonObject &jsonObj) const { -#if 0 switch (mChannelInfo.channelInfoType) { case ChannelBaseJob::ChannelInfoType::Unknown: qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Type is unknown. It's a bug!"; return; case ChannelBaseJob::ChannelInfoType::RoomId: - jsonObj[QLatin1String("roomId")] = roomId(); + jsonObj[QLatin1String("roomId")] = mChannelInfo.channelInfoIdentifier; break; case ChannelBaseJob::ChannelInfoType::RoomName: - jsonObj[QLatin1String("roomName")] = roomName(); + jsonObj[QLatin1String("roomName")] = mChannelInfo.channelInfoIdentifier; break; } -#endif - if (!mRoomId.isEmpty()) { - jsonObj[QLatin1String("roomId")] = roomId(); - } else if (!mRoomName.isEmpty()) { - jsonObj[QLatin1String("roomName")] = roomName(); - } else { - qCWarning(ROCKETCHATQTRESTAPI_LOG) << "roomId and roomName are empty. It's a bug!"; - } } void RocketChatRestApi::ChannelBaseJob::generateQuery(QUrlQuery &queryUrl) const { -#if 0 switch (mChannelInfo.channelInfoType) { case ChannelBaseJob::ChannelInfoType::Unknown: qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Type is unknown. It's a bug!"; return; case ChannelBaseJob::ChannelInfoType::RoomId: - queryUrl.addQueryItem(QStringLiteral("roomId"), roomId()); + queryUrl.addQueryItem(QStringLiteral("roomId"), mChannelInfo.channelInfoIdentifier); break; case ChannelBaseJob::ChannelInfoType::RoomName: - queryUrl.addQueryItem(QStringLiteral("roomName"), roomName()); + queryUrl.addQueryItem(QStringLiteral("roomName"), mChannelInfo.channelInfoIdentifier); break; } -#endif - if (!mRoomId.isEmpty()) { - queryUrl.addQueryItem(QStringLiteral("roomId"), roomId()); - } else if (!mRoomName.isEmpty()) { - queryUrl.addQueryItem(QStringLiteral("roomName"), roomName()); - } else { - qCWarning(ROCKETCHATQTRESTAPI_LOG) << "roomId and roomName are empty. It's a bug!"; - } } ChannelBaseJob::ChannelInfo ChannelBaseJob::channelInfo() const { return mChannelInfo; } void ChannelBaseJob::setChannelInfo(const ChannelInfo &channelInfo) { mChannelInfo = channelInfo; } diff --git a/src/rocketchatrestapi-qt5/channels/channelbasejob.h b/src/rocketchatrestapi-qt5/channels/channelbasejob.h index 684818f3..d0b12990 100644 --- a/src/rocketchatrestapi-qt5/channels/channelbasejob.h +++ b/src/rocketchatrestapi-qt5/channels/channelbasejob.h @@ -1,69 +1,61 @@ /* Copyright (c) 2020 Laurent Montel 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 CHANNELBASEJOB_H #define CHANNELBASEJOB_H #include "restapiabstractjob.h" #include "librestapi_private_export.h" #include #include namespace RocketChatRestApi { class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT ChannelBaseJob : public RestApiAbstractJob { Q_OBJECT public: explicit ChannelBaseJob(QObject *parent = nullptr); ~ChannelBaseJob() override; enum class ChannelInfoType { Unknown, RoomId, RoomName, }; struct ChannelInfo { QString channelInfoIdentifier; ChannelBaseJob::ChannelInfoType channelInfoType = ChannelBaseJob::ChannelInfoType::Unknown; }; - Q_REQUIRED_RESULT QString roomId() const; - void setRoomId(const QString &roomId); - - Q_REQUIRED_RESULT QString roomName() const; - void setRoomName(const QString &roomName); - Q_REQUIRED_RESULT bool hasRoomIdentifier() const; Q_REQUIRED_RESULT ChannelInfo channelInfo() const; void setChannelInfo(const ChannelInfo &channelInfo); protected: void generateJSon(QJsonObject &obj) const; void generateQuery(QUrlQuery &queryUrl) const; private: ChannelInfo mChannelInfo; - QString mRoomId; - QString mRoomName; }; } #endif // CHANNELBASEJOB_H diff --git a/src/rocketchatrestapi-qt5/channels/channelfilesjob.cpp b/src/rocketchatrestapi-qt5/channels/channelfilesjob.cpp index b72a3619..3fa7e4b6 100644 --- a/src/rocketchatrestapi-qt5/channels/channelfilesjob.cpp +++ b/src/rocketchatrestapi-qt5/channels/channelfilesjob.cpp @@ -1,135 +1,135 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channelfilesjob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" #include #include #include #include using namespace RocketChatRestApi; ChannelFilesJob::ChannelFilesJob(QObject *parent) : ChannelBaseJob(parent) { } ChannelFilesJob::~ChannelFilesJob() { } bool ChannelFilesJob::start() { if (!canStart()) { deleteLater(); return false; } addLoggerInfo("ChannelFilesJob::start: "); QNetworkReply *reply = mNetworkAccessManager->get(request()); connect(reply, &QNetworkReply::finished, this, &ChannelFilesJob::slotFilesinChannelFinished); return true; } void ChannelFilesJob::slotFilesinChannelFinished() { auto *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("channelFilesDone success: ") + replyJson.toJson(QJsonDocument::Indented)); - Q_EMIT channelFilesDone(replyObject, roomId()); + Q_EMIT channelFilesDone(replyObject, channelInfo()); } else { emitFailedMessage(replyObject, reply); addLoggerWarning(QByteArrayLiteral("channelFilesDone problem: ") + replyJson.toJson(QJsonDocument::Indented)); } reply->deleteLater(); } deleteLater(); } ChannelFilesJob::ChannelType ChannelFilesJob::channelType() const { return mChannelType; } void ChannelFilesJob::setChannelType(ChannelType channelType) { mChannelType = channelType; } bool ChannelFilesJob::requireHttpAuthentication() const { return true; } bool ChannelFilesJob::canStart() const { if (!hasRoomIdentifier()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelFilesJob: RoomId and RoomName are empty"; return false; } if (mChannelType == ChannelFilesJob::Unknown) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelFilesJob: Channel type is unknown."; return false; } if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelFilesJob job"; return false; } return true; } QNetworkRequest ChannelFilesJob::request() const { QUrl url; switch (mChannelType) { case Channel: url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsFiles); break; case Groups: url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::GroupsFiles); break; case Direct: url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ImFiles); break; case Unknown: qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelFilesJob: Type is not defined"; break; } QUrlQuery queryUrl; generateQuery(queryUrl); addQueryParameter(queryUrl); url.setQuery(queryUrl); QNetworkRequest request(url); addAuthRawHeader(request); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); return request; } bool RocketChatRestApi::ChannelFilesJob::hasQueryParameterSupport() const { return true; } diff --git a/src/rocketchatrestapi-qt5/channels/channelfilesjob.h b/src/rocketchatrestapi-qt5/channels/channelfilesjob.h index f2d335ff..c074b49d 100644 --- a/src/rocketchatrestapi-qt5/channels/channelfilesjob.h +++ b/src/rocketchatrestapi-qt5/channels/channelfilesjob.h @@ -1,62 +1,62 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 CHANNELFILESJOB_H #define CHANNELFILESJOB_H #include "restapiabstractjob.h" #include "librestapi_private_export.h" #include "channelbasejob.h" namespace RocketChatRestApi { class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT ChannelFilesJob : public ChannelBaseJob { Q_OBJECT public: enum ChannelType { Channel = 0, Groups, Direct, Unknown }; Q_ENUM(ChannelType) explicit ChannelFilesJob(QObject *parent = nullptr); ~ChannelFilesJob() 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 ChannelType channelType() const; void setChannelType(RocketChatRestApi::ChannelFilesJob::ChannelType channelType); Q_REQUIRED_RESULT bool hasQueryParameterSupport() const override; Q_SIGNALS: - void channelFilesDone(const QJsonObject &replyObjectj, const QString &roomId); + void channelFilesDone(const QJsonObject &replyObjectj, const ChannelBaseJob::ChannelInfo &channelInfo); private: Q_DISABLE_COPY(ChannelFilesJob) void slotFilesinChannelFinished(); ChannelType mChannelType = Unknown; }; } #endif // CHANNELFILESJOB_H diff --git a/src/rocketchatrestapi-qt5/channels/channelinfojob.cpp b/src/rocketchatrestapi-qt5/channels/channelinfojob.cpp index 261a2385..40d45498 100644 --- a/src/rocketchatrestapi-qt5/channels/channelinfojob.cpp +++ b/src/rocketchatrestapi-qt5/channels/channelinfojob.cpp @@ -1,101 +1,101 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 "channelinfojob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" #include #include #include #include using namespace RocketChatRestApi; ChannelInfoJob::ChannelInfoJob(QObject *parent) : ChannelBaseJob(parent) { } ChannelInfoJob::~ChannelInfoJob() { } bool ChannelInfoJob::start() { if (!canStart()) { deleteLater(); return false; } addLoggerInfo("ChannelInfoJob::start: "); QNetworkReply *reply = mNetworkAccessManager->get(request()); connect(reply, &QNetworkReply::finished, this, &ChannelInfoJob::slotFilesinChannelFinished); return true; } void ChannelInfoJob::slotFilesinChannelFinished() { auto *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("channelInfoDone success: ") + replyJson.toJson(QJsonDocument::Indented)); - Q_EMIT channelInfoDone(replyObject, roomId()); + Q_EMIT channelInfoDone(replyObject, channelInfo()); } else { emitFailedMessage(replyObject, reply); addLoggerWarning(QByteArrayLiteral("channelInfoDone problem: ") + replyJson.toJson(QJsonDocument::Indented)); } reply->deleteLater(); } deleteLater(); } bool ChannelInfoJob::requireHttpAuthentication() const { return true; } bool ChannelInfoJob::canStart() const { if (!hasRoomIdentifier()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelInfoJob: RoomId and RoomName are empty"; return false; } if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelInfoJob job"; return false; } return true; } QNetworkRequest ChannelInfoJob::request() const { QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsInfo); QUrlQuery queryUrl; generateQuery(queryUrl); url.setQuery(queryUrl); QNetworkRequest request(url); addAuthRawHeader(request); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); return request; } diff --git a/src/rocketchatrestapi-qt5/channels/channelinfojob.h b/src/rocketchatrestapi-qt5/channels/channelinfojob.h index a1d4129e..247b3f26 100644 --- a/src/rocketchatrestapi-qt5/channels/channelinfojob.h +++ b/src/rocketchatrestapi-qt5/channels/channelinfojob.h @@ -1,49 +1,49 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 CHANNELINFOJOB_H #define CHANNELINFOJOB_H #include "restapiabstractjob.h" #include "librestapi_private_export.h" #include "channelbasejob.h" namespace RocketChatRestApi { class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT ChannelInfoJob : public ChannelBaseJob { Q_OBJECT public: explicit ChannelInfoJob(QObject *parent = nullptr); ~ChannelInfoJob() 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_SIGNALS: - void channelInfoDone(const QJsonObject &replyObjectj, const QString &roomId); + void channelInfoDone(const QJsonObject &replyObjectj, const ChannelBaseJob::ChannelInfo &channelInfo); private: Q_DISABLE_COPY(ChannelInfoJob) void slotFilesinChannelFinished(); }; } #endif // CHANNELINFOJOB_H diff --git a/src/rocketchatrestapi-qt5/channels/channeljoinjob.cpp b/src/rocketchatrestapi-qt5/channels/channeljoinjob.cpp index c97970a2..4b3c85a0 100644 --- a/src/rocketchatrestapi-qt5/channels/channeljoinjob.cpp +++ b/src/rocketchatrestapi-qt5/channels/channeljoinjob.cpp @@ -1,125 +1,125 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channeljoinjob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" #include #include #include using namespace RocketChatRestApi; ChannelJoinJob::ChannelJoinJob(QObject *parent) : ChannelBaseJob(parent) { } ChannelJoinJob::~ChannelJoinJob() { } bool ChannelJoinJob::start() { if (!canStart()) { deleteLater(); return false; } const QByteArray baPostData = json().toJson(QJsonDocument::Compact); addLoggerInfo("ChannelJoinJob::start: " + baPostData); QNetworkReply *reply = mNetworkAccessManager->post(request(), baPostData); connect(reply, &QNetworkReply::finished, this, &ChannelJoinJob::slotChannelJoinFinished); return true; } void ChannelJoinJob::slotChannelJoinFinished() { auto *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("ChannelJoinJob success: ") + replyJson.toJson(QJsonDocument::Indented)); - Q_EMIT setChannelJoinDone(roomId()); + Q_EMIT setChannelJoinDone(channelInfo()); } else { emitFailedMessage(replyObject, reply); addLoggerWarning(QByteArrayLiteral("ChannelJoinJob problem: ") + replyJson.toJson(QJsonDocument::Indented)); //Invalid password const QString errorType = replyObject[QStringLiteral("errorType")].toString(); if (errorType == QLatin1String("error-code-invalid")) { - Q_EMIT missingChannelPassword(roomId()); + Q_EMIT missingChannelPassword(channelInfo()); } else if (errorType == QLatin1String("error-room-archived")) { - Q_EMIT openArchivedRoom(roomId()); + Q_EMIT openArchivedRoom(channelInfo()); } } reply->deleteLater(); } deleteLater(); } QString ChannelJoinJob::joinCode() const { return mJoinCode; } void ChannelJoinJob::setJoinCode(const QString &joinCode) { mJoinCode = joinCode; } bool ChannelJoinJob::requireHttpAuthentication() const { return true; } bool ChannelJoinJob::canStart() const { if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelJoinJob job"; return false; } if (!hasRoomIdentifier()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelJoinJob: RoomId and RoomName are empty"; return false; } return true; } QJsonDocument ChannelJoinJob::json() const { QJsonObject jsonObj; generateJSon(jsonObj); if (!mJoinCode.isEmpty()) { jsonObj[QLatin1String("joinCode")] = mJoinCode; } const QJsonDocument postData = QJsonDocument(jsonObj); return postData; } QNetworkRequest ChannelJoinJob::request() const { const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsJoin); QNetworkRequest request(url); addAuthRawHeader(request); addRequestAttribute(request); return request; } diff --git a/src/rocketchatrestapi-qt5/channels/channeljoinjob.h b/src/rocketchatrestapi-qt5/channels/channeljoinjob.h index e9a847ec..e0550789 100644 --- a/src/rocketchatrestapi-qt5/channels/channeljoinjob.h +++ b/src/rocketchatrestapi-qt5/channels/channeljoinjob.h @@ -1,56 +1,56 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 CHANNELJOINJOB_H #define CHANNELJOINJOB_H #include "librestapi_private_export.h" #include "channelbasejob.h" namespace RocketChatRestApi { class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT ChannelJoinJob : public ChannelBaseJob { Q_OBJECT public: explicit ChannelJoinJob(QObject *parent = nullptr); ~ChannelJoinJob() 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 joinCode() const; void setJoinCode(const QString &joinCode); Q_SIGNALS: - void setChannelJoinDone(const QString &roomId); - void missingChannelPassword(const QString &roomId); - void openArchivedRoom(const QString &roomId); + void setChannelJoinDone(const ChannelBaseJob::ChannelInfo &channelInfo); + void missingChannelPassword(const ChannelBaseJob::ChannelInfo &channelInfo); + void openArchivedRoom(const ChannelBaseJob::ChannelInfo &channelInfo); private: Q_DISABLE_COPY(ChannelJoinJob) void slotChannelJoinFinished(); QString mJoinCode; }; } #endif // CHANNELJOINJOB_H diff --git a/src/rocketchatrestapi-qt5/channels/channelmembersjob.cpp b/src/rocketchatrestapi-qt5/channels/channelmembersjob.cpp index dc120528..a78fed27 100644 --- a/src/rocketchatrestapi-qt5/channels/channelmembersjob.cpp +++ b/src/rocketchatrestapi-qt5/channels/channelmembersjob.cpp @@ -1,135 +1,135 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 "channelmembersjob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" #include #include #include #include using namespace RocketChatRestApi; ChannelMembersJob::ChannelMembersJob(QObject *parent) : ChannelBaseJob(parent) { } ChannelMembersJob::~ChannelMembersJob() { } bool ChannelMembersJob::start() { if (!canStart()) { deleteLater(); return false; } addLoggerInfo("ChannelMembersJob::start: "); QNetworkReply *reply = mNetworkAccessManager->get(request()); connect(reply, &QNetworkReply::finished, this, &ChannelMembersJob::slotChannelMembersFinished); return true; } void ChannelMembersJob::slotChannelMembersFinished() { auto *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("channelMembersDone success: ") + replyJson.toJson(QJsonDocument::Indented)); - Q_EMIT channelMembersDone(replyObject, roomId()); + Q_EMIT channelMembersDone(replyObject, channelInfo()); } else { emitFailedMessage(replyObject, reply); addLoggerWarning(QByteArrayLiteral("channelMembersDone problem: ") + replyJson.toJson(QJsonDocument::Indented)); } reply->deleteLater(); } deleteLater(); } ChannelMembersJob::ChannelType ChannelMembersJob::channelType() const { return mChannelType; } void ChannelMembersJob::setChannelType(ChannelType channelType) { mChannelType = channelType; } bool ChannelMembersJob::hasQueryParameterSupport() const { return true; } bool ChannelMembersJob::requireHttpAuthentication() const { return true; } bool ChannelMembersJob::canStart() const { if (!hasRoomIdentifier()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelMembersJob: RoomId and RoomName are empty"; return false; } if (mChannelType == ChannelMembersJob::Unknown) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelMembersJob: Channel type is unknown."; return false; } if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelMembersJob job"; return false; } return true; } QNetworkRequest ChannelMembersJob::request() const { QUrl url; switch (mChannelType) { case Channel: url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsMembers); break; case Groups: url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::GroupsMembers); break; case Direct: url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ImMembers); break; case Unknown: qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelMembersJob: Type is not defined"; break; } QUrlQuery queryUrl; generateQuery(queryUrl); addQueryParameter(queryUrl); url.setQuery(queryUrl); QNetworkRequest request(url); addAuthRawHeader(request); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); return request; } diff --git a/src/rocketchatrestapi-qt5/channels/channelmembersjob.h b/src/rocketchatrestapi-qt5/channels/channelmembersjob.h index 8c74ea68..b459ae49 100644 --- a/src/rocketchatrestapi-qt5/channels/channelmembersjob.h +++ b/src/rocketchatrestapi-qt5/channels/channelmembersjob.h @@ -1,62 +1,62 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 CHANNELMEMBERSJOB_H #define CHANNELMEMBERSJOB_H #include "librestapi_private_export.h" #include "channelbasejob.h" namespace RocketChatRestApi { class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT ChannelMembersJob : public ChannelBaseJob { Q_OBJECT public: enum ChannelType { Channel = 0, Groups, Direct, Unknown }; Q_ENUM(ChannelType) explicit ChannelMembersJob(QObject *parent = nullptr); ~ChannelMembersJob() 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 ChannelType channelType() const; void setChannelType(RocketChatRestApi::ChannelMembersJob::ChannelType channelType); Q_REQUIRED_RESULT bool hasQueryParameterSupport() const override; Q_SIGNALS: - void channelMembersDone(const QJsonObject &replyObjectj, const QString &roomId); + void channelMembersDone(const QJsonObject &replyObjectj, const ChannelBaseJob::ChannelInfo &channelInfo); private: Q_DISABLE_COPY(ChannelMembersJob) void slotChannelMembersFinished(); ChannelType mChannelType = Unknown; }; } #endif // CHANNELMEMBERSJOB_H diff --git a/src/rocketchatrestapi-qt5/channels/channelsmoderatorsjob.cpp b/src/rocketchatrestapi-qt5/channels/channelsmoderatorsjob.cpp index 65448ef7..cb76bc9b 100644 --- a/src/rocketchatrestapi-qt5/channels/channelsmoderatorsjob.cpp +++ b/src/rocketchatrestapi-qt5/channels/channelsmoderatorsjob.cpp @@ -1,101 +1,101 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "channelsmoderatorsjob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" #include #include #include #include using namespace RocketChatRestApi; ChannelsModeratorsJob::ChannelsModeratorsJob(QObject *parent) : ChannelBaseJob(parent) { } ChannelsModeratorsJob::~ChannelsModeratorsJob() { } bool ChannelsModeratorsJob::start() { if (!canStart()) { deleteLater(); return false; } addLoggerInfo("ChannelsModeratorsJob::start: "); QNetworkReply *reply = mNetworkAccessManager->get(request()); connect(reply, &QNetworkReply::finished, this, &ChannelsModeratorsJob::slotFilesinChannelFinished); return true; } void ChannelsModeratorsJob::slotFilesinChannelFinished() { auto *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("channelFilesDone success: ") + replyJson.toJson(QJsonDocument::Indented)); - Q_EMIT channelFilesDone(replyObject, roomId()); + Q_EMIT channelFilesDone(replyObject, channelInfo()); } else { emitFailedMessage(replyObject, reply); addLoggerWarning(QByteArrayLiteral("channelFilesDone problem: ") + replyJson.toJson(QJsonDocument::Indented)); } reply->deleteLater(); } deleteLater(); } bool ChannelsModeratorsJob::requireHttpAuthentication() const { return true; } bool ChannelsModeratorsJob::canStart() const { if (!hasRoomIdentifier()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelsModeratorsJob: RoomId and RoomName are empty"; return false; } if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelsModeratorsJob job"; return false; } return true; } QNetworkRequest ChannelsModeratorsJob::request() const { QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsModerators); QUrlQuery queryUrl; generateQuery(queryUrl); url.setQuery(queryUrl); QNetworkRequest request(url); addAuthRawHeader(request); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); return request; } diff --git a/src/rocketchatrestapi-qt5/channels/channelsmoderatorsjob.h b/src/rocketchatrestapi-qt5/channels/channelsmoderatorsjob.h index 0fe1c4fe..1ae4dab4 100644 --- a/src/rocketchatrestapi-qt5/channels/channelsmoderatorsjob.h +++ b/src/rocketchatrestapi-qt5/channels/channelsmoderatorsjob.h @@ -1,49 +1,49 @@ /* Copyright (c) 2019-2020 Laurent Montel 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 ChannelsModeratorsJob_H #define ChannelsModeratorsJob_H #include "librestapi_private_export.h" #include "channelbasejob.h" namespace RocketChatRestApi { class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT ChannelsModeratorsJob : public ChannelBaseJob { Q_OBJECT public: explicit ChannelsModeratorsJob(QObject *parent = nullptr); ~ChannelsModeratorsJob() 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_SIGNALS: - void channelFilesDone(const QJsonObject &replyObjectj, const QString &roomId); + void channelFilesDone(const QJsonObject &replyObjectj, const ChannelBaseJob::ChannelInfo &channelInfo); private: Q_DISABLE_COPY(ChannelsModeratorsJob) void slotFilesinChannelFinished(); }; } #endif // ChannelsModeratorsJob_H diff --git a/src/rocketchatrestapi-qt5/channels/getchannelrolesjob.cpp b/src/rocketchatrestapi-qt5/channels/getchannelrolesjob.cpp index 6a7dbff0..887d9b9d 100644 --- a/src/rocketchatrestapi-qt5/channels/getchannelrolesjob.cpp +++ b/src/rocketchatrestapi-qt5/channels/getchannelrolesjob.cpp @@ -1,110 +1,110 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 "getchannelrolesjob.h" #include "rocketchatqtrestapi_debug.h" #include "restapimethod.h" #include #include #include #include #include using namespace RocketChatRestApi; GetChannelRolesJob::GetChannelRolesJob(QObject *parent) : ChannelBaseJob(parent) { } GetChannelRolesJob::~GetChannelRolesJob() { } bool GetChannelRolesJob::canStart() const { if (!hasRoomIdentifier()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GetChannelRolesJob: RoomId and RoomName are empty"; return false; } if (!RestApiAbstractJob::canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GetChannelRolesJob job"; return false; } return true; } bool GetChannelRolesJob::start() { if (!canStart()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start server info job"; deleteLater(); return false; } QNetworkReply *reply = mNetworkAccessManager->get(request()); addLoggerInfo("GetChannelRolesJob::start"); connect(reply, &QNetworkReply::finished, this, &GetChannelRolesJob::slotGetChannelRolesFinished); return true; } QNetworkRequest GetChannelRolesJob::request() const { QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsRoles); QUrlQuery queryUrl; generateQuery(queryUrl); url.setQuery(queryUrl); QNetworkRequest request(url); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); addAuthRawHeader(request); return request; } bool GetChannelRolesJob::requireHttpAuthentication() const { return true; } void GetChannelRolesJob::slotGetChannelRolesFinished() { auto *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("GetChannelRolesJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); - Q_EMIT channelRolesDone(replyObject, roomId()); + Q_EMIT channelRolesDone(replyObject, channelInfo()); } else { emitFailedMessage(replyObject, reply); addLoggerWarning(QByteArrayLiteral("GetChannelRolesJob problem: ") + replyJson.toJson(QJsonDocument::Indented)); } reply->deleteLater(); } deleteLater(); } QString RocketChatRestApi::GetChannelRolesJob::jobName() const { return i18n("Extract Roles"); } diff --git a/src/rocketchatrestapi-qt5/channels/getchannelrolesjob.h b/src/rocketchatrestapi-qt5/channels/getchannelrolesjob.h index aecb2ec8..2bdcaa8c 100644 --- a/src/rocketchatrestapi-qt5/channels/getchannelrolesjob.h +++ b/src/rocketchatrestapi-qt5/channels/getchannelrolesjob.h @@ -1,53 +1,53 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 GETCHANNELROLESJOB_H #define GETCHANNELROLESJOB_H #include "librestapi_private_export.h" #include "channelbasejob.h" class QNetworkRequest; namespace RocketChatRestApi { class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT GetChannelRolesJob : public ChannelBaseJob { Q_OBJECT public: explicit GetChannelRolesJob(QObject *parent = nullptr); ~GetChannelRolesJob() override; Q_REQUIRED_RESULT bool start() override; Q_REQUIRED_RESULT bool canStart() const override; Q_REQUIRED_RESULT QNetworkRequest request() const override; Q_REQUIRED_RESULT bool requireHttpAuthentication() const override; protected: QString jobName() const override; Q_SIGNALS: - void channelRolesDone(const QJsonObject &obj, const QString &roomId); + void channelRolesDone(const QJsonObject &obj, const ChannelBaseJob::ChannelInfo &channelInfo); private: Q_DISABLE_COPY(GetChannelRolesJob) void slotGetChannelRolesFinished(); }; } #endif // GETCHANNELROLESJOB_H diff --git a/src/rocketchatrestapi-qt5/restapirequest.cpp b/src/rocketchatrestapi-qt5/restapirequest.cpp index 2a55dcac..08b04620 100644 --- a/src/rocketchatrestapi-qt5/restapirequest.cpp +++ b/src/rocketchatrestapi-qt5/restapirequest.cpp @@ -1,1667 +1,1725 @@ /* Copyright (c) 2017-2020 Laurent Montel 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 "users/setstatusjob.h" #include "users/userspresencejob.h" #include "misc/owninfojob.h" #include "emoji/loademojicustomjob.h" #include "authentication/logoutjob.h" #include "authentication/loginjob.h" #include "chat/starmessagejob.h" #include "chat/syncthreadmessagesjob.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 "chat/pinmessagejob.h" #include "chat/followmessagejob.h" #include "chat/unfollowmessagejob.h" #include "chat/getthreadsjob.h" #include "chat/getthreadmessagesjob.h" #include "chat/sendmessagejob.h" #include "chat/getpinnedmessagesjob.h" #include "chat/getsnippetedmessagesjob.h" #include "chat/getstarredmessagesjob.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 "channels/channelkickjob.h" #include "channels/channeladdownerjob.h" #include "channels/channelremoveownerjob.h" #include "channels/channeladdmoderatorjob.h" #include "channels/channelremovemoderatorjob.h" #include "channels/channeldeletejob.h" #include "channels/channelmembersjob.h" #include "channels/changechannelreadonlyjob.h" #include "channels/changechannelencryptedjob.h" #include "channels/channeladdleaderjob.h" #include "channels/channelremoveleaderjob.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 "groups/groupskickjob.h" #include "groups/groupaddleaderjob.h" #include "groups/groupremoveleaderjob.h" #include "groups/groupaddownerjob.h" #include "groups/groupremoveownerjob.h" #include "groups/groupaddmoderatorjob.h" #include "groups/groupremovemoderatorjob.h" #include "groups/groupsdeletejob.h" #include "groups/changegroupsreadonlyjob.h" #include "groups/changegroupsencryptedjob.h" #include "rooms/getroomsjob.h" #include "rooms/roomfavoritejob.h" #include "rooms/savenotificationjob.h" #include "rooms/roomstartdiscussionjob.h" #include "rooms/getdiscussionsjob.h" #include "rooms/roomsautocompletechannelandprivatejob.h" #include "directmessage/createdmjob.h" #include "directmessage/opendmjob.h" #include "subscriptions/markroomasreadjob.h" #include "subscriptions/markroomasunreadjob.h" #include "permissions/listpermissionsjob.h" #include "commands/listcommandsjob.h" #include "e2e/fetchmykeysjob.h" #include "video-conference/videoconfupdatejitsitimeoutjob.h" #include "autotranslate/getsupportedlanguagesjob.h" #include "autotranslate/translatesavesettingsjob.h" #include "custom/customsoundsjob.h" #include "custom/customuserstatusjob.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() { auto *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) { connect(job, &RocketChatRestApi::RestApiAbstractJob::failed, this, &RestApiRequest::failed); job->setNetworkAccessManager(mNetworkAccessManager); job->setRestApiLogger(mRuqolaLogger); job->setRestApiMethod(mRestApiMethod); if (job->requireHttpAuthentication()) { job->setAuthToken(mAuthToken); job->setUserId(mUserId); } } void RestApiRequest::logout() { auto *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() { auto *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) { auto *job = new GetAvatarJob(this); connect(job, &GetAvatarJob::avatar, this, &RestApiRequest::avatar); connect(job, &GetAvatarJob::redownloadAvatar, this, &RestApiRequest::redownloadAvatar); initializeRestApiJob(job); job->setAvatarUserId(userId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::getPrivateSettings() { auto *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() { auto *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) { auto *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) { auto *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(bool useDeprecatedVersion) { auto *job = new ServerInfoJob(this); job->setUseDeprecatedVersion(useDeprecatedVersion); initializeRestApiJob(job); connect(job, &ServerInfoJob::serverInfoDone, this, &RestApiRequest::getServerInfoDone); connect(job, &ServerInfoJob::serverInfoFailed, this, &RestApiRequest::getServerInfoFailed); 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) { auto *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) { auto *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) { auto *job = new ChangeGroupsTopicJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setTopic(topic); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeChannelReadOnly(const QString &roomId, bool b) { auto *job = new ChangeChannelReadonlyJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setReadOnly(b); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeGroupsReadOnly(const QString &roomId, bool b) { auto *job = new ChangeGroupsReadonlyJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setReadOnly(b); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeChannelEncrypted(const QString &roomId, bool b) { auto *job = new ChangeChannelEncryptedJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setEncrypted(b); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeGroupsEncrypted(const QString &roomId, bool b) { auto *job = new ChangeGroupsEncryptedJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setEncrypted(b); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeChannelAnnouncement(const QString &roomId, const QString &announcement) { auto *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) { auto *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) { auto *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) { auto *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) { auto *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) { auto *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) { auto *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) { auto *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) { auto *job = new LeaveChannelJob(this); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::leaveGroups(const QString &roomId) { auto *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, bool archive) { auto *job = new ArchiveChannelJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setArchive(archive); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::archiveGroups(const QString &roomId, bool archive) { auto *job = new ArchiveGroupsJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setArchive(archive); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::updateMessage(const QString &roomId, const QString &messageId, const QString &text) { auto *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) { auto *job = new ReactOnMessageJob(this); initializeRestApiJob(job); job->setMessageId(messageId); QString fixedEmoji = emoji; if (fixedEmoji.startsWith(QLatin1Char(':'))) { fixedEmoji.remove(0, 1); } if (fixedEmoji.endsWith(QLatin1Char(':'))) { fixedEmoji.chop(1); } job->setEmoji(fixedEmoji); job->setShouldReact(shouldReact); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::closeChannel(const QString &roomId, const QString &type) { auto *job = new ChannelCloseJob(this); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); if (type == QLatin1Char('d')) { job->setChannelType(ChannelCloseJob::Direct); } else if (type == QLatin1Char('p')) { job->setChannelType(ChannelCloseJob::Groups); } else if (type == QLatin1Char('c')) { job->setChannelType(ChannelCloseJob::Channel); } if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::historyChannel(const QString &roomId, const QString &type) { auto *job = new ChannelHistoryJob(this); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); if (type == QLatin1Char('d')) { job->setChannelType(ChannelHistoryJob::Direct); } else if (type == QLatin1Char('p')) { job->setChannelType(ChannelHistoryJob::Groups); } else if (type == QLatin1Char('c')) { job->setChannelType(ChannelHistoryJob::Channel); } if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::createDirectMessage(const QString &userName) { auto *job = new CreateDmJob(this); initializeRestApiJob(job); job->setUserName(userName); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::openDirectMessage(const QString &userId) { auto *job = new OpenDmJob(this); initializeRestApiJob(job); job->setDirectUserId(userId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::filesInRoom(const QString &roomId, const QString &type, int offset, int count) { auto *job = new ChannelFilesJob(this); connect(job, &ChannelFilesJob::channelFilesDone, this, &RestApiRequest::channelFilesDone); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); QueryParameters parameters; parameters.setCount(count); parameters.setOffset(offset); job->setQueryParameters(parameters); if (type == QLatin1Char('d')) { job->setChannelType(ChannelFilesJob::Direct); } else if (type == QLatin1Char('p')) { job->setChannelType(ChannelFilesJob::Groups); } else if (type == QLatin1Char('c')) { job->setChannelType(ChannelFilesJob::Channel); } if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } //FIXME void RestApiRequest::membersInRoom(const QString &roomId, const QString &type, int offset, int count) { auto *job = new ChannelMembersJob(this); QueryParameters parameters; parameters.setCount(count); parameters.setOffset(offset); job->setQueryParameters(parameters); connect(job, &ChannelMembersJob::channelMembersDone, this, &RestApiRequest::channelMembersDone); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); if (type == QLatin1Char('d')) { job->setChannelType(ChannelMembersJob::Direct); } else if (type == QLatin1Char('p')) { job->setChannelType(ChannelMembersJob::Groups); } else if (type == QLatin1Char('c')) { job->setChannelType(ChannelMembersJob::Channel); } if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::addUserInChannel(const QString &roomId, const QString &userId) { auto *job = new ChannelInviteJob(this); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); job->setInviteUserId(userId); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::addUserInGroup(const QString &roomId, const QString &userId) { auto *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() { auto *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) { auto *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) { auto *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) { auto *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) { auto *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) { auto *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() { auto *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) { auto *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) { auto *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) { auto *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setMuteGroupMentions(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::desktopDurationNotifications(const QString &roomId, int value) { auto *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setDesktopNotificationDuration(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::desktopSoundNotifications(const QString &roomId, const QString &value) { auto *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setAudioNotificationValue(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::changeGroupName(const QString &roomId, const QString &newName) { auto *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) { auto *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) { auto *job = new ChannelInfoJob(this); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::groupInfo(const QString &roomId) { auto *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) { auto *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) { auto *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) { auto *job = new SaveNotificationJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setDesktopNotifications(value); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::emailNotifications(const QString &roomId, const QString &value) { auto *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) { auto *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) { auto *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) { auto *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) { auto *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) { auto *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) { auto *job = new IgnoreUserJob(this); initializeRestApiJob(job); job->setIgnoreUserId(userId); job->setRoomId(roomId); job->setIgnore(ignore); connect(job, &IgnoreUserJob::ignoreUserDone, this, &RestApiRequest::ignoreUserDone); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::userPresence(const QString &userId) { auto *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) { auto *job = new ReportMessageJob(this); initializeRestApiJob(job); job->setMessageId(messageId); job->setReportMessage(message); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::setGroupType(const QString &roomId, bool isPrivate) { auto *job = new SetGroupTypeJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setType(isPrivate ? SetGroupTypeJob::Private : SetGroupTypeJob::Public); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::setChannelType(const QString &roomId, bool isPrivate) { auto *job = new SetChannelTypeJob(this); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); job->setType(isPrivate ? SetChannelTypeJob::Private : SetChannelTypeJob::Public); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::getGroupRoles(const QString &roomId) { auto *job = new GetGroupRolesJob(this); initializeRestApiJob(job); job->setRoomId(roomId); - connect(job, &GetGroupRolesJob::groupRolesDone, this, &RestApiRequest::channelRolesDone); + connect(job, &GetGroupRolesJob::groupRolesDone, this, &RestApiRequest::groupRolesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getGroupRoles job"; } } void RestApiRequest::getChannelRoles(const QString &roomId) { auto *job = new GetChannelRolesJob(this); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); connect(job, &GetChannelRolesJob::channelRolesDone, this, &RestApiRequest::channelRolesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GetChannelRolesJob job"; } } void RestApiRequest::getUsernameSuggestion() { auto *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() { auto *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() { auto *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() { auto *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) { auto *job = new SetJoinCodeChannelJob(this); initializeRestApiJob(job); job->setJoinCode(joinCode); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); + connect(job, &SetJoinCodeChannelJob::setJoinCodeDone, this, &RestApiRequest::setJoinCodeDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start setjoincode"; } } void RestApiRequest::updatejitsiTimeOut(const QString &roomId) { auto *job = new VideoConfUpdateJitsiTimeOutJob(this); initializeRestApiJob(job); job->setRoomId(roomId); connect(job, &VideoConfUpdateJitsiTimeOutJob::updateJitsiTimeOutDone, this, &RestApiRequest::updateJitsiTimeOutDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start VideoConfUpdateJitsiTimeOutJob"; } } void RestApiRequest::channelJoin(const QString &roomId, const QString &joinCode) { auto *job = new ChannelJoinJob(this); initializeRestApiJob(job); job->setJoinCode(joinCode); - job->setRoomName(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); 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, int offset, int count) { auto *job = new ChannelGetAllUserMentionsJob(this); initializeRestApiJob(job); job->setRoomId(roomId); QueryParameters parameters; QMap map; map.insert(QStringLiteral("_updatedAt"), QueryParameters::SortOrder::Descendant); parameters.setSorting(map); parameters.setCount(count); parameters.setOffset(offset); job->setQueryParameters(parameters); connect(job, &ChannelGetAllUserMentionsJob::channelGetAllUserMentionsDone, this, &RestApiRequest::channelGetAllUserMentionsDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start setChannelJoin"; } } void RestApiRequest::channelKick(const QString &roomId, const QString &userId) { auto *job = new ChannelKickJob(this); initializeRestApiJob(job); job->setKickUserId(userId); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); connect(job, &ChannelKickJob::kickUserDone, this, &RestApiRequest::channelKickUserDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start channelKick"; } } void RestApiRequest::groupKick(const QString &roomId, const QString &userId) { auto *job = new GroupsKickJob(this); initializeRestApiJob(job); job->setKickUserId(userId); job->setRoomId(roomId); connect(job, &GroupsKickJob::kickUserDone, this, &RestApiRequest::groupKickUserDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start channelKick"; } } void RestApiRequest::groupAddModerator(const QString &roomId, const QString &userId) { auto *job = new GroupAddModeratorJob(this); initializeRestApiJob(job); job->setAddModeratorUserId(userId); job->setRoomId(roomId); connect(job, &GroupAddModeratorJob::addModeratorDone, this, &RestApiRequest::addModeratorDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start groupAddModerator"; } } void RestApiRequest::groupRemoveModerator(const QString &roomId, const QString &userId) { auto *job = new GroupRemoveModeratorJob(this); initializeRestApiJob(job); job->setRemoveUserId(userId); job->setRoomId(roomId); connect(job, &GroupRemoveModeratorJob::removeModeratorDone, this, &RestApiRequest::removeModeratorDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start groupRemoveModerator"; } } void RestApiRequest::groupAddLeader(const QString &roomId, const QString &userId) { auto *job = new GroupAddLeaderJob(this); initializeRestApiJob(job); job->setAddLeaderUserId(userId); job->setRoomId(roomId); connect(job, &GroupAddLeaderJob::addLeaderDone, this, &RestApiRequest::addLeaderDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start groupAddLeader"; } } void RestApiRequest::groupRemoveLeader(const QString &roomId, const QString &userId) { auto *job = new GroupRemoveLeaderJob(this); initializeRestApiJob(job); job->setRemoveUserId(userId); job->setRoomId(roomId); connect(job, &GroupRemoveLeaderJob::removeLeaderDone, this, &RestApiRequest::removeLeaderDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start groupRemoveLeader"; } } void RestApiRequest::groupAddOwner(const QString &roomId, const QString &userId) { auto *job = new GroupAddOwnerJob(this); initializeRestApiJob(job); job->setAddownerUserId(userId); job->setRoomId(roomId); connect(job, &GroupAddOwnerJob::addOwnerDone, this, &RestApiRequest::addOwnerDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start groupAddOwner"; } } void RestApiRequest::groupRemoveOwner(const QString &roomId, const QString &userId) { auto *job = new GroupRemoveOwnerJob(this); initializeRestApiJob(job); job->setRemoveUserId(userId); job->setRoomId(roomId); connect(job, &GroupRemoveOwnerJob::removeOwnerDone, this, &RestApiRequest::removeOwnerDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start groupRemoveOwner"; } } void RestApiRequest::channelAddModerator(const QString &roomId, const QString &userId) { auto *job = new ChannelAddModeratorJob(this); initializeRestApiJob(job); job->setAddModeratorUserId(userId); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); connect(job, &ChannelAddModeratorJob::addModeratorDone, this, &RestApiRequest::addModeratorDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start channelAddModerator"; } } void RestApiRequest::channelRemoveModerator(const QString &roomId, const QString &userId) { auto *job = new ChannelRemoveModeratorJob(this); initializeRestApiJob(job); job->setRemoveUserId(userId); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); connect(job, &ChannelRemoveModeratorJob::removeModeratorDone, this, &RestApiRequest::removeModeratorDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelRemoveModeratorJob"; } } void RestApiRequest::channelAddLeader(const QString &roomId, const QString &userId) { auto *job = new ChannelAddLeaderJob(this); initializeRestApiJob(job); job->setAddLeaderUserId(userId); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); connect(job, &ChannelAddLeaderJob::addLeaderDone, this, &RestApiRequest::addLeaderDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start channelAddLeader"; } } void RestApiRequest::channelRemoveLeader(const QString &roomId, const QString &userId) { auto *job = new ChannelRemoveLeaderJob(this); initializeRestApiJob(job); job->setRemoveUserId(userId); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); connect(job, &ChannelRemoveLeaderJob::removeLeaderDone, this, &RestApiRequest::removeLeaderDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start channelRemoveLeader"; } } void RestApiRequest::channelAddOwner(const QString &roomId, const QString &userId) { auto *job = new ChannelAddOwnerJob(this); initializeRestApiJob(job); job->setAddownerUserId(userId); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); connect(job, &ChannelAddOwnerJob::addOwnerDone, this, &RestApiRequest::addOwnerDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelAddOwnerJob"; } } void RestApiRequest::channelRemoveOwner(const QString &roomId, const QString &userId) { auto *job = new ChannelRemoveOwnerJob(this); initializeRestApiJob(job); job->setRemoveUserId(userId); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); connect(job, &ChannelRemoveOwnerJob::removeOwnerDone, this, &RestApiRequest::removeOwnerDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelRemoveOwnerJob"; } } void RestApiRequest::channelDelete(const QString &roomId) { auto *job = new ChannelDeleteJob(this); initializeRestApiJob(job); - job->setRoomId(roomId); + ChannelBaseJob::ChannelInfo info; + info.channelInfoType = ChannelBaseJob::ChannelInfoType::RoomId; + info.channelInfoIdentifier = roomId; + job->setChannelInfo(info); connect(job, &ChannelDeleteJob::deletechannelDone, this, &RestApiRequest::deletechannelDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ChannelDeleteJob"; } } void RestApiRequest::groupDelete(const QString &roomId) { auto *job = new GroupsDeleteJob(this); initializeRestApiJob(job); job->setRoomId(roomId); connect(job, &GroupsDeleteJob::deleteGroupsDone, this, &RestApiRequest::deleteGroupsDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start GroupsDeleteJob"; } } void RestApiRequest::pinMessage(const QString &messageId, bool pinned) { auto *job = new PinMessageJob(this); initializeRestApiJob(job); job->setMessageId(messageId); job->setPinMessage(pinned); connect(job, &PinMessageJob::pinMessageDone, this, &RestApiRequest::pinMessageDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start PinMessageJob"; } } void RestApiRequest::followMessage(const QString &messageId) { auto *job = new FollowMessageJob(this); initializeRestApiJob(job); job->setMessageId(messageId); connect(job, &FollowMessageJob::followMessageDone, this, &RestApiRequest::followMessageDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start FollowMessageJob"; } } void RestApiRequest::unFollowMessage(const QString &messageId) { auto *job = new UnFollowMessageJob(this); initializeRestApiJob(job); job->setMessageId(messageId); connect(job, &UnFollowMessageJob::unFollowMessageDone, this, &RestApiRequest::unFollowMessageDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start unFollowMessageDone"; } } void RestApiRequest::createDiscussion(const QString &parentRoomId, const QString &discussionName, const QString &replyMessage, const QString &parentMessageId, const QStringList &users) { auto *job = new RoomStartDiscussionJob(this); initializeRestApiJob(job); job->setParentRoomId(parentRoomId); job->setDiscussionName(discussionName); job->setParentMessageId(parentMessageId); job->setReplyMessage(replyMessage); job->setUsers(users); connect(job, &RoomStartDiscussionJob::startDiscussionDone, this, &RestApiRequest::startDiscussionDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start roomStartDiscussion"; } } void RestApiRequest::getDiscussions(const QString &roomId, int offset, int count) { auto *job = new GetDiscussionsJob(this); initializeRestApiJob(job); QueryParameters parameters; parameters.setCount(count); parameters.setOffset(offset); job->setQueryParameters(parameters); job->setRoomId(roomId); connect(job, &GetDiscussionsJob::getDiscussionsDone, this, &RestApiRequest::getDiscussionsDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getDiscussions"; } } void RestApiRequest::getThreadsList(const QString &roomId, int offset, int count) { auto *job = new GetThreadsJob(this); initializeRestApiJob(job); job->setRoomId(roomId); QueryParameters parameters; QMap map; map.insert(QStringLiteral("_updatedAt"), QueryParameters::SortOrder::Descendant); parameters.setSorting(map); parameters.setCount(count); parameters.setOffset(offset); job->setQueryParameters(parameters); connect(job, &GetThreadsJob::getThreadsDone, this, &RestApiRequest::getThreadsDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getThreadsList"; } } void RestApiRequest::getPinnedMessages(const QString &roomId, int offset, int count) { auto *job = new GetPinnedMessagesJob(this); initializeRestApiJob(job); job->setRoomId(roomId); QueryParameters parameters; parameters.setCount(count); parameters.setOffset(offset); job->setQueryParameters(parameters); connect(job, &GetPinnedMessagesJob::getPinnedMessagesDone, this, &RestApiRequest::getPinnedMessagesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getPinnedMessagesList"; } } void RestApiRequest::getStarredMessages(const QString &roomId, int offset, int count) { auto *job = new GetStarredMessagesJob(this); initializeRestApiJob(job); job->setRoomId(roomId); QueryParameters parameters; parameters.setCount(count); parameters.setOffset(offset); job->setQueryParameters(parameters); connect(job, &GetStarredMessagesJob::getStarredMessagesDone, this, &RestApiRequest::getStarredMessagesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getStarredMessagesList"; } } void RestApiRequest::getSnippetedMessages(const QString &roomId, int offset, int count) { auto *job = new GetSnippetedMessagesJob(this); initializeRestApiJob(job); job->setRoomId(roomId); QueryParameters parameters; parameters.setCount(count); parameters.setOffset(offset); job->setQueryParameters(parameters); connect(job, &GetSnippetedMessagesJob::getSnippetedMessagesDone, this, &RestApiRequest::getSnippetedMessagesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getSnippetedMessagesList"; } } void RestApiRequest::getThreadMessages(const QString &threadMessageId) { auto *job = new GetThreadMessagesJob(this); initializeRestApiJob(job); job->setThreadMessageId(threadMessageId); connect(job, &GetThreadMessagesJob::getThreadMessagesDone, this, &RestApiRequest::getThreadMessagesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getThreadMessages"; } } void RestApiRequest::syncThreadMessages(const QString &threadMessageId, const QString ×tamp) { auto *job = new SyncThreadMessagesJob(this); initializeRestApiJob(job); job->setThreadMessageId(threadMessageId); job->setTimeStamp(timestamp); connect(job, &SyncThreadMessagesJob::syncThreadMessagesDone, this, &RestApiRequest::syncThreadMessagesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start syncThreadMessages"; } } void RestApiRequest::sendMessage(const QString &roomId, const QString &text, const QString &messageId, const QString &threadMessageId) { auto *job = new SendMessageJob(this); initializeRestApiJob(job); SendMessageJob::SendMessageArguments args; args.roomId = roomId; args.message = text; args.messageId = messageId; args.threadMessageId = threadMessageId; job->setSendMessageArguments(args); if (!job->start()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start job"; } } void RestApiRequest::getSupportedLanguagesMessages() { auto *job = new GetSupportedLanguagesJob(this); initializeRestApiJob(job); connect(job, &GetSupportedLanguagesJob::getSupportedLanguagesDone, this, &RestApiRequest::getSupportedLanguagesDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start getSupportedLanguagesMessages"; } } void RestApiRequest::autoTranslateSaveLanguageSettings(const QString &roomId, const QString &language) { auto *job = new TranslateSaveSettingsJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setType(TranslateSaveSettingsJob::LanguageSetting); job->setLanguage(language); connect(job, &TranslateSaveSettingsJob::translateSavesettingsDone, this, &RestApiRequest::translateSavesettingsDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start autoTranslateSaveLanguageSettings"; } } void RestApiRequest::autoTranslateSaveAutoTranslateSettings(const QString &roomId, bool autoTranslate) { auto *job = new TranslateSaveSettingsJob(this); initializeRestApiJob(job); job->setRoomId(roomId); job->setType(TranslateSaveSettingsJob::AutoTranslateSetting); job->setAutoTranslate(autoTranslate); connect(job, &TranslateSaveSettingsJob::translateSavesettingsDone, this, &RestApiRequest::translateSavesettingsDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start autoTranslateSaveAutoTranslateSettings"; } } void RestApiRequest::setUserStatus(const QString &userId, SetStatusJob::StatusType status, const QString &message) { auto *job = new SetStatusJob(this); initializeRestApiJob(job); job->setStatusUserId(userId); job->setStatus(status); job->setStatusMessage(message); connect(job, &SetStatusJob::setStatusDone, this, &RestApiRequest::setStatusDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start SetStatusJob"; } } void RestApiRequest::usersPresence() { auto *job = new UsersPresenceJob(this); initializeRestApiJob(job); connect(job, &UsersPresenceJob::usersPresenceDone, this, &RestApiRequest::usersPresenceDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start usersPresenceJob"; } } void RestApiRequest::customUserStatus() { auto *job = new CustomUserStatusJob(this); initializeRestApiJob(job); connect(job, &CustomUserStatusJob::customUserStatusDone, this, &RestApiRequest::customUserStatusDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start CustomUserStatusJob"; } } void RestApiRequest::customSounds() { auto *job = new CustomSoundsJob(this); initializeRestApiJob(job); connect(job, &CustomSoundsJob::customSoundsDone, this, &RestApiRequest::customSoundsDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start CustomSoundsJob"; } } void RestApiRequest::usersAutocomplete(const UsersAutocompleteJob::UsersAutocompleterInfo &info) { auto *job = new UsersAutocompleteJob(this); job->setUsersCompleterInfo(info); initializeRestApiJob(job); connect(job, &UsersAutocompleteJob::usersAutocompleteDone, this, &RestApiRequest::usersAutocompleteDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start UsersAutocompleteJob"; } } void RestApiRequest::roomsAutocomplete(const RoomsAutocompleteChannelAndPrivateJob::RoomsAutocompleteChannelAndPrivateInfo &info) { auto *job = new RoomsAutocompleteChannelAndPrivateJob(this); job->setRoomsCompleterInfo(info); initializeRestApiJob(job); connect(job, &RoomsAutocompleteChannelAndPrivateJob::roomsAutoCompleteChannelAndPrivateDone, this, &RestApiRequest::roomsAutoCompleteChannelAndPrivateDone); if (!job->start()) { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start RoomsAutocompleteChannelAndPrivateJob"; } } diff --git a/src/rocketchatrestapi-qt5/restapirequest.h b/src/rocketchatrestapi-qt5/restapirequest.h index 44952775..2c306a10 100644 --- a/src/rocketchatrestapi-qt5/restapirequest.h +++ b/src/rocketchatrestapi-qt5/restapirequest.h @@ -1,264 +1,266 @@ /* Copyright (c) 2017-2020 Laurent Montel 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 "channels/channelbasejob.h" #include "rooms/roomsautocompletechannelandprivatejob.h" #include "restapiutil.h" #include "users/setstatusjob.h" #include "users/usersautocompletejob.h" #include "librocketchatrestapi-qt5_export.h" class QNetworkAccessManager; class QNetworkReply; class QNetworkCookieJar; namespace RocketChatRestApi { class RestApiAbstractJob; class AbstractLogger; class LIBROCKETCHATRESTAPI_QT5_EXPORT RestApiRequest : public QObject { Q_OBJECT public: explicit RestApiRequest(QObject *parent = nullptr); ~RestApiRequest() override; 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(bool useDeprecatedVersion); 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, bool archive); void archiveGroups(const QString &roomId, bool archive); void filesInRoom(const QString &roomId, const QString &type, int offset = 0, int count = 50); 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, bool isPrivate); void setChannelType(const QString &roomId, bool isPrivate); 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 syncThreadMessages(const QString &threadMessageId, const QString ×tamp); 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, int offset = 0, int count = 50); void updatejitsiTimeOut(const QString &roomId); void openDirectMessage(const QString &userId); void channelKick(const QString &roomId, const QString &userId); void groupKick(const QString &roomId, const QString &userId); void groupAddModerator(const QString &roomId, const QString &userId); void groupRemoveModerator(const QString &roomId, const QString &userId); void groupAddLeader(const QString &roomId, const QString &userId); void groupRemoveLeader(const QString &roomId, const QString &userId); void groupAddOwner(const QString &roomId, const QString &userId); void groupRemoveOwner(const QString &roomId, const QString &userId); void channelAddModerator(const QString &roomId, const QString &userId); void channelRemoveModerator(const QString &roomId, const QString &userId); void channelAddOwner(const QString &roomId, const QString &userId); void channelRemoveOwner(const QString &roomId, const QString &userId); void channelDelete(const QString &roomId); void groupDelete(const QString &roomId); void membersInRoom(const QString &roomId, const QString &type, int offset = 0, int count = 50); void changeChannelReadOnly(const QString &roomId, bool b); void changeGroupsReadOnly(const QString &roomId, bool b); void channelAddLeader(const QString &roomId, const QString &userId); void channelRemoveLeader(const QString &roomId, const QString &userId); void changeChannelEncrypted(const QString &roomId, bool b); void changeGroupsEncrypted(const QString &roomId, bool b); void pinMessage(const QString &messageId, bool pinned); void desktopDurationNotifications(const QString &roomId, int value); void desktopSoundNotifications(const QString &roomId, const QString &value); void followMessage(const QString &messageId); void unFollowMessage(const QString &messageId); void createDiscussion(const QString &parentRoomId, const QString &discussionName, const QString &replyMessage, const QString &parentMessageId, const QStringList &users); void getDiscussions(const QString &roomId, int offset = 0, int count = 50); void getThreadsList(const QString &roomId, int offset = 0, int count = 50); void getThreadMessages(const QString &threadMessageId); void sendMessage(const QString &roomId, const QString &text, const QString &messageId = QString(), const QString &threadMessageId = QString()); void getPinnedMessages(const QString &roomId, int offset = 0, int count = 50); void getSupportedLanguagesMessages(); void autoTranslateSaveLanguageSettings(const QString &roomId, const QString &language); void autoTranslateSaveAutoTranslateSettings(const QString &roomId, bool autoTranslate); void setUserStatus(const QString &userId, SetStatusJob::StatusType status, const QString &message = QString()); void usersPresence(); void getStarredMessages(const QString &roomId, int offset = 0, int count = 50); void getSnippetedMessages(const QString &roomId, int offset = 0, int count = 50); void customUserStatus(); void customSounds(); void usersAutocomplete(const UsersAutocompleteJob::UsersAutocompleterInfo &info); void roomsAutocomplete(const RoomsAutocompleteChannelAndPrivateJob::RoomsAutocompleteChannelAndPrivateInfo &info); Q_SIGNALS: void avatar(const QString &userId, const QString &url); void redownloadAvatar(); 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 getServerInfoFailed(bool useDeprecatedVersion); void getOwnInfoDone(const QJsonObject &data); void privateInfoDone(const QByteArray &data); - void channelFilesDone(const QJsonObject &obj, const QString &roomId); - void channelMembersDone(const QJsonObject &obj, const QString &roomId); + void channelFilesDone(const QJsonObject &obj, const ChannelBaseJob::ChannelInfo &channelInfo); + void channelMembersDone(const QJsonObject &obj, const ChannelBaseJob::ChannelInfo &channelInfo); void syncThreadMessagesDone(const QJsonObject &obj, const QString &threadMessageId); 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 channelRolesDone(const QJsonObject &obj, const QString &roomId); + void channelRolesDone(const QJsonObject &obj, const ChannelBaseJob::ChannelInfo &channelInfo); 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 setChannelJoinDone(const ChannelBaseJob::ChannelInfo &channelInfo); + void missingChannelPassword(const ChannelBaseJob::ChannelInfo &channelInfo); + void openArchivedRoom(const ChannelBaseJob::ChannelInfo &channelInfo); void channelGetAllUserMentionsDone(const QJsonObject &obj, const QString &roomId); void updateJitsiTimeOutDone(const QString &datetime); void channelKickUserDone(const QJsonObject &obj); void groupKickUserDone(const QJsonObject &obj); void addModeratorDone(); void removeModeratorDone(); void addLeaderDone(); void removeLeaderDone(); void addOwnerDone(); void removeOwnerDone(); void deletechannelDone(); void deleteGroupsDone(); void pinMessageDone(); void ignoreUserDone(const QJsonObject &obj, const QString &roomId); + void groupRolesDone(const QJsonObject &obj, const QString &roomId); void followMessageDone(); void unFollowMessageDone(); void startDiscussionDone(); void getDiscussionsDone(const QJsonObject &obj, const QString &roomId); void getThreadsDone(const QJsonObject &obj, const QString &roomId); void getThreadMessagesDone(const QJsonObject &obj, const QString &threadMessageId); void getPinnedMessagesDone(const QJsonObject &obj, const QString &roomId); void getStarredMessagesDone(const QJsonObject &obj, const QString &roomId); void getSnippetedMessagesDone(const QJsonObject &obj, const QString &roomId); void getSupportedLanguagesDone(const QJsonObject &obj); void translateSavesettingsDone(); void setStatusDone(); void usersPresenceDone(const QJsonObject &obj); void customUserStatusDone(const QByteArray &); //TODO QByteArray or QJson ? void customSoundsDone(const QByteArray &); //TODO QByteArray or QJson ? void usersAutocompleteDone(const QJsonObject &obj); void roomsAutoCompleteChannelAndPrivateDone(const QJsonObject &obj); void failed(const QString &str); 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/widgets/ruqolamainwindow.cpp b/src/widgets/ruqolamainwindow.cpp index a696f665..b004bda3 100644 --- a/src/widgets/ruqolamainwindow.cpp +++ b/src/widgets/ruqolamainwindow.cpp @@ -1,478 +1,479 @@ /* Copyright (c) 2020 Laurent Montel 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 "ruqolamainwindow.h" #include "config-ruqola.h" #include "ruqola.h" #include "rocketchataccount.h" #include "accountmanager.h" #include "roomwrapper.h" #include "receivetypingnotificationmanager.h" #include "ruqolacentralwidget.h" #include "misc/accountmenu.h" #include "misc/accountsoverviewwidget.h" #include "dialogs/serverinfodialog.h" #include "dialogs/searchchanneldialog.h" #include "dialogs/createnewchanneldialog.h" #include "dialogs/createnewaccountdialog.h" #include "dialogs/showpinnedmessagesdialog.h" #include "dialogs/showstarredmessagesdialog.h" #include "dialogs/showmentionsmessagesdialog.h" #include "dialogs/showsnipperedmessagesdialog.h" #include "dialogs/searchmessagedialog.h" #include "dialogs/configurenotificationdialog.h" #include "dialogs/showattachmentdialog.h" #include "dialogs/showdiscussionsdialog.h" #include "dialogs/showthreadsdialog.h" #include "dialogs/channelpassworddialog.h" #include "dialogs/channelinfodialog.h" #include "dialogs/directchannelinfodialog.h" #include "dialogs/addusersinroomdialog.h" #include "configuredialog/configuresettingsdialog.h" #include #include #include #include #include #include #include #include #if HAVE_KUSERFEEDBACK #include "userfeedback/userfeedbackmanager.h" #include #include #endif namespace { static const char myConfigGroupName[] = "RuqolaMainWindow"; } RuqolaMainWindow::RuqolaMainWindow(QWidget *parent) : KXmlGuiWindow(parent) { mMainWidget = new RuqolaCentralWidget(this); mMainWidget->setObjectName(QStringLiteral("mMainWidget")); connect(mMainWidget, &RuqolaCentralWidget::channelSelected, this, [this]() { changeActionStatus(true); }); setCentralWidget(mMainWidget); setupActions(); setupStatusBar(); setupGUI(/*QStringLiteral(":/kxmlgui5/ruqola/ruqolaui.rc")*/); readConfig(); connect(Ruqola::self()->accountManager(), &AccountManager::currentAccountChanged, this, &RuqolaMainWindow::slotAccountChanged); slotAccountChanged(); #if HAVE_KUSERFEEDBACK KUserFeedback::NotificationPopup *userFeedBackNotificationPopup = new KUserFeedback::NotificationPopup(this); userFeedBackNotificationPopup->setFeedbackProvider(UserFeedBackManager::self()->userFeedbackProvider()); #endif } RuqolaMainWindow::~RuqolaMainWindow() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(myConfigGroupName); group.writeEntry("Size", size()); Ruqola::destroy(); } void RuqolaMainWindow::setupStatusBar() { mStatusBarTypingMessage = new QLabel(this); mStatusBarTypingMessage->setTextFormat(Qt::RichText); mStatusBarTypingMessage->setObjectName(QStringLiteral("mStatusBarTypingMessage")); statusBar()->addPermanentWidget(mStatusBarTypingMessage); mAccountOverviewWidget = new AccountsOverviewWidget(this); statusBar()->addPermanentWidget(mAccountOverviewWidget); } void RuqolaMainWindow::slotAccountChanged() { if (mCurrentRocketChatAccount) { disconnect(mCurrentRocketChatAccount, nullptr, this, nullptr); } mCurrentRocketChatAccount = Ruqola::self()->rocketChatAccount(); connect(mCurrentRocketChatAccount->receiveTypingNotificationManager(), &ReceiveTypingNotificationManager::notificationChanged, this, &RuqolaMainWindow::slotTypingNotificationChanged); connect(mCurrentRocketChatAccount->receiveTypingNotificationManager(), &ReceiveTypingNotificationManager::clearNotification, this, &RuqolaMainWindow::slotClearNotification); connect(mCurrentRocketChatAccount, &RocketChatAccount::missingChannelPassword, this, &RuqolaMainWindow::slotMissingChannelPassword); connect(mCurrentRocketChatAccount, &RocketChatAccount::publicSettingChanged, this, &RuqolaMainWindow::updateActions); connect(mCurrentRocketChatAccount, &RocketChatAccount::serverVersionChanged, this, &RuqolaMainWindow::updateActions); updateActions(); changeActionStatus(false); //Disable actions when switching. slotClearNotification(); //Clear notification when we switch too. mMainWidget->setCurrentRocketChatAccount(mCurrentRocketChatAccount); } void RuqolaMainWindow::changeActionStatus(bool enabled) { mShowMentions->setEnabled(enabled); mShowPinnedMessages->setEnabled(enabled); mShowStarredMessages->setEnabled(enabled); mShowSnipperedMessages->setEnabled(enabled); mSearchMessages->setEnabled(enabled); mConfigureNotification->setEnabled(enabled); mLoadChannelHistory->setEnabled(enabled); mShowFileAttachments->setEnabled(enabled); mShowDiscussions->setEnabled(enabled); mShowThreads->setEnabled(enabled); mChannelInfo->setEnabled(enabled); mListOfUsers->setEnabled(enabled); mStartVideoChat->setEnabled(enabled); RoomWrapper *roomWrapper = mMainWidget->roomWrapper(); mAddUserInRooms->setEnabled(enabled && roomWrapper && roomWrapper->canBeModify()); } void RuqolaMainWindow::updateActions() { mUnreadOnTop->setChecked(mCurrentRocketChatAccount->sortUnreadOnTop()); mShowPinnedMessages->setVisible(mCurrentRocketChatAccount->hasPinnedMessagesSupport() && mCurrentRocketChatAccount->allowMessagePinningEnabled()); mShowStarredMessages->setVisible(mCurrentRocketChatAccount->hasStarredMessagesSupport() && mCurrentRocketChatAccount->allowMessageStarringEnabled()); mShowSnipperedMessages->setVisible(mCurrentRocketChatAccount->hasSnippetedMessagesSupport() && mCurrentRocketChatAccount->allowMessageSnippetingEnabled()); mStartVideoChat->setVisible(mCurrentRocketChatAccount->jitsiEnabled()); } void RuqolaMainWindow::readConfig() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = KConfigGroup(config, myConfigGroupName); const QSize sizeDialog = group.readEntry("Size", QSize(800, 600)); if (sizeDialog.isValid()) { resize(sizeDialog); } } void RuqolaMainWindow::slotClearNotification() { mStatusBarTypingMessage->clear(); } void RuqolaMainWindow::slotTypingNotificationChanged(const QString &roomId, const QString ¬ificationStr) { if (mMainWidget->roomId() == roomId) { mStatusBarTypingMessage->setText(notificationStr); } } void RuqolaMainWindow::setupActions() { KActionCollection *ac = actionCollection(); KStandardAction::quit(this, &RuqolaMainWindow::close, ac); KStandardAction::preferences(this, &RuqolaMainWindow::slotConfigure, ac); QAction *act = new QAction(i18n("Add Account..."), this); connect(act, &QAction::triggered, this, &RuqolaMainWindow::slotAddAccount); ac->addAction(QStringLiteral("add_account"), act); //Move in specific server widget mServerInfo = new QAction(i18n("Server Info..."), this); connect(mServerInfo, &QAction::triggered, this, &RuqolaMainWindow::slotServerInfo); ac->addAction(QStringLiteral("server_info"), mServerInfo); mLogout = new QAction(i18n("Logout"), this); connect(mLogout, &QAction::triggered, this, &RuqolaMainWindow::slotLogout); ac->addAction(QStringLiteral("logout"), mLogout); mSearchChannel = new QAction(i18n("Search Channel..."), this); connect(mSearchChannel, &QAction::triggered, this, &RuqolaMainWindow::slotSearchChannel); ac->addAction(QStringLiteral("search_channel"), mSearchChannel); mCreateNewChannel = new QAction(i18n("Create New Channel..."), this); connect(mCreateNewChannel, &QAction::triggered, this, &RuqolaMainWindow::slotCreateNewChannel); ac->addAction(QStringLiteral("create_new_channel"), mCreateNewChannel); mShowMentions = new QAction(i18n("Show Mentions..."), this); connect(mShowMentions, &QAction::triggered, this, &RuqolaMainWindow::slotShowMentions); ac->addAction(QStringLiteral("show_mentions"), mShowMentions); mShowPinnedMessages = new QAction(i18n("Show Pinned Messages..."), this); connect(mShowPinnedMessages, &QAction::triggered, this, &RuqolaMainWindow::slotPinnedMessages); ac->addAction(QStringLiteral("show_pinned_messages"), mShowPinnedMessages); mShowStarredMessages = new QAction(i18n("Show Starred Messages..."), this); connect(mShowStarredMessages, &QAction::triggered, this, &RuqolaMainWindow::slotStarredMessages); ac->addAction(QStringLiteral("show_starred_messages"), mShowStarredMessages); mShowSnipperedMessages = new QAction(i18n("Show Snippered Messages..."), this); connect(mShowSnipperedMessages, &QAction::triggered, this, &RuqolaMainWindow::slotSnipperedMessages); ac->addAction(QStringLiteral("show_snippered_messages"), mShowSnipperedMessages); mSearchMessages = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("Search Messages..."), this); ac->setDefaultShortcuts(mSearchMessages, KStandardShortcut::find()); connect(mSearchMessages, &QAction::triggered, this, &RuqolaMainWindow::slotSearchMessages); ac->addAction(QStringLiteral("search_messages"), mSearchMessages); mConfigureNotification = new QAction(QIcon::fromTheme(QStringLiteral("preferences-desktop-notification")), i18n("Configure Notification..."), this); connect(mConfigureNotification, &QAction::triggered, this, &RuqolaMainWindow::slotConfigureNotification); ac->addAction(QStringLiteral("configure_notification"), mConfigureNotification); mLoadChannelHistory = new QAction(i18n("Load Recent History"), this); connect(mLoadChannelHistory, &QAction::triggered, this, &RuqolaMainWindow::slotLoadRecentHistory); ac->addAction(QStringLiteral("load_recent_history"), mLoadChannelHistory); mShowFileAttachments = new QAction(i18n("Show File Attachment..."), this); connect(mShowFileAttachments, &QAction::triggered, this, &RuqolaMainWindow::slotShowFileAttachments); ac->addAction(QStringLiteral("show_file_attachments"), mShowFileAttachments); mAccountMenu = new AccountMenu(this); ac->addAction(QStringLiteral("account_menu"), mAccountMenu); mShowDiscussions = new QAction(i18n("Show Discussions..."), this); connect(mShowDiscussions, &QAction::triggered, this, &RuqolaMainWindow::slotShowDiscussions); ac->addAction(QStringLiteral("show_discussions"), mShowDiscussions); mShowThreads = new QAction(i18n("Show Threads..."), this); connect(mShowThreads, &QAction::triggered, this, &RuqolaMainWindow::slotShowThreads); ac->addAction(QStringLiteral("show_threads"), mShowThreads); mUnreadOnTop = new QAction(i18n("Unread on Top"), this); mUnreadOnTop->setCheckable(true); connect(mUnreadOnTop, &QAction::triggered, this, &RuqolaMainWindow::slotUnreadOnTop); ac->addAction(QStringLiteral("unread_on_top"), mUnreadOnTop); mChannelInfo = new QAction(i18n("Channel Info..."), this); connect(mChannelInfo, &QAction::triggered, this, &RuqolaMainWindow::slotShowChannelInfo); ac->addAction(QStringLiteral("channel_info"), mChannelInfo); mAddUserInRooms = new QAction(i18n("Add Users in Channel..."), this); connect(mAddUserInRooms, &QAction::triggered, this, &RuqolaMainWindow::slotAddUsersInRoom); ac->addAction(QStringLiteral("add_user_in_room"), mAddUserInRooms); auto clearAlerts = new QAction(i18n("Mark all channels read"), this); ac->setDefaultShortcut(clearAlerts, Qt::SHIFT + Qt::Key_Escape); connect(clearAlerts, &QAction::triggered, this, &RuqolaMainWindow::slotClearAccountAlerts); ac->addAction(QStringLiteral("mark_all_channels_read"), clearAlerts); mListOfUsers = new QAction(QIcon::fromTheme(QStringLiteral("system-users")), i18n("List of Users"), this); connect(mListOfUsers, &QAction::triggered, this, &RuqolaMainWindow::slotListOfUsersInRoom); ac->addAction(QStringLiteral("list_of_users_in_room"), mListOfUsers); mStartVideoChat = new QAction(QIcon::fromTheme(QStringLiteral("camera-video")), i18n("Video Chat"), this); connect(mStartVideoChat, &QAction::triggered, this, &RuqolaMainWindow::slotStartVideoChat); ac->addAction(QStringLiteral("video_chat"), mStartVideoChat); } void RuqolaMainWindow::slotAddUsersInRoom() { QPointer dlg = new AddUsersInRoomDialog(this); if (dlg->exec()) { qWarning() << " Not implement yet"; } delete dlg; } void RuqolaMainWindow::slotClearAccountAlerts() { if (auto acct = Ruqola::self()->accountManager()->account()) { acct->clearAllUnreadMessages(); } } void RuqolaMainWindow::slotShowThreads() { QPointer dlg = new ShowThreadsDialog(this); dlg->setModel(mCurrentRocketChatAccount->threadsFilterProxyModel()); const QString roomId = mMainWidget->roomId(); mCurrentRocketChatAccount->threadsInRoom(roomId); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotShowDiscussions() { QPointer dlg = new ShowDiscussionsDialog(this); dlg->setModel(mCurrentRocketChatAccount->discussionsFilterProxyModel()); const QString roomId = mMainWidget->roomId(); mCurrentRocketChatAccount->discussionsInRoom(roomId); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotShowChannelInfo() { RoomWrapper *roomWrapper = mMainWidget->roomWrapper(); if (roomWrapper) { const QString roomType = mMainWidget->roomType(); if (roomType == QLatin1String("d")) { QPointer dlg = new DirectChannelInfoDialog(this); dlg->exec(); delete dlg; } else { QPointer dlg = new ChannelInfoDialog(this); dlg->setRoomWrapper(roomWrapper); dlg->exec(); delete dlg; } } } void RuqolaMainWindow::slotShowFileAttachments() { QPointer dlg = new ShowAttachmentDialog(this); const QString roomId = mMainWidget->roomId(); const QString roomType = mMainWidget->roomType(); mCurrentRocketChatAccount->roomFiles(roomId, roomType); dlg->setModel(mCurrentRocketChatAccount->filesForRoomFilterProxyModel()); dlg->setRoomId(roomId); dlg->setRoomType(roomType); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotLoadRecentHistory() { mCurrentRocketChatAccount->loadHistory(mMainWidget->roomId()); } void RuqolaMainWindow::slotConfigureNotification() { QPointer dlg = new ConfigureNotificationDialog(this); dlg->setRoomWrapper(mMainWidget->roomWrapper()); if (dlg->exec()) { } delete dlg; } void RuqolaMainWindow::slotSearchMessages() { QPointer dlg = new SearchMessageDialog(this); dlg->setRoomId(mMainWidget->roomId()); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotStarredMessages() { QPointer dlg = new ShowStarredMessagesDialog(this); dlg->setRoomId(mMainWidget->roomId()); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); mCurrentRocketChatAccount->getListMessages(mMainWidget->roomId(), ListMessagesModel::StarredMessages); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotPinnedMessages() { QPointer dlg = new ShowPinnedMessagesDialog(this); dlg->setRoomId(mMainWidget->roomId()); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); mCurrentRocketChatAccount->getListMessages(mMainWidget->roomId(), ListMessagesModel::PinnedMessages); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotShowMentions() { QPointer dlg = new ShowMentionsMessagesDialog(this); dlg->setRoomId(mMainWidget->roomId()); dlg->setModel(Ruqola::self()->rocketChatAccount()->listMessagesFilterProxyModel()); Ruqola::self()->rocketChatAccount()->getListMessages(mMainWidget->roomId(), ListMessagesModel::MentionsMessages); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotSnipperedMessages() { QPointer dlg = new ShowSnipperedMessagesDialog(this); dlg->setRoomId(mMainWidget->roomId()); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); mCurrentRocketChatAccount->getListMessages(mMainWidget->roomId(), ListMessagesModel::SnipperedMessages); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotCreateNewChannel() { QPointer dlg = new CreateNewChannelDialog(this); if (dlg->exec()) { const CreateNewChannelDialog::NewChannelInfo info = dlg->channelInfo(); mCurrentRocketChatAccount->createNewChannel(info.channelName, info.readOnly, info.privateChannel, info.usersName, info.encryptedRoom, info.password, info.broadCast); } delete dlg; } void RuqolaMainWindow::slotConfigure() { QPointer dlg = new ConfigureSettingsDialog(this); if (dlg->exec()) { mAccountOverviewWidget->updateButtons(); } delete dlg; } void RuqolaMainWindow::slotAddAccount() { QPointer dlg = new CreateNewAccountDialog(this); if (dlg->exec()) { const CreateNewAccountDialog::AccountInfo info = dlg->accountInfo(); Ruqola::self()->accountManager()->addAccount(info.accountName, info.userName, info.serverName); } delete dlg; } void RuqolaMainWindow::slotServerInfo() { QPointer dlg = new ServerInfoDialog(this); dlg->setServerConfigInfo(mCurrentRocketChatAccount->serverConfigInfo()); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotLogout() { mCurrentRocketChatAccount->logOut(); } void RuqolaMainWindow::slotSearchChannel() { QPointer dlg = new SearchChannelDialog(this); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotUnreadOnTop(bool checked) { mCurrentRocketChatAccount->setSortUnreadOnTop(checked); } -void RuqolaMainWindow::slotMissingChannelPassword(const QString &roomId) +void RuqolaMainWindow::slotMissingChannelPassword(const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo) { //TODO move in room page ? QPointer dlg = new ChannelPasswordDialog(this); //TODO add channel name! if (dlg->exec()) { - mCurrentRocketChatAccount->joinRoom(roomId, dlg->password()); + //FIXME channelinfo + mCurrentRocketChatAccount->joinRoom(channelInfo.channelInfoIdentifier, dlg->password()); } delete dlg; } void RuqolaMainWindow::slotListOfUsersInRoom() { //TODO } void RuqolaMainWindow::slotStartVideoChat() { mCurrentRocketChatAccount->createJitsiConfCall(mMainWidget->roomId()); } diff --git a/src/widgets/ruqolamainwindow.h b/src/widgets/ruqolamainwindow.h index 35c2265c..dfd5f65e 100644 --- a/src/widgets/ruqolamainwindow.h +++ b/src/widgets/ruqolamainwindow.h @@ -1,99 +1,100 @@ /* Copyright (c) 2020 Laurent Montel 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 RUQOLAMAINWINDOW_H #define RUQOLAMAINWINDOW_H #include #include +#include "channels/channelbasejob.h" #include "libruqolawidgets_export.h" class RuqolaCentralWidget; class QAction; class AccountMenu; class RocketChatAccount; class QLabel; class AccountsOverviewWidget; class LIBRUQOLAWIDGETS_EXPORT RuqolaMainWindow : public KXmlGuiWindow { Q_OBJECT public: explicit RuqolaMainWindow(QWidget *parent = nullptr); ~RuqolaMainWindow() override; private: void setupActions(); void readConfig(); void setupStatusBar(); void slotAddAccount(); void slotServerInfo(); void slotConfigure(); void slotLogout(); void slotSearchChannel(); void slotCreateNewChannel(); void slotShowMentions(); void slotPinnedMessages(); void slotStarredMessages(); void slotSnipperedMessages(); void slotSearchMessages(); void slotConfigureNotification(); void slotTypingNotificationChanged(const QString &roomId, const QString ¬ificationStr); void slotClearNotification(); void slotLoadRecentHistory(); void slotShowFileAttachments(); void slotAccountChanged(); void slotShowDiscussions(); void slotShowThreads(); void slotUnreadOnTop(bool checked); void updateActions(); - void slotMissingChannelPassword(const QString &roomId); + void slotMissingChannelPassword(const RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo); void slotShowChannelInfo(); void slotAddUsersInRoom(); void changeActionStatus(bool enabled); void slotClearAccountAlerts(); void slotListOfUsersInRoom(); void slotStartVideoChat(); RuqolaCentralWidget *mMainWidget = nullptr; QAction *mServerInfo = nullptr; QAction *mLogout = nullptr; QAction *mSearchChannel = nullptr; QAction *mCreateNewChannel = nullptr; QAction *mShowMentions = nullptr; QAction *mShowPinnedMessages = nullptr; QAction *mShowStarredMessages = nullptr; QAction *mShowSnipperedMessages = nullptr; QAction *mSearchMessages = nullptr; QAction *mConfigureNotification = nullptr; QAction *mLoadChannelHistory = nullptr; QAction *mShowFileAttachments = nullptr; QAction *mShowDiscussions = nullptr; QAction *mShowThreads = nullptr; QAction *mUnreadOnTop = nullptr; QAction *mChannelInfo = nullptr; QAction *mAddUserInRooms = nullptr; QAction *mListOfUsers = nullptr; QAction *mStartVideoChat = nullptr; AccountMenu *mAccountMenu = nullptr; QPointer mCurrentRocketChatAccount; QLabel *mStatusBarTypingMessage = nullptr; AccountsOverviewWidget *mAccountOverviewWidget = nullptr; }; #endif // RUQOLAMAINWINDOW_H