ChannelWatcher::ChannelWatcher(const Tp::TextChannelPtr &channel, const QString &accountObjectPath, QObject *parent) : QObject(parent), m_channel(channel), m_accountObjectPath(accountObjectPath), m_db(QSqlDatabase::database()), m_contactDbId(0), //sqlite auto-increment starts at 1 m_accountDbId(0) { qDebug() << "Delivery reports support" << channel->deliveryReportingSupport(); connect(channel.data(), &Tp::TextChannel::invalidated, this, &ChannelWatcher::invalidated); connect(channel.data(), &Tp::TextChannel::invalidated, this, [=]() { qDebug() << "Channel invalidated"; }); connect(channel.data(), &Tp::TextChannel::messageReceived, this, &ChannelWatcher::onMessageReceived); connect(channel.data(), &Tp::TextChannel::messageSent, this, &ChannelWatcher::onMessageSent); qDebug() << this << "New channel being watched" << channel.data(); storeContactInfo(); storeAccountInfo(); Q_FOREACH (const Tp::ReceivedMessage &message, channel->messageQueue()) { onMessageReceived(message); } }