From c82f16e3b18a05a592912c43bf2ccd96325ff44a Mon Sep 17 00:00:00 2001 From: Maciej-Mudita Date: Fri, 20 Jan 2023 16:16:54 +0100 Subject: [PATCH] [MOS-340] Fix notifications of unread SMS threads on the home screen Conversation marked in OPTIONS as read did not disappear from notifications about SMS threads on the main screen. --- .../ApplicationMessages.cpp | 19 ++++++++++++++----- .../ApplicationMessages.hpp | 4 ++-- .../windows/SMSThreadViewWindow.cpp | 13 ++----------- .../windows/ThreadWindowOptions.cpp | 4 ++-- pure_changelog.md | 1 + 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/module-apps/application-messages/ApplicationMessages.cpp b/module-apps/application-messages/ApplicationMessages.cpp index 5f109dba270cc6d31b8a5cb90035ee02d4bb48be..6487b6b0c9ba5f7706dafb3048e73aaa8df95a5d 100644 --- a/module-apps/application-messages/ApplicationMessages.cpp +++ b/module-apps/application-messages/ApplicationMessages.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApplicationMessages.hpp" @@ -165,19 +165,28 @@ namespace app void ApplicationMessages::destroyUserInterface() {} - bool ApplicationMessages::markSmsThreadAsRead(const uint32_t id) + bool ApplicationMessages::markSmsThreadAsRead(const ThreadRecord *record) { using namespace db::query; - LOG_DEBUG("markSmsThreadAsRead"); + if (record == nullptr) { + LOG_ERROR("Trying to mark as read a null SMS thread!"); + return false; + } DBServiceAPI::GetQuery( - this, db::Interface::Name::SMSThread, std::make_unique(id, MarkAsRead::Read::True)); + this, db::Interface::Name::SMSThread, std::make_unique(record->ID, MarkAsRead::Read::True)); + + if (record->unreadMsgCount) { + DBServiceAPI::GetQuery( + this, + db::Interface::Name::Notifications, + std::make_unique(NotificationsRecord::Key::Sms, record->unreadMsgCount)); + } return true; } bool ApplicationMessages::markSmsThreadAsUnread(const uint32_t id) { using namespace db::query; - LOG_DEBUG("markSmsThreadAsUnRead"); DBServiceAPI::GetQuery( this, db::Interface::Name::SMSThread, std::make_unique(id, MarkAsRead::Read::False)); return true; diff --git a/module-apps/application-messages/include/application-messages/ApplicationMessages.hpp b/module-apps/application-messages/include/application-messages/ApplicationMessages.hpp index 46434d2bdfa83cc7918255c54b1b244736a04ad9..8ed34dd384ea95ea4d7ee377c191e3a7828cf52e 100644 --- a/module-apps/application-messages/include/application-messages/ApplicationMessages.hpp +++ b/module-apps/application-messages/include/application-messages/ApplicationMessages.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -42,7 +42,7 @@ namespace app bool removeSms(const SMSRecord &record); bool removeSmsThread(const ThreadRecord *record); - bool markSmsThreadAsRead(const uint32_t id); + bool markSmsThreadAsRead(const ThreadRecord *record); bool markSmsThreadAsUnread(const uint32_t id); /// show dialog with big search icon and text which was used for query bool searchEmpty(const std::string &query = ""); diff --git a/module-apps/application-messages/windows/SMSThreadViewWindow.cpp b/module-apps/application-messages/windows/SMSThreadViewWindow.cpp index fa1b94f5c8edd6d2da0089ccc499d0fe2aa5b3c9..d38ca7791b81f2b68f9fdb36606be36a7561496b 100644 --- a/module-apps/application-messages/windows/SMSThreadViewWindow.cpp +++ b/module-apps/application-messages/windows/SMSThreadViewWindow.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApplicationMessages.hpp" @@ -72,21 +72,12 @@ namespace gui auto app = dynamic_cast(application); assert(app != nullptr); if (application->getCurrentWindow() == this) { - app->markSmsThreadAsRead(pdata->thread->ID); + app->markSmsThreadAsRead(pdata->thread.get()); } } smsModel->numberID = pdata->thread->numberID; smsModel->smsThreadID = pdata->thread->ID; smsList->rebuildList(); - - if (pdata->thread->unreadMsgCount) { - const auto countToClear = pdata->thread->unreadMsgCount; - - DBServiceAPI::GetQuery( - application, - db::Interface::Name::Notifications, - std::make_unique(NotificationsRecord::Key::Sms, countToClear)); - } } else if (smsModel->numberID != DB_ID_NONE) { requestContact(smsModel->numberID); diff --git a/module-apps/application-messages/windows/ThreadWindowOptions.cpp b/module-apps/application-messages/windows/ThreadWindowOptions.cpp index ee68a31dcfc94b3fde7288501a3b742d86cf7afe..8e6ad506259ac8aeac4eb0c3e562e9361343a057 100644 --- a/module-apps/application-messages/windows/ThreadWindowOptions.cpp +++ b/module-apps/application-messages/windows/ThreadWindowOptions.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ThreadWindowOptions.hpp" @@ -74,7 +74,7 @@ namespace gui if (record->isUnread()) { options.emplace_back(gui::Option{utils::translate("sms_mark_read"), [=](gui::Item &item) { - app->markSmsThreadAsRead(record->ID); + app->markSmsThreadAsRead(record); app->returnToPreviousWindow(); return true; }}); diff --git a/pure_changelog.md b/pure_changelog.md index b073b94d837c39ce0bdbbe17ed86f656940e53ed..3b335ba2985ed0b8a0b18321a49e716c4508ab4f 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -36,6 +36,7 @@ * Fixed crash when trying to play 96kHz FLAC with USB cable connected * Fixed the notification of unread messages are not deleted with the thread * Fixed several MTP issues +* Fixed notifications of unread SMS threads on the home screen ### Added