From b83e459f4ed6deda6e46b7ae12e49e197ef3bb12 Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Sun, 28 Jun 2020 01:49:43 -0400 Subject: [PATCH] client: Add AsNeededBacklogRequester, faster login Add AsNeededBacklogRequester, which behaves exactly like the FixedBacklogRequester for legacy cores older than v0.13.0 (lacking Feature::BufferActivitySync). For modern cores, no backlog is initially fetched. This should speed up logging in with no loss of buffer activity signaling. This breaks the "Show messages from backlog" feature as no backlog is fetched. The original always-fetch backlog requesters remain available for those who prefer having the backlog in the Chat Monitor. Add a warning to the Chat Monitor settings page when "Only fetch when needed" Backlog Fetching is enabled. Don't allow BacklogSettings to return the GlobalUnread backlog requester type. The UI for choosing it has been disabled, but it could have accidentally been selected in the past. If this had happened before this change, AsNeeded will be selected instead. --- src/client/backlogrequester.cpp | 27 ++++++ src/client/backlogrequester.h | 18 ++++ src/client/backlogsettings.cpp | 20 ++++- src/client/backlogsettings.h | 17 ++++ src/client/clientbacklogmanager.cpp | 4 + .../settingspages/backlogsettingspage.cpp | 3 +- src/qtui/settingspages/backlogsettingspage.ui | 90 +++++++++++++++++++ .../settingspages/chatmonitorsettingspage.cpp | 38 ++++++++ .../settingspages/chatmonitorsettingspage.h | 12 +++ .../settingspages/chatmonitorsettingspage.ui | 34 +++++-- 10 files changed, 253 insertions(+), 10 deletions(-) diff --git a/src/client/backlogrequester.cpp b/src/client/backlogrequester.cpp index 93399b68..26fb4862 100644 --- a/src/client/backlogrequester.cpp +++ b/src/client/backlogrequester.cpp @@ -131,3 +131,30 @@ void PerBufferUnreadBacklogRequester::requestBacklog(const BufferIdList& bufferI backlogManager->requestBacklog(bufferId, Client::networkModel()->lastSeenMsgId(bufferId), -1, _limit, _additional); } } + +// ======================================== +// AS NEEDED BACKLOG REQUESTER +// ======================================== +AsNeededBacklogRequester::AsNeededBacklogRequester(ClientBacklogManager* backlogManager) + : BacklogRequester(false, BacklogRequester::AsNeeded, backlogManager) +{ + BacklogSettings backlogSettings; + _legacyBacklogCount = backlogSettings.asNeededLegacyBacklogAmount(); +} + +void AsNeededBacklogRequester::requestBacklog(const BufferIdList& bufferIds) +{ + // Check if the core supports activity tracking + if (Client::isCoreFeatureEnabled(Quassel::Feature::BufferActivitySync)) { + // Don't fetch any backlog, the core will track buffer activity for us + return; + } + + setWaitingBuffers(bufferIds); + backlogManager->emitMessagesRequested(QObject::tr("Requesting a total of up to %1 backlog messages for %2 buffers") + .arg(_legacyBacklogCount * bufferIds.count()) + .arg(bufferIds.count())); + foreach (BufferId bufferId, bufferIds) { + backlogManager->requestBacklog(bufferId, -1, -1, _legacyBacklogCount); + } +} diff --git a/src/client/backlogrequester.h b/src/client/backlogrequester.h index 73571270..3acd793e 100644 --- a/src/client/backlogrequester.h +++ b/src/client/backlogrequester.h @@ -39,6 +39,7 @@ public: InvalidRequester = 0, PerBufferFixed, PerBufferUnread, + AsNeeded, ///< Only request backlog on cores without Feature::BufferActivitySync GlobalUnread }; @@ -114,3 +115,20 @@ private: int _limit; int _additional; }; + +// ======================================== +// AS NEEDED BACKLOG REQUESTER +// ======================================== +/** + * Backlog requester that only fetches initial backlog when the core doesn't support buffer activity + * tracking + */ +class AsNeededBacklogRequester : public BacklogRequester +{ +public: + AsNeededBacklogRequester(ClientBacklogManager* backlogManager); + void requestBacklog(const BufferIdList& bufferIds) override; + +private: + int _legacyBacklogCount; +}; diff --git a/src/client/backlogsettings.cpp b/src/client/backlogsettings.cpp index d6a25f73..fda30762 100644 --- a/src/client/backlogsettings.cpp +++ b/src/client/backlogsettings.cpp @@ -26,11 +26,17 @@ BacklogSettings::BacklogSettings() int BacklogSettings::requesterType() const { - return localValue("RequesterType", BacklogRequester::PerBufferUnread).toInt(); + int _requesterType = localValue("RequesterType", BacklogRequester::PerBufferUnread).toInt(); + if (_requesterType == BacklogRequester::GlobalUnread) { + // GlobalUnread is currently disabled; don't allow it to be used. Reset to default instead. + _requesterType = BacklogRequester::PerBufferUnread; + } + return _requesterType; } void BacklogSettings::setRequesterType(int requesterType) { + // This settings key is also used within ChatMonitorSettingsPage::ChatMonitorSettingsPage() setLocalValue("RequesterType", requesterType); } @@ -104,3 +110,15 @@ void BacklogSettings::setPerBufferUnreadBacklogAdditional(int additional) { return setLocalValue("PerBufferUnreadBacklogAdditional", additional); } + +int BacklogSettings::asNeededLegacyBacklogAmount() const +{ + // Mimic FixedBacklogAmount defaults. This is only used on cores lacking + // Feature::BufferActivitySync. + return localValue("AsNeededLegacyBacklogAmount", 500).toInt(); +} + +void BacklogSettings::setAsNeededLegacyBacklogAmount(int amount) +{ + return setLocalValue("AsNeededLegacyBacklogAmount", amount); +} diff --git a/src/client/backlogsettings.h b/src/client/backlogsettings.h index aee0376d..76f51adc 100644 --- a/src/client/backlogsettings.h +++ b/src/client/backlogsettings.h @@ -62,4 +62,21 @@ public: void setPerBufferUnreadBacklogLimit(int limit); int perBufferUnreadBacklogAdditional() const; void setPerBufferUnreadBacklogAdditional(int additional); + + /** + * Get the initial amount of backlog fetched across all buffers for legacy cores that do not + * support Quassel::Feature::BufferActivitySync + * + * @seealso Quassel::Feature::BufferActivitySync + * @return The amount of backlog to fetch per buffer + */ + int asNeededLegacyBacklogAmount() const; + /** + * Set the initial amount of backlog fetched across all buffers for legacy cores that do not + * support Quassel::Feature::BufferActivitySync + * + * @seealso BacklogSettings::asNeededLegacyBacklogAmount() + * @param amount The amount of backlog to fetch per buffer + */ + void setAsNeededLegacyBacklogAmount(int amount); }; diff --git a/src/client/clientbacklogmanager.cpp b/src/client/clientbacklogmanager.cpp index 3eafc862..3398f1a7 100644 --- a/src/client/clientbacklogmanager.cpp +++ b/src/client/clientbacklogmanager.cpp @@ -97,6 +97,9 @@ void ClientBacklogManager::requestInitialBacklog() BacklogSettings settings; switch (settings.requesterType()) { + case BacklogRequester::AsNeeded: + _requester = new AsNeededBacklogRequester(this); + break; case BacklogRequester::GlobalUnread: _requester = new GlobalUnreadBacklogRequester(this); break; @@ -144,6 +147,7 @@ void ClientBacklogManager::checkForBacklog(const QList& bufferIds) break; case BacklogRequester::PerBufferUnread: case BacklogRequester::PerBufferFixed: + case BacklogRequester::AsNeeded: default: { BufferIdList buffers = filterNewBufferIds(bufferIds); if (!buffers.isEmpty()) diff --git a/src/qtui/settingspages/backlogsettingspage.cpp b/src/qtui/settingspages/backlogsettingspage.cpp index 450e73f1..e7978613 100644 --- a/src/qtui/settingspages/backlogsettingspage.cpp +++ b/src/qtui/settingspages/backlogsettingspage.cpp @@ -33,7 +33,8 @@ BacklogSettingsPage::BacklogSettingsPage(QWidget* parent) // not an auto widget, because we store index + 1 // FIXME: global backlog requester disabled until issues ruled out - ui.requesterType->removeItem(2); + ui.requesterType->removeItem(3); + // If modifying ui.requesterType's item list, set to the index of "Globally unread messages" connectToWidgetChangedSignal(ui.requesterType, this, &BacklogSettingsPage::widgetHasChanged); } diff --git a/src/qtui/settingspages/backlogsettingspage.ui b/src/qtui/settingspages/backlogsettingspage.ui index dd15894a..feac9cd4 100644 --- a/src/qtui/settingspages/backlogsettingspage.ui +++ b/src/qtui/settingspages/backlogsettingspage.ui @@ -104,6 +104,11 @@ Unread messages per chat + + + Only fetch when needed + + Globally unread messages @@ -332,6 +337,91 @@ You can also choose to fetch additional older chatlines to provide a better cont + + + + + + <p>On modern cores (v0.13.0 or newer), no backlog will be fetched. The core keeps track of chat activity automatically.<br/> +<i>Note: Chat Monitor won't show past messages.</i> +</p> +<p>On older cores, this requester fetches a fixed amount of lines for each chat window from the backlog.</p> + + + Qt::RichText + + + true + + + + + + + + + Amount of messages per buffer that are requested after the core connection has been established. + + + For legacy cores, initial backlog amount: + + + + + + + + + + 0 + + + 99999 + + + 10 + + + 500 + + + AsNeededLegacyBacklogAmount + + + 500 + + + + + + + Qt::Horizontal + + + + 263 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 47 + + + + + + diff --git a/src/qtui/settingspages/chatmonitorsettingspage.cpp b/src/qtui/settingspages/chatmonitorsettingspage.cpp index 16c3627f..414cd6d7 100644 --- a/src/qtui/settingspages/chatmonitorsettingspage.cpp +++ b/src/qtui/settingspages/chatmonitorsettingspage.cpp @@ -20,8 +20,11 @@ #include "chatmonitorsettingspage.h" +#include #include +#include "backlogrequester.h" +#include "backlogsettings.h" #include "buffermodel.h" #include "bufferview.h" #include "bufferviewconfig.h" @@ -67,6 +70,10 @@ ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget* parent) connect(ui.alwaysOwn, &QAbstractButton::toggled, this, &ChatMonitorSettingsPage::widgetHasChanged); connect(ui.showBacklog, &QAbstractButton::toggled, this, &ChatMonitorSettingsPage::widgetHasChanged); connect(ui.includeRead, &QAbstractButton::toggled, this, &ChatMonitorSettingsPage::widgetHasChanged); + + // AsNeededBacklogRequester conflicts with showing backlog in Chat Monitor + BacklogSettings backlogSettings; + backlogSettings.initAndNotify("RequesterType", this, &ChatMonitorSettingsPage::setRequesterType, BacklogRequester::PerBufferUnread); } bool ChatMonitorSettingsPage::hasDefaults() const @@ -279,3 +286,34 @@ void ChatMonitorSettingsPage::switchOperationMode(int idx) } widgetHasChanged(); } + +void ChatMonitorSettingsPage::setRequesterType(const QVariant& v) +{ + bool usingAsNeededRequester = (v.toInt() == BacklogRequester::AsNeeded); + ui.showBacklogUnavailableDetails->setVisible(usingAsNeededRequester); + if (usingAsNeededRequester) { + ui.showBacklog->setText(tr("Show messages from backlog (not available)")); + } + else { + ui.showBacklog->setText(tr("Show messages from backlog")); + } +} + +void ChatMonitorSettingsPage::on_showBacklogUnavailableDetails_clicked() +{ + // Explain that backlog fetching is disabled, so backlog messages won't show up + // + // Technically, backlog messages *will* show up once fetched, e.g. after clicking on a buffer. + // This might be too trivial of a detail to warrant explaining, though. + QMessageBox::information(this, + tr("Messages from backlog are not fetched"), + QString("

