mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-07-16 13:35:23 +02:00
swarm: add support for lazy loading conversations
depends on https://review.jami.net/c/ring-lrc/+/16720 Change-Id: Ic254459827c189fc92595be6e2485e0eed31edd8
This commit is contained in:
parent
11119e51f6
commit
951eb3cf85
3 changed files with 38 additions and 4 deletions
|
@ -252,6 +252,10 @@ Rectangle {
|
|||
function parseI18nData() {
|
||||
return MessagesAdapter.chatviewTranslatedStrings
|
||||
}
|
||||
|
||||
function loadMessages(n) {
|
||||
return MessagesAdapter.loadMessages(n)
|
||||
}
|
||||
}
|
||||
|
||||
WebEngineView {
|
||||
|
|
|
@ -156,7 +156,7 @@ MessagesAdapter::connectConversationModel()
|
|||
|
||||
newMessagesAvailableConnection_
|
||||
= QObject::connect(currentConversationModel,
|
||||
&lrc::api::ConversationModel::newMessagesAvailable,
|
||||
&ConversationModel::newMessagesAvailable,
|
||||
[this](const QString& accountId, const QString& conversationId) {
|
||||
auto* convModel = lrcInstance_->accountModel()
|
||||
.getAccountInfo(accountId)
|
||||
|
@ -164,7 +164,9 @@ MessagesAdapter::connectConversationModel()
|
|||
auto optConv = convModel->getConversationForUid(conversationId);
|
||||
if (!optConv)
|
||||
return;
|
||||
printHistory(*convModel, optConv->get().interactions);
|
||||
updateHistory(*convModel,
|
||||
optConv->get().interactions,
|
||||
optConv->get().allMessagesLoaded);
|
||||
Utils::oneShotConnect(qmlObj_,
|
||||
SIGNAL(messagesLoaded()),
|
||||
this,
|
||||
|
@ -228,7 +230,7 @@ MessagesAdapter::slotMessagesCleared()
|
|||
return;
|
||||
if (convOpt->get().mode != lrc::api::conversation::Mode::NON_SWARM
|
||||
&& !convOpt->get().allMessagesLoaded) {
|
||||
convModel->loadConversationMessages(convOpt->get().uid, 0);
|
||||
convModel->loadConversationMessages(convOpt->get().uid, 20);
|
||||
} else {
|
||||
printHistory(*convModel, convOpt->get().interactions);
|
||||
Utils::oneShotConnect(qmlObj_, SIGNAL(messagesLoaded()), this, SLOT(slotMessagesLoaded()));
|
||||
|
@ -556,6 +558,18 @@ MessagesAdapter::printHistory(lrc::api::ConversationModel& conversationModel,
|
|||
QMetaObject::invokeMethod(qmlObj_, "webViewRunJavaScript", Q_ARG(QVariant, s));
|
||||
}
|
||||
|
||||
void
|
||||
MessagesAdapter::updateHistory(lrc::api::ConversationModel& conversationModel,
|
||||
MessagesList interactions,
|
||||
bool allLoaded)
|
||||
{
|
||||
auto interactionsStr = interactionsToJsonArrayObject(conversationModel, interactions).toUtf8();
|
||||
QString s = QString::fromLatin1("updateHistory(%1, %2);")
|
||||
.arg(interactionsStr.constData())
|
||||
.arg(allLoaded);
|
||||
QMetaObject::invokeMethod(qmlObj_, "webViewRunJavaScript", Q_ARG(QVariant, s));
|
||||
}
|
||||
|
||||
void
|
||||
MessagesAdapter::setSenderImage(const QString& sender, const QString& senderImage)
|
||||
{
|
||||
|
@ -717,3 +731,15 @@ MessagesAdapter::removeConversation(const QString& accountId,
|
|||
if (convUid == currentConvUid_)
|
||||
currentConvUid_.clear();
|
||||
}
|
||||
|
||||
void
|
||||
MessagesAdapter::loadMessages(int n)
|
||||
{
|
||||
auto* convModel = lrcInstance_->getCurrentConversationModel();
|
||||
auto convOpt = convModel->getConversationForUid(currentConvUid_);
|
||||
if (!convOpt)
|
||||
return;
|
||||
if (convOpt->get().mode != lrc::api::conversation::Mode::NON_SWARM
|
||||
&& !convOpt->get().allMessagesLoaded)
|
||||
convModel->loadConversationMessages(convOpt->get().uid, n);
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ protected:
|
|||
Q_INVOKABLE void refuseFile(const QString& arg);
|
||||
Q_INVOKABLE void pasteKeyDetected();
|
||||
Q_INVOKABLE void onComposing(bool isComposing);
|
||||
Q_INVOKABLE void loadMessages(int n);
|
||||
|
||||
// Manually update draft when hiding message web view (Back to welcome page).
|
||||
Q_INVOKABLE void updateDraft();
|
||||
|
@ -76,7 +77,10 @@ protected:
|
|||
void requestSendMessageContent();
|
||||
void setInvitation(bool show, const QString& contactUri = {}, const QString& contactId = {});
|
||||
void clear();
|
||||
void printHistory(lrc::api::ConversationModel& conversationModel, MessagesList interactions);
|
||||
void printHistory(ConversationModel& conversationModel, MessagesList interactions);
|
||||
void updateHistory(ConversationModel& conversationModel,
|
||||
MessagesList interactions,
|
||||
bool allLoaded);
|
||||
void setSenderImage(const QString& sender, const QString& senderImage);
|
||||
void printNewInteraction(lrc::api::ConversationModel& conversationModel,
|
||||
const QString& msgId,
|
||||
|
|
Loading…
Add table
Reference in a new issue