Commit 6339bcfd authored by David Edmundson's avatar David Edmundson

Use updated message processor in Declarative MessagesModel

parent 1d8ae32c
......@@ -45,7 +45,7 @@ Conversation::Conversation(const Tp::TextChannelPtr &channel,
d->account = account;
d->messages = new MessagesModel(this);
d->messages = new MessagesModel(account, this);
d->messages->setTextChannel(channel);
d->target = new ConversationTarget(account, channel->targetContact(), this);
......
......@@ -23,6 +23,9 @@
#include <KLocalizedString>
#include <TelepathyQt/ReceivedMessage>
#include <TelepathyQt/TextChannel>
#include <TelepathyQt/Account>
#include "message-processor.h"
......@@ -47,11 +50,12 @@ class MessagesModel::MessagesModelPrivate
{
public:
Tp::TextChannelPtr textChannel;
Tp::AccountPtr account;
QList<MessageItem> messages;
bool visible;
};
MessagesModel::MessagesModel(QObject *parent):
MessagesModel::MessagesModel(const Tp::AccountPtr &account, QObject *parent) :
QAbstractListModel(parent),
d(new MessagesModelPrivate)
{
......@@ -64,6 +68,7 @@ MessagesModel::MessagesModel(QObject *parent):
roles[TypeRole] = "type";
setRoleNames(roles);
d->account = account;
d->visible = false;
}
......@@ -138,9 +143,12 @@ void MessagesModel::onMessageReceived(const Tp::ReceivedMessage &message)
int length = rowCount();
beginInsertRows(QModelIndex(), length, length);
//TODO simply use ktpMessage as d->messages()
KTp::Message ktpMessage = KTp::MessageProcessor::instance()->processMessage(message, d->account, d->textChannel);
d->messages.append(MessageItem(
message.sender()->alias(),
KTp::MessageProcessor::instance()->processIncomingMessage(message).finalizedMessage(),
ktpMessage.finalizedMessage(),
message.received(),
message.messageType() == Tp::ChannelTextMessageTypeAction ? MessageTypeAction : MessageTypeIncoming,
message.messageToken()
......@@ -167,9 +175,11 @@ void MessagesModel::onMessageSent(const Tp::Message &message, Tp::MessageSending
beginInsertRows(QModelIndex(), length, length);
kDebug() << "text =" << message.text();
KTp::Message ktpMessage = KTp::MessageProcessor::instance()->processMessage(message, d->account, d->textChannel);
d->messages.append(MessageItem(
i18n("Me"), //FIXME : use actual nickname from Tp::AccountPtr
KTp::MessageProcessor::instance()->processOutgoingMessage(message).finalizedMessage(),
ktpMessage.finalizedMessage(),
message.sent(),
message.messageType() == Tp::ChannelTextMessageTypeAction ? MessageTypeAction : MessageTypeOutgoing,
message.messageToken()
......
......@@ -21,7 +21,10 @@
#define MESSAGES_MODEL_H
#include <QAbstractItemModel>
#include <TelepathyQt/TextChannel>
#include <TelepathyQt/Types>
#include <TelepathyQt/ReceivedMessage>
#include "conversation-queue-manager.h"
......@@ -34,7 +37,7 @@ class MessagesModel : public QAbstractListModel, public Queueable
Q_PROPERTY(bool shouldStartOpened READ shouldStartOpened CONSTANT)
public:
MessagesModel(QObject *parent = 0);
MessagesModel(const Tp::AccountPtr &account, QObject *parent = 0);
virtual ~MessagesModel();
enum Roles {
......
......@@ -139,26 +139,26 @@ QString MessageProcessor::header()
return out;
}
KTp::Message MessageProcessor::processIncomingMessage(const Tp::Message &message, const Tp::AccountPtr &account, const Tp::TextChannelPtr &channel)
KTp::Message MessageProcessor::processMessage(const Tp::Message &message, const Tp::AccountPtr &account, const Tp::TextChannelPtr &channel)
{
KTp::MessageContext context(account, channel);
return processMessage(KTp::Message(message, context), context);
}
KTp::Message KTp::MessageProcessor::processIncomingMessage(const Tp::ReceivedMessage &message, const Tp::AccountPtr &account, const Tp::TextChannelPtr &channel)
KTp::Message KTp::MessageProcessor::processMessage(const Tp::ReceivedMessage &message, const Tp::AccountPtr &account, const Tp::TextChannelPtr &channel)
{
KTp::MessageContext context(account, channel);
return processMessage(KTp::Message(message, context), context);
}
KTp::Message KTp::MessageProcessor::processIncomingMessage(const Tpl::TextEventPtr &message, const Tp::AccountPtr &account, const Tp::TextChannelPtr &channel)
KTp::Message KTp::MessageProcessor::processMessage(const Tpl::TextEventPtr &message, const Tp::AccountPtr &account, const Tp::TextChannelPtr &channel)
{
KTp::MessageContext context(account, channel);
return processMessage(KTp::Message(message, context), context);
}
KTp::Message MessageProcessor::processMessage(Message message, const MessageContext &context)
KTp::Message MessageProcessor::processMessage(KTp::Message message, const KTp::MessageContext &context)
{
Q_FOREACH (AbstractMessageFilter *filter, d->filters) {
kDebug() << "running filter :" << filter->metaObject()->className();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment