diff options
Diffstat (limited to 'saltoqd')
-rw-r--r-- | saltoqd/commmanager.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/saltoqd/commmanager.cpp b/saltoqd/commmanager.cpp index 01aaf4b..ba0d06c 100644 --- a/saltoqd/commmanager.cpp +++ b/saltoqd/commmanager.cpp @@ -16,7 +16,7 @@ CommManager::CommManager(Settings *settings, StorageManager *storage, ContactsMa { _calls->setQueryMode(EventModel::AsyncQuery); _calls->setSorting(CallModel::SortByTime); - _calls->setResolveContacts(true); + _calls->setResolveContacts(EventModel::ResolveImmediately); _calls->setLimit(RECORD_LIMIT); _convs->setQueryMode(EventModel::AsyncQuery); @@ -70,21 +70,27 @@ void CommManager::refresh() for (int i = 0; i < rows; i++) { QModelIndex index = _calls->index(i, 0); Event e = _calls->event(index); - QList<Event::Contact> contacts = e.contacts(); - QString name; - if (!contacts.empty()) { - name = contacts.first().second; + const RecipientList &recipients = e.recipients(); + + if (recipients.isEmpty()) { + qCritical() << "Empty recipient list while reading event:" << e.toString(); } + + const Recipient &recipient = recipients.first(); + + QString name = recipient.contactName(); if (name.isEmpty()) { - name = e.remoteUid(); + name = recipient.contactId(); } if (name.isEmpty()) { + // TODO Check if this is still necessary name = tr("Private number"); } + QDateTime dt = e.startTime(); QJsonObject obj; obj.insert("Name", name); - obj.insert("ContactId", _contacts->getRecordIdForContact(e.contactId())); + obj.insert("ContactId", _contacts->getRecordIdForContact(recipient.contactId())); QJsonArray records; if (_calls->hasChildren(index)) { @@ -95,7 +101,7 @@ void CommManager::refresh() QJsonObject record; record.insert("CommsType", QLatin1String("Call")); record.insert("ReceivedTime", qint64(e.startTime().toTime_t())); - record.insert("CallerId", e.remoteUid()); + record.insert("CallerId", recipient.remoteUid()); record.insert("ItemId", e.id()); QJsonObject details; details.insert("Duration", e.startTime().secsTo(e.endTime())); @@ -131,21 +137,25 @@ void CommManager::refresh() for (int i = 0; i < rows; i++) { Group g = _convs->group(_convs->index(i, 0)); - QList<Event::Contact> contacts = g.contacts(); - QString name; - if (!contacts.empty()) { - name = contacts.first().second; + const RecipientList &recipients = g.recipients(); + + if (recipients.isEmpty()) { + qCritical() << "Empty recipient list while reading event:" << g.toString(); } - if (name.isEmpty() && !g.remoteUids().isEmpty()) { - name = g.remoteUids().first(); + + const Recipient &recipient = recipients.first(); + QString name = recipient.contactName(); + if (name.isEmpty()) { + name = recipient.contactId(); } if (name.isEmpty()) { + // TODO Check if this is still necessary name = tr("Unknown contact"); } QJsonObject obj; obj.insert("Name", name); - obj.insert("ContactId", _contacts->getRecordIdForContact(g.contactId())); + obj.insert("ContactId", _contacts->getRecordIdForContact(recipient.contactId())); QJsonArray records; @@ -156,7 +166,7 @@ void CommManager::refresh() QJsonObject record; record.insert("CommsType", QLatin1String("Text")); record.insert("ReceivedTime", qint64(e.startTime().toTime_t())); - record.insert("CallerId", e.remoteUid()); + record.insert("CallerId", recipient.remoteUid()); record.insert("ItemId", e.id()); QJsonObject details; details.insert("Message", e.freeText()); @@ -181,7 +191,7 @@ void CommManager::refresh() QJsonObject record; record.insert("CommsType", QLatin1String("Text")); record.insert("ReceivedTime", qint64(g.startTime().toTime_t())); - record.insert("CallerId", g.remoteUids().first()); + record.insert("CallerId", recipient.remoteUid()); record.insert("ItemId", g.id()); QJsonObject details; details.insert("Message", g.lastMessageText()); |