From edeb310b623048b94f4d56d3612ca3a0f20ce0ea Mon Sep 17 00:00:00 2001 From: alek Date: Wed, 15 Jul 2020 22:05:39 +0200 Subject: [PATCH] [EDG-3402] minor clean up and error handling --- module-db/Interface/SMSRecord.cpp | 54 +++++++++++++++++----------- module-db/Interface/ThreadRecord.cpp | 2 -- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/module-db/Interface/SMSRecord.cpp b/module-db/Interface/SMSRecord.cpp index f5d6a04397356522bd5191b7422e0f20422afb3c..901c2570d1f1883af5a7c399e35884022c87426e 100644 --- a/module-db/Interface/SMSRecord.cpp +++ b/module-db/Interface/SMSRecord.cpp @@ -52,23 +52,33 @@ bool SMSRecordInterface::Add(const SMSRecord &rec) ThreadRecord re; re.contactID = contactID; - threadInterface.Add(re); + if (!threadInterface.Add(re)) { + LOG_ERROR("Cannot create new thread"); + return false; + } threadRec = threadInterface.GetLimitOffsetByField( 0, 1, ThreadRecordField::ContactID, std::to_string(contactID).c_str()); + if (threadRec->size() == 0) { + LOG_ERROR("Thread not found"); + return false; + } } threadID = (*threadRec)[0].ID; // Create SMS - smsDB->sms.add(SMSTableRow{.threadID = threadID, - .contactID = contactID, - .date = rec.date, - .dateSent = rec.dateSent, - .errorCode = rec.errorCode, - .body = rec.body, - .type = rec.type - - }); + if (!smsDB->sms.add(SMSTableRow{.threadID = threadID, + .contactID = contactID, + .date = rec.date, + .dateSent = rec.dateSent, + .errorCode = rec.errorCode, + .body = rec.body, + .type = rec.type + + })) { + LOG_ERROR("Cannot add sms"); + return false; + } // TODO: error check @@ -80,9 +90,13 @@ bool SMSRecordInterface::Add(const SMSRecord &rec) thread.msgCount++; if (rec.type == SMSType::INBOX) { thread.unreadMsgCount++; + LOG_DEBUG("unreadMsgCount = %" PRIu32 " for thread = %" PRIu32, thread.unreadMsgCount, thread.ID); } - threadInterface.Update(thread); + if (!threadInterface.Update(thread)) { + LOG_ERROR("Cannot update thread"); + return false; + } return true; } @@ -161,16 +175,14 @@ bool SMSRecordInterface::Update(const SMSRecord &rec) return false; } - 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 true; + 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}); } bool SMSRecordInterface::RemoveByID(uint32_t id) diff --git a/module-db/Interface/ThreadRecord.cpp b/module-db/Interface/ThreadRecord.cpp index 7180f2aad5e5466a228dafe20e5011956a23575e..f0f8496c9ce3d1d9ea78636f88530f93acd4386c 100644 --- a/module-db/Interface/ThreadRecord.cpp +++ b/module-db/Interface/ThreadRecord.cpp @@ -58,8 +58,6 @@ uint32_t ThreadRecordInterface::GetCount(EntryState state) return smsDB->threads.count(state); } -bool markAsRead(); - std::unique_ptr> ThreadRecordInterface::GetLimitOffset(uint32_t offset, uint32_t limit) { auto records = std::make_unique>();