~aleteoryx/muditaos

70e9ef0d03b9d338bc8029e9650db8170a48213d — Pawel Olejniczak 4 years ago f741703
[CP-77] Replace receivedAt and sentAt fields with createdAt

sentAt json field was never updated and was not used.
Cleaned up DB and DB interface from unused date_send.
M image/user/db/sms_001.sql => image/user/db/sms_001.sql +0 -1
@@ 7,7 7,6 @@ CREATE TABLE IF NOT EXISTS sms
    thread_id  INTEGER,
    contact_id INTEGER,
    date       INTEGER,
    date_send  INTEGER,
    error_code INTEGER,
    body       TEXT NOT_NULL,
    type       INTEGER,

M image/user/db/sms_003.sql => image/user/db/sms_003.sql +6 -6
@@ 1,12 1,12 @@
-- Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-- For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
BEGIN TRANSACTION;
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","date_send","error_code","body","type") VALUES (1,2,2,1547492320,3,0,'Thank you for today!' || CHAR(10) || 'You chose a fantastic place :)',8);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","date_send","error_code","body","type") VALUES (2,2,2,1547492321,4,0,'It was great seeing you too :*',4);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","date_send","error_code","body","type") VALUES (3,1,1,1618907731,3,2,'Hi! How are you today?',8);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","date_send","error_code","body","type") VALUES (4,1,1,1618907732,3,2,'I hope you''re feeling better now...',8);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","date_send","error_code","body","type") VALUES (5,1,1,1618907733,3,2,'Thanks :) Today is better than yesterday',4);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","date_send","error_code","body","type") VALUES (6,1,1,1618907734,3,2,'I''m happy to hear that :)',8);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","error_code","body","type") VALUES (1,2,2,1547492320,0,'Thank you for today!' || CHAR(10) || 'You chose a fantastic place :)',8);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","error_code","body","type") VALUES (2,2,2,1547492321,0,'It was great seeing you too :*',4);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","error_code","body","type") VALUES (3,1,1,1618907731,2,'Hi! How are you today?',8);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","error_code","body","type") VALUES (4,1,1,1618907732,2,'I hope you''re feeling better now...',8);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","error_code","body","type") VALUES (5,1,1,1618907733,2,'Thanks :) Today is better than yesterday',4);
INSERT OR REPLACE INTO "sms" ("_id","thread_id","contact_id","date","error_code","body","type") VALUES (6,1,1,1618907734,2,'I''m happy to hear that :)',8);
INSERT OR REPLACE INTO "templates" ("_id","text","lastUsageTimestamp") VALUES (1,'Thanks for reaching out. I can''t talk right now, I''ll call you later',4);
INSERT OR REPLACE INTO "templates" ("_id","text","lastUsageTimestamp") VALUES (2,'I''ll call you later',3);
INSERT OR REPLACE INTO "templates" ("_id","text","lastUsageTimestamp") VALUES (3,'I''ll be there in 15 minutes',2);

M module-db/Interface/SMSRecord.cpp => module-db/Interface/SMSRecord.cpp +0 -2
@@ 68,7 68,6 @@ bool SMSRecordInterface::Add(const SMSRecord &rec)
                                    .threadID  = thread.ID,
                                    .contactID = contactID,
                                    .date      = rec.date,
                                    .dateSent  = rec.dateSent,
                                    .errorCode = rec.errorCode,
                                    .body      = rec.body,
                                    .type      = rec.type


@@ 175,7 174,6 @@ bool SMSRecordInterface::Update(const SMSRecord &recUpdated)
                                  .threadID  = recCurrent.threadID,
                                  .contactID = recCurrent.contactID,
                                  .date      = recUpdated.date,
                                  .dateSent  = recUpdated.dateSent,
                                  .errorCode = recUpdated.errorCode,
                                  .body      = recUpdated.body,
                                  .type      = recUpdated.type});

