Files
MuditaOS/module-db/Interface/ThreadRecord.hpp
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

80 lines
2.5 KiB
C++

/*
* @file ThreadRecord.hpp
* @author Mateusz Piesta (mateusz.piesta@mudita.com)
* @date 29.05.19
* @brief
* @copyright Copyright (C) 2019 mudita.com
* @details
*/
#pragma once
#include "Record.hpp"
#include <stdint.h>
#include "utf8/UTF8.hpp"
#include "../Databases/SmsDB.hpp"
#include "../Databases/ContactsDB.hpp"
#include "../Common/Common.hpp"
#include "../queries/sms/QuerySMSSearch.hpp"
struct ThreadRecord
{
uint32_t dbID = 0;
uint32_t date = 0;
uint32_t msgCount = 0;
uint32_t msgRead = 0;
UTF8 snippet = "";
SMSType type = SMSType::ALL;
uint32_t contactID = 0;
ThreadRecord() = default;
ThreadRecord(const ThreadsTableRow &rec)
{
dbID = rec.ID;
date = rec.date;
msgCount = rec.msgCount;
msgRead = rec.msgRead;
snippet = rec.snippet;
type = rec.type;
contactID = rec.contactID;
}
};
enum class ThreadRecordField
{
ContactID,
};
class ThreadRecordInterface : public RecordInterface<ThreadRecord, ThreadRecordField>
{
public:
ThreadRecordInterface(SmsDB *smsDb, ContactsDB *contactsDb);
~ThreadRecordInterface();
bool Add(const ThreadRecord &rec) override final;
bool RemoveByID(uint32_t id) override final;
bool Update(const ThreadRecord &rec) override final;
ThreadRecord GetByID(uint32_t id) override final;
ThreadRecord GetByContact(uint32_t contact_id);
uint32_t GetCount() override final;
std::unique_ptr<std::vector<ThreadRecord>> GetLimitOffset(uint32_t offset, uint32_t limit) override final;
std::unique_ptr<std::vector<ThreadRecord>> GetLimitOffsetByField(uint32_t offset,
uint32_t limit,
ThreadRecordField field,
const char *str) override final;
std::unique_ptr<db::QueryResult> runQuery(const db::Query *query) override;
private:
SmsDB *smsDB;
ContactsDB *contactsDB;
/// for now implementation between Interface <-> Database
/// it would only make sense to pass Query from Inteface to multiple databases to get all data we are interested in
/// or better split it to smaller entities... this could be done with any db high level interface - left as it is
std::unique_ptr<db::query::SMSSearchResult> runQueryImpl(const db::query::SMSSearch *query);
};