mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-01-01 10:28:52 -05:00
1. Prepare Pure and Bell specific `Application` classes and add them to `app` target: - `products/BellHybrid/apps/Application.cpp` - `products/PurePhone/apps/Application.cpp` 2. Update `CMakeLists.txt` files. 3. Move `ApplicationBell` implementation to Bell-specific `Application` class and remove `ApplicationBell` files. 4. Change Bell apps parent classes from `ApplicationBell` to Bell-specific `Application` class. 5. Rename `Application` to `ApplicationCommon` in the rest of the files.
85 lines
2.6 KiB
C++
85 lines
2.6 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "DBNotificationsHandler.hpp"
|
|
|
|
#include <module-db/queries/messages/threads/QueryThreadsGetCount.hpp>
|
|
#include <module-db/queries/calllog/QueryCalllogGetCount.hpp>
|
|
#include <service-appmgr/Controller.hpp>
|
|
#include <service-db/DBNotificationMessage.hpp>
|
|
|
|
using namespace app;
|
|
|
|
namespace
|
|
{
|
|
bool requestUnreadThreadsCount(app::ApplicationCommon *app)
|
|
{
|
|
const auto [succeed, _] = DBServiceAPI::GetQuery(
|
|
app, db::Interface::Name::SMSThread, std::make_unique<db::query::ThreadGetCount>(EntryState::UNREAD));
|
|
return succeed;
|
|
}
|
|
|
|
bool requestUnreadCallsCount(app::ApplicationCommon *app)
|
|
{
|
|
const auto [succeed, _] = DBServiceAPI::GetQuery(
|
|
app, db::Interface::Name::Calllog, std::make_unique<db::query::CalllogGetCount>(EntryState::UNREAD));
|
|
return succeed;
|
|
}
|
|
} // namespace
|
|
|
|
DBNotificationsHandler::DBNotificationsHandler(ApplicationCommon *ownerApp)
|
|
: ownerApp(ownerApp), notifications{{Type::notReadSMS, 0}, {Type::notReadCall, 0}}
|
|
{}
|
|
|
|
void DBNotificationsHandler::setNotification(Type type, int value)
|
|
{
|
|
notifications[type] = value;
|
|
}
|
|
|
|
bool DBNotificationsHandler::hasNotification(Type type) const
|
|
{
|
|
try {
|
|
return notifications.at(type) > 0;
|
|
}
|
|
catch (const std::out_of_range &e) {
|
|
LOG_ERROR("Uninitialized notification type");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool DBNotificationsHandler::handle(db::NotificationMessage *msg)
|
|
{
|
|
if (msg->type == db::Query::Type::Read) {
|
|
return false;
|
|
}
|
|
|
|
if (auto msgInterface = msg->interface; msgInterface == db::Interface::Name::Calllog) {
|
|
return requestUnreadCallsCount(ownerApp);
|
|
}
|
|
else if (msgInterface == db::Interface::Name::SMSThread || msgInterface == db::Interface::Name::SMS) {
|
|
return requestUnreadThreadsCount(ownerApp);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool DBNotificationsHandler::handle(db::QueryResult *msg)
|
|
{
|
|
if (auto response = dynamic_cast<db::query::ThreadGetCountResult *>(msg);
|
|
response != nullptr && response->getState() == EntryState::UNREAD) {
|
|
notifications[Type::notReadSMS] = response->getCount();
|
|
return true;
|
|
}
|
|
if (auto response = dynamic_cast<db::query::CalllogGetCountResult *>(msg);
|
|
response != nullptr && response->getState() == EntryState::UNREAD) {
|
|
notifications[Type::notReadCall] = response->getCount();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void DBNotificationsHandler::initHandler()
|
|
{
|
|
requestUnreadThreadsCount(ownerApp);
|
|
requestUnreadCallsCount(ownerApp);
|
|
}
|