diff --git a/module-apps/application-messages/ApplicationMessages.cpp b/module-apps/application-messages/ApplicationMessages.cpp index 6d01bd24e..8340aebdc 100644 --- a/module-apps/application-messages/ApplicationMessages.cpp +++ b/module-apps/application-messages/ApplicationMessages.cpp @@ -257,7 +257,7 @@ namespace app // update date sent - it will display an old, failed sms at the the bottom, but this is correct auto time = utils::time::Timestamp(); resendRecord.date = time.getTime(); - return DBServiceAPI::SMSUpdate(this, resendRecord) != DB_ID_NONE; + return DBServiceAPI::SMSUpdate(this, resendRecord); } bool ApplicationMessages::handleSendSmsFromThread(const utils::PhoneNumber::View &number, const UTF8 &body) diff --git a/module-db/Interface/SMSRecord.cpp b/module-db/Interface/SMSRecord.cpp index 9234976c1..d32ab813d 100644 --- a/module-db/Interface/SMSRecord.cpp +++ b/module-db/Interface/SMSRecord.cpp @@ -7,16 +7,10 @@ #include SMSRecord::SMSRecord(const SMSTableRow &w, const utils::PhoneNumber::View &num) + : date(w.date), dateSent(w.dateSent), errorCode(w.errorCode), body(w.body), type(w.type), threadID(w.threadID), + contactID(w.contactID), number(num) { - ID = w.ID; - date = w.date; - dateSent = w.dateSent; - errorCode = w.errorCode; - number = num; - body = w.body; - type = w.type; - threadID = w.threadID; - contactID = w.contactID; + this->ID = w.ID; } SMSRecordInterface::SMSRecordInterface(SmsDB *smsDb, ContactsDB *contactsDb) : smsDB(smsDb), contactsDB(contactsDb) @@ -158,21 +152,22 @@ std::unique_ptr> SMSRecordInterface::GetLimitOffset(uint3 return records; } -bool SMSRecordInterface::Update(const SMSRecord &rec) +bool SMSRecordInterface::Update(const SMSRecord &recUpdated) { - auto sms = smsDB->sms.getById(rec.ID); - if (!sms.isValid()) { + + auto recCurrent = GetByID(recUpdated.ID); + if (!recCurrent.isValid()) { // if updating non-existent entry return false; } - return smsDB->sms.update(SMSTableRow{{.ID = rec.ID}, - .threadID = sms.threadID, - .contactID = sms.contactID, - .date = rec.date, - .dateSent = rec.dateSent, - .errorCode = rec.errorCode, - .body = rec.body, - .type = rec.type}); + return smsDB->sms.update(SMSTableRow{{.ID = recUpdated.ID}, + .threadID = recCurrent.threadID, + .contactID = recCurrent.contactID, + .date = recUpdated.date, + .dateSent = recUpdated.dateSent, + .errorCode = recUpdated.errorCode, + .body = recUpdated.body, + .type = recUpdated.type}); } bool SMSRecordInterface::RemoveByID(uint32_t id) diff --git a/module-db/Interface/SMSRecord.hpp b/module-db/Interface/SMSRecord.hpp index baf9990e2..1df407f7e 100644 --- a/module-db/Interface/SMSRecord.hpp +++ b/module-db/Interface/SMSRecord.hpp @@ -41,7 +41,7 @@ class SMSRecordInterface : public RecordInterface bool Add(const SMSRecord &rec) override final; bool RemoveByID(uint32_t id) override final; bool RemoveByField(SMSRecordField field, const char *str) override final; - bool Update(const SMSRecord &rec) override final; + bool Update(const SMSRecord &recUpdated) override final; SMSRecord GetByID(uint32_t id) override final; uint32_t GetCount() override final; diff --git a/module-db/Interface/ThreadRecord.hpp b/module-db/Interface/ThreadRecord.hpp index 4fd4b7c22..90aa9a8f0 100644 --- a/module-db/Interface/ThreadRecord.hpp +++ b/module-db/Interface/ThreadRecord.hpp @@ -16,19 +16,15 @@ struct ThreadRecord : Record uint32_t msgCount = 0; uint32_t unreadMsgCount = 0; UTF8 snippet; - SMSType type = SMSType::UNKNOWN; - uint32_t contactID = DB_ID_NONE; + SMSType type = SMSType::UNKNOWN; + uint32_t contactID = DB_ID_NONE; ThreadRecord() = default; ThreadRecord(const ThreadsTableRow &rec) + : date(rec.date), msgCount(rec.msgCount), unreadMsgCount(rec.unreadMsgCount), snippet(rec.snippet), + type(rec.type), contactID(rec.contactID) { - ID = rec.ID; - date = rec.date; - msgCount = rec.msgCount; - unreadMsgCount = rec.unreadMsgCount; - snippet = rec.snippet; - type = rec.type; - contactID = rec.contactID; + ID = rec.ID; } bool isUnread() const diff --git a/module-services/service-db/api/DBServiceAPI.cpp b/module-services/service-db/api/DBServiceAPI.cpp index 4ec00736b..6dc787670 100644 --- a/module-services/service-db/api/DBServiceAPI.cpp +++ b/module-services/service-db/api/DBServiceAPI.cpp @@ -106,9 +106,7 @@ SMSRecord DBServiceAPI::SMSGetLastRecord(sys::Service *serv) return (*smsResponse->records)[0]; } else { - SMSRecord rec; - rec.ID = 0; - return rec; + return SMSRecord(); } } diff --git a/module-services/service-db/messages/DBNotificationMessage.hpp b/module-services/service-db/messages/DBNotificationMessage.hpp index 757b3a106..d4b898d61 100644 --- a/module-services/service-db/messages/DBNotificationMessage.hpp +++ b/module-services/service-db/messages/DBNotificationMessage.hpp @@ -12,7 +12,7 @@ namespace db { public: NotificationMessage(db::Interface::Name interface, Query::Type type); - db::Interface::Name interface; + const db::Interface::Name interface; const Query::Type type; }; } // namespace db