~aleteoryx/muditaos

0a60b15953ce80b4f4fd5f5772a81a0d21729a78 — Marcin Zieliński 2 years ago e1a73af
[MOS-663] Regression fix

Fixed a regression that the SMS template list showed always
the state representing no templates defined, regardless if
there were any in the database.

There's a minor side effect that querying the database and
refreshing the window is doubled which can be seen in
debugging, but it's unnoticeable in usage.
M module-apps/application-messages/models/SMSTemplateModel.cpp => module-apps/application-messages/models/SMSTemplateModel.cpp +10 -12
@@ 10,11 10,7 @@
#include <service-db/DBServiceAPI.hpp>

SMSTemplateModel::SMSTemplateModel(app::ApplicationCommon *app) : DatabaseModel(app), app::AsyncCallbackReceiver{app}
{
    /* In the base class DatabaseModel, this is initialised to maximal unsigned int value, but in fact should be 0.
       Not wanting to tinker with the whole database handling framework, let's correct this here in a smaller scale. */
    recordsCount = 0;
}
{}

unsigned int SMSTemplateModel::requestRecordsCount()
{


@@ 71,14 67,16 @@ auto SMSTemplateModel::handleQueryResponse(db::QueryResult *queryResult) -> bool
    auto msgResponse = dynamic_cast<db::query::SMSTemplateGetForListResult *>(queryResult);
    assert(msgResponse != nullptr);

    // If list record count has changed we need to rebuild list.
    if (recordsCount != (msgResponse->getCount())) {
        recordsCount = msgResponse->getCount();
        list->reSendLastRebuildRequest();
        return false;
    if (recordsCount == msgResponse->getCount()) {
        return this->updateRecords(msgResponse->getResults());
    }

    auto records = msgResponse->getResults();
    recordsCount = msgResponse->getCount();
    if (list->isEmpty()) {
        list->clear();
    }

    return this->updateRecords(std::move(records));
    // refreshWindow(...) does too few in this case
    application->switchWindow(gui::name::window::sms_templates);
    return false;
}

M module-apps/application-messages/windows/SMSTemplatesWindow.cpp => module-apps/application-messages/windows/SMSTemplatesWindow.cpp +6 -5
@@ 40,6 40,7 @@ namespace gui
        setTitle(utils::translate("app_messages_templates"));

        navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::use));
        navBar->setActive(nav_bar::Side::Center, false);
        navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::back));

        namespace style = style::messages::templates::list;


@@ 103,11 104,11 @@ namespace gui
        preventsAutoLock = false;
        if (mode == ShowMode::GUI_SHOW_INIT) {
            list->rebuildList();
            if (list->isEmpty()) {
                list->setVisible(false);
                navBar->setActive(nav_bar::Side::Center, false);
                emptyListIcon->setVisible(true);
            }
        }

        if (list->isEmpty()) {
            navBar->setActive(nav_bar::Side::Center, false);
            emptyListIcon->setVisible(true);
        }

        if (auto switchData = dynamic_cast<SMSTemplateRequest *>(data)) {