mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-18 12:04:03 -04:00
Introduce a new way to handle query responses allowing to deal with races: - bind reponse with request, - handle responses with an observer-like interface. Signed-off-by: Marcin Smoczyński <smoczynski.marcin@gmail.com>
70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "Record.hpp"
|
|
#include "ThreadRecord.hpp"
|
|
#include "module-db/Databases/SmsDB.hpp"
|
|
#include "module-db/Databases/ContactsDB.hpp"
|
|
#include "module-db/queries/sms/QuerySMSSearchByType.hpp"
|
|
#include "module-db/Common/Common.hpp"
|
|
|
|
#include <utf8/UTF8.hpp>
|
|
#include <PhoneNumber.hpp>
|
|
|
|
struct SMSRecord : public Record
|
|
{
|
|
uint32_t date = 0;
|
|
uint32_t dateSent = 0;
|
|
uint32_t errorCode = 0;
|
|
UTF8 body;
|
|
SMSType type = SMSType::UNKNOWN;
|
|
uint32_t threadID = 0;
|
|
uint32_t contactID = 0;
|
|
utils::PhoneNumber::View number;
|
|
|
|
SMSRecord() = default;
|
|
SMSRecord(const SMSTableRow &, const utils::PhoneNumber::View &);
|
|
};
|
|
|
|
enum class SMSRecordField
|
|
{
|
|
Number,
|
|
ThreadID,
|
|
ContactID
|
|
};
|
|
|
|
class SMSRecordInterface : public RecordInterface<SMSRecord, SMSRecordField>
|
|
{
|
|
public:
|
|
SMSRecordInterface(SmsDB *smsDb, ContactsDB *contactsDb);
|
|
~SMSRecordInterface() = default;
|
|
|
|
bool Add(const SMSRecord &rec) override final;
|
|
bool RemoveByID(uint32_t id) override final;
|
|
bool RemoveByField(SMSRecordField field, const char *str) override final;
|
|
bool Update(const SMSRecord &recUpdated) override final;
|
|
SMSRecord GetByID(uint32_t id) override final;
|
|
|
|
uint32_t GetCount() override final;
|
|
uint32_t GetLastID(void);
|
|
std::unique_ptr<std::vector<SMSRecord>> GetLimitOffset(uint32_t offset, uint32_t limit) override final;
|
|
|
|
std::unique_ptr<std::vector<SMSRecord>> GetLimitOffsetByField(uint32_t offset,
|
|
uint32_t limit,
|
|
SMSRecordField field,
|
|
const char *str) override final;
|
|
|
|
std::unique_ptr<db::QueryResult> runQuery(std::shared_ptr<db::Query> query) override;
|
|
|
|
private:
|
|
static const uint32_t snippetLength = 45;
|
|
SmsDB *smsDB = nullptr;
|
|
ContactsDB *contactsDB = nullptr;
|
|
|
|
std::unique_ptr<db::query::SMSSearchByTypeResult> runQueryImpl(const db::query::SMSSearchByType *query);
|
|
|
|
static void UpdateThreadSummary(ThreadRecord &threadToUpdate, const SMSRecord &rec);
|
|
};
|