Removing entries from call history programmatically

Hi guys, is someone aware of, and could please point me to, some documentation or example code about how to programmatically (C++) remove entries from the call history?

So… not possible, or no one knows? :roll_eyes:

Quickly checking think it’s libcommhistory → callmodel/eventmodel → deleteEvent() etc. There’s commhistory-tool on the libcommhistory repository too with c++ implementation.

3 Likes

OK, thanks a lot @pvuorela for your suggestion! It seems to work fine. The following does the job for me:

CommHistory::CallModel::Sorting sorting = CommHistory::CallModel::SortByContact;
    CommHistory::CallModel::ContactResolveType resolve = CommHistory::CallModel::DoNotResolve;
    CommHistory::CallModel model;
        model.setFilter(sorting, CommHistory::CallEvent::CallType::ReceivedCallType);
        model.setResolveContacts(resolve);
        model.setQueryMode(resolve == CommHistory::CallModel::ResolveImmediately ? CommHistory::EventModel::AsyncQuery : CommHistory::EventModel::SyncQuery);

QVector<QStringList> array;
        for ( int i = 0; i < model.rowCount(); i++ )
            {
                CommHistory::Event e = model.event(model.index(i, 0));
                QString text = e.toString();
                array.append(text.split("|"));
            }

        for (int c = 0; c < model.rowCount(); c++)
                {
            if (array[c][9].contains(callingNumber))
            {
                 model.deleteEvent(array[c][0].toInt());
            }
        }

Note that I had to manually split event string to a list / array for easier processing, i.e. something like

QString text = e.toString();
                array.append(text.split("|"));

because I couldn’t make CommHistory::Event::toList() work (the result is always empty). Only CommHistory::Event::toString() works for me, and then I manually split it by the “|” character to e.g. a QStringList.

Note 2: after deleting a call event from commhistory, it doesn’t seem to disappear right away from the list in the History tab of the Voicecall-ui. Sometimes it takes closing and reopening, or even restarting voicecall-ui for it to notice it. Should it be signalled somehow for voicecall-ui to automatically refresh the history?

I still have this problem and can’t find any solution:

After successfully deleting a call event from commhistory (it gets correctly deleted from both the model in the code and from the actual commhistory database), it is still visible in the History tab of the Voicecall-ui (whereas at the same time it is no longer visible on the corresponding contact’s or phone number’s details page where its full communication history is listed - that list is correctly updated and no longer includes the deleted event). But in case of the Voicecall-UI’s “History” tab, it takes killing / restarting voicecall-ui-prestart for that list to get reloaded / refreshed and no longer show the deleted event.

Does anyone know how to trigger Voicecall-ui to refresh the “History” list after deleting an event?