Commit 82862b4f authored by Sébastien Blin's avatar Sébastien Blin Committed by Amin Bandali

accountmodel: add notifications count

Change-Id: I9b0ed430c5612afec2481ed71d071a3f7eaaea46
parent 192638d2
......@@ -358,6 +358,10 @@ public:
* @return number of conversations requests
*/
int pendingRequestCount() const;
/**
* @return number of conversations requests + unread
*/
int notificationsCount() const;
const VectorString peersForConversation(const QString& conversationId);
// Presentation
......
......@@ -255,6 +255,10 @@ public:
* @return if all moderator is enabled
*/
bool isAllModerators(const QString& accountID);
/**
* Get notifications count across accounts
*/
int notificationsCount() const;
Q_SIGNALS:
/**
......
......@@ -992,6 +992,22 @@ ConversationModel::pendingRequestCount() const
return pendingRequestCount;
}
int
ConversationModel::notificationsCount() const
{
int notificationsCount = 0;
std::for_each(pimpl_->conversations.begin(),
pimpl_->conversations.end(),
[&notificationsCount](const auto& c) {
if (c.isRequest)
notificationsCount += 1;
else {
notificationsCount += c.unreadMessages;
}
});
return notificationsCount;
}
QString
ConversationModel::title(const QString& conversationId) const
{
......@@ -2872,7 +2888,10 @@ ConversationModelPimpl::indexOfContact(const QString& uri) const
if (!conversations.at(i).isCoreDialog()) {
continue;
}
if (peersForConversation(conversations.at(i)).front() == uri)
auto peers = peersForConversation(conversations.at(i));
if (peers.isEmpty())
continue;
if (peers.front() == uri)
return i;
}
return -1;
......
......@@ -1209,6 +1209,16 @@ NewAccountModel::isAllModerators(const QString& accountID)
return ConfigurationManager::instance().isAllModerators(accountID);
}
int
NewAccountModel::notificationsCount() const
{
auto total = 0;
for (const auto& [_id, account] : pimpl_->accounts) {
total += account.first.conversationModel->notificationsCount();
}
return total;
}
} // namespace lrc
#include "api/moc_newaccountmodel.cpp"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment