From 70e9ef0d03b9d338bc8029e9650db8170a48213d Mon Sep 17 00:00:00 2001 From: Pawel Olejniczak Date: Tue, 25 May 2021 19:22:32 +0200 Subject: [PATCH] [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. --- image/user/db/sms_001.sql | 1 - image/user/db/sms_003.sql | 12 +-- module-db/Interface/SMSRecord.cpp | 2 - module-db/Interface/SMSRecord.hpp | 11 ++- module-db/Tables/SMSTable.cpp | 82 ++++++++----------- module-db/Tables/SMSTable.hpp | 3 +- module-db/tests/SMSRecord_tests.cpp | 2 - module-db/tests/SMSTable_tests.cpp | 2 - module-db/tests/ThreadRecord_tests.cpp | 2 - .../endpoints/messages/MessageHelper.cpp | 3 +- .../service-desktop/parser/ParserUtils.hpp | 3 +- .../service-desktop/tests/unittest.cpp | 4 +- 12 files changed, 50 insertions(+), 77 deletions(-) diff --git a/image/user/db/sms_001.sql b/image/user/db/sms_001.sql index 9de1a1c491b1e69ff7b92783f4cbce0eadb68c5b..5c9b3161abb48907f44e120d8f0e8647c9302f2e 100644 --- a/image/user/db/sms_001.sql +++ b/image/user/db/sms_001.sql @@ -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, diff --git a/image/user/db/sms_003.sql b/image/user/db/sms_003.sql index 3fc518a298f229ec912d7a7e61a9390795febd23..8ac55166f178a6fd26d08c81a9a710883a57c13f 100644 --- a/image/user/db/sms_003.sql +++ b/image/user/db/sms_003.sql @@ -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); diff --git a/module-db/Interface/SMSRecord.cpp b/module-db/Interface/SMSRecord.cpp index 1085b8aac07273bc542dcaa2b08130a21445bd8e..d1d3d6cac84cc3c3de42be44c91b4cf989b714b8 100644 --- a/module-db/Interface/SMSRecord.cpp +++ b/module-db/Interface/SMSRecord.cpp @@ -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}); diff --git a/module-db/Interface/SMSRecord.hpp b/module-db/Interface/SMSRecord.hpp index 86da89cfbf675d97e267ae5c1fe43ac5920424c3..66ba81b2420f6bdc2eff86989d166bbaba65d329 100644 --- a/module-db/Interface/SMSRecord.hpp +++ b/module-db/Interface/SMSRecord.hpp @@ -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) {} }; diff --git a/module-db/Tables/SMSTable.cpp b/module-db/Tables/SMSTable.cpp index 7fb05d29206a4092b412d12dfe0938ff71c9d14c..c55a69f641fbb38d1ac917fb213658f0525893d1 100644 --- a/module-db/Tables/SMSTable.cpp +++ b/module-db/Tables/SMSTable.cpp @@ -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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*retQuery)[6].getUInt32()), // type }; } @@ -101,10 +98,9 @@ std::vector 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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*retQuery)[6].getUInt32()), // type }); } while (retQuery->nextRow()); @@ -130,10 +126,9 @@ std::vector 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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*retQuery)[6].getUInt32()), // type }); } while (retQuery->nextRow()); @@ -146,7 +141,7 @@ std::vector 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 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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*retQuery)[6].getUInt32()), // type }; } @@ -224,10 +217,9 @@ std::vector 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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*retQuery)[6].getUInt32()), // type }); } while (retQuery->nextRow()); @@ -249,10 +241,9 @@ std::vector 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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*retQuery)[6].getUInt32()), // type }); } while (retQuery->nextRow()); return ret; @@ -274,10 +265,9 @@ std::vector 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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*retQuery)[6].getUInt32()), // type }); } while (retQuery->nextRow()); @@ -323,10 +313,9 @@ std::vector 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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*retQuery)[6].getUInt32()), // type }); } while (retQuery->nextRow()); @@ -375,10 +364,9 @@ std::pair> 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((*retQuery)[7].getUInt32()), // type + (*retQuery)[4].getUInt32(), // errorCode + (*retQuery)[5].getString(), // body + static_cast((*retQuery)[6].getUInt32()), // type }); } while (retQuery->nextRow()); } diff --git a/module-db/Tables/SMSTable.hpp b/module-db/Tables/SMSTable.hpp index 85f7117551ee8eefa126260a9f161236c6b84062..3ae1d508559555ce9f8df42cd31478720b4eb2c3 100644 --- a/module-db/Tables/SMSTable.hpp +++ b/module-db/Tables/SMSTable.hpp @@ -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; diff --git a/module-db/tests/SMSRecord_tests.cpp b/module-db/tests/SMSRecord_tests.cpp index 92a257fee980969ad1e54cc98a706315e7f4674f..14e1f21dbf9c0c458e68fb3ef5f95fb13f558db8 100644 --- a/module-db/tests/SMSRecord_tests.cpp +++ b/module-db/tests/SMSRecord_tests.cpp @@ -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; diff --git a/module-db/tests/SMSTable_tests.cpp b/module-db/tests/SMSTable_tests.cpp index b96f9fe39a4a4f14c80d4f726a183cbc963ecdee..3d58c55934a26118803e1938ea8ee1ca6129f423 100644 --- a/module-db/tests/SMSTable_tests.cpp +++ b/module-db/tests/SMSTable_tests.cpp @@ -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 diff --git a/module-db/tests/ThreadRecord_tests.cpp b/module-db/tests/ThreadRecord_tests.cpp index adbe5146e331fb47afea8e7c6433ae9d64e0363c..bb7383944e702523cdba0a1dba780a3cefaf9cb0 100644 --- a/module-db/tests/ThreadRecord_tests.cpp +++ b/module-db/tests/ThreadRecord_tests.cpp @@ -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; diff --git a/module-services/service-desktop/endpoints/messages/MessageHelper.cpp b/module-services/service-desktop/endpoints/messages/MessageHelper.cpp index ae26337b175ed7a724830c8f07b7e3965acb4652..24d9fdfa19a5d09793ff84be78e2a8bb0d326deb 100644 --- a/module-services/service-desktop/endpoints/messages/MessageHelper.cpp +++ b/module-services/service-desktop/endpoints/messages/MessageHelper.cpp @@ -41,8 +41,7 @@ namespace parserFSM { auto recordEntry = json11::Json::object{{json::messages::contactID, static_cast(record.contactID)}, - {json::messages::receivedAt, static_cast(record.date)}, - {json::messages::sentAt, static_cast(record.dateSent)}, + {json::messages::createdAt, static_cast(record.date)}, {json::messages::messageID, static_cast(record.ID)}, {json::messages::messageBody, record.body.c_str()}, {json::messages::messageType, static_cast(record.type)}, diff --git a/module-services/service-desktop/parser/ParserUtils.hpp b/module-services/service-desktop/parser/ParserUtils.hpp index 4239ccf34baf472242a6a700c8979f2f716713d1..8ac46e18a13d53be13855ec30db7a9e66a6346ef 100644 --- a/module-services/service-desktop/parser/ParserUtils.hpp +++ b/module-services/service-desktop/parser/ParserUtils.hpp @@ -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"; diff --git a/module-services/service-desktop/tests/unittest.cpp b/module-services/service-desktop/tests/unittest.cpp index a99fbba81537ffeeeb11e937579e24a52ff5a477..bf1be1895ff1c6e0bc6b218daeb786825e12e0a0 100644 --- a/module-services/service-desktop/tests/unittest.cpp +++ b/module-services/service-desktop/tests/unittest.cpp @@ -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);