~aleteoryx/muditaos

ref: sign_test muditaos/module-db/Tables/ContactsTable.hpp -rw-r--r-- 2.8 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Common/Common.hpp"
#include "Common/Logging.hpp"
#include "Record.hpp"
#include "Table.hpp"
#include "utf8/UTF8.hpp"
#include <module-apps/application-phonebook/data/ContactsMap.hpp>

#include <string>
#include <vector>
#include <map>

struct ContactsTableRow : public Record
{
    std::uint32_t nameID    = DB_ID_NONE;
    std::string numbersID = "";
    std::uint32_t ringID    = DB_ID_NONE;
    std::uint32_t addressID = DB_ID_NONE;
    std::string speedDial = "";
    UTF8 namePrimary      = "";
    UTF8 nameAlternative  = "";
};

enum class ContactTableFields
{
    SpeedDial
};

class ContactsTable : public Table<ContactsTableRow, ContactTableFields>
{
  public:
    enum class MatchType
    {
        Name,
        TextNumber,
        Group,
        None
    };

    ContactsTable(Database *db);
    virtual ~ContactsTable();

    bool create() override final;
    bool add(ContactsTableRow entry) override final;
    bool removeById(std::uint32_t id) override final;
    bool update(ContactsTableRow entry) override final;

    ContactsTableRow getById(std::uint32_t id) override final;
    ContactsTableRow getByIdWithTemporary(std::uint32_t id);

    bool BlockByID(std::uint32_t id, bool shouldBeBlocked);

    std::vector<ContactsTableRow> Search(const std::string &primaryName,
                                         const std::string &alternativeName,
                                         const std::string &number);

    std::vector<ContactsTableRow> getLimitOffset(std::uint32_t offset, std::uint32_t limit) override final;
    std::vector<ContactsTableRow> getLimitOffsetByField(std::uint32_t offset,
                                                        std::uint32_t limit,
                                                        ContactTableFields field,
                                                        const char *str) override final;

    uint32_t count() override final;
    uint32_t countByFieldId(const char *field, uint32_t id) override final;

    std::vector<std::uint32_t> GetIDsSortedByField(MatchType matchType,
                                                   const std::string &text,
                                                   std::uint32_t groupId,
                                                   std::uint32_t limit  = 0,
                                                   std::uint32_t offset = 0);
    std::vector<std::uint32_t> GetIDsSortedByName(std::uint32_t limit = 0, std::uint32_t offset = 0);

    ContactsMapData GetPosOfFirstLetters();
    std::string GetSortedByNameQueryString(ContactQuerySection section);

  private:
    ContactsTableRow getByIdCommon(std::unique_ptr<QueryResult> retQuery);
};