mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-10-25 16:08:30 -04:00
[EGD-3532] identify thread with a number
Use phone number instead of contact number to identify a message thread to allow having multiple threads for a contact if contact has multiple numbers.
This commit is contained in:
1 parent
9566c074fb
commit
204dd621ef
22 files changed
+376
-75
No files matched your search
@@ -1,5 +1,9 @@
|
||||
#include "ThreadRecord.hpp"
|
||||
#include "SMSRecord.hpp"
|
||||
#include "ContactRecord.hpp"
|
||||
|
||||
#include <queries/sms/QueryThreadGetByNumber.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <log/log.hpp>
|
||||
|
||||
@@ -14,6 +18,7 @@ bool ThreadRecordInterface::Add(const ThreadRecord &rec)
|
||||
.msgCount = rec.msgCount,
|
||||
.unreadMsgCount = rec.unreadMsgCount,
|
||||
.contactID = rec.contactID,
|
||||
.numberID = rec.numberID,
|
||||
.snippet = rec.snippet,
|
||||
.type = rec.type});
|
||||
|
||||
@@ -38,6 +43,7 @@ bool ThreadRecordInterface::Update(const ThreadRecord &rec)
|
||||
.msgCount = rec.msgCount,
|
||||
.unreadMsgCount = rec.unreadMsgCount,
|
||||
.contactID = rec.contactID,
|
||||
.numberID = rec.numberID,
|
||||
.snippet = rec.snippet,
|
||||
.type = rec.type
|
||||
|
||||
@@ -74,14 +80,19 @@ std::unique_ptr<std::vector<ThreadRecord>> ThreadRecordInterface::GetLimitOffset
|
||||
{
|
||||
auto records = std::make_unique<std::vector<ThreadRecord>>();
|
||||
|
||||
ThreadsTableFields threadsField;
|
||||
switch (field) {
|
||||
case ThreadRecordField::ContactID: {
|
||||
auto ret = smsDB->threads.getLimitOffsetByField(offset, limit, ThreadsTableFields::ContactID, str);
|
||||
|
||||
for (const auto &w : ret) {
|
||||
records->push_back(w);
|
||||
}
|
||||
threadsField = ThreadsTableFields::ContactID;
|
||||
} break;
|
||||
case ThreadRecordField::NumberID: {
|
||||
threadsField = ThreadsTableFields::NumberID;
|
||||
} break;
|
||||
}
|
||||
|
||||
auto ret = smsDB->threads.getLimitOffsetByField(offset, limit, threadsField, str);
|
||||
for (const auto &w : ret) {
|
||||
records->push_back(w);
|
||||
}
|
||||
|
||||
return records;
|
||||
@@ -119,6 +130,24 @@ ThreadRecord ThreadRecordInterface::GetByContact(uint32_t contact_id)
|
||||
return ThreadRecord(ret[0]);
|
||||
}
|
||||
|
||||
ThreadRecord ThreadRecordInterface::GetByNumber(const utils::PhoneNumber::View &phoneNumber)
|
||||
{
|
||||
auto contactInterface = ContactRecordInterface(contactsDB);
|
||||
auto match = contactInterface.MatchByNumber(phoneNumber);
|
||||
|
||||
if (!match.has_value()) {
|
||||
return ThreadRecord();
|
||||
}
|
||||
|
||||
auto threadRec = GetLimitOffsetByField(0, 1, ThreadRecordField::NumberID, std::to_string(match->numberId).c_str());
|
||||
|
||||
if (threadRec->size() == 0) {
|
||||
return ThreadRecord();
|
||||
}
|
||||
|
||||
return threadRec->at(0);
|
||||
}
|
||||
|
||||
std::unique_ptr<db::QueryResult> ThreadRecordInterface::runQuery(std::shared_ptr<db::Query> query)
|
||||
{
|
||||
if (const auto localQuery = dynamic_cast<const db::query::SMSSearch *>(query.get())) {
|
||||
@@ -142,6 +171,13 @@ std::unique_ptr<db::QueryResult> ThreadRecordInterface::runQuery(std::shared_ptr
|
||||
response->setRequestQuery(query);
|
||||
return response;
|
||||
}
|
||||
|
||||
if (const auto local_query = dynamic_cast<const db::query::ThreadGetByNumber *>(query.get())) {
|
||||
auto response = std::make_unique<db::query::ThreadGetByNumberResult>(GetByNumber(local_query->getNumber()));
|
||||
response->setRequestQuery(query);
|
||||
return response;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user