diff --git a/src/restapi/rooms/savenotificationjob.cpp b/src/restapi/rooms/savenotificationjob.cpp index a65abb5e..7c95cdd0 100644 --- a/src/restapi/rooms/savenotificationjob.cpp +++ b/src/restapi/rooms/savenotificationjob.cpp @@ -1,230 +1,230 @@ /* Copyright (c) 2018 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "savenotificationjob.h" #include "restapimethod.h" #include "ruqola_restapi_debug.h" #include #include #include SaveNotificationJob::SaveNotificationJob(QObject *parent) : RestApiAbstractJob(parent) { } SaveNotificationJob::~SaveNotificationJob() { } bool SaveNotificationJob::start() { if (!canStart()) { deleteLater(); return false; } const QByteArray baPostData = json().toJson(QJsonDocument::Compact); addLoggerInfo("SaveNotificationJob::start: " + baPostData); QNetworkReply *reply = mNetworkAccessManager->post(request(), baPostData); connect(reply, &QNetworkReply::finished, this, &SaveNotificationJob::slotChangeNotificationFinished); addLoggerInfo(QByteArrayLiteral("SaveNotificationJob: start")); return true; } void SaveNotificationJob::slotChangeNotificationFinished() { QNetworkReply *reply = qobject_cast(sender()); if (reply) { const QByteArray data = reply->readAll(); addLoggerInfo(QByteArrayLiteral("SaveNotificationJob: finished: ") + data); Q_EMIT changeNotificationDone(); } deleteLater(); } QString SaveNotificationJob::unreadAlert() const { return mUnreadAlert; } void SaveNotificationJob::setUnreadAlert(const QString &unreadAlert) { mSettingsWillBeChanged = mSettingsWillBeChanged & UnreadAlert; mUnreadAlert = unreadAlert; } int SaveNotificationJob::desktopNotificationDuration() const { return mDesktopNotificationDuration; } void SaveNotificationJob::setDesktopNotificationDuration(int desktopNotificationDuration) { mSettingsWillBeChanged |= DesktopNotificationDuration; mDesktopNotificationDuration = desktopNotificationDuration; } QString SaveNotificationJob::audioNotificationValue() const { return mAudioNotificationValue; } void SaveNotificationJob::setAudioNotificationValue(const QString &audioNotificationValue) { mSettingsWillBeChanged |= AudioNotificationValue; mAudioNotificationValue = audioNotificationValue; } QString SaveNotificationJob::mobilePushNotifications() const { return mMobilePushNotifications; } void SaveNotificationJob::setMobilePushNotifications(const QString &mobilePushNotifications) { mSettingsWillBeChanged |= MobilePushNotifications; mMobilePushNotifications = mobilePushNotifications; } QString SaveNotificationJob::audioNotifications() const { return mAudioNotifications; } void SaveNotificationJob::setAudioNotifications(const QString &audioNotifications) { mSettingsWillBeChanged |= AudioNotifications; mAudioNotifications = audioNotifications; } QString SaveNotificationJob::emailNotifications() const { return mEmailNotifications; } void SaveNotificationJob::setEmailNotifications(const QString &emailNotifications) { mSettingsWillBeChanged |= EmailNotifications; mEmailNotifications = emailNotifications; } bool SaveNotificationJob::hideUnreadStatus() const { return mHideUnreadStatus; } void SaveNotificationJob::setHideUnreadStatus(bool hideUnreadStatus) { mSettingsWillBeChanged |= HideUnreadStatus; mHideUnreadStatus = hideUnreadStatus; } bool SaveNotificationJob::disableNotifications() const { return mDisableNotifications; } void SaveNotificationJob::setDisableNotifications(bool disableNotifications) { mSettingsWillBeChanged |= DisableNotifications; mDisableNotifications = disableNotifications; } QString SaveNotificationJob::roomId() const { return mRoomId; } void SaveNotificationJob::setRoomId(const QString &roomId) { mRoomId = roomId; } bool SaveNotificationJob::requireHttpAuthentication() const { return true; } bool SaveNotificationJob::canStart() const { if (!RestApiAbstractJob::canStart()) { qCWarning(RUQOLA_RESTAPI_LOG) << "Impossible to start SaveNotificationJob"; return false; } if (mRoomId.isEmpty()) { qCWarning(RUQOLA_RESTAPI_LOG) << "SaveNotificationJob: mRoomId is empty"; return false; } if (mSettingsWillBeChanged == Unknown) { qCWarning(RUQOLA_RESTAPI_LOG) << "SaveNotificationJob: any settings will be changed! it's a bug"; return false; } return true; } QNetworkRequest SaveNotificationJob::request() const { const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::RoomsSaveNotification); QNetworkRequest request(url); addAuthRawHeader(request); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/json")); return request; } QJsonDocument SaveNotificationJob::json() const { QJsonObject jsonObj; jsonObj[QLatin1String("roomId")] = mRoomId; QJsonObject notificationsJson; if (mSettingsWillBeChanged & EmailNotifications) { - + notificationsJson[QLatin1String("emailNotifications")] = emailNotifications(); } if (mSettingsWillBeChanged & AudioNotifications) { - + notificationsJson[QLatin1String("audioNotifications")] = audioNotifications(); } if (mSettingsWillBeChanged & MobilePushNotifications) { - + notificationsJson[QLatin1String("mobilePushNotifications")] = mobilePushNotifications(); } if (mSettingsWillBeChanged & AudioNotificationValue) { - + notificationsJson[QLatin1String("audioNotificationValue")] = audioNotificationValue(); } if (mSettingsWillBeChanged & UnreadAlert) { - + notificationsJson[QLatin1String("unreadAlert")] = unreadAlert(); } if (mSettingsWillBeChanged & DesktopNotificationDuration) { - + notificationsJson[QLatin1String("desktopNotificationDuration")] = desktopNotificationDuration(); } if (mSettingsWillBeChanged & DisableNotifications) { - + notificationsJson[QLatin1String("disableNotifications")] = disableNotifications(); } if (mSettingsWillBeChanged & HideUnreadStatus) { - + notificationsJson[QLatin1String("hideUnreadStatus")] = hideUnreadStatus(); } //TODO don't assign all. => todo add enum jsonObj[QLatin1String("notifications")] = notificationsJson; const QJsonDocument postData = QJsonDocument(jsonObj); return postData; } diff --git a/src/restapi/rooms/savenotificationjob.h b/src/restapi/rooms/savenotificationjob.h index 44a6fafc..c75cae00 100644 --- a/src/restapi/rooms/savenotificationjob.h +++ b/src/restapi/rooms/savenotificationjob.h @@ -1,104 +1,105 @@ /* Copyright (c) 2018 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SAVENOTIFICATIONJOB_H #define SAVENOTIFICATIONJOB_H #include "restapiabstractjob.h" #include "libruqola_private_export.h" class LIBRUQOLACORE_TESTS_EXPORT SaveNotificationJob : public RestApiAbstractJob { Q_OBJECT public: //Since 0.63 explicit SaveNotificationJob(QObject *parent = nullptr); ~SaveNotificationJob() override; bool start() override; bool requireHttpAuthentication() const override; bool canStart() const override; QNetworkRequest request() const override; QJsonDocument json() const; QString roomId() const; void setRoomId(const QString &roomId); bool disableNotifications() const; void setDisableNotifications(bool disableNotifications); bool hideUnreadStatus() const; void setHideUnreadStatus(bool hideUnreadStatus); QString emailNotifications() const; void setEmailNotifications(const QString &emailNotifications); QString audioNotifications() const; void setAudioNotifications(const QString &audioNotifications); QString mobilePushNotifications() const; void setMobilePushNotifications(const QString &mobilePushNotifications); QString audioNotificationValue() const; void setAudioNotificationValue(const QString &audioNotificationValue); int desktopNotificationDuration() const; void setDesktopNotificationDuration(int desktopNotificationDuration); QString unreadAlert() const; void setUnreadAlert(const QString &unreadAlert); Q_SIGNALS: void changeNotificationDone(); private: Q_DISABLE_COPY(SaveNotificationJob) void slotChangeNotificationFinished(); enum SettingChanged { Unknown = 0, EmailNotifications = 1, AudioNotifications = 2, MobilePushNotifications = 4, AudioNotificationValue = 8, UnreadAlert = 16, DesktopNotificationDuration = 32, DisableNotifications = 64, HideUnreadStatus = 128 }; Q_DECLARE_FLAGS(SettingsChanged, SettingChanged) SettingsChanged mSettingsWillBeChanged = SettingChanged::Unknown; QString mRoomId; + //TODO ? desktopNotifications ???? QString mEmailNotifications; QString mAudioNotifications; QString mMobilePushNotifications; QString mAudioNotificationValue; QString mUnreadAlert; int mDesktopNotificationDuration = 0; bool mDisableNotifications = false; bool mHideUnreadStatus = false; }; #endif // SAVENOTIFICATIONJOB_H