%1

%2

") + .arg(tr("No initial backlog will be fetched when using the backlog request method of %1.") + .arg(tr("Only fetch when needed").replace(" ", " ")), + tr("Configure this in the %1 settings page.") + .arg(tr("Backlog Fetching").replace(" ", " ")) + ) + ); + // Re-use translations of "Only fetch when needed" and "Backlog Fetching" as this is a + // word-for-word reference, forcing all spaces to be non-breaking +} diff --git a/src/qtui/settingspages/chatmonitorsettingspage.h b/src/qtui/settingspages/chatmonitorsettingspage.h index aaa5c2f3..c72f52aa 100644 --- a/src/qtui/settingspages/chatmonitorsettingspage.h +++ b/src/qtui/settingspages/chatmonitorsettingspage.h @@ -49,6 +49,18 @@ private slots: void on_deactivateBuffer_clicked(); void switchOperationMode(int idx); + /** + * Sets the local cache of the current backlog requester type, used to determine if showing + * backlog in the Chat Monitor will work + * + * @seealso BacklogSettings::setRequesterType() + */ + void setRequesterType(const QVariant&); + + /** + * Event handler for Show Backlog Unavailable Details button + */ + void on_showBacklogUnavailableDetails_clicked(); private: Ui::ChatMonitorSettingsPage ui; QHash settings; diff --git a/src/qtui/settingspages/chatmonitorsettingspage.ui b/src/qtui/settingspages/chatmonitorsettingspage.ui index 61e3e7c9..a5439088 100644 --- a/src/qtui/settingspages/chatmonitorsettingspage.ui +++ b/src/qtui/settingspages/chatmonitorsettingspage.ui @@ -189,14 +189,31 @@ p, li { white-space: pre-wrap; }
- - - Display messages from backlog on reconnect - - - Show messages from backlog - - + + + + + Display messages from backlog on reconnect + + + Show messages from backlog + + + + + + + + 0 + 0 + + + + Details... + + + + @@ -247,6 +264,7 @@ p, li { white-space: pre-wrap; } showOwnMessages alwaysOwn showBacklog + showBacklogUnavailableDetails includeRead -- 2.20.1