mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-10-26 16:38:31 -04:00
* 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
83 lines
3.0 KiB
C++
83 lines
3.0 KiB
C++
|
|
/*
|
|
* @file ThreadsTable.hpp
|
|
* @author Mateusz Piesta (mateusz.piesta@mudita.com)
|
|
* @date 27.05.19
|
|
* @brief
|
|
* @copyright Copyright (C) 2019 mudita.com
|
|
* @details
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "Table.hpp"
|
|
#include "Database/Database.hpp"
|
|
#include "utf8/UTF8.hpp"
|
|
#include "Common/Common.hpp"
|
|
|
|
struct ThreadsTableRow
|
|
{
|
|
uint32_t ID = 0;
|
|
uint32_t date;
|
|
uint32_t msgCount;
|
|
uint32_t msgRead;
|
|
uint32_t contactID;
|
|
UTF8 snippet;
|
|
SMSType type;
|
|
};
|
|
|
|
enum class ThreadsTableFields
|
|
{
|
|
Date,
|
|
MsgCount,
|
|
MsgRead,
|
|
ContactID,
|
|
Type
|
|
};
|
|
|
|
class ThreadsTable : public Table<ThreadsTableRow, ThreadsTableFields>
|
|
{
|
|
public:
|
|
ThreadsTable(Database *db);
|
|
virtual ~ThreadsTable();
|
|
|
|
bool Create() override final;
|
|
bool Add(ThreadsTableRow entry) override final;
|
|
bool RemoveByID(uint32_t id) override final;
|
|
bool Update(ThreadsTableRow entry) override final;
|
|
ThreadsTableRow GetByID(uint32_t id) override final;
|
|
std::vector<ThreadsTableRow> GetLimitOffset(uint32_t offset, uint32_t limit) override final;
|
|
std::vector<ThreadsTableRow> GetLimitOffsetByField(uint32_t offset,
|
|
uint32_t limit,
|
|
ThreadsTableFields field,
|
|
const char *str) override final;
|
|
|
|
uint32_t GetCount() override final;
|
|
uint32_t GetCountByFieldID(const char *field, uint32_t id) override final;
|
|
ThreadsTableRow getByContact(uint32_t contact_id);
|
|
|
|
/// returns: { maximum_query_depth, vector {requested amount of data which match} }
|
|
std::pair<uint32_t, std::vector<ThreadsTableRow>> getBySMSQuery(std::string text, uint32_t offset, uint32_t limit);
|
|
|
|
private:
|
|
const char *createTableQuery = "CREATE TABLE IF NOT EXISTS threads("
|
|
"_id INTEGER PRIMARY KEY,"
|
|
"date INTEGER,"
|
|
"msg_count INTEGER,"
|
|
"read INTEGER,"
|
|
"contact_id INTEGER,"
|
|
"snippet TEXT NOT NULL,"
|
|
"last_dir INTEGER"
|
|
");";
|
|
|
|
const char *createTableThreadsCounterQuery = "CREATE TABLE IF NOT EXISTS threads_count "
|
|
"(_id INTEGER PRIMARY KEY,"
|
|
"count INTEGER );";
|
|
|
|
const char *threadsCounterInsertionQuery = "INSERT OR IGNORE INTO threads_count ( _id, count ) VALUES (1,0);";
|
|
const char *threadInsertTriggerQuery = "CREATE TRIGGER IF NOT EXISTS on_thread_insert AFTER INSERT ON threads "
|
|
"BEGIN UPDATE threads_count SET count=count+1 WHERE _id=1; END";
|
|
const char *threadRemoveTriggerQuery = "CREATE TRIGGER IF NOT EXISTS on_thread_remove AFTER DELETE ON threads "
|
|
"BEGIN UPDATE threads_count SET count=count-1 WHERE _id=1; END";
|
|
};
|