Commit 71e7718e authored by Martin Klapetek's avatar Martin Klapetek Committed by Alexander Akulich
Browse files

[declarative] Support fetching history based only on contact id



Allows for showing backlog in the chat view even without being online
Reviewed-by: Alexander Akulich's avatarAlexander Akulich <akulichalexander@gmail.com>
parent 4a2470df
......@@ -46,6 +46,7 @@ class Conversation::ConversationPrivate
//and not handling it.
bool delegated;
bool valid;
QString contactAlias;
Tp::AccountPtr account;
QTimer *pausedStateTimer;
// May be null for group chats.
......@@ -87,10 +88,8 @@ Conversation::Conversation(QObject *parent)
void Conversation::setTextChannel(const Tp::TextChannelPtr &channel)
{
if (!d->messages) {
d->messages = new MessagesModel(d->account, this);
connect(d->messages, &MessagesModel::unreadCountChanged, this, &Conversation::unreadMessagesChanged);
connect(d->messages, &MessagesModel::lastMessageChanged, this, &Conversation::lastMessageChanged);
if (d->messages->account().isNull()) {
d->messages->setAccount(d->account);
}
if (d->messages->textChannel() != channel) {
d->messages->setTextChannel(channel);
......@@ -116,6 +115,20 @@ void Conversation::setTextChannel(const Tp::TextChannelPtr &channel)
}
}
void Conversation::setContactData(const QString &contactId, const QString &contactAlias)
{
if (!d->messages) {
qWarning() << "Needs messages model first!";
return;
}
qDebug() << "Setting contact data";
d->contactAlias = contactAlias;
d->messages->setContactData(contactId, contactAlias);
Q_EMIT titleChanged();
}
Tp::TextChannelPtr Conversation::textChannel() const
{
return d->messages->textChannel();
......@@ -135,7 +148,7 @@ QString Conversation::title() const
return d->targetContact->alias();
}
return QString();
return d->contactAlias;
}
QIcon Conversation::presenceIcon() const
......@@ -191,6 +204,7 @@ Tp::Account* Conversation::accountObject() const
void Conversation::setAccount(const Tp::AccountPtr &account)
{
d->messages->setAccount(account);
d->account = account;
}
......
......@@ -50,6 +50,11 @@ public:
void setTextChannel(const Tp::TextChannelPtr &channel);
Tp::TextChannelPtr textChannel() const;
/**
* Useful for offline history retrieving (as there's no text channel when offline)
*/
void setContactData(const QString &contactId, const QString &contactAlias);
MessagesModel* messages() const;
QString title() const;
QIcon presenceIcon() const;
......
......@@ -178,6 +178,17 @@ void MessagesModel::setAccount(const Tp::AccountPtr &account)
d->account = account;
}
void MessagesModel::setContactData(const QString &contactId, const QString &contactAlias)
{
d->logManager->setAccountAndContact(d->account, contactId, contactAlias);
//Load messages unless they have already been loaded
if (!d->logsLoaded) {
qDebug() << "Fetching scrollback";
d->logManager->fetchScrollback();
}
}
void MessagesModel::onHistoryFetched(const QList<KTp::Message> &messages)
{
QList<KTp::Message> messagesToAdd;
......
......@@ -77,6 +77,11 @@ class MessagesModel : public QAbstractListModel
Tp::AccountPtr account() const;
void setAccount(const Tp::AccountPtr &account);
/**
* Useful for offline history retrieving (as there's no text channel when offline)
*/
void setContactData(const QString &contactId, const QString &contactAlias);
bool isVisibleToUser() const;
void setVisibleToUser(bool visible);
......
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