M module-db/Interface/SMSRecord.hpp => module-db/Interface/SMSRecord.hpp +5 -6
@@ 1,4 1,4 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 23,7 23,6 @@ namespace db::query
struct SMSRecord : public Record
{
    uint32_t date      = 0;
    uint32_t dateSent  = 0;
    uint32_t errorCode = 0;
    UTF8 body;
    SMSType type       = SMSType::UNKNOWN;


@@ 33,12 32,12 @@ struct SMSRecord : public Record

    SMSRecord() = default;
    SMSRecord(const SMSTableRow &w)
        : Record(w.ID), date(w.date), dateSent(w.dateSent), errorCode(w.errorCode), body(w.body), type(w.type),
          threadID(w.threadID), contactID(w.contactID)
        : Record(w.ID), date(w.date), errorCode(w.errorCode), body(w.body), type(w.type), threadID(w.threadID),
          contactID(w.contactID)
    {}
    SMSRecord(const SMSTableRow &w, const utils::PhoneNumber::View &num)
        : Record(w.ID), date(w.date), dateSent(w.dateSent), errorCode(w.errorCode), body(w.body), type(w.type),
          threadID(w.threadID), contactID(w.contactID), number(num)
        : Record(w.ID), date(w.date), errorCode(w.errorCode), body(w.body), type(w.type), threadID(w.threadID),
          contactID(w.contactID), number(num)
    {}
};


M module-db/Tables/SMSTable.cpp => module-db/Tables/SMSTable.cpp +35 -47
@@ 1,4 1,4 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SMSTable.hpp"


@@ 14,12 14,11 @@ bool SMSTable::create()

bool SMSTable::add(SMSTableRow entry)
{
    return db->execute("INSERT or ignore INTO sms ( thread_id,contact_id, date, date_send, error_code, body, "
                       "type ) VALUES (%lu,%lu,%lu,%lu,0,'%q',%d);",
    return db->execute("INSERT or ignore INTO sms ( thread_id,contact_id, date, error_code, body, "
                       "type ) VALUES (%lu,%lu,%lu,0,'%q',%d);",
                       entry.threadID,
                       entry.contactID,
                       entry.date,
                       entry.dateSent,
                       entry.body.c_str(),
                       entry.type);
}


@@ 54,12 53,11 @@ bool SMSTable::removeByField(SMSTableFields field, const char *str)

bool SMSTable::update(SMSTableRow entry)
{
    return db->execute("UPDATE sms SET thread_id = %lu, contact_id = %lu ,date = %lu, date_send = %lu, error_code = 0, "
    return db->execute("UPDATE sms SET thread_id = %lu, contact_id = %lu ,date = %lu, error_code = 0, "
                       "body = '%q', type =%d WHERE _id=%lu;",
                       entry.threadID,
                       entry.contactID,
                       entry.date,
                       entry.dateSent,
                       entry.body.c_str(),
                       entry.type,
                       entry.ID);


@@ 78,10 76,9 @@ SMSTableRow SMSTable::getById(uint32_t id)
        (*retQuery)[1].getUInt32(),                       // threadID
        (*retQuery)[2].getUInt32(),                       // contactID
        (*retQuery)[3].getUInt32(),                       // date
        (*retQuery)[4].getUInt32(),                       // dateSent
        (*retQuery)[5].getUInt32(),                       // errorCode
        (*retQuery)[6].getString(),                       // body
        static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
        (*retQuery)[4].getUInt32(),                       // errorCode
        (*retQuery)[5].getString(),                       // body
        static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
    };
}



@@ 101,10 98,9 @@ std::vector<SMSTableRow> SMSTable::getByContactId(uint32_t contactId)
            (*retQuery)[1].getUInt32(),                       // threadID
            (*retQuery)[2].getUInt32(),                       // contactID
            (*retQuery)[3].getUInt32(),                       // date
            (*retQuery)[4].getUInt32(),                       // dateSent
            (*retQuery)[5].getUInt32(),                       // errorCode
            (*retQuery)[6].getString(),                       // body
            static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
            (*retQuery)[4].getUInt32(),                       // errorCode
            (*retQuery)[5].getString(),                       // body
            static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
        });
    } while (retQuery->nextRow());



