~aleteoryx/muditaos

ref: 5b0ea283eb9cc6e453cf9bae898b98e1f65038f0 muditaos/module-db/Tables/ContactsTable.hpp -rw-r--r-- 2.8 KiB
5b0ea283 — Adam Wulkiewicz [BH-000] Update changelog for 1.8.2 and 1.9.0 2 years 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
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2017-2021, 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
{
    uint32_t nameID       = DB_ID_NONE;
    std::string numbersID = "";
    uint32_t ringID       = DB_ID_NONE;
    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(uint32_t id) override final;

    bool update(ContactsTableRow entry) override final;

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

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

  public:
    bool BlockByID(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(uint32_t offset, uint32_t limit) override final;

    std::vector<ContactsTableRow> getLimitOffsetByField(uint32_t offset,
                                                        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:
};