~ci-train-bot/history-service/history-service-ubuntu-zesty-2629

« back to all changes in this revision

Viewing changes to Ubuntu/History/historyeventmodel.cpp

  • Committer: Bileto Bot
  • Author(s): Gustavo Pichorim Boiko
  • Date: 2017-03-23 01:28:52 UTC
  • mfrom: (230.2.35 staging)
  • Revision ID: ci-train-bot@canonical.com-20170323012852-vzmjcare13zofbna
- Adapt to support VOIP accounts.
- Improve the notifications of participants changing
- Only start saving information events about contacts joining and leaving after the self contact is in the local list of participants.
- Improve Roles management performance by caching the retrieved data.
- Mark entire conversations as read.
- Allow pass multiple fields on sort clause.
- Reduce the dbus traffic when marking messages and threads as read.
- Use a QLockFile to ensure there will be only one instance of the daemon per user. As we now delay the registration on dbus, sometimes we ended up having two instances of the daeon running (because of dbus activation). This change makes sure that won't happen.
- Do not load the participants from threads automatically. If the client really needs it, it can use the newly added API to fetch the participants.
- Make it possible to debug sqlite commands.

Approved by: system-apps-ci-bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2013-2015 Canonical, Ltd.
 
2
 * Copyright (C) 2013-2017 Canonical, Ltd.
3
3
 *
4
4
 * Authors:
5
5
 *  Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
29
29
#include <QTimerEvent>
30
30
 
31
31
HistoryEventModel::HistoryEventModel(QObject *parent) :
32
 
    HistoryModel(parent), mCanFetchMore(true), mEventWritingTimer(0)
 
32
    HistoryModel(parent), mCanFetchMore(true)
33
33
{
34
34
    // configure the roles
35
35
    mRoles = HistoryModel::roleNames();
95
95
        result = event.eventId();
96
96
        break;
97
97
    case SenderIdRole:
98
 
        result = event.senderId();
 
98
        result = History::ContactMatcher::normalizeId(event.senderId());
99
99
        break;
100
100
    case SenderRole:
101
 
        result = History::ContactMatcher::instance()->contactInfo(event.accountId(), event.senderId());
 
101
        if (mMatchContacts) {
 
102
            result = History::ContactMatcher::instance()->contactInfo(event.accountId(), event.senderId());
 
103
        } else {
 
104
            QVariantMap map;
 
105
            map[History::FieldIdentifier] = event.senderId();
 
106
            map[History::FieldAccountId] = event.accountId();
 
107
            result = map;
 
108
        }
102
109
        break;
103
110
    case TimestampRole:
104
111
        result = event.timestamp();
168
175
        break;
169
176
    case RemoteParticipantRole:
170
177
        if (!voiceEvent.isNull()) {
171
 
            result = voiceEvent.remoteParticipant();
 
178
            result = History::ContactMatcher::normalizeId(voiceEvent.remoteParticipant());
172
179
        }
173
180
        break;
174
181
    case SubjectAsAliasRole:
175
182
        if (!textEvent.isNull()) {
176
 
            QVariantMap contactInfo = History::ContactMatcher::instance()->contactInfo(event.accountId(), textEvent.subject());
177
 
            QString returnValue = contactInfo[History::FieldAlias].toString();
178
 
            if (returnValue.isEmpty()) {
179
 
                returnValue = contactInfo[History::FieldIdentifier].toString();
 
183
            if (mMatchContacts) {
 
184
                QVariantMap contactInfo = History::ContactMatcher::instance()->contactInfo(event.accountId(), textEvent.subject());
 
185
                QString returnValue = contactInfo[History::FieldAlias].toString();
 
186
                if (returnValue.isEmpty()) {
 
187
                    returnValue = contactInfo[History::FieldIdentifier].toString();
 
188
                }
 
189
                return returnValue;
 
190
 
180
191
            }
181
 
            return returnValue;
 
192
            return textEvent.subject();
182
193
        }
183
194
        break;
184
195
    }
307
318
    return History::Manager::instance()->writeEvents(History::Events() << textEvent);
308
319
}
309
320
 
310
 
bool HistoryEventModel::markEventAsRead(const QString &accountId, const QString &threadId, const QString &eventId, int eventType)
311
 
{
312
 
    History::Event event = History::Manager::instance()->getSingleEvent((History::EventType)eventType, accountId, threadId, eventId);
313
 
    event.setNewEvent(false);
314
 
    if (event.type() == History::EventTypeText) {
315
 
        History::TextEvent textEvent = event;
316
 
        textEvent.setReadTimestamp(QDateTime::currentDateTime());
317
 
        event = textEvent;
318
 
    }
319
 
    mEventWritingQueue << event;
320
 
    if (mEventWritingTimer != 0) {
321
 
        killTimer(mEventWritingTimer);
322
 
    }
323
 
    mEventWritingTimer  = startTimer(500);
324
 
    return true;
325
 
}
326
 
 
327
321
void HistoryEventModel::updateQuery()
328
322
{
329
323
    // remove all events from the model
341
335
        mView->disconnect(this);
342
336
    }
343
337
 
344
 
    if (mFilter) {
 
338
    if (mFilter && mFilter->filter().isValid()) {
345
339
        queryFilter = mFilter->filter();
346
340
    } else {
347
341
        // we should not return anything if there is no filter
363
357
            SIGNAL(eventsRemoved(History::Events)),
364
358
            SLOT(onEventsRemoved(History::Events)));
365
359
    connect(mView.data(),
 
360
            SIGNAL(threadsRemoved(History::Threads)),
 
361
            SLOT(onThreadsRemoved(History::Threads)));
 
362
    connect(mView.data(),
366
363
            SIGNAL(invalidated()),
367
364
            SLOT(triggerQueryUpdate()));
368
365
 
439
436
    // should be handle internally in History::EventView?
440
437
}
441
438
 
442
 
void HistoryEventModel::timerEvent(QTimerEvent *event)
 
439
void HistoryEventModel::onThreadsRemoved(const History::Threads &threads)
443
440
{
444
 
    HistoryModel::timerEvent(event);
445
 
    if (event->timerId() == mEventWritingTimer) {
446
 
        killTimer(mEventWritingTimer);
447
 
        mEventWritingTimer = 0;
448
 
 
449
 
        if (mEventWritingQueue.isEmpty()) {
450
 
            return;
451
 
        }
452
 
 
453
 
        qDebug() << "Goint to update" << mEventWritingQueue.count() << "events.";
454
 
        if (History::Manager::instance()->writeEvents(mEventWritingQueue)) {
455
 
            qDebug() << "... succeeded!";
456
 
            mEventWritingQueue.clear();
 
441
    // When a thread is removed we don't get event removed signals,
 
442
    // so we compare and find if we have an event matching that thread.
 
443
    // in case we find it, we invalidate the whole view as there might be
 
444
    // out of date cached data on the daemon side
 
445
    int count = rowCount();
 
446
    Q_FOREACH(const History::Thread &thread, threads) {
 
447
        for (int i = 0; i < count; ++i) {
 
448
            QModelIndex idx = index(i);
 
449
            if (idx.data(AccountIdRole).toString() == thread.accountId() &&
 
450
                idx.data(ThreadIdRole).toString() == thread.threadId()) {
 
451
                triggerQueryUpdate();
 
452
                return;
 
453
            }
457
454
        }
458
455
    }
459
456
}