From: Claudio Cambra Date: Wed, 5 Jul 2023 13:35:33 +0000 (+0800) Subject: Add method to get user pointer in UserModel by AccountState pointer X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~92^2^2~57^2~32 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=10989fa8106998a8246292cd284d3c8e2f02da9d;p=nextcloud-desktop.git Add method to get user pointer in UserModel by AccountState pointer Signed-off-by: Claudio Cambra --- diff --git a/src/gui/tray/usermodel.cpp b/src/gui/tray/usermodel.cpp index e9a5ed73a..2d4bef2fb 100644 --- a/src/gui/tray/usermodel.cpp +++ b/src/gui/tray/usermodel.cpp @@ -1526,6 +1526,21 @@ User *UserModel::currentUser() const return _users[currentUserId()]; } +User *UserModel::findUserForAccount(AccountState *account) const +{ + Q_ASSERT(account); + + const auto it = std::find_if(_users.cbegin(), _users.cend(), [account](const User *user) { + return user->account()->id() == account->account()->id(); + }); + + if (it == _users.cend()) { + return nullptr; + } + + return *it; +} + int UserModel::findUserIdForAccount(AccountState *account) const { const auto it = std::find_if(std::cbegin(_users), std::cend(_users), [=](const User *user) { diff --git a/src/gui/tray/usermodel.h b/src/gui/tray/usermodel.h index bfeaff46d..b39a49b5d 100644 --- a/src/gui/tray/usermodel.h +++ b/src/gui/tray/usermodel.h @@ -210,8 +210,8 @@ public: [[nodiscard]] QImage avatarById(const int id) const; [[nodiscard]] User *currentUser() const; - - int findUserIdForAccount(AccountState *account) const; + [[nodiscard]] User *findUserForAccount(AccountState *account) const; + [[nodiscard]] int findUserIdForAccount(AccountState *account) const; Q_INVOKABLE int numUsers(); Q_INVOKABLE QString currentUserServer();