From 6d6cc3852bab3566d7e0641f70a9ea05800bb95b Mon Sep 17 00:00:00 2001 From: Camila Date: Mon, 3 Aug 2020 19:00:45 +0200 Subject: [PATCH 1/2] Fix #2243: use server url instead of hard coded string. Signed-off-by: Camila --- src/gui/tray/UserModel.cpp | 16 +++++++++++----- src/gui/tray/UserModel.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/gui/tray/UserModel.cpp b/src/gui/tray/UserModel.cpp index 77c5e3991..f7008c42c 100644 --- a/src/gui/tray/UserModel.cpp +++ b/src/gui/tray/UserModel.cpp @@ -486,6 +486,11 @@ bool User::serverHasTalk() const return _account->hasTalk(); } +AccountApp *User::talkApp() const +{ + return _account->findApp(QStringLiteral("spreed")); +} + bool User::hasActivities() const { return _account->account()->capabilities().hasActivities(); @@ -643,14 +648,15 @@ Q_INVOKABLE void UserModel::openCurrentAccountLocalFolder() Q_INVOKABLE void UserModel::openCurrentAccountTalk() { - if (_users.isEmpty()) + if (!currentUser()) return; - QString url = _users[_currentUserId]->server(false) + "/apps/spreed"; - if (!(url.contains("http://") || url.contains("https://"))) { - url = "https://" + _users[_currentUserId]->server(false) + "/apps/spreed"; + const auto talkApp = currentUser()->talkApp(); + if (talkApp) { + QDesktopServices::openUrl(talkApp->url()); + } else { + qCWarning(lcActivity) << "The Talk app is not enabled on" << currentUser()->server(); } - QDesktopServices::openUrl(QUrl(url)); } Q_INVOKABLE void UserModel::openCurrentAccountServer() diff --git a/src/gui/tray/UserModel.h b/src/gui/tray/UserModel.h index 3a28e65e3..3057f0c28 100644 --- a/src/gui/tray/UserModel.h +++ b/src/gui/tray/UserModel.h @@ -36,6 +36,7 @@ public: QString server(bool shortened = true) const; bool hasLocalFolder() const; bool serverHasTalk() const; + AccountApp *talkApp() const; bool hasActivities() const; AccountAppList appList() const; QImage avatar(bool whiteBg = false) const; From 8f300ffe661ff79e644f49470132703e7b57aadc Mon Sep 17 00:00:00 2001 From: Camila Date: Mon, 3 Aug 2020 19:48:33 +0200 Subject: [PATCH 2/2] Remove extra check for talk app on server in AccountState. - Remove repeated hard coded "spreed" string. Signed-off-by: Camila --- src/gui/accountstate.cpp | 10 ---------- src/gui/accountstate.h | 3 --- src/gui/tray/UserModel.cpp | 13 +++---------- src/gui/tray/UserModel.h | 1 - 4 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index be7aa5832..3b56a8d7f 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -44,7 +44,6 @@ AccountState::AccountState(AccountPtr account) , _waitingForNewCredentials(false) , _maintenanceToConnectedDelay(60000 + (qrand() % (4 * 60000))) // 1-5min delay , _remoteWipe(new RemoteWipe(_account)) - , _hasTalk(false) { qRegisterMetaType("AccountState*"); @@ -74,11 +73,6 @@ AccountPtr AccountState::account() const return _account; } -bool AccountState::hasTalk() const -{ - return _hasTalk; -} - AccountState::ConnectionStatus AccountState::connectionStatus() const { return _connectionStatus; @@ -444,7 +438,6 @@ void AccountState::slotNavigationAppsFetched(const QJsonDocument &reply, int sta qCWarning(lcAccountState) << "Status code " << statusCode << " Not Modified - No new navigation apps."; } else { _apps.clear(); - _hasTalk = false; if(!reply.isEmpty()){ auto element = reply.object().value("ocs").toObject().value("data"); @@ -458,9 +451,6 @@ void AccountState::slotNavigationAppsFetched(const QJsonDocument &reply, int sta navLink.value("id").toString(), QUrl(navLink.value("icon").toString())); _apps << app; - - if(app->id() == QLatin1String("spreed")) - _hasTalk = true; } } } diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index 433fb5116..f1209a47a 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -103,8 +103,6 @@ public: bool isSignedOut() const; - bool hasTalk() const; - AccountAppList appList() const; AccountApp* findApp(const QString &appId) const; @@ -195,7 +193,6 @@ private: ConnectionStatus _connectionStatus; QStringList _connectionErrors; bool _waitingForNewCredentials; - bool _hasTalk; QElapsedTimer _timeSinceLastETagCheck; QPointer _connectionValidator; QByteArray _notificationsEtagResponseHeader; diff --git a/src/gui/tray/UserModel.cpp b/src/gui/tray/UserModel.cpp index f7008c42c..386c7f762 100644 --- a/src/gui/tray/UserModel.cpp +++ b/src/gui/tray/UserModel.cpp @@ -483,7 +483,7 @@ bool User::hasLocalFolder() const bool User::serverHasTalk() const { - return _account->hasTalk(); + return talkApp() != nullptr; } AccountApp *User::talkApp() const @@ -602,14 +602,6 @@ Q_INVOKABLE QString UserModel::currentUserServer() return _users[_currentUserId]->server(); } -Q_INVOKABLE bool UserModel::currentServerHasTalk() -{ - if (_users.isEmpty()) - return false; - - return _users[_currentUserId]->serverHasTalk(); -} - void UserModel::addUser(AccountStatePtr &user, const bool &isCurrent) { bool containsUser = false; @@ -870,9 +862,10 @@ void UserAppsModel::buildAppList() } if (UserModel::instance()->appList().count() > 0) { + const auto talkApp = UserModel::instance()->currentUser()->talkApp(); foreach (AccountApp *app, UserModel::instance()->appList()) { // Filter out Talk because we have a dedicated button for it - if (app->id() == QLatin1String("spreed")) + if (talkApp && app->id() == talkApp->id()) continue; beginInsertRows(QModelIndex(), rowCount(), rowCount()); diff --git a/src/gui/tray/UserModel.h b/src/gui/tray/UserModel.h index 3057f0c28..10836dfd6 100644 --- a/src/gui/tray/UserModel.h +++ b/src/gui/tray/UserModel.h @@ -113,7 +113,6 @@ public: Q_INVOKABLE QString currentUserServer(); Q_INVOKABLE bool currentUserHasActivities(); Q_INVOKABLE bool currentUserHasLocalFolder(); - Q_INVOKABLE bool currentServerHasTalk(); Q_INVOKABLE int currentUserId() const; Q_INVOKABLE bool isUserConnected(const int &id); Q_INVOKABLE void switchCurrentUser(const int &id);