Commit 7e824024 authored by Martin Klapetek's avatar Martin Klapetek Committed by Alexander Akulich
Browse files

[logger] Allow fetching contact history through ScrollbackManager when offline



The history can be fetched even without an active text channel (that
means being offline), so this allows to query the history based on
contact id and an account, without a channel.
Reviewed-by: Alexander Akulich's avatarAlexander Akulich <akulichalexander@gmail.com>
parent 4338d50d
......@@ -89,6 +89,19 @@ void ScrollbackManager::setTextChannel(const Tp::AccountPtr &account, const Tp::
}
}
void ScrollbackManager::setAccountAndContact(const Tp::AccountPtr &account, const QString &contactId, const QString &contactAlias)
{
d->account = account;
if (d->account.isNull()) {
return;
}
d->contactEntity = KTp::LogEntity(Tp::HandleTypeContact,
contactId,
contactAlias);
}
void ScrollbackManager::setScrollbackLength(int n)
{
d->scrollbackLength = n;
......@@ -106,15 +119,13 @@ void ScrollbackManager::fetchScrollback()
void ScrollbackManager::fetchHistory(int n, const QString &fromMessageToken)
{
if (n > 0 && !d->account.isNull() && !d->textChannel.isNull()) {
if (d->contactEntity.isValid()) {
d->fromMessageToken = fromMessageToken;
KTp::LogManager *manager = KTp::LogManager::instance();
KTp::PendingLoggerDates *dates = manager->queryDates(d->account, d->contactEntity);
connect(dates, SIGNAL(finished(KTp::PendingLoggerOperation*)),
this, SLOT(onDatesFinished(KTp::PendingLoggerOperation*)));
return;
}
if (n > 0 && !d->account.isNull() && d->contactEntity.isValid()) {
d->fromMessageToken = fromMessageToken;
KTp::LogManager *manager = KTp::LogManager::instance();
KTp::PendingLoggerDates *dates = manager->queryDates(d->account, d->contactEntity);
connect(dates, SIGNAL(finished(KTp::PendingLoggerOperation*)),
this, SLOT(onDatesFinished(KTp::PendingLoggerOperation*)));
return;
}
//in all other cases finish immediately.
......
......@@ -39,6 +39,14 @@ public:
void setTextChannel(const Tp::AccountPtr &account, const Tp::TextChannelPtr &textChannel);
/**
* This is an alternative for setTextChannel() to allow for offline scrollback
*
* @param account The account of the contact
* @param contactId id of the contact for which the screollback is requested
*/
void setAccountAndContact(const Tp::AccountPtr &account, const QString &contactId, const QString &contactAlias = QString());
/**
* Sets amount of messages to be fetched via @p fetchScrollback()
*/
......
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