mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Add checks in case userStatus is not available/fails on the server side.
Signed-off-by: Camila <hello@camila.codes>
This commit is contained in:
parent
d9a0778e52
commit
9219926a74
@ -186,6 +186,8 @@ void User::slotRefreshImmediately() {
|
||||
|
||||
void User::slotRefresh()
|
||||
{
|
||||
slotRefreshUserStatus();
|
||||
|
||||
if (checkPushNotificationsAreReady()) {
|
||||
// we are relying on WebSocket push notifications - ignore refresh attempts from UI
|
||||
_timeSinceLastCheck[_account.data()].invalidate();
|
||||
@ -208,7 +210,6 @@ void User::slotRefresh()
|
||||
slotRefreshActivities();
|
||||
}
|
||||
slotRefreshNotifications();
|
||||
_account.data()->fetchUserStatus();
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
@ -218,6 +219,13 @@ void User::slotRefreshActivities()
|
||||
_activityModel->slotRefreshActivity();
|
||||
}
|
||||
|
||||
void User::slotRefreshUserStatus() {
|
||||
// TODO: check for _account->account()->capabilities().userStatus()
|
||||
if (_account.data() && _account.data()->isConnected()) {
|
||||
_account.data()->fetchUserStatus();
|
||||
}
|
||||
}
|
||||
|
||||
void User::slotRefreshNotifications()
|
||||
{
|
||||
// start a server notification handler if no notification requests
|
||||
|
||||
@ -74,6 +74,7 @@ public slots:
|
||||
void slotRefreshNotifications();
|
||||
void slotRefreshActivities();
|
||||
void slotRefresh();
|
||||
void slotRefreshUserStatus();
|
||||
void slotRefreshImmediately();
|
||||
void setNotificationRefreshInterval(std::chrono::milliseconds interval);
|
||||
void slotRebuildNavigationAppList();
|
||||
|
||||
@ -26,6 +26,8 @@
|
||||
|
||||
namespace OCC {
|
||||
|
||||
Q_LOGGING_CATEGORY(lcUserStatus, "nextcloud.gui.userstatus", QtInfoMsg)
|
||||
|
||||
UserStatus::UserStatus(QObject *parent)
|
||||
: QObject(parent)
|
||||
, _message("")
|
||||
@ -51,9 +53,20 @@ void UserStatus::fetchUserStatus(AccountPtr account)
|
||||
_job->start();
|
||||
}
|
||||
|
||||
void UserStatus::slotFetchUserStatusFinished(const QJsonDocument &json)
|
||||
void UserStatus::slotFetchUserStatusFinished(const QJsonDocument &json, const int statusCode)
|
||||
{
|
||||
const auto retrievedData = json.object().value("ocs").toObject().value("data").toObject();
|
||||
const QJsonObject defaultValues
|
||||
{
|
||||
{"icon", ""},
|
||||
{"message", ""},
|
||||
{"status", "online"}
|
||||
};
|
||||
|
||||
if (statusCode != 200) {
|
||||
qCInfo(lcUserStatus) << "Slot fetch UserStatus finished with status code" << statusCode;
|
||||
qCInfo(lcUserStatus) << "Using then default values as if user has not set any status" << defaultValues;
|
||||
}
|
||||
const auto retrievedData = json.object().value("ocs").toObject().value("data").toObject(defaultValues);
|
||||
const auto emoji = retrievedData.value("icon").toString();
|
||||
const auto message = retrievedData.value("message").toString();
|
||||
auto statusString = retrievedData.value("status").toString();
|
||||
|
||||
@ -15,13 +15,11 @@
|
||||
#ifndef USERSTATUS_H
|
||||
#define USERSTATUS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QVariant>
|
||||
#include <QMetaEnum>
|
||||
#include "accountfwd.h"
|
||||
|
||||
namespace OCC {
|
||||
|
||||
class JsonApiJob;
|
||||
|
||||
class UserStatus : public QObject
|
||||
@ -44,7 +42,7 @@ public:
|
||||
QUrl icon() const;
|
||||
|
||||
private slots:
|
||||
void slotFetchUserStatusFinished(const QJsonDocument &json);
|
||||
void slotFetchUserStatusFinished(const QJsonDocument &json, const int statusCode);
|
||||
|
||||
signals:
|
||||
void fetchUserStatusFinished();
|
||||
|
||||
@ -177,6 +177,11 @@ bool Capabilities::chunkingNg() const
|
||||
return _capabilities["dav"].toMap()["chunking"].toByteArray() >= "1.0";
|
||||
}
|
||||
|
||||
bool Capabilities::userStatus() const
|
||||
{
|
||||
return _capabilities.contains("notifications") && _capabilities["notifications"].toMap().contains("user-status");
|
||||
}
|
||||
|
||||
PushNotificationTypes Capabilities::availablePushNotifications() const
|
||||
{
|
||||
if (!_capabilities.contains("notify_push")) {
|
||||
|
||||
@ -56,6 +56,7 @@ public:
|
||||
bool sharePublicLinkMultiple() const;
|
||||
bool shareResharing() const;
|
||||
bool chunkingNg() const;
|
||||
bool userStatus() const;
|
||||
|
||||
/// Returns which kind of push notfications are available
|
||||
PushNotificationTypes availablePushNotifications() const;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user