#include "logger.h"
#include "configfile.h"
#include "ocsnavigationappsjob.h"
+#include "ocsuserstatusconnector.h"
#include "pushnotifications.h"
#include <QSettings>
this, &AccountState::slotCredentialsAsked);
connect(account.data(), &Account::pushNotificationsReady,
this, &AccountState::slotPushNotificationsReady);
+ connect(account.data(), &Account::serverUserStatusChanged, this,
+ &AccountState::slotServerUserStatusChanged);
connect(this, &AccountState::isConnectedChanged, [=]{
// Get the Apps available on the server if we're now connected.
}
}
+void AccountState::slotServerUserStatusChanged()
+{
+ setDesktopNotificationsAllowed(_account->userStatusConnector()->userStatus().state() != UserStatus::OnlineStatus::DoNotDisturb);
+}
+
void AccountState::slotNavigationAppsFetched(const QJsonDocument &reply, int statusCode)
{
if(_account){
void slotCheckConnection();
void slotPushNotificationsReady();
+ void slotServerUserStatusChanged();
private:
AccountPtr _account;
this, &ServerNotificationHandler::slotNotificationsReceived);
QObject::connect(_notificationJob.data(), &JsonApiJob::etagResponseHeaderReceived,
this, &ServerNotificationHandler::slotEtagResponseHeaderReceived);
- QObject::connect(_notificationJob.data(), &JsonApiJob::allowDesktopNotificationsChanged,
- this, &ServerNotificationHandler::slotAllowDesktopNotificationsChanged);
_notificationJob->setProperty(propertyAccountStateC, QVariant::fromValue<AccountState *>(_accountState));
_notificationJob->addRawHeader("If-None-Match", _accountState->notificationsEtagResponseHeader());
_notificationJob->start();
}
}
-void ServerNotificationHandler::slotAllowDesktopNotificationsChanged(bool isAllowed)
-{
- auto *account = qvariant_cast<AccountState *>(sender()->property(propertyAccountStateC));
- if (account != nullptr) {
- account->setDesktopNotificationsAllowed(isAllowed);
- }
-}
-
void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &json, int statusCode)
{
if (statusCode != successStatusCode && statusCode != notModifiedStatusCode) {
private slots:
void slotNotificationsReceived(const QJsonDocument &json, int statusCode);
void slotEtagResponseHeaderReceived(const QByteArray &value, int statusCode);
- void slotAllowDesktopNotificationsChanged(bool isAllowed);
private:
QPointer<JsonApiJob> _notificationJob;
}
_userStatus.setState(status);
+ _userStatusConnector->setUserStatus(_userStatus);
emit onlineStatusChanged();
}
connect(_userStatusConnector.get(), &UserStatusConnector::userStatusFetched, this, [this](const UserStatus &) {
emit userStatusChanged();
});
+ connect(_userStatusConnector.get(), &UserStatusConnector::serverUserStatusChanged, this, &Account::serverUserStatusChanged);
connect(_userStatusConnector.get(), &UserStatusConnector::messageCleared, this, [this] {
emit userStatusChanged();
});
+
+ _userStatusConnector->fetchUserStatus();
}
QString Account::serverVersion() const
void userStatusChanged();
+ void serverUserStatusChanged();
+
void capabilitiesChanged();
void lockFileSuccess();
if(reply()->rawHeaderList().contains("ETag"))
emit etagResponseHeaderReceived(reply()->rawHeader("ETag"), statusCode);
- const auto desktopNotificationsAllowed = reply()->rawHeader(QByteArray("X-Nextcloud-User-Status"));
- if(!desktopNotificationsAllowed.isEmpty()) {
- emit allowDesktopNotificationsChanged(desktopNotificationsAllowed == "online");
- }
-
QJsonParseError error;
auto json = QJsonDocument::fromJson(jsonStr.toUtf8(), &error);
// empty or invalid response and status code is != 304 because jsonStr is expected to be empty
*/
void etagResponseHeaderReceived(const QByteArray &value, int statusCode);
- /**
- * @brief desktopNotificationStatusReceived - signal to report if notifications are allowed
- * @param status - set desktop notifications allowed status
- */
- void allowDesktopNotificationsChanged(bool isAllowed);
-
private:
QByteArray _body;
QUrlQuery _additionalParams;
return;
}
+ const auto oldOnlineState = _userStatus.state();
_userStatus = jsonToUserStatus(json);
+
emit userStatusFetched(_userStatus);
+
+ if (oldOnlineState != _userStatus.state()) {
+ emit serverUserStatusChanged();
+ }
}
void OcsUserStatusConnector::startFetchPredefinedStatuses()
return;
}
- setUserStatusOnlineStatus(userStatus.state());
+ if (userStatus.state() != _userStatus.state()) {
+ setUserStatusOnlineStatus(userStatus.state());
+ }
setUserStatusMessage(userStatus);
}
emit error(Error::CouldNotSetUserStatus);
return;
}
+
+ const auto oldOnlineState = _userStatus.state();
+ _userStatus.setState(jsonToUserStatus(json).state());
+
+ emit userStatusSet();
+
+ if (oldOnlineState != _userStatus.state()) {
+ emit serverUserStatusChanged();
+ }
}
void OcsUserStatusConnector::onUserStatusMessageSet(const QJsonDocument &json, int statusCode)
return;
}
+ const auto onlineState = _userStatus.state();
+
_userStatus = {};
+ _userStatus.setState(onlineState);
emit messageCleared();
}
}
void userStatusFetched(const UserStatus &userStatus);
void predefinedStatusesFetched(const std::vector<UserStatus> &statuses);
void userStatusSet();
+ void serverUserStatusChanged();
void messageCleared();
void error(Error error);
};