Add method to get user pointer in UserModel by AccountState pointer

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-07-05 21:35:33 +08:00
parent 29cc9c06f9
commit 10989fa810
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 17 additions and 2 deletions

View file

@ -1526,6 +1526,21 @@ User *UserModel::currentUser() const
return _users[currentUserId()]; 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 int UserModel::findUserIdForAccount(AccountState *account) const
{ {
const auto it = std::find_if(std::cbegin(_users), std::cend(_users), [=](const User *user) { const auto it = std::find_if(std::cbegin(_users), std::cend(_users), [=](const User *user) {

View file

@ -210,8 +210,8 @@ public:
[[nodiscard]] QImage avatarById(const int id) const; [[nodiscard]] QImage avatarById(const int id) const;
[[nodiscard]] User *currentUser() const; [[nodiscard]] User *currentUser() const;
[[nodiscard]] User *findUserForAccount(AccountState *account) const;
int findUserIdForAccount(AccountState *account) const; [[nodiscard]] int findUserIdForAccount(AccountState *account) const;
Q_INVOKABLE int numUsers(); Q_INVOKABLE int numUsers();
Q_INVOKABLE QString currentUserServer(); Q_INVOKABLE QString currentUserServer();