~aleteoryx/muditaos

ref: sign_test muditaos/module-db/Interface/CalllogRecord.hpp -rw-r--r-- 3.2 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
83
84
// Copyright (c) 2017-2022, 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 "ContactRecord.hpp"
#include "module-db/databases/CalllogDB.hpp"
#include "Record.hpp"
#include "queries/calllog/QueryCalllogSetAllRead.hpp"
#include <PhoneNumber.hpp>
#include <utf8/UTF8.hpp>

#include <cstdint>
#include <vector>

struct CalllogRecord : public Record
{
    PresentationType presentation        = PresentationType::PR_UNKNOWN;
    time_t date                          = 0;
    time_t duration                      = 0;
    CallType type                        = CallType::CT_NONE;
    UTF8 name                            = "";
    utils::PhoneNumber::View phoneNumber = utils::PhoneNumber::View();
    bool isRead                          = true;

    friend std::ostream &operator<<(std::ostream &out, const CalllogRecord &point);
    [[nodiscard]] std::string str() const;

    CalllogRecord() = default;
    CalllogRecord(const CalllogRecord &rhs);
    CalllogRecord(const CallType type, const utils::PhoneNumber::View &number);
    CalllogRecord(const CalllogTableRow &tableRow);
    CalllogRecord &operator=(const CalllogRecord &);
};

enum class CalllogRecordField
{
    DATE,
    TYPE,
};

class CalllogRecordInterface : public RecordInterface<CalllogRecord, CalllogRecordField>
{
  public:
    CalllogRecordInterface(CalllogDB *CalllogDb, ContactsDB *contactsDb);

    bool Add(const CalllogRecord &rec) override final;
    bool RemoveByID(uint32_t id) override final;
    bool RemoveByField(CalllogRecordField field, const char *str) override final;
    bool Update(const CalllogRecord &rec) override final;
    CalllogRecord GetByID(uint32_t id) override final;

    uint32_t GetCount() override final;
    uint32_t GetCount(EntryState state);
    bool SetAllRead();
    bool DeleteAll();

    std::unique_ptr<std::vector<CalllogRecord>> GetLimitOffset(uint32_t offset, uint32_t limit) override final;

    std::unique_ptr<std::vector<CalllogRecord>> GetLimitOffsetByField(uint32_t offset,
                                                                      uint32_t limit,
                                                                      CalllogRecordField field,
                                                                      const char *str) override final;

    uint32_t GetLastID();

    std::unique_ptr<db::QueryResult> runQuery(std::shared_ptr<db::Query> query) override;

  private:
    CalllogDB *calllogDB   = nullptr;
    ContactsDB *contactsDB = nullptr;

    std::vector<CalllogRecord> GetByContactID(uint32_t id);

    std::unique_ptr<db::QueryResult> getQuery(std::shared_ptr<db::Query> query);
    std::unique_ptr<db::QueryResult> setAllReadQuery(std::shared_ptr<db::Query> query);
    std::unique_ptr<db::QueryResult> deleteAllQuery(std::shared_ptr<db::Query> query);
    std::unique_ptr<db::QueryResult> getCountQuery(std::shared_ptr<db::Query> query);
    std::unique_ptr<db::QueryResult> removeQuery(std::shared_ptr<db::Query> query);
    std::unique_ptr<db::QueryResult> getByContactIDQuery(std::shared_ptr<db::Query> query);

    std::optional<ContactRecord> getContactByNumber(utils::PhoneNumber::View number);
};