mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-01 00:08:02 +00:00
Save admin log state to memento and restore it.
This commit is contained in:
parent
85e234938d
commit
0a9db8533b
@ -335,35 +335,22 @@ QPoint InnerWidget::tooltipPos() const {
|
|||||||
return _mousePosition;
|
return _mousePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::saveState(gsl::not_null<SectionMemento*> memento) const {
|
void InnerWidget::saveState(gsl::not_null<SectionMemento*> memento) {
|
||||||
//if (auto count = _items.size()) {
|
memento->setItems(std::move(_items), std::move(_itemsByIds), _upLoaded, _downLoaded);
|
||||||
// QList<gsl::not_null<PeerData*>> groups;
|
memento->setIdManager(std::move(_idManager));
|
||||||
// groups.reserve(count);
|
_upLoaded = _downLoaded = true; // Don't load or handle anything anymore.
|
||||||
// for_const (auto item, _items) {
|
|
||||||
// groups.push_back(item->peer);
|
|
||||||
// }
|
|
||||||
// memento->setCommonGroups(groups);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::restoreState(gsl::not_null<const SectionMemento*> memento) {
|
void InnerWidget::restoreState(gsl::not_null<SectionMemento*> memento) {
|
||||||
//auto list = memento->getCommonGroups();
|
_items = memento->takeItems();
|
||||||
//_allLoaded = false;
|
_itemsByIds = memento->takeItemsByIds();
|
||||||
//if (!list.empty()) {
|
_idManager = memento->takeIdManager();
|
||||||
// showInitial(list);
|
_upLoaded = memento->upLoaded();
|
||||||
//}
|
_downLoaded = memento->downLoaded();
|
||||||
|
updateMinMaxIds();
|
||||||
|
updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
//void InnerWidget::showInitial(const QList<PeerData*> &list) {
|
|
||||||
// for_const (auto group, list) {
|
|
||||||
// if (auto item = computeItem(group)) {
|
|
||||||
// _items.push_back(item);
|
|
||||||
// }
|
|
||||||
// _preloadGroupId = group->bareId();
|
|
||||||
// }
|
|
||||||
// updateSize();
|
|
||||||
//}
|
|
||||||
|
|
||||||
void InnerWidget::preloadMore(Direction direction) {
|
void InnerWidget::preloadMore(Direction direction) {
|
||||||
auto &requestId = (direction == Direction::Up) ? _preloadUpRequestId : _preloadDownRequestId;
|
auto &requestId = (direction == Direction::Up) ? _preloadUpRequestId : _preloadDownRequestId;
|
||||||
auto &loadedFlag = (direction == Direction::Up) ? _upLoaded : _downLoaded;
|
auto &loadedFlag = (direction == Direction::Up) ? _upLoaded : _downLoaded;
|
||||||
@ -394,6 +381,10 @@ void InnerWidget::preloadMore(Direction direction) {
|
|||||||
auto &results = result.c_channels_adminLogResults();
|
auto &results = result.c_channels_adminLogResults();
|
||||||
App::feedUsers(results.vusers);
|
App::feedUsers(results.vusers);
|
||||||
App::feedChats(results.vchats);
|
App::feedChats(results.vchats);
|
||||||
|
|
||||||
|
if (loadedFlag) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto &events = results.vevents.v;
|
auto &events = results.vevents.v;
|
||||||
if (!events.empty()) {
|
if (!events.empty()) {
|
||||||
auto oldItemsCount = _items.size();
|
auto oldItemsCount = _items.size();
|
||||||
@ -401,10 +392,14 @@ void InnerWidget::preloadMore(Direction direction) {
|
|||||||
for_const (auto &event, events) {
|
for_const (auto &event, events) {
|
||||||
t_assert(event.type() == mtpc_channelAdminLogEvent);
|
t_assert(event.type() == mtpc_channelAdminLogEvent);
|
||||||
auto &data = event.c_channelAdminLogEvent();
|
auto &data = event.c_channelAdminLogEvent();
|
||||||
|
if (_itemsByIds.find(data.vid.v) != _itemsByIds.cend()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto count = 0;
|
auto count = 0;
|
||||||
GenerateItems(_history, _idManager, data, [this, id = data.vid.v, &count](HistoryItemOwned item) {
|
GenerateItems(_history, _idManager, data, [this, id = data.vid.v, &count](HistoryItemOwned item) {
|
||||||
_items.push_back(std::move(item));
|
|
||||||
_itemsByIds.emplace(id, item.get());
|
_itemsByIds.emplace(id, item.get());
|
||||||
|
_items.push_back(std::move(item));
|
||||||
++count;
|
++count;
|
||||||
});
|
});
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
@ -433,11 +428,7 @@ void InnerWidget::preloadMore(Direction direction) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_maxId = (--_itemsByIds.end())->first;
|
updateMinMaxIds();
|
||||||
_minId = _itemsByIds.begin()->first;
|
|
||||||
if (_minId == 1) {
|
|
||||||
_upLoaded = true;
|
|
||||||
}
|
|
||||||
itemsAdded(direction);
|
itemsAdded(direction);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -449,6 +440,18 @@ void InnerWidget::preloadMore(Direction direction) {
|
|||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InnerWidget::updateMinMaxIds() {
|
||||||
|
if (_itemsByIds.empty()) {
|
||||||
|
_maxId = _minId = 0;
|
||||||
|
} else {
|
||||||
|
_maxId = (--_itemsByIds.end())->first;
|
||||||
|
_minId = _itemsByIds.begin()->first;
|
||||||
|
if (_minId == 1) {
|
||||||
|
_upLoaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void InnerWidget::itemsAdded(Direction direction) {
|
void InnerWidget::itemsAdded(Direction direction) {
|
||||||
updateSize();
|
updateSize();
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,8 @@ public:
|
|||||||
return TWidget::resizeToWidth(newWidth);
|
return TWidget::resizeToWidth(newWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveState(gsl::not_null<SectionMemento*> memento) const;
|
void saveState(gsl::not_null<SectionMemento*> memento);
|
||||||
void restoreState(gsl::not_null<const SectionMemento*> memento);
|
void restoreState(gsl::not_null<SectionMemento*> memento);
|
||||||
void setCancelledCallback(base::lambda<void()> callback) {
|
void setCancelledCallback(base::lambda<void()> callback) {
|
||||||
_cancelledCallback = std::move(callback);
|
_cancelledCallback = std::move(callback);
|
||||||
}
|
}
|
||||||
@ -151,6 +151,7 @@ private:
|
|||||||
void preloadMore(Direction direction);
|
void preloadMore(Direction direction);
|
||||||
void itemsAdded(Direction direction);
|
void itemsAdded(Direction direction);
|
||||||
void updateSize();
|
void updateSize();
|
||||||
|
void updateMinMaxIds();
|
||||||
void paintEmpty(Painter &p);
|
void paintEmpty(Painter &p);
|
||||||
|
|
||||||
void toggleScrollDateShown();
|
void toggleScrollDateShown();
|
||||||
@ -213,7 +214,9 @@ private:
|
|||||||
uint64 _minId = 0;
|
uint64 _minId = 0;
|
||||||
mtpRequestId _preloadUpRequestId = 0;
|
mtpRequestId _preloadUpRequestId = 0;
|
||||||
mtpRequestId _preloadDownRequestId = 0;
|
mtpRequestId _preloadDownRequestId = 0;
|
||||||
bool _upLoaded = false;
|
|
||||||
|
// Don't load anything until the memento was read.
|
||||||
|
bool _upLoaded = true;
|
||||||
bool _downLoaded = true;
|
bool _downLoaded = true;
|
||||||
|
|
||||||
MouseAction _mouseAction = MouseAction::None;
|
MouseAction _mouseAction = MouseAction::None;
|
||||||
|
@ -61,7 +61,7 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
object_ptr<Window::SectionWidget> SectionMemento::createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) const {
|
object_ptr<Window::SectionWidget> SectionMemento::createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) {
|
||||||
auto result = object_ptr<Widget>(parent, controller, _channel);
|
auto result = object_ptr<Widget>(parent, controller, _channel);
|
||||||
result->setInternalState(geometry, this);
|
result->setInternalState(geometry, this);
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
@ -168,34 +168,34 @@ void Widget::doSetInnerFocus() {
|
|||||||
_inner->setFocus();
|
_inner->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::showInternal(const Window::SectionMemento *memento) {
|
bool Widget::showInternal(gsl::not_null<Window::SectionMemento*> memento) {
|
||||||
if (auto profileMemento = dynamic_cast<const SectionMemento*>(memento)) {
|
if (auto logMemento = dynamic_cast<SectionMemento*>(memento.get())) {
|
||||||
if (profileMemento->getChannel() == channel()) {
|
if (logMemento->getChannel() == channel()) {
|
||||||
restoreState(profileMemento);
|
restoreState(logMemento);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::setInternalState(const QRect &geometry, gsl::not_null<const SectionMemento*> memento) {
|
void Widget::setInternalState(const QRect &geometry, gsl::not_null<SectionMemento*> memento) {
|
||||||
setGeometry(geometry);
|
setGeometry(geometry);
|
||||||
myEnsureResized(this);
|
myEnsureResized(this);
|
||||||
restoreState(memento);
|
restoreState(memento);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Window::SectionMemento> Widget::createMemento() const {
|
std::unique_ptr<Window::SectionMemento> Widget::createMemento() {
|
||||||
auto result = std::make_unique<SectionMemento>(channel());
|
auto result = std::make_unique<SectionMemento>(channel());
|
||||||
saveState(result.get());
|
saveState(result.get());
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::saveState(gsl::not_null<SectionMemento*> memento) const {
|
void Widget::saveState(gsl::not_null<SectionMemento*> memento) {
|
||||||
memento->setScrollTop(_scroll->scrollTop());
|
memento->setScrollTop(_scroll->scrollTop());
|
||||||
_inner->saveState(memento);
|
_inner->saveState(memento);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::restoreState(gsl::not_null<const SectionMemento*> memento) {
|
void Widget::restoreState(gsl::not_null<SectionMemento*> memento) {
|
||||||
_inner->restoreState(memento);
|
_inner->restoreState(memento);
|
||||||
auto scrollTop = memento->getScrollTop();
|
auto scrollTop = memento->getScrollTop();
|
||||||
_scroll->scrollToY(scrollTop);
|
_scroll->scrollToY(scrollTop);
|
||||||
|
@ -22,6 +22,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||||||
|
|
||||||
#include "window/section_widget.h"
|
#include "window/section_widget.h"
|
||||||
#include "window/section_memento.h"
|
#include "window/section_memento.h"
|
||||||
|
#include "history/history_admin_log_item.h"
|
||||||
|
#include "history/history_admin_log_inner.h"
|
||||||
|
|
||||||
namespace Notify {
|
namespace Notify {
|
||||||
struct PeerUpdate;
|
struct PeerUpdate;
|
||||||
@ -58,10 +60,10 @@ public:
|
|||||||
|
|
||||||
QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms) override;
|
QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms) override;
|
||||||
|
|
||||||
bool showInternal(const Window::SectionMemento *memento) override;
|
bool showInternal(gsl::not_null<Window::SectionMemento*> memento) override;
|
||||||
std::unique_ptr<Window::SectionMemento> createMemento() const override;
|
std::unique_ptr<Window::SectionMemento> createMemento() override;
|
||||||
|
|
||||||
void setInternalState(const QRect &geometry, gsl::not_null<const SectionMemento*> memento);
|
void setInternalState(const QRect &geometry, gsl::not_null<SectionMemento*> memento);
|
||||||
|
|
||||||
// Float player interface.
|
// Float player interface.
|
||||||
bool wheelEventFromFloatPlayer(QEvent *e, Window::Column myColumn, Window::Column playerColumn) override;
|
bool wheelEventFromFloatPlayer(QEvent *e, Window::Column myColumn, Window::Column playerColumn) override;
|
||||||
@ -81,8 +83,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void onScroll();
|
void onScroll();
|
||||||
void updateAdaptiveLayout();
|
void updateAdaptiveLayout();
|
||||||
void saveState(gsl::not_null<SectionMemento*> memento) const;
|
void saveState(gsl::not_null<SectionMemento*> memento);
|
||||||
void restoreState(gsl::not_null<const SectionMemento*> memento);
|
void restoreState(gsl::not_null<SectionMemento*> memento);
|
||||||
|
|
||||||
object_ptr<Ui::ScrollArea> _scroll;
|
object_ptr<Ui::ScrollArea> _scroll;
|
||||||
QPointer<InnerWidget> _inner;
|
QPointer<InnerWidget> _inner;
|
||||||
@ -97,7 +99,7 @@ public:
|
|||||||
SectionMemento(gsl::not_null<ChannelData*> channel) : _channel(channel) {
|
SectionMemento(gsl::not_null<ChannelData*> channel) : _channel(channel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
object_ptr<Window::SectionWidget> createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) const override;
|
object_ptr<Window::SectionWidget> createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) override;
|
||||||
|
|
||||||
gsl::not_null<ChannelData*> getChannel() const {
|
gsl::not_null<ChannelData*> getChannel() const {
|
||||||
return _channel;
|
return _channel;
|
||||||
@ -109,9 +111,39 @@ public:
|
|||||||
return _scrollTop;
|
return _scrollTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setItems(std::vector<HistoryItemOwned> &&items, std::map<uint64, HistoryItem*> &&itemsByIds, bool upLoaded, bool downLoaded) {
|
||||||
|
_items = std::move(items);
|
||||||
|
_itemsByIds = std::move(itemsByIds);
|
||||||
|
_upLoaded = upLoaded;
|
||||||
|
_downLoaded = downLoaded;
|
||||||
|
}
|
||||||
|
void setIdManager(LocalIdManager &&manager) {
|
||||||
|
_idManager = std::move(manager);
|
||||||
|
}
|
||||||
|
std::vector<HistoryItemOwned> takeItems() {
|
||||||
|
return std::move(_items);
|
||||||
|
}
|
||||||
|
std::map<uint64, HistoryItem*> takeItemsByIds() {
|
||||||
|
return std::move(_itemsByIds);
|
||||||
|
}
|
||||||
|
LocalIdManager takeIdManager() {
|
||||||
|
return std::move(_idManager);
|
||||||
|
}
|
||||||
|
bool upLoaded() const {
|
||||||
|
return _upLoaded;
|
||||||
|
}
|
||||||
|
bool downLoaded() const {
|
||||||
|
return _downLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
gsl::not_null<ChannelData*> _channel;
|
gsl::not_null<ChannelData*> _channel;
|
||||||
int _scrollTop = 0;
|
int _scrollTop = 0;
|
||||||
|
std::vector<HistoryItemOwned> _items;
|
||||||
|
std::map<uint64, HistoryItem*> _itemsByIds;
|
||||||
|
bool _upLoaded = false;
|
||||||
|
bool _downLoaded = true;
|
||||||
|
LocalIdManager _idManager;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2517,15 +2517,6 @@ void MainWidget::ui_showPeerHistory(quint64 peerId, qint32 showAtMsgId, Ui::Show
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dlgUpdated();
|
|
||||||
if (back || (way == Ui::ShowWay::ClearStack)) {
|
|
||||||
_peerInStack = nullptr;
|
|
||||||
_msgIdInStack = 0;
|
|
||||||
} else {
|
|
||||||
saveSectionInStack();
|
|
||||||
}
|
|
||||||
dlgUpdated();
|
|
||||||
|
|
||||||
auto wasActivePeer = activePeer();
|
auto wasActivePeer = activePeer();
|
||||||
|
|
||||||
Ui::hideSettingsAndLayer();
|
Ui::hideSettingsAndLayer();
|
||||||
@ -2556,6 +2547,16 @@ void MainWidget::ui_showPeerHistory(quint64 peerId, qint32 showAtMsgId, Ui::Show
|
|||||||
|
|
||||||
auto animationParams = animatedShow() ? prepareHistoryAnimation(peerId) : Window::SectionSlideParams();
|
auto animationParams = animatedShow() ? prepareHistoryAnimation(peerId) : Window::SectionSlideParams();
|
||||||
|
|
||||||
|
dlgUpdated();
|
||||||
|
if (back || (way == Ui::ShowWay::ClearStack)) {
|
||||||
|
_peerInStack = nullptr;
|
||||||
|
_msgIdInStack = 0;
|
||||||
|
} else {
|
||||||
|
// This may modify the current section, for example remove its contents.
|
||||||
|
saveSectionInStack();
|
||||||
|
}
|
||||||
|
dlgUpdated();
|
||||||
|
|
||||||
if (_history->peer() && _history->peer()->id != peerId && way != Ui::ShowWay::Forward) {
|
if (_history->peer() && _history->peer()->id != peerId && way != Ui::ShowWay::Forward) {
|
||||||
clearBotStartToken(_history->peer());
|
clearBotStartToken(_history->peer());
|
||||||
}
|
}
|
||||||
@ -2708,11 +2709,11 @@ void MainWidget::showMediaOverview(PeerData *peer, MediaOverviewType type, bool
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
auto animationParams = animatedShow() ? prepareOverviewAnimation() : Window::SectionSlideParams();
|
auto animationParams = animatedShow() ? prepareOverviewAnimation() : Window::SectionSlideParams();
|
||||||
|
setFocus(); // otherwise dialogs widget could be focused.
|
||||||
|
|
||||||
if (!back) {
|
if (!back) {
|
||||||
saveSectionInStack();
|
saveSectionInStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
setFocus(); // otherwise dialogs widget could be focused.
|
|
||||||
if (_overview) {
|
if (_overview) {
|
||||||
_overview->hide();
|
_overview->hide();
|
||||||
_overview->clear();
|
_overview->clear();
|
||||||
@ -2751,12 +2752,12 @@ void MainWidget::showMediaOverview(PeerData *peer, MediaOverviewType type, bool
|
|||||||
orderWidgets();
|
orderWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::showWideSection(const Window::SectionMemento &memento) {
|
void MainWidget::showWideSection(Window::SectionMemento &&memento) {
|
||||||
Ui::hideSettingsAndLayer();
|
Ui::hideSettingsAndLayer();
|
||||||
if (_wideSection && _wideSection->showInternal(&memento)) {
|
if (_wideSection && _wideSection->showInternal(&memento)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showNewWideSection(&memento, false, true);
|
showNewWideSection(std::move(memento), false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::SectionSlideParams MainWidget::prepareShowAnimation(bool willHaveTopBarShadow, bool willHaveTabbedSection) {
|
Window::SectionSlideParams MainWidget::prepareShowAnimation(bool willHaveTopBarShadow, bool willHaveTabbedSection) {
|
||||||
@ -2856,7 +2857,7 @@ Window::SectionSlideParams MainWidget::prepareDialogsAnimation() {
|
|||||||
return prepareShowAnimation(false, false);
|
return prepareShowAnimation(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::showNewWideSection(const Window::SectionMemento *memento, bool back, bool saveInStack) {
|
void MainWidget::showNewWideSection(Window::SectionMemento &&memento, bool back, bool saveInStack) {
|
||||||
QPixmap animCache;
|
QPixmap animCache;
|
||||||
|
|
||||||
_controller->dialogsListFocused().set(false, true);
|
_controller->dialogsListFocused().set(false, true);
|
||||||
@ -2864,7 +2865,7 @@ void MainWidget::showNewWideSection(const Window::SectionMemento *memento, bool
|
|||||||
|
|
||||||
auto sectionTop = getSectionTop();
|
auto sectionTop = getSectionTop();
|
||||||
auto newWideGeometry = QRect(_history->x(), sectionTop, _history->width(), height() - sectionTop);
|
auto newWideGeometry = QRect(_history->x(), sectionTop, _history->width(), height() - sectionTop);
|
||||||
auto newWideSection = memento->createWidget(this, _controller, newWideGeometry);
|
auto newWideSection = memento.createWidget(this, _controller, newWideGeometry);
|
||||||
auto animatedShow = [this] {
|
auto animatedShow = [this] {
|
||||||
if (_a_show.animating() || App::passcoded()) {
|
if (_a_show.animating() || App::passcoded()) {
|
||||||
return false;
|
return false;
|
||||||
@ -2876,11 +2877,12 @@ void MainWidget::showNewWideSection(const Window::SectionMemento *memento, bool
|
|||||||
};
|
};
|
||||||
auto animationParams = animatedShow() ? prepareWideSectionAnimation(newWideSection) : Window::SectionSlideParams();
|
auto animationParams = animatedShow() ? prepareWideSectionAnimation(newWideSection) : Window::SectionSlideParams();
|
||||||
|
|
||||||
|
setFocus(); // otherwise dialogs widget could be focused.
|
||||||
|
|
||||||
if (saveInStack) {
|
if (saveInStack) {
|
||||||
|
// This may modify the current section, for example remove its contents.
|
||||||
saveSectionInStack();
|
saveSectionInStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
setFocus(); // otherwise dialogs widget could be focused.
|
|
||||||
if (_overview) {
|
if (_overview) {
|
||||||
_overview->hide();
|
_overview->hide();
|
||||||
_overview->clear();
|
_overview->clear();
|
||||||
@ -2949,7 +2951,7 @@ void MainWidget::showBackFromStack() {
|
|||||||
_history->setReplyReturns(historyItem->peer->id, historyItem->replyReturns);
|
_history->setReplyReturns(historyItem->peer->id, historyItem->replyReturns);
|
||||||
} else if (item->type() == SectionStackItem) {
|
} else if (item->type() == SectionStackItem) {
|
||||||
auto sectionItem = static_cast<StackItemSection*>(item.get());
|
auto sectionItem = static_cast<StackItemSection*>(item.get());
|
||||||
showNewWideSection(sectionItem->memento(), true, false);
|
showNewWideSection(std::move(*sectionItem->memento()), true, false);
|
||||||
} else if (item->type() == OverviewStackItem) {
|
} else if (item->type() == OverviewStackItem) {
|
||||||
auto overviewItem = static_cast<StackItemOverview*>(item.get());
|
auto overviewItem = static_cast<StackItemOverview*>(item.get());
|
||||||
showMediaOverview(overviewItem->peer, overviewItem->mediaType, true, overviewItem->lastScrollTop);
|
showMediaOverview(overviewItem->peer, overviewItem->mediaType, true, overviewItem->lastScrollTop);
|
||||||
|
@ -215,7 +215,7 @@ public:
|
|||||||
int backgroundFromY() const;
|
int backgroundFromY() const;
|
||||||
PeerData *overviewPeer();
|
PeerData *overviewPeer();
|
||||||
bool showMediaTypeSwitch() const;
|
bool showMediaTypeSwitch() const;
|
||||||
void showWideSection(const Window::SectionMemento &memento);
|
void showWideSection(Window::SectionMemento &&memento);
|
||||||
void showMediaOverview(PeerData *peer, MediaOverviewType type, bool back = false, int32 lastScrollTop = -1);
|
void showMediaOverview(PeerData *peer, MediaOverviewType type, bool back = false, int32 lastScrollTop = -1);
|
||||||
bool stackIsEmpty() const;
|
bool stackIsEmpty() const;
|
||||||
void showBackFromStack();
|
void showBackFromStack();
|
||||||
@ -521,7 +521,7 @@ private:
|
|||||||
void mediaOverviewUpdated(const Notify::PeerUpdate &update);
|
void mediaOverviewUpdated(const Notify::PeerUpdate &update);
|
||||||
|
|
||||||
Window::SectionSlideParams prepareShowAnimation(bool willHaveTopBarShadow, bool willHaveTabbedSection);
|
Window::SectionSlideParams prepareShowAnimation(bool willHaveTopBarShadow, bool willHaveTabbedSection);
|
||||||
void showNewWideSection(const Window::SectionMemento *memento, bool back, bool saveInStack);
|
void showNewWideSection(Window::SectionMemento &&memento, bool back, bool saveInStack);
|
||||||
|
|
||||||
// All this methods use the prepareShowAnimation().
|
// All this methods use the prepareShowAnimation().
|
||||||
Window::SectionSlideParams prepareWideSectionAnimation(Window::SectionWidget *section);
|
Window::SectionSlideParams prepareWideSectionAnimation(Window::SectionWidget *section);
|
||||||
|
@ -35,9 +35,9 @@ public:
|
|||||||
virtual void showFinished() {
|
virtual void showFinished() {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void saveState(SectionMemento *memento) const {
|
virtual void saveState(gsl::not_null<SectionMemento*> memento) {
|
||||||
}
|
}
|
||||||
virtual void restoreState(const SectionMemento *memento) {
|
virtual void restoreState(gsl::not_null<SectionMemento*> memento) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -42,7 +42,7 @@ constexpr int kCommonGroupsPerPage = 40;
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
object_ptr<Window::SectionWidget> SectionMemento::createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) const {
|
object_ptr<Window::SectionWidget> SectionMemento::createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) {
|
||||||
auto result = object_ptr<Widget>(parent, controller, _user);
|
auto result = object_ptr<Widget>(parent, controller, _user);
|
||||||
result->setInternalState(geometry, this);
|
result->setInternalState(geometry, this);
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
@ -118,7 +118,7 @@ void InnerWidget::checkPreloadMore() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::saveState(SectionMemento *memento) const {
|
void InnerWidget::saveState(gsl::not_null<SectionMemento*> memento) {
|
||||||
if (auto count = _items.size()) {
|
if (auto count = _items.size()) {
|
||||||
QList<gsl::not_null<PeerData*>> groups;
|
QList<gsl::not_null<PeerData*>> groups;
|
||||||
groups.reserve(count);
|
groups.reserve(count);
|
||||||
@ -129,7 +129,7 @@ void InnerWidget::saveState(SectionMemento *memento) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::restoreState(const SectionMemento *memento) {
|
void InnerWidget::restoreState(gsl::not_null<SectionMemento*> memento) {
|
||||||
auto list = memento->getCommonGroups();
|
auto list = memento->getCommonGroups();
|
||||||
_allLoaded = false;
|
_allLoaded = false;
|
||||||
if (!list.empty()) {
|
if (!list.empty()) {
|
||||||
@ -374,8 +374,8 @@ void Widget::doSetInnerFocus() {
|
|||||||
_inner->setFocus();
|
_inner->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::showInternal(const Window::SectionMemento *memento) {
|
bool Widget::showInternal(gsl::not_null<Window::SectionMemento*> memento) {
|
||||||
if (auto profileMemento = dynamic_cast<const SectionMemento*>(memento)) {
|
if (auto profileMemento = dynamic_cast<SectionMemento*>(memento.get())) {
|
||||||
if (profileMemento->getUser() == user()) {
|
if (profileMemento->getUser() == user()) {
|
||||||
restoreState(profileMemento);
|
restoreState(profileMemento);
|
||||||
return true;
|
return true;
|
||||||
@ -384,24 +384,24 @@ bool Widget::showInternal(const Window::SectionMemento *memento) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::setInternalState(const QRect &geometry, const SectionMemento *memento) {
|
void Widget::setInternalState(const QRect &geometry, gsl::not_null<SectionMemento*> memento) {
|
||||||
setGeometry(geometry);
|
setGeometry(geometry);
|
||||||
myEnsureResized(this);
|
myEnsureResized(this);
|
||||||
restoreState(memento);
|
restoreState(memento);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Window::SectionMemento> Widget::createMemento() const {
|
std::unique_ptr<Window::SectionMemento> Widget::createMemento() {
|
||||||
auto result = std::make_unique<SectionMemento>(user());
|
auto result = std::make_unique<SectionMemento>(user());
|
||||||
saveState(result.get());
|
saveState(result.get());
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::saveState(SectionMemento *memento) const {
|
void Widget::saveState(gsl::not_null<SectionMemento*> memento) {
|
||||||
memento->setScrollTop(_scroll->scrollTop());
|
memento->setScrollTop(_scroll->scrollTop());
|
||||||
_inner->saveState(memento);
|
_inner->saveState(memento);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::restoreState(const SectionMemento *memento) {
|
void Widget::restoreState(gsl::not_null<SectionMemento*> memento) {
|
||||||
_inner->restoreState(memento);
|
_inner->restoreState(memento);
|
||||||
auto scrollTop = memento->getScrollTop();
|
auto scrollTop = memento->getScrollTop();
|
||||||
_scroll->scrollToY(scrollTop);
|
_scroll->scrollToY(scrollTop);
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
SectionMemento(gsl::not_null<UserData*> user) : _user(user) {
|
SectionMemento(gsl::not_null<UserData*> user) : _user(user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
object_ptr<Window::SectionWidget> createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) const override;
|
object_ptr<Window::SectionWidget> createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) override;
|
||||||
|
|
||||||
gsl::not_null<UserData*> getUser() const {
|
gsl::not_null<UserData*> getUser() const {
|
||||||
return _user;
|
return _user;
|
||||||
@ -110,8 +110,8 @@ public:
|
|||||||
return TWidget::resizeToWidth(newWidth);
|
return TWidget::resizeToWidth(newWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveState(SectionMemento *memento) const;
|
void saveState(gsl::not_null<SectionMemento*> memento);
|
||||||
void restoreState(const SectionMemento *memento);
|
void restoreState(gsl::not_null<SectionMemento*> memento);
|
||||||
|
|
||||||
~InnerWidget();
|
~InnerWidget();
|
||||||
|
|
||||||
@ -184,10 +184,10 @@ public:
|
|||||||
|
|
||||||
QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms) override;
|
QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms) override;
|
||||||
|
|
||||||
bool showInternal(const Window::SectionMemento *memento) override;
|
bool showInternal(gsl::not_null<Window::SectionMemento*> memento) override;
|
||||||
std::unique_ptr<Window::SectionMemento> createMemento() const override;
|
std::unique_ptr<Window::SectionMemento> createMemento() override;
|
||||||
|
|
||||||
void setInternalState(const QRect &geometry, const SectionMemento *memento);
|
void setInternalState(const QRect &geometry, gsl::not_null<SectionMemento*> memento);
|
||||||
|
|
||||||
// Float player interface.
|
// Float player interface.
|
||||||
bool wheelEventFromFloatPlayer(QEvent *e, Window::Column myColumn, Window::Column playerColumn) override;
|
bool wheelEventFromFloatPlayer(QEvent *e, Window::Column myColumn, Window::Column playerColumn) override;
|
||||||
@ -205,8 +205,8 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateAdaptiveLayout();
|
void updateAdaptiveLayout();
|
||||||
void saveState(SectionMemento *memento) const;
|
void saveState(gsl::not_null<SectionMemento*> memento);
|
||||||
void restoreState(const SectionMemento *memento);
|
void restoreState(gsl::not_null<SectionMemento*> memento);
|
||||||
|
|
||||||
object_ptr<Ui::ScrollArea> _scroll;
|
object_ptr<Ui::ScrollArea> _scroll;
|
||||||
QPointer<InnerWidget> _inner;
|
QPointer<InnerWidget> _inner;
|
||||||
|
@ -89,13 +89,13 @@ bool InnerWidget::shareContactButtonShown() const {
|
|||||||
return _cover->shareContactButtonShown();
|
return _cover->shareContactButtonShown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::saveState(SectionMemento *memento) const {
|
void InnerWidget::saveState(gsl::not_null<SectionMemento*> memento) {
|
||||||
for_const (auto &blockData, _blocks) {
|
for_const (auto &blockData, _blocks) {
|
||||||
blockData.block->saveState(memento);
|
blockData.block->saveState(memento);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::restoreState(const SectionMemento *memento) {
|
void InnerWidget::restoreState(gsl::not_null<SectionMemento*> memento) {
|
||||||
for_const (auto &blockData, _blocks) {
|
for_const (auto &blockData, _blocks) {
|
||||||
blockData.block->restoreState(memento);
|
blockData.block->restoreState(memento);
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ public:
|
|||||||
// It should show it only if it is hidden in the cover.
|
// It should show it only if it is hidden in the cover.
|
||||||
bool shareContactButtonShown() const;
|
bool shareContactButtonShown() const;
|
||||||
|
|
||||||
void saveState(SectionMemento *memento) const;
|
void saveState(gsl::not_null<SectionMemento*> memento);
|
||||||
void restoreState(const SectionMemento *memento);
|
void restoreState(gsl::not_null<SectionMemento*> memento);
|
||||||
|
|
||||||
void showFinished();
|
void showFinished();
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||||||
|
|
||||||
namespace Profile {
|
namespace Profile {
|
||||||
|
|
||||||
object_ptr<Window::SectionWidget> SectionMemento::createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) const {
|
object_ptr<Window::SectionWidget> SectionMemento::createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) {
|
||||||
auto result = object_ptr<Widget>(parent, controller, _peer);
|
auto result = object_ptr<Widget>(parent, controller, _peer);
|
||||||
result->setInternalState(geometry, this);
|
result->setInternalState(geometry, this);
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
SectionMemento(PeerData *peer) : _peer(peer) {
|
SectionMemento(PeerData *peer) : _peer(peer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
object_ptr<Window::SectionWidget> createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) const override;
|
object_ptr<Window::SectionWidget> createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) override;
|
||||||
|
|
||||||
PeerData *getPeer() const {
|
PeerData *getPeer() const {
|
||||||
return _peer;
|
return _peer;
|
||||||
|
@ -76,8 +76,8 @@ void Widget::doSetInnerFocus() {
|
|||||||
_inner->setFocus();
|
_inner->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::showInternal(const Window::SectionMemento *memento) {
|
bool Widget::showInternal(gsl::not_null<Window::SectionMemento*> memento) {
|
||||||
if (auto profileMemento = dynamic_cast<const SectionMemento*>(memento)) {
|
if (auto profileMemento = dynamic_cast<SectionMemento*>(memento.get())) {
|
||||||
if (profileMemento->getPeer() == peer()) {
|
if (profileMemento->getPeer() == peer()) {
|
||||||
restoreState(profileMemento);
|
restoreState(profileMemento);
|
||||||
return true;
|
return true;
|
||||||
@ -86,24 +86,24 @@ bool Widget::showInternal(const Window::SectionMemento *memento) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::setInternalState(const QRect &geometry, const SectionMemento *memento) {
|
void Widget::setInternalState(const QRect &geometry, gsl::not_null<SectionMemento*> memento) {
|
||||||
setGeometry(geometry);
|
setGeometry(geometry);
|
||||||
myEnsureResized(this);
|
myEnsureResized(this);
|
||||||
restoreState(memento);
|
restoreState(memento);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Window::SectionMemento> Widget::createMemento() const {
|
std::unique_ptr<Window::SectionMemento> Widget::createMemento() {
|
||||||
auto result = std::make_unique<SectionMemento>(peer());
|
auto result = std::make_unique<SectionMemento>(peer());
|
||||||
saveState(result.get());
|
saveState(result.get());
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::saveState(SectionMemento *memento) const {
|
void Widget::saveState(gsl::not_null<SectionMemento*> memento) {
|
||||||
memento->setScrollTop(_scroll->scrollTop());
|
memento->setScrollTop(_scroll->scrollTop());
|
||||||
_inner->saveState(memento);
|
_inner->saveState(memento);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::restoreState(const SectionMemento *memento) {
|
void Widget::restoreState(gsl::not_null<SectionMemento*> memento) {
|
||||||
_inner->restoreState(memento);
|
_inner->restoreState(memento);
|
||||||
auto scrollTop = memento->getScrollTop();
|
auto scrollTop = memento->getScrollTop();
|
||||||
_scroll->scrollToY(scrollTop);
|
_scroll->scrollToY(scrollTop);
|
||||||
|
@ -49,10 +49,10 @@ public:
|
|||||||
|
|
||||||
QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms) override;
|
QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms) override;
|
||||||
|
|
||||||
bool showInternal(const Window::SectionMemento *memento) override;
|
bool showInternal(gsl::not_null<Window::SectionMemento*> memento) override;
|
||||||
std::unique_ptr<Window::SectionMemento> createMemento() const override;
|
std::unique_ptr<Window::SectionMemento> createMemento() override;
|
||||||
|
|
||||||
void setInternalState(const QRect &geometry, const SectionMemento *memento);
|
void setInternalState(const QRect &geometry, gsl::not_null<SectionMemento*> memento);
|
||||||
|
|
||||||
// Float player interface.
|
// Float player interface.
|
||||||
bool wheelEventFromFloatPlayer(QEvent *e, Window::Column myColumn, Window::Column playerColumn) override;
|
bool wheelEventFromFloatPlayer(QEvent *e, Window::Column myColumn, Window::Column playerColumn) override;
|
||||||
@ -71,8 +71,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void updateScrollState();
|
void updateScrollState();
|
||||||
void updateAdaptiveLayout();
|
void updateAdaptiveLayout();
|
||||||
void saveState(SectionMemento *memento) const;
|
void saveState(gsl::not_null<SectionMemento*> memento);
|
||||||
void restoreState(const SectionMemento *memento);
|
void restoreState(gsl::not_null<SectionMemento*> memento);
|
||||||
|
|
||||||
object_ptr<Ui::ScrollArea> _scroll;
|
object_ptr<Ui::ScrollArea> _scroll;
|
||||||
QPointer<InnerWidget> _inner;
|
QPointer<InnerWidget> _inner;
|
||||||
|
@ -27,7 +27,7 @@ class SectionWidget;
|
|||||||
|
|
||||||
class SectionMemento {
|
class SectionMemento {
|
||||||
public:
|
public:
|
||||||
virtual object_ptr<Window::SectionWidget> createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) const = 0;
|
virtual object_ptr<Window::SectionWidget> createWidget(QWidget *parent, gsl::not_null<Window::Controller*> controller, const QRect &geometry) = 0;
|
||||||
virtual ~SectionMemento() {
|
virtual ~SectionMemento() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,10 +96,14 @@ public:
|
|||||||
// Attempt to show the required section inside the existing one.
|
// Attempt to show the required section inside the existing one.
|
||||||
// For example if this section already shows exactly the required
|
// For example if this section already shows exactly the required
|
||||||
// memento it can simply return true - it is shown already.
|
// memento it can simply return true - it is shown already.
|
||||||
virtual bool showInternal(const SectionMemento *memento) = 0;
|
//
|
||||||
|
// If this method returns false it is not supposed to modify the memento.
|
||||||
|
// If this method returns true it may modify the memento ("take" heavy items).
|
||||||
|
virtual bool showInternal(gsl::not_null<SectionMemento*> memento) = 0;
|
||||||
|
|
||||||
// Create a memento of that section to store it in the history stack.
|
// Create a memento of that section to store it in the history stack.
|
||||||
virtual std::unique_ptr<SectionMemento> createMemento() const = 0;
|
// This method may modify the section ("take" heavy items).
|
||||||
|
virtual std::unique_ptr<SectionMemento> createMemento() = 0;
|
||||||
|
|
||||||
void setInnerFocus() {
|
void setInnerFocus() {
|
||||||
doSetInnerFocus();
|
doSetInnerFocus();
|
||||||
|
Loading…
Reference in New Issue
Block a user