@@ 130,10 126,9 @@ std::vector<SMSTableRow> SMSTable::getByThreadId(uint32_t threadId, uint32_t off
            (*retQuery)[1].getUInt32(),                       // threadID
            (*retQuery)[2].getUInt32(),                       // contactID
            (*retQuery)[3].getUInt32(),                       // date
            (*retQuery)[4].getUInt32(),                       // dateSent
            (*retQuery)[5].getUInt32(),                       // errorCode
            (*retQuery)[6].getString(),                       // body
            static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
            (*retQuery)[4].getUInt32(),                       // errorCode
            (*retQuery)[5].getString(),                       // body
            static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
        });
    } while (retQuery->nextRow());



@@ 146,7 141,7 @@ std::vector<SMSTableRow> SMSTable::getByThreadIdWithoutDraftWithEmptyInput(uint3
{
    auto retQuery = db->query("SELECT * FROM sms WHERE thread_id= %u AND type != %u UNION ALL SELECT 0 as _id, 0 as "
                              "thread_id, 0 as contact_id, 0 as "
                              "date, 0 as date_send, 0 as error_code, 0 as body, %u as type LIMIT %u OFFSET %u",
                              "date, 0 as error_code, 0 as body, %u as type LIMIT %u OFFSET %u",
                              threadId,
                              SMSType::DRAFT,
                              SMSType::INPUT,


@@ 165,10 160,9 @@ std::vector<SMSTableRow> SMSTable::getByThreadIdWithoutDraftWithEmptyInput(uint3
            (*retQuery)[1].getUInt32(),                       // threadID
            (*retQuery)[2].getUInt32(),                       // contactID
            (*retQuery)[3].getUInt32(),                       // date
            (*retQuery)[4].getUInt32(),                       // dateSent
            (*retQuery)[5].getUInt32(),                       // errorCode
            (*retQuery)[6].getString(),                       // body
            static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
            (*retQuery)[4].getUInt32(),                       // errorCode
            (*retQuery)[5].getString(),                       // body
            static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
        });
    } while (retQuery->nextRow());



@@ 200,10 194,9 @@ SMSTableRow SMSTable::getDraftByThreadId(uint32_t threadId)
        (*retQuery)[1].getUInt32(),                       // threadID
        (*retQuery)[2].getUInt32(),                       // contactID
        (*retQuery)[3].getUInt32(),                       // date
        (*retQuery)[4].getUInt32(),                       // dateSent
        (*retQuery)[5].getUInt32(),                       // errorCode
        (*retQuery)[6].getString(),                       // body
        static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
        (*retQuery)[4].getUInt32(),                       // errorCode
        (*retQuery)[5].getString(),                       // body
        static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
    };
}



@@ 224,10 217,9 @@ std::vector<SMSTableRow> SMSTable::getByText(std::string text)
            (*retQuery)[1].getUInt32(),                       // threadID
            (*retQuery)[2].getUInt32(),                       // contactID
            (*retQuery)[3].getUInt32(),                       // date
            (*retQuery)[4].getUInt32(),                       // dateSent
            (*retQuery)[5].getUInt32(),                       // errorCode
            (*retQuery)[6].getString(),                       // body
            static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
            (*retQuery)[4].getUInt32(),                       // errorCode
            (*retQuery)[5].getString(),                       // body
            static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
        });
    } while (retQuery->nextRow());



@@ 249,10 241,9 @@ std::vector<SMSTableRow> SMSTable::getByText(std::string text, uint32_t threadId
            (*retQuery)[1].getUInt32(),                       // threadID
            (*retQuery)[2].getUInt32(),                       // contactID
            (*retQuery)[3].getUInt32(),                       // date
            (*retQuery)[4].getUInt32(),                       // dateSent
            (*retQuery)[5].getUInt32(),                       // errorCode
            (*retQuery)[6].getString(),                       // body
            static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
            (*retQuery)[4].getUInt32(),                       // errorCode
            (*retQuery)[5].getString(),                       // body
            static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
        });
    } while (retQuery->nextRow());
    return ret;


