2018-01-09 20:08:31 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "history/feed/history_feed_section.h"
|
|
|
|
|
|
|
|
#include "history/view/history_view_top_bar_widget.h"
|
|
|
|
#include "history/view/history_view_list_widget.h"
|
2018-01-11 22:33:26 +03:00
|
|
|
#include "history/view/history_view_element.h"
|
2018-01-17 19:21:01 +03:00
|
|
|
#include "history/view/history_view_message.h"
|
|
|
|
#include "history/view/history_view_service_message.h"
|
2018-01-26 18:40:11 +03:00
|
|
|
#include "history/history_item.h"
|
2018-02-05 23:19:51 +03:00
|
|
|
#include "history/history_service.h"
|
|
|
|
#include "history/history_inner_widget.h"
|
2018-02-04 22:57:03 +03:00
|
|
|
#include "core/event_filter.h"
|
2018-11-16 16:15:14 +04:00
|
|
|
#include "core/shortcuts.h"
|
2018-01-09 20:08:31 +03:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/shadow.h"
|
|
|
|
#include "ui/widgets/scroll_area.h"
|
2018-01-25 13:10:52 +03:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2018-02-04 22:57:03 +03:00
|
|
|
#include "ui/special_buttons.h"
|
2018-01-09 20:08:31 +03:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "window/window_controller.h"
|
2018-01-26 18:40:11 +03:00
|
|
|
#include "window/window_peer_menu.h"
|
2018-01-09 20:08:31 +03:00
|
|
|
#include "data/data_feed_messages.h"
|
2018-01-25 13:10:52 +03:00
|
|
|
#include "data/data_photo.h"
|
|
|
|
#include "data/data_document.h"
|
2018-01-29 16:52:09 +03:00
|
|
|
#include "data/data_session.h"
|
2018-01-09 20:08:31 +03:00
|
|
|
#include "storage/storage_feed_messages.h"
|
2018-01-29 16:52:09 +03:00
|
|
|
#include "mainwidget.h"
|
2018-02-02 15:51:18 +03:00
|
|
|
#include "apiwrap.h"
|
2018-01-29 16:52:09 +03:00
|
|
|
#include "auth_session.h"
|
2018-01-09 20:08:31 +03:00
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
#include "styles/style_history.h"
|
|
|
|
|
|
|
|
namespace HistoryFeed {
|
|
|
|
|
|
|
|
Memento::Memento(
|
|
|
|
not_null<Data::Feed*> feed,
|
2018-02-16 18:46:24 +03:00
|
|
|
Data::MessagePosition position)
|
2018-01-09 20:08:31 +03:00
|
|
|
: _feed(feed)
|
2018-02-16 18:46:24 +03:00
|
|
|
, _position(position)
|
|
|
|
, _list(std::make_unique<HistoryView::ListMemento>(position)) {
|
2018-01-09 20:08:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Memento::~Memento() = default;
|
|
|
|
|
|
|
|
object_ptr<Window::SectionWidget> Memento::createWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
Window::Column column,
|
|
|
|
const QRect &geometry) {
|
|
|
|
if (column == Window::Column::Third) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto result = object_ptr<Widget>(parent, controller, _feed);
|
|
|
|
result->setInternalState(geometry, this);
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
not_null<Data::Feed*> feed)
|
|
|
|
: Window::SectionWidget(parent, controller)
|
|
|
|
, _feed(feed)
|
|
|
|
, _scroll(this, st::historyScroll, false)
|
|
|
|
, _topBar(this, controller)
|
|
|
|
, _topBarShadow(this)
|
2018-02-12 14:10:40 +03:00
|
|
|
, _showNext(nullptr)
|
|
|
|
//, _showNext(
|
|
|
|
// this,
|
|
|
|
// lang(lng_feed_show_next).toUpper(),
|
|
|
|
// st::historyComposeButton)
|
2018-02-04 22:57:03 +03:00
|
|
|
, _scrollDown(_scroll, st::historyToDown) {
|
2018-01-22 20:39:20 +03:00
|
|
|
_topBar->setActiveChat(_feed);
|
|
|
|
|
2018-01-09 20:08:31 +03:00
|
|
|
_topBar->move(0, 0);
|
|
|
|
_topBar->resizeToWidth(width());
|
|
|
|
_topBar->show();
|
2019-08-08 18:07:55 +01:00
|
|
|
|
2018-01-26 18:40:11 +03:00
|
|
|
_topBar->forwardSelectionRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
forwardSelected();
|
|
|
|
}, _topBar->lifetime());
|
|
|
|
_topBar->deleteSelectionRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
confirmDeleteSelected();
|
|
|
|
}, _topBar->lifetime());
|
|
|
|
_topBar->clearSelectionRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
clearSelected();
|
|
|
|
}, _topBar->lifetime());
|
2018-01-09 20:08:31 +03:00
|
|
|
|
|
|
|
_topBarShadow->raise();
|
|
|
|
updateAdaptiveLayout();
|
|
|
|
subscribe(Adaptive::Changed(), [this] { updateAdaptiveLayout(); });
|
|
|
|
|
|
|
|
_inner = _scroll->setOwnedWidget(
|
|
|
|
object_ptr<HistoryView::ListWidget>(this, controller, this));
|
|
|
|
_scroll->move(0, _topBar->height());
|
|
|
|
_scroll->show();
|
|
|
|
|
|
|
|
connect(
|
|
|
|
_scroll,
|
|
|
|
&Ui::ScrollArea::scrolled,
|
|
|
|
this,
|
|
|
|
[this] { onScroll(); });
|
|
|
|
|
2018-02-12 14:10:40 +03:00
|
|
|
//_showNext->setClickedCallback([this] {
|
|
|
|
// // TODO feeds show next
|
|
|
|
//});
|
2018-01-09 20:08:31 +03:00
|
|
|
|
|
|
|
_feed->unreadPositionChanges(
|
|
|
|
) | rpl::filter([=](const Data::MessagePosition &position) {
|
|
|
|
return _undefinedAroundPosition && position;
|
|
|
|
}) | rpl::start_with_next([=](const Data::MessagePosition &position) {
|
|
|
|
auto memento = HistoryView::ListMemento(position);
|
|
|
|
_inner->restoreState(&memento);
|
|
|
|
}, lifetime());
|
2018-01-29 16:52:09 +03:00
|
|
|
|
|
|
|
rpl::single(
|
|
|
|
Data::FeedUpdate{ _feed, Data::FeedUpdateFlag::Channels }
|
|
|
|
) | rpl::then(
|
2018-01-30 17:31:25 +03:00
|
|
|
Auth().data().feedUpdated(
|
|
|
|
) | rpl::filter([=](const Data::FeedUpdate &update) {
|
|
|
|
return (update.feed == _feed)
|
|
|
|
&& (update.flag == Data::FeedUpdateFlag::Channels);
|
|
|
|
})
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
crl::on_main(this, [=] { checkForSingleChannelFeed(); });
|
2018-01-29 16:52:09 +03:00
|
|
|
}, lifetime());
|
2018-02-04 22:57:03 +03:00
|
|
|
|
|
|
|
setupScrollDownButton();
|
2018-11-16 16:15:14 +04:00
|
|
|
setupShortcuts();
|
2018-02-04 22:57:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setupScrollDownButton() {
|
|
|
|
_scrollDown->setClickedCallback([=] {
|
|
|
|
scrollDownClicked();
|
|
|
|
});
|
|
|
|
Core::InstallEventFilter(_scrollDown, [=](not_null<QEvent*> event) {
|
|
|
|
if (event->type() == QEvent::Wheel) {
|
|
|
|
return _scroll->viewportEvent(event);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
updateScrollDownVisibility();
|
|
|
|
_feed->unreadCountValue(
|
|
|
|
) | rpl::start_with_next([=](int count) {
|
|
|
|
_scrollDown->setUnreadCount(count);
|
|
|
|
}, _scrollDown->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::scrollDownClicked() {
|
2018-02-16 18:46:24 +03:00
|
|
|
_currentMessageId = Data::MaxMessagePosition.fullId;
|
2018-02-04 22:57:03 +03:00
|
|
|
showAtPosition(Data::MaxMessagePosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::showAtPosition(Data::MessagePosition position) {
|
2018-02-16 20:59:35 +03:00
|
|
|
if (showAtPositionNow(position)) {
|
|
|
|
if (const auto highlight = base::take(_highlightMessageId)) {
|
|
|
|
_inner->highlightMessage(highlight);
|
|
|
|
}
|
|
|
|
} else {
|
2018-02-04 22:57:03 +03:00
|
|
|
_nextAnimatedScrollPosition = position;
|
|
|
|
_nextAnimatedScrollDelta = _inner->isBelowPosition(position)
|
|
|
|
? -_scroll->height()
|
|
|
|
: _inner->isAbovePosition(position)
|
|
|
|
? _scroll->height()
|
|
|
|
: 0;
|
|
|
|
auto memento = HistoryView::ListMemento(position);
|
|
|
|
_inner->restoreState(&memento);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::showAtPositionNow(Data::MessagePosition position) {
|
|
|
|
if (const auto scrollTop = _inner->scrollTopForPosition(position)) {
|
|
|
|
const auto currentScrollTop = _scroll->scrollTop();
|
|
|
|
const auto wanted = snap(*scrollTop, 0, _scroll->scrollTopMax());
|
|
|
|
const auto fullDelta = (wanted - currentScrollTop);
|
|
|
|
const auto limit = _scroll->height();
|
|
|
|
const auto scrollDelta = snap(fullDelta, -limit, limit);
|
|
|
|
_inner->animatedScrollTo(
|
|
|
|
wanted,
|
|
|
|
position,
|
|
|
|
scrollDelta,
|
|
|
|
(std::abs(fullDelta) > limit
|
|
|
|
? HistoryView::ListWidget::AnimatedScroll::Part
|
|
|
|
: HistoryView::ListWidget::AnimatedScroll::Full));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateScrollDownVisibility() {
|
2018-02-20 19:56:41 +03:00
|
|
|
if (animating()) {
|
2018-02-04 22:57:03 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-21 19:28:46 +03:00
|
|
|
const auto scrollDownIsVisible = [&]() -> std::optional<bool> {
|
2018-02-04 22:57:03 +03:00
|
|
|
const auto top = _scroll->scrollTop() + st::historyToDownShownAfter;
|
|
|
|
if (top < _scroll->scrollTopMax()) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-20 19:56:41 +03:00
|
|
|
if (_inner->loadedAtBottomKnown()) {
|
|
|
|
return !_inner->loadedAtBottom();
|
|
|
|
}
|
2018-09-21 19:28:46 +03:00
|
|
|
return std::nullopt;
|
2018-02-04 22:57:03 +03:00
|
|
|
};
|
2018-02-20 19:56:41 +03:00
|
|
|
const auto scrollDownIsShown = scrollDownIsVisible();
|
|
|
|
if (!scrollDownIsShown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_scrollDownIsShown != *scrollDownIsShown) {
|
|
|
|
_scrollDownIsShown = *scrollDownIsShown;
|
2018-02-04 22:57:03 +03:00
|
|
|
_scrollDownShown.start(
|
|
|
|
[=] { updateScrollDownPosition(); },
|
|
|
|
_scrollDownIsShown ? 0. : 1.,
|
|
|
|
_scrollDownIsShown ? 1. : 0.,
|
|
|
|
st::historyToDownDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateScrollDownPosition() {
|
|
|
|
// _scrollDown is a child widget of _scroll, not me.
|
|
|
|
auto top = anim::interpolate(
|
|
|
|
0,
|
|
|
|
_scrollDown->height() + st::historyToDownPosition.y(),
|
2019-04-02 13:13:30 +04:00
|
|
|
_scrollDownShown.value(_scrollDownIsShown ? 1. : 0.));
|
2018-02-04 22:57:03 +03:00
|
|
|
_scrollDown->moveToRight(
|
|
|
|
st::historyToDownPosition.x(),
|
|
|
|
_scroll->height() - top);
|
|
|
|
auto shouldBeHidden = !_scrollDownIsShown && !_scrollDownShown.animating();
|
|
|
|
if (shouldBeHidden != _scrollDown->isHidden()) {
|
|
|
|
_scrollDown->setVisible(!shouldBeHidden);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::scrollDownAnimationFinish() {
|
2019-04-02 13:13:30 +04:00
|
|
|
_scrollDownShown.stop();
|
2018-02-04 22:57:03 +03:00
|
|
|
updateScrollDownPosition();
|
2018-01-29 16:52:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::checkForSingleChannelFeed() {
|
|
|
|
const auto &channels = _feed->channels();
|
|
|
|
if (channels.size() > 1) {
|
|
|
|
return;
|
|
|
|
} else if (!channels.empty()) {
|
|
|
|
controller()->showPeerHistory(channels[0]);
|
|
|
|
} else {
|
|
|
|
controller()->clearSectionStack();
|
|
|
|
}
|
2018-01-09 20:08:31 +03:00
|
|
|
}
|
|
|
|
|
2018-01-22 19:42:25 +03:00
|
|
|
Dialogs::RowDescriptor Widget::activeChat() const {
|
2018-02-16 18:46:24 +03:00
|
|
|
return Dialogs::RowDescriptor(_feed, _currentMessageId);
|
2018-01-22 19:42:25 +03:00
|
|
|
}
|
|
|
|
|
2018-01-09 20:08:31 +03:00
|
|
|
void Widget::updateAdaptiveLayout() {
|
|
|
|
_topBarShadow->moveToLeft(
|
|
|
|
Adaptive::OneColumn() ? 0 : st::lineWidth,
|
|
|
|
_topBar->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap Widget::grabForShowAnimation(const Window::SectionSlideParams ¶ms) {
|
|
|
|
if (params.withTopBarShadow) _topBarShadow->hide();
|
|
|
|
auto result = Ui::GrabWidget(this);
|
|
|
|
if (params.withTopBarShadow) _topBarShadow->show();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::doSetInnerFocus() {
|
|
|
|
_inner->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::showInternal(
|
|
|
|
not_null<Window::SectionMemento*> memento,
|
|
|
|
const Window::SectionShow ¶ms) {
|
|
|
|
if (const auto feedMemento = dynamic_cast<Memento*>(memento.get())) {
|
|
|
|
if (feedMemento->feed() == _feed) {
|
|
|
|
restoreState(feedMemento);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<Memento*> memento) {
|
|
|
|
setGeometry(geometry);
|
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
2018-11-16 16:15:14 +04:00
|
|
|
void Widget::setupShortcuts() {
|
|
|
|
Shortcuts::Requests(
|
2018-11-16 17:36:42 +04:00
|
|
|
) | rpl::filter([=] {
|
|
|
|
return isActiveWindow() && !Ui::isLayerShown() && inFocusChain();
|
|
|
|
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
|
2018-11-16 16:15:14 +04:00
|
|
|
using Command = Shortcuts::Command;
|
2019-03-09 21:44:46 +03:00
|
|
|
request->check(Command::Search, 2) && request->handle([=] {
|
2018-11-16 17:36:42 +04:00
|
|
|
App::main()->searchInChat(_feed);
|
|
|
|
return true;
|
|
|
|
});
|
2018-11-16 16:15:14 +04:00
|
|
|
}, lifetime());
|
2018-01-09 20:08:31 +03:00
|
|
|
}
|
|
|
|
|
2018-01-10 16:13:33 +03:00
|
|
|
HistoryView::Context Widget::listContext() {
|
|
|
|
return HistoryView::Context::Feed;
|
|
|
|
}
|
|
|
|
|
2018-01-09 20:08:31 +03:00
|
|
|
void Widget::listScrollTo(int top) {
|
|
|
|
if (_scroll->scrollTop() != top) {
|
|
|
|
_scroll->scrollToY(top);
|
|
|
|
} else {
|
|
|
|
updateInnerVisibleArea();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 19:41:06 +03:00
|
|
|
void Widget::listCancelRequest() {
|
2018-01-09 20:08:31 +03:00
|
|
|
controller()->showBackFromStack();
|
|
|
|
}
|
|
|
|
|
2018-01-27 19:41:06 +03:00
|
|
|
void Widget::listDeleteRequest() {
|
|
|
|
confirmDeleteSelected();
|
|
|
|
}
|
|
|
|
|
2018-01-09 20:08:31 +03:00
|
|
|
rpl::producer<Data::MessagesSlice> Widget::listSource(
|
|
|
|
Data::MessagePosition aroundId,
|
|
|
|
int limitBefore,
|
|
|
|
int limitAfter) {
|
|
|
|
return Data::FeedMessagesViewer(
|
|
|
|
Storage::FeedMessagesKey(_feed->id(), aroundId),
|
|
|
|
limitBefore,
|
|
|
|
limitAfter);
|
|
|
|
}
|
|
|
|
|
2018-01-26 18:40:11 +03:00
|
|
|
bool Widget::listAllowsMultiSelect() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::listIsLessInOrder(
|
|
|
|
not_null<HistoryItem*> first,
|
|
|
|
not_null<HistoryItem*> second) {
|
|
|
|
return first->position() < second->position();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::listSelectionChanged(HistoryView::SelectedItems &&items) {
|
|
|
|
HistoryView::TopBarWidget::SelectedState state;
|
|
|
|
state.count = items.size();
|
|
|
|
for (const auto item : items) {
|
|
|
|
if (item.canForward) {
|
|
|
|
++state.canForwardCount;
|
|
|
|
}
|
|
|
|
if (item.canDelete) {
|
|
|
|
++state.canDeleteCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_topBar->showSelected(state);
|
|
|
|
}
|
|
|
|
|
2018-02-02 15:51:18 +03:00
|
|
|
void Widget::listVisibleItemsChanged(HistoryItemsList &&items) {
|
|
|
|
const auto reversed = ranges::view::reverse(items);
|
|
|
|
const auto good = ranges::find_if(reversed, [](auto item) {
|
|
|
|
return IsServerMsgId(item->id);
|
|
|
|
});
|
|
|
|
if (good != end(reversed)) {
|
|
|
|
Auth().api().readFeed(_feed, (*good)->position());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 19:28:46 +03:00
|
|
|
std::optional<int> Widget::listUnreadBarView(
|
2018-02-02 15:51:18 +03:00
|
|
|
const std::vector<not_null<Element*>> &elements) {
|
|
|
|
const auto position = _feed->unreadPosition();
|
2018-02-04 22:57:03 +03:00
|
|
|
if (!position || elements.empty() || !_feed->unreadCount()) {
|
2018-09-21 19:28:46 +03:00
|
|
|
return std::nullopt;
|
2018-02-02 15:51:18 +03:00
|
|
|
}
|
|
|
|
const auto minimal = ranges::upper_bound(
|
|
|
|
elements,
|
|
|
|
position,
|
|
|
|
std::less<>(),
|
|
|
|
[](auto view) { return view->data()->position(); });
|
|
|
|
if (minimal == end(elements)) {
|
2018-09-21 19:28:46 +03:00
|
|
|
return std::nullopt;
|
2018-02-02 15:51:18 +03:00
|
|
|
}
|
|
|
|
const auto view = *minimal;
|
|
|
|
const auto unreadMessagesHeight = elements.back()->y()
|
|
|
|
+ elements.back()->height()
|
|
|
|
- view->y();
|
|
|
|
if (unreadMessagesHeight < _scroll->height()) {
|
2018-09-21 19:28:46 +03:00
|
|
|
return std::nullopt;
|
2018-02-02 15:51:18 +03:00
|
|
|
}
|
|
|
|
return base::make_optional(int(minimal - begin(elements)));
|
|
|
|
}
|
|
|
|
|
2018-02-05 23:19:51 +03:00
|
|
|
void Widget::validateEmptyTextItem() {
|
|
|
|
if (!_inner->isEmpty()) {
|
|
|
|
_emptyTextView = nullptr;
|
|
|
|
_emptyTextItem = nullptr;
|
|
|
|
update();
|
|
|
|
return;
|
|
|
|
} else if (_emptyTextItem) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto channels = _feed->channels();
|
|
|
|
if (channels.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto history = channels[0];
|
|
|
|
_emptyTextItem.reset(new HistoryService(
|
|
|
|
history,
|
|
|
|
clientMsgId(),
|
|
|
|
unixtime(),
|
|
|
|
{ lang(lng_feed_no_messages) }));
|
|
|
|
_emptyTextView = _emptyTextItem->createView(
|
|
|
|
HistoryInner::ElementDelegate());
|
|
|
|
updateControlsGeometry();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-02-04 22:57:03 +03:00
|
|
|
void Widget::listContentRefreshed() {
|
2018-02-05 23:19:51 +03:00
|
|
|
validateEmptyTextItem();
|
|
|
|
|
2018-02-04 22:57:03 +03:00
|
|
|
if (!_nextAnimatedScrollPosition) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto position = *base::take(_nextAnimatedScrollPosition);
|
|
|
|
if (const auto scrollTop = _inner->scrollTopForPosition(position)) {
|
|
|
|
const auto wanted = snap(*scrollTop, 0, _scroll->scrollTopMax());
|
|
|
|
_inner->animatedScrollTo(
|
|
|
|
wanted,
|
|
|
|
position,
|
|
|
|
_nextAnimatedScrollDelta,
|
|
|
|
HistoryView::ListWidget::AnimatedScroll::Part);
|
2018-02-16 20:59:35 +03:00
|
|
|
if (const auto highlight = base::take(_highlightMessageId)) {
|
|
|
|
_inner->highlightMessage(highlight);
|
|
|
|
}
|
2018-02-04 22:57:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 02:59:56 +03:00
|
|
|
ClickHandlerPtr Widget::listDateLink(not_null<Element*> view) {
|
|
|
|
if (!_dateLink) {
|
|
|
|
_dateLink = std::make_shared<Window::DateClickHandler>(_feed, view->dateTime().date());
|
|
|
|
} else {
|
|
|
|
_dateLink->setDate(view->dateTime().date());
|
|
|
|
}
|
|
|
|
return _dateLink;
|
|
|
|
}
|
|
|
|
|
2018-01-09 20:08:31 +03:00
|
|
|
std::unique_ptr<Window::SectionMemento> Widget::createMemento() {
|
|
|
|
auto result = std::make_unique<Memento>(_feed);
|
|
|
|
saveState(result.get());
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::saveState(not_null<Memento*> memento) {
|
|
|
|
_inner->saveState(memento->list());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::restoreState(not_null<Memento*> memento) {
|
|
|
|
const auto list = memento->list();
|
|
|
|
if (!list->aroundPosition()) {
|
|
|
|
if (const auto position = _feed->unreadPosition()) {
|
|
|
|
list->setAroundPosition(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_undefinedAroundPosition = !list->aroundPosition();
|
|
|
|
_inner->restoreState(memento->list());
|
2018-02-16 18:46:24 +03:00
|
|
|
if (const auto position = memento->position()) {
|
2018-02-16 20:59:35 +03:00
|
|
|
_currentMessageId = _highlightMessageId = position.fullId;
|
2018-02-16 18:46:24 +03:00
|
|
|
showAtPosition(position);
|
|
|
|
}
|
2018-01-09 20:08:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::resizeEvent(QResizeEvent *e) {
|
|
|
|
if (!width() || !height()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateControlsGeometry() {
|
|
|
|
const auto contentWidth = width();
|
|
|
|
|
2018-02-02 15:51:18 +03:00
|
|
|
const auto newScrollTop = _scroll->isHidden()
|
2018-09-21 19:28:46 +03:00
|
|
|
? std::nullopt
|
2018-02-02 15:51:18 +03:00
|
|
|
: base::make_optional(_scroll->scrollTop() + topDelta());
|
2018-01-09 20:08:31 +03:00
|
|
|
_topBar->resizeToWidth(contentWidth);
|
|
|
|
_topBarShadow->resize(contentWidth, st::lineWidth);
|
|
|
|
|
|
|
|
const auto bottom = height();
|
|
|
|
const auto scrollHeight = bottom
|
2018-02-08 12:20:14 +03:00
|
|
|
- _topBar->height();
|
|
|
|
// - _showNext->height();
|
2018-01-09 20:08:31 +03:00
|
|
|
const auto scrollSize = QSize(contentWidth, scrollHeight);
|
|
|
|
if (_scroll->size() != scrollSize) {
|
2018-02-02 15:51:18 +03:00
|
|
|
_skipScrollEvent = true;
|
2018-01-09 20:08:31 +03:00
|
|
|
_scroll->resize(scrollSize);
|
|
|
|
_inner->resizeToWidth(scrollSize.width(), _scroll->height());
|
2018-02-02 15:51:18 +03:00
|
|
|
_skipScrollEvent = false;
|
2018-01-09 20:08:31 +03:00
|
|
|
}
|
|
|
|
if (!_scroll->isHidden()) {
|
2018-02-02 15:51:18 +03:00
|
|
|
if (newScrollTop) {
|
|
|
|
_scroll->scrollToY(*newScrollTop);
|
2018-01-09 20:08:31 +03:00
|
|
|
}
|
|
|
|
updateInnerVisibleArea();
|
|
|
|
}
|
2018-02-04 22:57:03 +03:00
|
|
|
|
|
|
|
updateScrollDownPosition();
|
2018-02-08 12:20:14 +03:00
|
|
|
//const auto fullWidthButtonRect = myrtlrect(
|
|
|
|
// 0,
|
|
|
|
// bottom - _showNext->height(),
|
|
|
|
// contentWidth,
|
|
|
|
// _showNext->height());
|
|
|
|
//_showNext->setGeometry(fullWidthButtonRect);
|
2018-02-05 23:19:51 +03:00
|
|
|
|
|
|
|
if (_emptyTextView) {
|
|
|
|
_emptyTextView->resizeGetHeight(width());
|
|
|
|
}
|
2018-01-09 20:08:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::paintEvent(QPaintEvent *e) {
|
|
|
|
if (animating()) {
|
|
|
|
SectionWidget::paintEvent(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Ui::skipPaintEvent(this, e)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//if (hasPendingResizedItems()) {
|
|
|
|
// updateListSize();
|
|
|
|
//}
|
|
|
|
|
2019-03-19 17:50:36 +04:00
|
|
|
SectionWidget::PaintBackground(this, e->rect());
|
2018-02-05 23:19:51 +03:00
|
|
|
|
|
|
|
if (_emptyTextView) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
const auto clip = e->rect();
|
|
|
|
const auto left = 0;
|
|
|
|
const auto top = (height()
|
2018-02-08 12:20:14 +03:00
|
|
|
// - _showNext->height()
|
2018-02-05 23:19:51 +03:00
|
|
|
- _emptyTextView->height()) / 2;
|
|
|
|
p.translate(left, top);
|
|
|
|
_emptyTextView->draw(
|
|
|
|
p,
|
|
|
|
clip.translated(-left, -top),
|
|
|
|
TextSelection(),
|
2019-02-19 10:57:53 +04:00
|
|
|
crl::now());
|
2018-02-05 23:19:51 +03:00
|
|
|
}
|
2018-01-09 20:08:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::onScroll() {
|
2018-02-02 15:51:18 +03:00
|
|
|
if (_skipScrollEvent) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-09 20:08:31 +03:00
|
|
|
updateInnerVisibleArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateInnerVisibleArea() {
|
|
|
|
const auto scrollTop = _scroll->scrollTop();
|
|
|
|
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
2018-02-04 22:57:03 +03:00
|
|
|
updateScrollDownVisibility();
|
2018-01-09 20:08:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::showAnimatedHook(
|
|
|
|
const Window::SectionSlideParams ¶ms) {
|
|
|
|
_topBar->setAnimatingMode(true);
|
|
|
|
if (params.withTopBarShadow) _topBarShadow->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::showFinishedHook() {
|
|
|
|
_topBar->setAnimatingMode(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::wheelEventFromFloatPlayer(QEvent *e) {
|
|
|
|
return _scroll->viewportEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect Widget::rectForFloatPlayer() const {
|
|
|
|
return mapToGlobal(_scroll->geometry());
|
|
|
|
}
|
|
|
|
|
2018-01-26 18:40:11 +03:00
|
|
|
void Widget::forwardSelected() {
|
|
|
|
auto items = _inner->getSelectedItems();
|
|
|
|
if (items.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto weak = make_weak(this);
|
|
|
|
Window::ShowForwardMessagesBox(std::move(items), [=] {
|
|
|
|
if (const auto strong = weak.data()) {
|
|
|
|
strong->clearSelected();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::confirmDeleteSelected() {
|
|
|
|
auto items = _inner->getSelectedItems();
|
|
|
|
if (items.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto weak = make_weak(this);
|
|
|
|
const auto box = Ui::show(Box<DeleteMessagesBox>(std::move(items)));
|
|
|
|
box->setDeleteConfirmedCallback([=] {
|
|
|
|
if (const auto strong = weak.data()) {
|
|
|
|
strong->clearSelected();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::clearSelected() {
|
|
|
|
_inner->cancelSelection();
|
|
|
|
}
|
|
|
|
|
2018-01-09 20:08:31 +03:00
|
|
|
} // namespace HistoryFeed
|