Files
MuditaOS/module-apps/application-messages/models/SearchResultsModel.cpp
pholat 23df384c55 EGD-3087 SMS Search implemented (#374)
* EGD-3087 WIP adding SMS Querry

* EGD-3087 Added query virtual interface on Service top layer

Service shouldn't implement query logic and should be proxying that.

additionally:
- small fixes in includes
- shared service db name same way as apps and event manager

* EGD-3087 Query - want to work on interface not on db

* EGD-3087 Query gluecode works fine. Our query in SMS search calls getBySMSQuery

Changes cut off before any potential orm interface layer

* EGD-3087 WIP Interface in use

* EGD-3087 Query for SMS search works as designed

* EGD-3087 Query results should be on screen

* EGD-3087 BUG workaround - need to deep refresh display to show data

* EGD-3087 Searching for text from input works fine

* EGD-3087 Showing results / or empty results depending on query

* EGD-3087 Pre PR fixups

* EGD-3087 Empty search - getting back to prewious window ignore current

* EGD-3087 PR applied

* EGD-3087 PR - style fixed

* EGD-3087 Review - DB ListView handling moved to separate function

* EGD-3087 Workaround: crash on use after free fix

* EGD-3087 PR stylistic changes

* EGD-3087 PR cleanup applied

* EGD-3087 Added test for Query interface

* EGD-3087 renamed getByQuery to getQuery & finished tests

* EGD-3087 Post rebase fixup

* EGD-3087 PR - moved ListView request part to separate function

* EGD-3087 PR Fixups

* EGD-3087 Post rebase style fix

* EGD-3087 Added variable for DB service stack & const to getter function
2020-05-27 13:49:50 +02:00

60 lines
1.8 KiB
C++

#include "SearchResultsModel.hpp"
#include "time/time_conversion.hpp"
#include "../widgets/SearchResultsItem.hpp"
#include "service-db/api/DBServiceAPI.hpp"
#include <module-db/queries/sms/QuerySMSSearch.hpp>
namespace gui::model
{
SearchResultsModel::SearchResultsModel(app::Application *app) : BaseThreadRecordModel(app)
{}
gui::ListItem *SearchResultsModel::getItem(int index)
{
std::shared_ptr<ThreadRecord> thread = getRecord(index);
if (thread.get() == nullptr) {
return nullptr;
}
auto ret = new gui::SearchResultsItem();
{
auto contactRec = DBServiceAPI::ContactGetByID(getApplication(), thread->contactID);
auto cont = contactRec->front();
ret->setContact(cont.getFormattedName());
}
ret->setTimestamp(utils::time::DateTime(thread->date));
{
// The only thing that differs with ThreadModel actually - here show what was found
ret->setPreview(thread->snippet);
}
ret->setID(index);
return ret;
}
void SearchResultsModel::requestRecordsCount()
{}
void SearchResultsModel::requestRecords(uint32_t offset, uint32_t limit)
{
if (std::string(search_value).compare("") != 0) {
DBServiceAPI::GetQuery(
getApplication(),
db::Interface::Name::SMSThread,
std::make_unique<db::query::SMSSearch>(search_value, offset, max_search_items_on_screen));
}
}
void SearchResultsModel::setRecordsCount(uint32_t count)
{
recordsCount = count;
}
void SearchResultsModel::setSearchValue(const UTF8 &search_value)
{
this->search_value = search_value;
}
}; // namespace gui::model