@@ 274,10 265,9 @@ std::vector<SMSTableRow> SMSTable::getLimitOffset(uint32_t offset, uint32_t limi
            (*retQuery)[1].getUInt32(),                       // threadID
            (*retQuery)[2].getUInt32(),                       // contactID
            (*retQuery)[3].getUInt32(),                       // date
            (*retQuery)[4].getUInt32(),                       // dateSent
            (*retQuery)[5].getUInt32(),                       // errorCode
            (*retQuery)[6].getString(),                       // body
            static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
            (*retQuery)[4].getUInt32(),                       // errorCode
            (*retQuery)[5].getString(),                       // body
            static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
        });
    } while (retQuery->nextRow());



@@ 323,10 313,9 @@ std::vector<SMSTableRow> SMSTable::getLimitOffsetByField(uint32_t offset,
            (*retQuery)[1].getUInt32(),                       // threadID
            (*retQuery)[2].getUInt32(),                       // contactID
            (*retQuery)[3].getUInt32(),                       // date
            (*retQuery)[4].getUInt32(),                       // dateSent
            (*retQuery)[5].getUInt32(),                       // errorCode
            (*retQuery)[6].getString(),                       // body
            static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
            (*retQuery)[4].getUInt32(),                       // errorCode
            (*retQuery)[5].getString(),                       // body
            static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
        });
    } while (retQuery->nextRow());



@@ 375,10 364,9 @@ std::pair<uint32_t, std::vector<SMSTableRow>> SMSTable::getManyByType(SMSType ty
                    (*retQuery)[1].getUInt32(),                       // threadID
                    (*retQuery)[2].getUInt32(),                       // contactID
                    (*retQuery)[3].getUInt32(),                       // date
                    (*retQuery)[4].getUInt32(),                       // dateSent
                    (*retQuery)[5].getUInt32(),                       // errorCode
                    (*retQuery)[6].getString(),                       // body
                    static_cast<SMSType>((*retQuery)[7].getUInt32()), // type
                    (*retQuery)[4].getUInt32(),                       // errorCode
                    (*retQuery)[5].getString(),                       // body
                    static_cast<SMSType>((*retQuery)[6].getUInt32()), // type
                });
            } while (retQuery->nextRow());
        }

M module-db/Tables/SMSTable.hpp => module-db/Tables/SMSTable.hpp +1 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 14,7 14,6 @@ struct SMSTableRow : public Record
    uint32_t threadID;
    uint32_t contactID;
    uint32_t date;
    uint32_t dateSent;
    uint32_t errorCode;
    UTF8 body;
    SMSType type;

M module-db/tests/SMSRecord_tests.cpp => module-db/tests/SMSRecord_tests.cpp +0 -2
@@ 40,7 40,6 @@ TEST_CASE("SMS Record tests")
    SmsDB smsDB(smsPath.c_str());

    const uint32_t dateTest      = 123456789;
    const uint32_t dateSentTest  = 987654321;
    const uint32_t errorCodeTest = 555;
    auto numberTest              = utils::PhoneNumber("+48600123456", utils::country::Id::UNKNOWN).getView();
    auto numberTest2             = utils::PhoneNumber("222333444", utils::country::Id::UNKNOWN).getView();


@@ 52,7 51,6 @@ TEST_CASE("SMS Record tests")

    SMSRecord recordIN;
    recordIN.date      = dateTest;
    recordIN.dateSent  = dateSentTest;
    recordIN.errorCode = errorCodeTest;
    recordIN.number    = numberTest;
    recordIN.body      = bodyTest;

M module-db/tests/SMSTable_tests.cpp => module-db/tests/SMSTable_tests.cpp +0 -2
@@ 28,7 28,6 @@ TEST_CASE("SMS Table tests")
                            .threadID  = 0,
                            .contactID = 0,
                            .date      = 0,
                            .dateSent  = 0,
                            .errorCode = 0,
                            .body      = "Test SMS message 1",
                            .type      = SMSType ::INBOX


