mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Preload chats in support switch.
This commit is contained in:
parent
0aa20b4479
commit
d89d8b09da
12 changed files with 200 additions and 12 deletions
|
@ -3025,6 +3025,24 @@ void InnerWidget::updateRowCornerStatusShown(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RowDescriptor InnerWidget::resolveChatNext(RowDescriptor from) const {
|
||||||
|
const auto row = from.key ? from : _controller->activeChatEntryCurrent();
|
||||||
|
return row.key
|
||||||
|
? computeJump(
|
||||||
|
chatListEntryAfter(row),
|
||||||
|
JumpSkip::NextOrEnd)
|
||||||
|
: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
RowDescriptor InnerWidget::resolveChatPrevious(RowDescriptor from) const {
|
||||||
|
const auto row = from.key ? from : _controller->activeChatEntryCurrent();
|
||||||
|
return row.key
|
||||||
|
? computeJump(
|
||||||
|
chatListEntryBefore(row),
|
||||||
|
JumpSkip::PreviousOrBegin)
|
||||||
|
: row;
|
||||||
|
}
|
||||||
|
|
||||||
void InnerWidget::setupShortcuts() {
|
void InnerWidget::setupShortcuts() {
|
||||||
Shortcuts::Requests(
|
Shortcuts::Requests(
|
||||||
) | rpl::filter([=] {
|
) | rpl::filter([=] {
|
||||||
|
@ -3197,7 +3215,7 @@ void InnerWidget::setupShortcuts() {
|
||||||
|
|
||||||
RowDescriptor InnerWidget::computeJump(
|
RowDescriptor InnerWidget::computeJump(
|
||||||
const RowDescriptor &to,
|
const RowDescriptor &to,
|
||||||
JumpSkip skip) {
|
JumpSkip skip) const {
|
||||||
auto result = to;
|
auto result = to;
|
||||||
if (result.key) {
|
if (result.key) {
|
||||||
const auto down = (skip == JumpSkip::NextOrEnd)
|
const auto down = (skip == JumpSkip::NextOrEnd)
|
||||||
|
|
|
@ -125,6 +125,9 @@ public:
|
||||||
[[nodiscard]] rpl::producer<ChosenRow> chosenRow() const;
|
[[nodiscard]] rpl::producer<ChosenRow> chosenRow() const;
|
||||||
[[nodiscard]] rpl::producer<> updated() const;
|
[[nodiscard]] rpl::producer<> updated() const;
|
||||||
|
|
||||||
|
[[nodiscard]] RowDescriptor resolveChatNext(RowDescriptor from = {}) const;
|
||||||
|
[[nodiscard]] RowDescriptor resolveChatPrevious(RowDescriptor from = {}) const;
|
||||||
|
|
||||||
~InnerWidget();
|
~InnerWidget();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
@ -238,7 +241,7 @@ private:
|
||||||
void setupShortcuts();
|
void setupShortcuts();
|
||||||
RowDescriptor computeJump(
|
RowDescriptor computeJump(
|
||||||
const RowDescriptor &to,
|
const RowDescriptor &to,
|
||||||
JumpSkip skip);
|
JumpSkip skip) const;
|
||||||
bool jumpToDialogRow(RowDescriptor to);
|
bool jumpToDialogRow(RowDescriptor to);
|
||||||
|
|
||||||
RowDescriptor chatListEntryBefore(const RowDescriptor &which) const;
|
RowDescriptor chatListEntryBefore(const RowDescriptor &which) const;
|
||||||
|
|
|
@ -1685,6 +1685,14 @@ void Widget::updateForwardBar() {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RowDescriptor Widget::resolveChatNext(RowDescriptor from) const {
|
||||||
|
return _inner->resolveChatNext(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
RowDescriptor Widget::resolveChatPrevious(RowDescriptor from) const {
|
||||||
|
return _inner->resolveChatPrevious(from);
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::keyPressEvent(QKeyEvent *e) {
|
void Widget::keyPressEvent(QKeyEvent *e) {
|
||||||
if (e->key() == Qt::Key_Escape) {
|
if (e->key() == Qt::Key_Escape) {
|
||||||
if (_openedFolder) {
|
if (_openedFolder) {
|
||||||
|
|
|
@ -91,6 +91,9 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<> closeForwardBarRequests() const;
|
[[nodiscard]] rpl::producer<> closeForwardBarRequests() const;
|
||||||
|
|
||||||
|
[[nodiscard]] RowDescriptor resolveChatNext(RowDescriptor from = {}) const;
|
||||||
|
[[nodiscard]] RowDescriptor resolveChatPrevious(RowDescriptor from = {}) const;
|
||||||
|
|
||||||
// Float player interface.
|
// Float player interface.
|
||||||
bool floatPlayerHandleWheelEvent(QEvent *e) override;
|
bool floatPlayerHandleWheelEvent(QEvent *e) override;
|
||||||
QRect floatPlayerAvailableRect() override;
|
QRect floatPlayerAvailableRect() override;
|
||||||
|
|
|
@ -818,6 +818,13 @@ HistoryWidget::HistoryWidget(
|
||||||
}
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
if (session().supportMode()) {
|
||||||
|
session().data().chatListEntryRefreshes(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
crl::on_main(this, [=] { checkSupportPreload(true); });
|
||||||
|
}, lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
setupScheduledToggle();
|
setupScheduledToggle();
|
||||||
setupSendAsToggle();
|
setupSendAsToggle();
|
||||||
orderWidgets();
|
orderWidgets();
|
||||||
|
@ -2299,9 +2306,11 @@ void HistoryWidget::setHistory(History *history) {
|
||||||
history->forceFullResize();
|
history->forceFullResize();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_history) {
|
if (_history) {
|
||||||
unregisterDraftSources();
|
unregisterDraftSources();
|
||||||
clearAllLoadRequests();
|
clearAllLoadRequests();
|
||||||
|
clearSupportPreloadRequest();
|
||||||
const auto wasHistory = base::take(_history);
|
const auto wasHistory = base::take(_history);
|
||||||
const auto wasMigrated = base::take(_migrated);
|
const auto wasMigrated = base::take(_migrated);
|
||||||
unloadHeavyViewParts(wasHistory);
|
unloadHeavyViewParts(wasHistory);
|
||||||
|
@ -2371,6 +2380,16 @@ void HistoryWidget::clearDelayedShowAtRequest() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HistoryWidget::clearSupportPreloadRequest() {
|
||||||
|
Expects(_history != nullptr);
|
||||||
|
|
||||||
|
if (_supportPreloadRequest) {
|
||||||
|
auto &histories = _history->owner().histories();
|
||||||
|
histories.cancelRequest(_supportPreloadRequest);
|
||||||
|
_supportPreloadRequest = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HistoryWidget::clearAllLoadRequests() {
|
void HistoryWidget::clearAllLoadRequests() {
|
||||||
Expects(_history != nullptr);
|
Expects(_history != nullptr);
|
||||||
|
|
||||||
|
@ -2990,6 +3009,9 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages
|
||||||
setMsgId(_delayedShowAtMsgId);
|
setMsgId(_delayedShowAtMsgId);
|
||||||
historyLoaded();
|
historyLoaded();
|
||||||
}
|
}
|
||||||
|
if (session().supportMode()) {
|
||||||
|
crl::on_main(this, [=] { checkSupportPreload(); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::historyLoaded() {
|
void HistoryWidget::historyLoaded() {
|
||||||
|
@ -3337,6 +3359,96 @@ void HistoryWidget::preloadHistoryByScroll() {
|
||||||
if (scrollTop <= kPreloadHeightsCount * scrollHeight) {
|
if (scrollTop <= kPreloadHeightsCount * scrollHeight) {
|
||||||
loadMessages();
|
loadMessages();
|
||||||
}
|
}
|
||||||
|
if (session().supportMode()) {
|
||||||
|
crl::on_main(this, [=] { checkSupportPreload(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HistoryWidget::checkSupportPreload(bool force) {
|
||||||
|
if (!_history
|
||||||
|
|| _firstLoadRequest
|
||||||
|
|| _preloadRequest
|
||||||
|
|| _preloadDownRequest
|
||||||
|
|| (_supportPreloadRequest && !force)
|
||||||
|
|| controller()->activeChatEntryCurrent().key.history() != _history) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto setting = session().settings().supportSwitch();
|
||||||
|
const auto command = Support::GetSwitchCommand(setting);
|
||||||
|
const auto descriptor = !command
|
||||||
|
? Dialogs::RowDescriptor()
|
||||||
|
: (*command == Shortcuts::Command::ChatNext)
|
||||||
|
? controller()->resolveChatNext()
|
||||||
|
: controller()->resolveChatPrevious();
|
||||||
|
auto history = descriptor.key.history();
|
||||||
|
if (!history || _supportPreloadHistory == history) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearSupportPreloadRequest();
|
||||||
|
_supportPreloadHistory = history;
|
||||||
|
auto offsetId = MsgId();
|
||||||
|
auto offset = 0;
|
||||||
|
auto loadCount = kMessagesPerPage;
|
||||||
|
if (const auto around = history->loadAroundId()) {
|
||||||
|
history->getReadyFor(ShowAtUnreadMsgId);
|
||||||
|
offset = -loadCount / 2;
|
||||||
|
offsetId = around;
|
||||||
|
}
|
||||||
|
const auto offsetDate = 0;
|
||||||
|
const auto maxId = 0;
|
||||||
|
const auto minId = 0;
|
||||||
|
const auto historyHash = uint64(0);
|
||||||
|
const auto tmp = history->peer->name.toStdString();
|
||||||
|
const auto tmp2 = _history->peer->name.toStdString();
|
||||||
|
LOG(("PRELOADING FROM: %1 FOR: %2").arg(_history->peer->name).arg(history->peer->name));
|
||||||
|
const auto type = Data::Histories::RequestType::History;
|
||||||
|
auto &histories = history->owner().histories();
|
||||||
|
_supportPreloadRequest = histories.sendRequest(history, type, [=](Fn<void()> finish) {
|
||||||
|
return history->session().api().request(MTPmessages_GetHistory(
|
||||||
|
history->peer->input,
|
||||||
|
MTP_int(offsetId),
|
||||||
|
MTP_int(offsetDate),
|
||||||
|
MTP_int(offset),
|
||||||
|
MTP_int(loadCount),
|
||||||
|
MTP_int(maxId),
|
||||||
|
MTP_int(minId),
|
||||||
|
MTP_long(historyHash)
|
||||||
|
)).done([=](const MTPmessages_Messages &result) {
|
||||||
|
if (const auto around = history->loadAroundId()) {
|
||||||
|
if (around != offsetId) {
|
||||||
|
LOG(("RE-PRELOADING FOR: %1").arg(history->peer->name));
|
||||||
|
_supportPreloadRequest = 0;
|
||||||
|
_supportPreloadHistory = nullptr;
|
||||||
|
crl::on_main(this, [=] { checkSupportPreload(); });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
history->clear(History::ClearType::Unload);
|
||||||
|
history->getReadyFor(ShowAtUnreadMsgId);
|
||||||
|
} else if (offsetId) {
|
||||||
|
LOG(("RE-PRELOADING FOR: %1").arg(history->peer->name));
|
||||||
|
_supportPreloadRequest = 0;
|
||||||
|
_supportPreloadHistory = nullptr;
|
||||||
|
crl::on_main(this, [=] { checkSupportPreload(); });
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
history->clear(History::ClearType::Unload);
|
||||||
|
history->getReadyFor(ShowAtTheEndMsgId);
|
||||||
|
}
|
||||||
|
LOG(("PRELOADED FOR: %1").arg(history->peer->name));
|
||||||
|
auto count = 0;
|
||||||
|
const QVector<MTPMessage> emptyList, *histList = &emptyList;
|
||||||
|
result.match([](const MTPDmessages_messagesNotModified&) {
|
||||||
|
}, [&](const auto &data) {
|
||||||
|
history->owner().processUsers(data.vusers());
|
||||||
|
history->owner().processChats(data.vchats());
|
||||||
|
history->addOlderSlice(data.vmessages().v);
|
||||||
|
});
|
||||||
|
finish();
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
finish();
|
||||||
|
}).send();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::checkReplyReturns() {
|
void HistoryWidget::checkReplyReturns() {
|
||||||
|
@ -7534,10 +7646,7 @@ HistoryWidget::~HistoryWidget() {
|
||||||
// Saving a draft on account switching.
|
// Saving a draft on account switching.
|
||||||
saveFieldToHistoryLocalDraft();
|
saveFieldToHistoryLocalDraft();
|
||||||
session().api().saveDraftToCloudDelayed(_history);
|
session().api().saveDraftToCloudDelayed(_history);
|
||||||
|
|
||||||
clearAllLoadRequests();
|
|
||||||
setHistory(nullptr);
|
setHistory(nullptr);
|
||||||
unregisterDraftSources();
|
|
||||||
}
|
}
|
||||||
setTabbedPanel(nullptr);
|
setTabbedPanel(nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,6 +234,7 @@ public:
|
||||||
Ui::ReportReason reason,
|
Ui::ReportReason reason,
|
||||||
Fn<void(MessageIdsList)> callback);
|
Fn<void(MessageIdsList)> callback);
|
||||||
void clearAllLoadRequests();
|
void clearAllLoadRequests();
|
||||||
|
void clearSupportPreloadRequest();
|
||||||
void clearDelayedShowAtRequest();
|
void clearDelayedShowAtRequest();
|
||||||
void clearDelayedShowAt();
|
void clearDelayedShowAt();
|
||||||
void saveFieldToHistoryLocalDraft();
|
void saveFieldToHistoryLocalDraft();
|
||||||
|
@ -598,6 +599,7 @@ private:
|
||||||
bool readyToForward() const;
|
bool readyToForward() const;
|
||||||
bool hasSilentToggle() const;
|
bool hasSilentToggle() const;
|
||||||
|
|
||||||
|
void checkSupportPreload(bool force = false);
|
||||||
void handleSupportSwitch(not_null<History*> updated);
|
void handleSupportSwitch(not_null<History*> updated);
|
||||||
|
|
||||||
void inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result);
|
void inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result);
|
||||||
|
@ -685,6 +687,9 @@ private:
|
||||||
MsgId _delayedShowAtMsgId = -1;
|
MsgId _delayedShowAtMsgId = -1;
|
||||||
int _delayedShowAtRequest = 0; // Not real mtpRequestId.
|
int _delayedShowAtRequest = 0; // Not real mtpRequestId.
|
||||||
|
|
||||||
|
History *_supportPreloadHistory = nullptr;
|
||||||
|
int _supportPreloadRequest = 0; // Not real mtpRequestId.
|
||||||
|
|
||||||
object_ptr<HistoryView::TopBarWidget> _topBar;
|
object_ptr<HistoryView::TopBarWidget> _topBar;
|
||||||
object_ptr<Ui::ContinuousScroll> _scroll;
|
object_ptr<Ui::ContinuousScroll> _scroll;
|
||||||
QPointer<HistoryInner> _list;
|
QPointer<HistoryInner> _list;
|
||||||
|
|
|
@ -1779,6 +1779,16 @@ bool MainWidget::isThirdSectionShown() const {
|
||||||
return _thirdSection != nullptr;
|
return _thirdSection != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dialogs::RowDescriptor MainWidget::resolveChatNext(
|
||||||
|
Dialogs::RowDescriptor from) const {
|
||||||
|
return _dialogs ? _dialogs->resolveChatNext(from) : Dialogs::RowDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialogs::RowDescriptor MainWidget::resolveChatPrevious(
|
||||||
|
Dialogs::RowDescriptor from) const {
|
||||||
|
return _dialogs ? _dialogs->resolveChatPrevious(from) : Dialogs::RowDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
bool MainWidget::stackIsEmpty() const {
|
bool MainWidget::stackIsEmpty() const {
|
||||||
return _stack.empty();
|
return _stack.empty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,11 @@ public:
|
||||||
[[nodiscard]] bool isMainSectionShown() const;
|
[[nodiscard]] bool isMainSectionShown() const;
|
||||||
[[nodiscard]] bool isThirdSectionShown() const;
|
[[nodiscard]] bool isThirdSectionShown() const;
|
||||||
|
|
||||||
|
[[nodiscard]] Dialogs::RowDescriptor resolveChatNext(
|
||||||
|
Dialogs::RowDescriptor from) const;
|
||||||
|
[[nodiscard]] Dialogs::RowDescriptor resolveChatPrevious(
|
||||||
|
Dialogs::RowDescriptor from) const;
|
||||||
|
|
||||||
void returnTabbedSelector();
|
void returnTabbedSelector();
|
||||||
|
|
||||||
void showAnimated(const QPixmap &bgAnimCache, bool back = false);
|
void showAnimated(const QPixmap &bgAnimCache, bool back = false);
|
||||||
|
|
|
@ -21,14 +21,19 @@ Qt::KeyboardModifiers SkipSwitchModifiers() {
|
||||||
return Qt::ControlModifier | Qt::ShiftModifier;
|
return Qt::ControlModifier | Qt::ShiftModifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
FnMut<bool()> GetSwitchMethod(SwitchSettings value) {
|
std::optional<Shortcuts::Command> GetSwitchCommand(SwitchSettings value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case SwitchSettings::Next:
|
case SwitchSettings::Next:
|
||||||
return Shortcuts::RequestHandler(Shortcuts::Command::ChatNext);
|
return Shortcuts::Command::ChatNext;
|
||||||
case SwitchSettings::Previous:
|
case SwitchSettings::Previous:
|
||||||
return Shortcuts::RequestHandler(Shortcuts::Command::ChatPrevious);
|
return Shortcuts::Command::ChatPrevious;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
FnMut<bool()> GetSwitchMethod(SwitchSettings value) {
|
||||||
|
const auto command = GetSwitchCommand(value);
|
||||||
|
return command ? Shortcuts::RequestHandler(*command) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Support
|
} // namespace Support
|
||||||
|
|
|
@ -7,6 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
namespace Shortcuts {
|
||||||
|
enum class Command;
|
||||||
|
} // namespace Shortcuts
|
||||||
|
|
||||||
namespace Support {
|
namespace Support {
|
||||||
|
|
||||||
enum class SwitchSettings {
|
enum class SwitchSettings {
|
||||||
|
@ -15,8 +19,10 @@ enum class SwitchSettings {
|
||||||
Previous,
|
Previous,
|
||||||
};
|
};
|
||||||
|
|
||||||
Qt::KeyboardModifiers SkipSwitchModifiers();
|
[[nodiscard]] Qt::KeyboardModifiers SkipSwitchModifiers();
|
||||||
bool HandleSwitch(Qt::KeyboardModifiers modifiers);
|
[[nodiscard]] bool HandleSwitch(Qt::KeyboardModifiers modifiers);
|
||||||
FnMut<bool()> GetSwitchMethod(SwitchSettings value);
|
[[nodiscard]] std::optional<Shortcuts::Command> GetSwitchCommand(
|
||||||
|
SwitchSettings value);
|
||||||
|
[[nodiscard]] FnMut<bool()> GetSwitchMethod(SwitchSettings value);
|
||||||
|
|
||||||
} // namespace Support
|
} // namespace Support
|
||||||
|
|
|
@ -795,6 +795,16 @@ bool SessionController::jumpToChatListEntry(Dialogs::RowDescriptor row) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dialogs::RowDescriptor SessionController::resolveChatNext(
|
||||||
|
Dialogs::RowDescriptor from) const {
|
||||||
|
return content()->resolveChatNext(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialogs::RowDescriptor SessionController::resolveChatPrevious(
|
||||||
|
Dialogs::RowDescriptor from) const {
|
||||||
|
return content()->resolveChatPrevious(from);
|
||||||
|
}
|
||||||
|
|
||||||
void SessionController::pushToChatEntryHistory(Dialogs::RowDescriptor row) {
|
void SessionController::pushToChatEntryHistory(Dialogs::RowDescriptor row) {
|
||||||
if (!_chatEntryHistory.empty()
|
if (!_chatEntryHistory.empty()
|
||||||
&& _chatEntryHistory[_chatEntryHistoryPosition] == row) {
|
&& _chatEntryHistory[_chatEntryHistoryPosition] == row) {
|
||||||
|
|
|
@ -301,6 +301,12 @@ public:
|
||||||
rpl::producer<Dialogs::RowDescriptor> activeChatEntryValue() const;
|
rpl::producer<Dialogs::RowDescriptor> activeChatEntryValue() const;
|
||||||
rpl::producer<Dialogs::Key> activeChatValue() const;
|
rpl::producer<Dialogs::Key> activeChatValue() const;
|
||||||
bool jumpToChatListEntry(Dialogs::RowDescriptor row);
|
bool jumpToChatListEntry(Dialogs::RowDescriptor row);
|
||||||
|
|
||||||
|
[[nodiscard]] Dialogs::RowDescriptor resolveChatNext(
|
||||||
|
Dialogs::RowDescriptor from = {}) const;
|
||||||
|
[[nodiscard]] Dialogs::RowDescriptor resolveChatPrevious(
|
||||||
|
Dialogs::RowDescriptor from = {}) const;
|
||||||
|
|
||||||
void showEditPeerBox(PeerData *peer);
|
void showEditPeerBox(PeerData *peer);
|
||||||
|
|
||||||
void enableGifPauseReason(GifPauseReason reason);
|
void enableGifPauseReason(GifPauseReason reason);
|
||||||
|
|
Loading…
Add table
Reference in a new issue