Exemplo n.º 1
0
void ChannelWatcher::onMessageReceived(const Tp::ReceivedMessage &message)
{
    if (!message.isDeliveryReport()) {
        StorageMessage msg;
        msg.messageDateTime = message.received();
        msg.accountObjectPathId = m_accountDbId;
        msg.targetContactId = m_contactDbId;
        msg.message = message.text();
        msg.messageToken = message.messageToken();
        msg.isIncoming = true;
        msg.isDelivered = true;
        msg.type = 1;

        if (msg.messageToken.isEmpty()) {
            msg.messageToken = QCryptographicHash::hash(QString(msg.messageDateTime.toString() + msg.message).toUtf8(),
                                                        QCryptographicHash::Md5);
        }

        storeMessage(msg);
    } else {
        qDebug() << "Received a delivery report for message" << message.deliveryDetails().originalToken();

        //TODO
        //     QSqlQuery updateQuery;
        //     updateQuery.prepare("UPDATE data SET deliveredDateTime = :deliveredDateTime, isDelivered = :isDelivered WHERE id = :id");
        //     updateQuery.bindValue(":deliveredDateTime", message.deliveredDateTime);
        //     updateQuery.bindValue(":isDelivered", message.isDelivered);
        //     updateQuery.bindValue(":id", message.id);
        //
        //     bool transactionBegin = d->db.transaction();
        //     qDebug() << "Update transaction begins" << transactionBegin;
        //     bool queryResult = updateQuery.exec();
        //     qDebug() << "Update query gut" << queryResult;
        //     if (queryResult) {
        //         d->db.commit();
        //     } else {
        //         qWarning() << updateQuery.lastError().text();
        //         d->db.rollback();
        //     }

    }
}
Message::Message(const Tp::ReceivedMessage &original, const KTp::MessageContext &context) :
    d(new Private)
{
    Q_UNUSED(context)

    d->sentTime = original.sent();
    if (d->sentTime.isNull()) {
        d->sentTime = original.received();
    }

    d->token = original.messageToken();
    d->messageType = original.messageType();
    d->isHistory = original.isScrollback();
    d->direction = KTp::Message::RemoteToLocal;

    setMainMessagePart(original.text());

    if (!original.sender().isNull()) {
        d->sender = KTp::ContactPtr::qObjectCast(original.sender());
    } else {
        d->senderAlias = original.senderNickname();
    }
}