diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 5ce8f3564a..07dc36bc75 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -3133,7 +3133,7 @@ void HistoryWidget::sendActionDone(const MTPBool &result, mtpRequestId req) { } void HistoryWidget::activate() { - if (_history) updateListSize(0, true); + if (_history) updateListSize(true); if (App::wnd()) App::wnd()->setInnerFocus(); } @@ -3239,7 +3239,7 @@ void HistoryWidget::notify_clipStopperHidden(ClipStopperType type) { } void HistoryWidget::notify_historyItemResized(const HistoryItem *row, bool scrollToIt) { - updateListSize(0, false, false, row, scrollToIt); + updateListSize(false, false, { ScrollChangeNone, 0 }, row, scrollToIt); } void HistoryWidget::cmd_search() { @@ -4955,7 +4955,7 @@ void HistoryWidget::doneShow() { updateReportSpamStatus(); updateBotKeyboard(); updateControlsVisibility(); - updateListSize(0, true); + updateListSize(true); onListScroll(); if (App::wnd()) { App::wnd()->checkHistoryActivation(); @@ -6215,7 +6215,7 @@ void HistoryWidget::resizeEvent(QResizeEvent *e) { _attachPhoto.move(_attachDocument.x(), _attachDocument.y()); _fieldBarCancel.move(width() - _fieldBarCancel.width(), _field.y() - st::sendPadding - _fieldBarCancel.height()); - updateListSize(App::main() ? App::main()->contentScrollAddToY() : 0); + updateListSize(false, false, { ScrollChangeAdd, App::main() ? App::main()->contentScrollAddToY() : 0 }); bool kbShowShown = _history && !_kbShown && _keyboard.hasMarkup(); _field.resize(width() - _send.width() - _attachDocument.width() - _attachEmoji.width() - (kbShowShown ? _kbShow.width() : 0) - (_cmdStartShown ? _cmdStart.width() : 0) - (hasBroadcastToggle() ? _broadcast.width() : 0) - (hasSilentToggle() ? _silent.width() : 0), _field.height()); @@ -6301,7 +6301,7 @@ MsgId HistoryWidget::replyToId() const { return _replyToId ? _replyToId : (_kbReplyTo ? _kbReplyTo->id : 0); } -void HistoryWidget::updateListSize(int32 addToY, bool initial, bool loadedDown, const HistoryItem *resizedItem, bool scrollToIt) { +void HistoryWidget::updateListSize(bool initial, bool loadedDown, const ScrollChange &change, const HistoryItem *resizedItem, bool scrollToIt) { if (!_history || (initial && _histInited) || (!initial && !_histInited)) return; if (_firstLoadRequest) { if (resizedItem) _list->recountHeight(resizedItem); @@ -6360,6 +6360,12 @@ void HistoryWidget::updateListSize(int32 addToY, bool initial, bool loadedDown, } if ((!initial && !wasAtBottom) || (loadedDown && (!_history->showFrom || _history->unreadBar || _history->loadedAtBottom()) && (!_migrated || !_migrated->showFrom || _migrated->unreadBar || _history->loadedAtBottom()))) { + int32 addToY = 0; + if (change.type == ScrollChangeAdd) { + addToY = change.value; + } else if (change.type == ScrollChangeOldHistoryHeight) { + addToY = _list->historyHeight() - change.value; + } _scroll.scrollToY(newSt + addToY); return; } @@ -6378,7 +6384,7 @@ void HistoryWidget::updateListSize(int32 addToY, bool initial, bool loadedDown, if (iy < 0) { setMsgId(0); _histInited = false; - return updateListSize(addToY, initial); + return updateListSize(initial, false, change); } else { toY = (_scroll.height() > item->height()) ? qMax(iy - (_scroll.height() - item->height()) / 2, 0) : iy; _animActiveStart = getms(); @@ -6391,7 +6397,7 @@ void HistoryWidget::updateListSize(int32 addToY, bool initial, bool loadedDown, if (iy < 0) { setMsgId(0); _histInited = false; - return updateListSize(addToY, initial); + return updateListSize(initial, false, change); } else { toY = (_scroll.height() > item->height()) ? qMax(iy - (_scroll.height() - item->height()) / 2, 0) : iy; _animActiveStart = getms(); @@ -6429,7 +6435,7 @@ void HistoryWidget::updateListSize(int32 addToY, bool initial, bool loadedDown, _fixedInScrollMsgId = 0; _fixedInScrollMsgTop = 0; _histInited = false; - return updateListSize(addToY, initial); + return updateListSize(initial, false, change); } } else { toY = qMax(iy + item->height() - _fixedInScrollMsgTop, 0); @@ -6445,7 +6451,7 @@ void HistoryWidget::updateListSize(int32 addToY, bool initial, bool loadedDown, if (_migrated->unreadBar) { setMsgId(ShowAtUnreadMsgId); _histInited = false; - updateListSize(0, true); + updateListSize(true); App::wnd()->checkHistoryActivation(); return; } @@ -6457,7 +6463,7 @@ void HistoryWidget::updateListSize(int32 addToY, bool initial, bool loadedDown, if (_history->unreadBar) { setMsgId(ShowAtUnreadMsgId); _histInited = false; - updateListSize(0, true); + updateListSize(true); App::wnd()->checkHistoryActivation(); return; } @@ -6468,10 +6474,16 @@ void HistoryWidget::updateListSize(int32 addToY, bool initial, bool loadedDown, } void HistoryWidget::addMessagesToFront(PeerData *peer, const QVector &messages, const QVector *collapsed) { - int32 oldH = _list->historyHeight(); + int oldH = _list->historyHeight(); _list->messagesReceived(peer, messages, collapsed); if (!_firstLoadRequest) { - updateListSize(_list->historyHeight() - oldH); + updateListSize(false, false, { ScrollChangeOldHistoryHeight, oldH }); + if (_animActiveTimer.isActive() && _activeAnimMsgId > 0 && _migrated && !_migrated->isEmpty() && _migrated->loadedAtBottom() && _migrated->blocks.back()->items.back()->isGroupMigrate() && _list->historyTop() != _list->historyDrawTop() && _history) { + HistoryItem *animActiveItem = App::histItemById(_history->channelId(), _activeAnimMsgId); + if (animActiveItem && animActiveItem->isGroupMigrate()) { + _activeAnimMsgId = -_migrated->blocks.back()->items.back()->id; + } + } updateBotKeyboard(); } } @@ -6479,7 +6491,7 @@ void HistoryWidget::addMessagesToFront(PeerData *peer, const QVector void HistoryWidget::addMessagesToBack(PeerData *peer, const QVector &messages, const QVector *collapsed) { _list->messagesReceivedDown(peer, messages, collapsed); if (!_firstLoadRequest) { - updateListSize(0, false, true); + updateListSize(false, true); } } diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index a787bb978d..917eb73018 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -782,10 +782,20 @@ private: QList _replyReturns; bool messagesFailed(const RPCError &error, mtpRequestId requestId); - void updateListSize(int32 addToY = 0, bool initial = false, bool loadedDown = false, const HistoryItem *resizedItem = 0, bool scrollToIt = false); void addMessagesToFront(PeerData *peer, const QVector &messages, const QVector *collapsed); void addMessagesToBack(PeerData *peer, const QVector &messages, const QVector *collapsed); + enum ScrollChangeType { + ScrollChangeNone, + ScrollChangeAdd, + ScrollChangeOldHistoryHeight, + }; + struct ScrollChange { + ScrollChangeType type; + int value; + }; + void updateListSize(bool initial = false, bool loadedDown = false, const ScrollChange &change = { ScrollChangeNone, 0 }, const HistoryItem *resizedItem = 0, bool scrollToIt = false); + void saveGifDone(DocumentData *doc, const MTPBool &result); void reportSpamDone(PeerData *peer, const MTPBool &result, mtpRequestId request); diff --git a/Telegram/SourceFiles/window.cpp b/Telegram/SourceFiles/window.cpp index 4d82a0711f..66a3a02a11 100644 --- a/Telegram/SourceFiles/window.cpp +++ b/Telegram/SourceFiles/window.cpp @@ -78,7 +78,10 @@ void ConnectingWidget::onReconnect() { MTP::restart(); } -NotifyWindow::NotifyWindow(HistoryItem *msg, int32 x, int32 y, int32 fwdCount) : history(msg->history()), item(msg), fwdCount(fwdCount) +NotifyWindow::NotifyWindow(HistoryItem *msg, int32 x, int32 y, int32 fwdCount) : TWidget(0) +, history(msg->history()) +, item(msg) +, fwdCount(fwdCount) #ifdef Q_OS_WIN , started(GetTickCount()) #endif