From c42f4abd25d59b7781e1b875351b9672ba151be6 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Wed, 7 Oct 2020 12:27:32 +0200 Subject: [PATCH] Add a function to know the user id matching a given account Signed-off-by: Kevin Ottens --- src/gui/tray/UserModel.cpp | 14 ++++++++++++++ src/gui/tray/UserModel.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/gui/tray/UserModel.cpp b/src/gui/tray/UserModel.cpp index 1a76a50c6..5f59e8074 100644 --- a/src/gui/tray/UserModel.cpp +++ b/src/gui/tray/UserModel.cpp @@ -810,6 +810,20 @@ User *UserModel::currentUser() const return _users[currentUserId()]; } +int UserModel::findUserIdForAccount(AccountState *account) const +{ + const auto it = std::find_if(std::cbegin(_users), std::cend(_users), [=](const User *user) { + return user->account()->id() == account->account()->id(); + }); + + if (it == std::cend(_users)) { + return -1; + } + + const auto id = std::distance(std::cbegin(_users), it); + return id; +} + /*-------------------------------------------------------------------------------------*/ ImageProvider::ImageProvider() diff --git a/src/gui/tray/UserModel.h b/src/gui/tray/UserModel.h index 09b42b175..7c7d11096 100644 --- a/src/gui/tray/UserModel.h +++ b/src/gui/tray/UserModel.h @@ -107,6 +107,8 @@ public: User *currentUser() const; + int findUserIdForAccount(AccountState *account) const; + Q_INVOKABLE void fetchCurrentActivityModel(); Q_INVOKABLE void openCurrentAccountLocalFolder(); Q_INVOKABLE void openCurrentAccountTalk(); -- 2.30.2