@@ 39,7 38,6 @@ TEST_CASE("SMS Table tests")
                            .threadID  = 0,
                            .contactID = 0,
                            .date      = 0,
                            .dateSent  = 0,
                            .errorCode = 0,
                            .body      = "Test Draft SMS",
                            .type      = SMSType ::DRAFT

M module-db/tests/ThreadRecord_tests.cpp => module-db/tests/ThreadRecord_tests.cpp +0 -2
@@ 218,7 218,6 @@ TEST_CASE("Thread Record tests")
        SMSRecordInterface smsRecInterface(&smsDB, &contactsDB);
        SMSRecord recordIN;
        recordIN.date      = 123456789;
        recordIN.dateSent  = 987654321;
        recordIN.errorCode = 0;
        recordIN.number    = phoneNumber.getView();
        recordIN.body      = "Ala";


@@ 274,7 273,6 @@ TEST_CASE("Thread Record tests")
        SMSRecordInterface smsRecInterface(&smsDB, &contactsDB);
        SMSRecord recordIN;
        recordIN.date      = 123456789;
        recordIN.dateSent  = 987654321;
        recordIN.errorCode = 0;
        recordIN.number    = phoneNumber.getView();
        recordIN.type      = SMSType ::DRAFT;

M module-services/service-desktop/endpoints/messages/MessageHelper.cpp => module-services/service-desktop/endpoints/messages/MessageHelper.cpp +1 -2
@@ 41,8 41,7 @@ namespace parserFSM
    {

        auto recordEntry = json11::Json::object{{json::messages::contactID, static_cast<int>(record.contactID)},
                                                {json::messages::receivedAt, static_cast<int>(record.date)},
                                                {json::messages::sentAt, static_cast<int>(record.dateSent)},
                                                {json::messages::createdAt, static_cast<int>(record.date)},
                                                {json::messages::messageID, static_cast<int>(record.ID)},
                                                {json::messages::messageBody, record.body.c_str()},
                                                {json::messages::messageType, static_cast<int>(record.type)},

M module-services/service-desktop/parser/ParserUtils.hpp => module-services/service-desktop/parser/ParserUtils.hpp +1 -2
@@ 155,8 155,7 @@ namespace parserFSM
            inline constexpr auto messageID          = "messageID";
            inline constexpr auto messageType        = "messageType";
            inline constexpr auto phoneNumber        = "phoneNumber";
            inline constexpr auto receivedAt         = "receivedAt";
            inline constexpr auto sentAt             = "sentAt";
            inline constexpr auto createdAt          = "createdAt";
            inline constexpr auto lastUsedAt         = "lastUsedAt";
            inline constexpr auto lastUpdatedAt      = "lastUpdatedAt";
            inline constexpr auto isUnread           = "isUnread";

M module-services/service-desktop/tests/unittest.cpp => module-services/service-desktop/tests/unittest.cpp +1 -3
@@ 187,7 187,6 @@ TEST_CASE("DB Helpers test - json encoding (messages)")
    message->body      = "test message";
    message->contactID = 1;
    message->date      = 12345;
    message->dateSent  = 54321;
    message->errorCode = 0;
    message->number    = contactNum.number;
    message->threadID  = 1;


@@ 198,8 197,7 @@ TEST_CASE("DB Helpers test - json encoding (messages)")

    REQUIRE(messageJson[json::messages::messageBody] == "test message");
    REQUIRE(messageJson[json::messages::contactID] == 1);
    REQUIRE(messageJson[json::messages::receivedAt] == 12345);
    REQUIRE(messageJson[json::messages::sentAt] == 54321);
    REQUIRE(messageJson[json::messages::createdAt] == 12345);
    REQUIRE(messageJson[json::messages::threadID] == 1);
    REQUIRE(messageJson[json::messages::messageID] == 10);