Message::Message(const Tp::Message &original, const KTp::MessageContext &context) :
    d(new Private)
{
    d->sentTime = original.sent();
    d->token = original.messageToken();
    d->messageType = original.messageType();
    d->isHistory = false;
    d->direction = KTp::Message::LocalToRemote;

    setMainMessagePart(original.text());

    if (context.account()->connection()) {
        d->sender = KTp::ContactPtr::qObjectCast(context.account()->connection()->selfContact());
    } else {
        d->senderAlias = context.account()->nickname();
        d->senderId = context.account()->uniqueIdentifier();
    }
}
Пример #2
0
void ChannelWatcher::onMessageSent(const Tp::Message &message)
{
    StorageMessage msg;
    msg.messageDateTime = message.sent();
    msg.accountObjectPathId = m_accountDbId;
    msg.targetContactId = m_contactDbId;
    msg.message = message.text();
    msg.messageToken = message.messageToken();
    msg.isIncoming = false;
    msg.isDelivered = false;
    msg.type = 1;

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

    storeMessage(msg);
}