void OtrProxyChannel::Adaptee::onMessageReceived(const Tp::ReceivedMessage &receivedMessage)
{
    const uint id = receivedMessage.header()[QLatin1String("pending-message-id")].variant().toUInt(nullptr);
    OTR::Message otrMsg(receivedMessage.parts());
    // no private key - should generate on now
    if(otrMsg.isOTRmessage() && otrSes.localFingerprint().isEmpty() && ps->getPolicy() != OTRL_POLICY_NEVER) {
        enqueuedMessages << receivedMessage;
        acquirePrivateKey();
        return;
    // private key is currently being generated
    } else if(isGenerating) {
        enqueuedMessages << receivedMessage;
        return;
    }

    qCDebug(KTP_PROXY) << "Received message with id: " << id;
    const OTR::CryptResult cres = otrSes.decrypt(otrMsg);

    if(cres == OTR::CryptResult::CHANGED || cres == OTR::CryptResult::UNCHANGED) {
        messages.insert(id, receivedMessage);

        Q_EMIT messageReceived(otrMsg.parts());
    } else {
        // Error or OTR message - acknowledge right now
        if(cres == OTR::CryptResult::ERROR) {
            qCWarning(KTP_PROXY) << "Decryption error of the message: " << otrMsg.text();
        }
        chan->acknowledge(QList<Tp::ReceivedMessage>() << receivedMessage);
    }
}
Ejemplo n.º 2
0
void ChatSession::OnMessageReceived(const Tp::ReceivedMessage &message)
{
    QList<Tp::ReceivedMessage> messages;
    messages.append(message);
    tp_text_channel_->acknowledge(messages);

    ChatSessionParticipant* from = GetParticipant(message.sender());
    ChatMessage* m = new ChatMessage(from, message.received(), message.text());
    message_history_.push_back(m);
    emit( MessageReceived(*m) );
}
Ejemplo n.º 3
0
void TpSessionChannel::onMessageReceived(const Tp::ReceivedMessage &msg)
{
    QDEBUG_FUNCTION_BEGIN
    qDebug() << "TpSessionChannel::onMessageReceived " << msg.text();
    emit messageReceived(msg, this);
    QDEBUG_FUNCTION_END
};
void OtrProxyChannel::Adaptee::onPendingMessageRemoved(const Tp::ReceivedMessage &receivedMessage)
{
    const uint id = receivedMessage.header().value(QLatin1String("pending-message-id")).variant().toUInt(nullptr);
    if(messages.remove(id)) {
        Q_EMIT pendingMessagesRemoved(Tp::UIntList() << id);
    } else {
        qCDebug(KTP_PROXY) << "Text channel removed missing pending message with id or an OTR message: " << id;
    }
}
Ejemplo n.º 5
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();
    }
}