28
28
#include "textevent.h"
29
29
#include "manager.h"
30
30
#include "utils_p.h"
31
#include "voiceevent.h"
31
32
#include <QTimerEvent>
32
33
#include <QCryptographicHash>
35
36
HistoryModel::HistoryModel(QObject *parent) :
36
37
QAbstractListModel(parent), mFilter(0), mSort(new HistoryQmlSort(this)),
37
mType(EventTypeText), mMatchContacts(false), mUpdateTimer(0), mEventWritingTimer(0), mWaitingForQml(false)
38
mType(EventTypeText), mMatchContacts(false), mUpdateTimer(0), mEventWritingTimer(0), mThreadWritingTimer(0), mWaitingForQml(false)
39
40
// configure the roles
40
41
mRoles[AccountIdRole] = "accountId";
425
426
qDebug() << "... succeeded!";
426
427
mEventWritingQueue.clear();
429
} else if (event->timerId() == mThreadWritingTimer) {
430
killTimer(mThreadWritingTimer);
431
mThreadWritingTimer = 0;
433
if (mThreadWritingQueue.isEmpty()) {
437
History::Manager::instance()->markThreadsAsRead(mThreadWritingQueue);
438
mThreadWritingQueue.clear();
496
bool HistoryModel::markEventAsRead(const QString &accountId, const QString &threadId, const QString &eventId, int eventType)
507
bool HistoryModel::markEventAsRead(const QVariantMap &eventProperties)
498
History::Event event = History::Manager::instance()->getSingleEvent((History::EventType)eventType, accountId, threadId, eventId);
509
History::Event event;
510
History::EventType type = (History::EventType) eventProperties[History::FieldType].toInt();
512
case History::EventTypeText:
513
event = History::TextEvent::fromProperties(eventProperties);
515
case History::EventTypeVoice:
516
event = History::VoiceEvent::fromProperties(eventProperties);
499
520
event.setNewEvent(false);
500
521
if (event.type() == History::EventTypeText) {
501
522
History::TextEvent textEvent = event;
502
523
textEvent.setReadTimestamp(QDateTime::currentDateTime());
503
524
event = textEvent;
526
// for repeated events, keep the last called one only
527
if (mEventWritingQueue.contains(event)) {
528
mEventWritingQueue.removeOne(event);
505
530
mEventWritingQueue << event;
506
531
if (mEventWritingTimer != 0) {
507
532
killTimer(mEventWritingTimer);
509
mEventWritingTimer = startTimer(500);
534
mEventWritingTimer = startTimer(500);
513
538
void HistoryModel::markThreadsAsRead(const QVariantList &threadsProperties)
515
History::Threads threads;
516
540
Q_FOREACH(const QVariant &entry, threadsProperties) {
517
541
QVariantMap threadProperties = entry.toMap();
518
542
History::Thread thread = History::Thread::fromProperties(threadProperties);
520
544
if (!thread.isNull()) {
545
if (mThreadWritingQueue.contains(thread)) {
546
mThreadWritingQueue.removeOne(thread);
548
mThreadWritingQueue << thread;
525
if (threads.isEmpty()) {
552
if (mThreadWritingTimer != 0) {
553
killTimer(mThreadWritingTimer);
529
History::Manager::instance()->markThreadsAsRead(threads);
555
mThreadWritingTimer = startTimer(500);
532
558
void HistoryModel::classBegin()