2020-10-20 16:29:24 +00: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/view/history_view_pinned_section.h"
|
|
|
|
|
|
|
|
#include "history/view/history_view_top_bar_widget.h"
|
|
|
|
#include "history/view/history_view_list_widget.h"
|
|
|
|
#include "history/history.h"
|
|
|
|
#include "history/history_item_components.h"
|
|
|
|
#include "history/history_item.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
#include "ui/widgets/shadow.h"
|
|
|
|
#include "ui/layers/generic_box.h"
|
|
|
|
#include "ui/item_text_options.h"
|
|
|
|
#include "ui/toast/toast.h"
|
|
|
|
#include "ui/text/format_values.h"
|
|
|
|
#include "ui/text/text_utilities.h"
|
|
|
|
#include "ui/special_buttons.h"
|
|
|
|
#include "ui/ui_utility.h"
|
|
|
|
#include "ui/toasts/common_toasts.h"
|
|
|
|
#include "base/timer_rpl.h"
|
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "window/window_peer_menu.h"
|
|
|
|
#include "base/event_filter.h"
|
|
|
|
#include "base/call_delayed.h"
|
|
|
|
#include "core/file_utilities.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_user.h"
|
2020-10-22 12:40:33 +00:00
|
|
|
#include "data/data_chat.h"
|
2020-10-20 16:29:24 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_changes.h"
|
|
|
|
#include "data/data_sparse_ids.h"
|
|
|
|
#include "data/data_shared_media.h"
|
2020-10-22 12:40:33 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2020-10-20 16:29:24 +00:00
|
|
|
#include "storage/storage_account.h"
|
|
|
|
#include "platform/platform_specific.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
|
|
|
#include "styles/style_chat.h"
|
|
|
|
#include "styles/style_window.h"
|
|
|
|
#include "styles/style_info.h"
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
|
|
|
|
#include <QtCore/QMimeData>
|
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
|
|
|
|
namespace HistoryView {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-10-20 18:31:47 +00:00
|
|
|
PinnedMemento::PinnedMemento(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId highlightId)
|
|
|
|
: _history(history)
|
|
|
|
, _highlightId(highlightId) {
|
|
|
|
_list.setAroundPosition({
|
|
|
|
.fullId = FullMsgId(
|
|
|
|
history->channelId(),
|
|
|
|
highlightId),
|
|
|
|
.date = TimeId(0),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:29:24 +00:00
|
|
|
object_ptr<Window::SectionWidget> PinnedMemento::createWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
Window::Column column,
|
|
|
|
const QRect &geometry) {
|
|
|
|
if (column == Window::Column::Third) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto result = object_ptr<PinnedWidget>(
|
|
|
|
parent,
|
|
|
|
controller,
|
|
|
|
_history);
|
|
|
|
result->setInternalState(geometry, this);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PinnedWidget::PinnedWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<History*> history)
|
|
|
|
: Window::SectionWidget(parent, controller)
|
2020-10-22 12:40:33 +00:00
|
|
|
, _history(history->migrateToOrMe())
|
|
|
|
, _migratedPeer(_history->peer->migrateFrom())
|
2020-10-20 16:29:24 +00:00
|
|
|
, _topBar(this, controller)
|
|
|
|
, _topBarShadow(this)
|
|
|
|
, _scroll(std::make_unique<Ui::ScrollArea>(this, st::historyScroll, false))
|
2020-10-22 07:53:56 +00:00
|
|
|
, _clearButton(std::make_unique<Ui::FlatButton>(
|
|
|
|
this,
|
|
|
|
QString(),
|
|
|
|
st::historyComposeButton))
|
2020-10-20 16:29:24 +00:00
|
|
|
, _scrollDown(_scroll.get(), st::historyToDown) {
|
|
|
|
_topBar->setActiveChat(
|
2020-11-11 20:47:40 +00:00
|
|
|
TopBarWidget::ActiveChat{
|
|
|
|
.key = _history,
|
2020-11-12 15:46:17 +00:00
|
|
|
.section = Dialogs::EntryState::Section::Pinned,
|
2020-11-11 20:47:40 +00:00
|
|
|
},
|
2020-10-20 16:29:24 +00:00
|
|
|
nullptr);
|
|
|
|
|
|
|
|
_topBar->move(0, 0);
|
|
|
|
_topBar->resizeToWidth(width());
|
|
|
|
_topBar->show();
|
2020-10-21 14:41:13 +00:00
|
|
|
_topBar->setCustomTitle(tr::lng_contacts_loading(tr::now));
|
2020-10-20 16:29:24 +00:00
|
|
|
|
|
|
|
_topBar->deleteSelectionRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
confirmDeleteSelected();
|
|
|
|
}, _topBar->lifetime());
|
|
|
|
_topBar->forwardSelectionRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
confirmForwardSelected();
|
|
|
|
}, _topBar->lifetime());
|
|
|
|
_topBar->clearSelectionRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
clearSelected();
|
|
|
|
}, _topBar->lifetime());
|
|
|
|
|
|
|
|
_topBarShadow->raise();
|
|
|
|
updateAdaptiveLayout();
|
|
|
|
subscribe(Adaptive::Changed(), [=] { updateAdaptiveLayout(); });
|
|
|
|
|
|
|
|
_inner = _scroll->setOwnedWidget(object_ptr<ListWidget>(
|
|
|
|
this,
|
|
|
|
controller,
|
|
|
|
static_cast<ListDelegate*>(this)));
|
|
|
|
_scroll->move(0, _topBar->height());
|
|
|
|
_scroll->show();
|
|
|
|
connect(_scroll.get(), &Ui::ScrollArea::scrolled, [=] { onScroll(); });
|
|
|
|
|
2020-10-22 07:53:56 +00:00
|
|
|
setupClearButton();
|
2020-10-20 16:29:24 +00:00
|
|
|
setupScrollDownButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
PinnedWidget::~PinnedWidget() = default;
|
|
|
|
|
|
|
|
void PinnedWidget::setupScrollDownButton() {
|
|
|
|
_scrollDown->setClickedCallback([=] {
|
|
|
|
scrollDownClicked();
|
|
|
|
});
|
|
|
|
base::install_event_filter(_scrollDown, [=](not_null<QEvent*> event) {
|
|
|
|
if (event->type() != QEvent::Wheel) {
|
|
|
|
return base::EventFilterResult::Continue;
|
|
|
|
}
|
|
|
|
return _scroll->viewportEvent(event)
|
|
|
|
? base::EventFilterResult::Cancel
|
|
|
|
: base::EventFilterResult::Continue;
|
|
|
|
});
|
|
|
|
updateScrollDownVisibility();
|
|
|
|
}
|
|
|
|
|
2020-10-22 07:53:56 +00:00
|
|
|
void PinnedWidget::setupClearButton() {
|
|
|
|
Data::CanPinMessagesValue(
|
|
|
|
_history->peer
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
refreshClearButtonText();
|
|
|
|
}, _clearButton->lifetime());
|
|
|
|
|
|
|
|
_clearButton->setClickedCallback([=] {
|
|
|
|
if (!_history->peer->canPinMessages()) {
|
|
|
|
const auto callback = [=] {
|
|
|
|
controller()->showBackFromStack();
|
|
|
|
};
|
|
|
|
Window::HidePinnedBar(
|
|
|
|
controller(),
|
|
|
|
_history->peer,
|
|
|
|
crl::guard(this, callback));
|
|
|
|
} else {
|
|
|
|
Window::UnpinAllMessages(controller(), _history);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:29:24 +00:00
|
|
|
void PinnedWidget::scrollDownClicked() {
|
|
|
|
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) {
|
|
|
|
showAtEnd();
|
|
|
|
//} else if (_replyReturn) {
|
|
|
|
// showAtPosition(_replyReturn->position());
|
|
|
|
} else {
|
|
|
|
showAtEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::showAtStart() {
|
|
|
|
showAtPosition(Data::MinMessagePosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::showAtEnd() {
|
|
|
|
showAtPosition(Data::MaxMessagePosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::showAtPosition(
|
|
|
|
Data::MessagePosition position,
|
|
|
|
HistoryItem *originItem) {
|
|
|
|
if (!showAtPositionNow(position, originItem)) {
|
|
|
|
_inner->showAroundPosition(position, [=] {
|
|
|
|
return showAtPositionNow(position, originItem);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::showAtPositionNow(
|
|
|
|
Data::MessagePosition position,
|
2020-10-21 12:31:15 +00:00
|
|
|
HistoryItem *originItem,
|
|
|
|
anim::type animated) {
|
|
|
|
using AnimatedScroll = HistoryView::ListWidget::AnimatedScroll;
|
|
|
|
|
2020-10-20 16:29:24 +00:00
|
|
|
const auto item = position.fullId
|
|
|
|
? _history->owner().message(position.fullId)
|
|
|
|
: nullptr;
|
|
|
|
const auto use = item ? item->position() : position;
|
|
|
|
if (const auto scrollTop = _inner->scrollTopForPosition(use)) {
|
|
|
|
const auto currentScrollTop = _scroll->scrollTop();
|
2021-01-23 03:29:50 +00:00
|
|
|
const auto wanted = std::clamp(
|
|
|
|
*scrollTop,
|
|
|
|
0,
|
|
|
|
_scroll->scrollTopMax());
|
2020-10-20 16:29:24 +00:00
|
|
|
const auto fullDelta = (wanted - currentScrollTop);
|
|
|
|
const auto limit = _scroll->height();
|
2021-01-23 03:29:50 +00:00
|
|
|
const auto scrollDelta = std::clamp(fullDelta, -limit, limit);
|
2020-10-21 12:31:15 +00:00
|
|
|
const auto type = (animated == anim::type::instant)
|
|
|
|
? AnimatedScroll::None
|
|
|
|
: (std::abs(fullDelta) > limit)
|
|
|
|
? AnimatedScroll::Part
|
|
|
|
: AnimatedScroll::Full;
|
|
|
|
_inner->scrollTo(
|
2020-10-20 16:29:24 +00:00
|
|
|
wanted,
|
|
|
|
use,
|
|
|
|
scrollDelta,
|
2020-10-21 12:31:15 +00:00
|
|
|
type);
|
2020-10-20 16:29:24 +00:00
|
|
|
if (use != Data::MaxMessagePosition
|
|
|
|
&& use != Data::UnreadMessagePosition) {
|
|
|
|
_inner->highlightMessage(use.fullId);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::updateScrollDownVisibility() {
|
|
|
|
if (animating()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto scrollDownIsVisible = [&]() -> std::optional<bool> {
|
|
|
|
const auto top = _scroll->scrollTop() + st::historyToDownShownAfter;
|
|
|
|
if (top < _scroll->scrollTopMax()) {
|
|
|
|
return true;
|
|
|
|
} else if (_inner->loadedAtBottomKnown()) {
|
|
|
|
return !_inner->loadedAtBottom();
|
|
|
|
}
|
|
|
|
return std::nullopt;
|
|
|
|
};
|
|
|
|
const auto scrollDownIsShown = scrollDownIsVisible();
|
|
|
|
if (!scrollDownIsShown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_scrollDownIsShown != *scrollDownIsShown) {
|
|
|
|
_scrollDownIsShown = *scrollDownIsShown;
|
|
|
|
_scrollDownShown.start(
|
|
|
|
[=] { updateScrollDownPosition(); },
|
|
|
|
_scrollDownIsShown ? 0. : 1.,
|
|
|
|
_scrollDownIsShown ? 1. : 0.,
|
|
|
|
st::historyToDownDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::updateScrollDownPosition() {
|
|
|
|
// _scrollDown is a child widget of _scroll, not me.
|
|
|
|
auto top = anim::interpolate(
|
|
|
|
0,
|
|
|
|
_scrollDown->height() + st::historyToDownPosition.y(),
|
|
|
|
_scrollDownShown.value(_scrollDownIsShown ? 1. : 0.));
|
|
|
|
_scrollDown->moveToRight(
|
|
|
|
st::historyToDownPosition.x(),
|
|
|
|
_scroll->height() - top);
|
|
|
|
auto shouldBeHidden = !_scrollDownIsShown && !_scrollDownShown.animating();
|
|
|
|
if (shouldBeHidden != _scrollDown->isHidden()) {
|
|
|
|
_scrollDown->setVisible(!shouldBeHidden);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::scrollDownAnimationFinish() {
|
|
|
|
_scrollDownShown.stop();
|
|
|
|
updateScrollDownPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::updateAdaptiveLayout() {
|
|
|
|
_topBarShadow->moveToLeft(
|
|
|
|
Adaptive::OneColumn() ? 0 : st::lineWidth,
|
|
|
|
_topBar->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<History*> PinnedWidget::history() const {
|
|
|
|
return _history;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dialogs::RowDescriptor PinnedWidget::activeChat() const {
|
|
|
|
return {
|
|
|
|
_history,
|
|
|
|
FullMsgId(_history->channelId(), ShowAtUnreadMsgId)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap PinnedWidget::grabForShowAnimation(const Window::SectionSlideParams ¶ms) {
|
|
|
|
_topBar->updateControlsVisibility();
|
|
|
|
if (params.withTopBarShadow) _topBarShadow->hide();
|
|
|
|
auto result = Ui::GrabWidget(this);
|
|
|
|
if (params.withTopBarShadow) _topBarShadow->show();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::doSetInnerFocus() {
|
2020-10-21 14:41:13 +00:00
|
|
|
_inner->setFocus();
|
2020-10-20 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::showInternal(
|
|
|
|
not_null<Window::SectionMemento*> memento,
|
|
|
|
const Window::SectionShow ¶ms) {
|
|
|
|
if (auto logMemento = dynamic_cast<PinnedMemento*>(memento.get())) {
|
2020-10-22 12:40:33 +00:00
|
|
|
if (logMemento->getHistory() == history()
|
|
|
|
|| logMemento->getHistory()->migrateToOrMe() == history()) {
|
2020-10-20 16:29:24 +00:00
|
|
|
restoreState(logMemento);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<PinnedMemento*> memento) {
|
|
|
|
setGeometry(geometry);
|
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
2020-12-14 14:48:10 +00:00
|
|
|
std::shared_ptr<Window::SectionMemento> PinnedWidget::createMemento() {
|
|
|
|
auto result = std::make_shared<PinnedMemento>(history());
|
2020-10-20 16:29:24 +00:00
|
|
|
saveState(result.get());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::showMessage(
|
|
|
|
PeerId peerId,
|
|
|
|
const Window::SectionShow ¶ms,
|
|
|
|
MsgId messageId) {
|
2020-10-21 14:41:13 +00:00
|
|
|
return false; // We want 'Go to original' to work.
|
2020-10-20 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::saveState(not_null<PinnedMemento*> memento) {
|
|
|
|
_inner->saveState(memento->list());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::restoreState(not_null<PinnedMemento*> memento) {
|
|
|
|
_inner->restoreState(memento->list());
|
|
|
|
if (const auto highlight = memento->getHighlightId()) {
|
|
|
|
const auto position = Data::MessagePosition{
|
2020-10-22 12:40:33 +00:00
|
|
|
.fullId = ((highlight > 0 || !_migratedPeer)
|
|
|
|
? FullMsgId(_history->channelId(), highlight)
|
|
|
|
: FullMsgId(0, -highlight)),
|
2020-10-20 16:29:24 +00:00
|
|
|
.date = TimeId(0),
|
|
|
|
};
|
|
|
|
_inner->showAroundPosition(position, [=] {
|
2020-10-21 12:31:15 +00:00
|
|
|
return showAtPositionNow(position, nullptr, anim::type::instant);
|
2020-10-20 16:29:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
if (!width() || !height()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
recountChatWidth();
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::recountChatWidth() {
|
|
|
|
auto layout = (width() < st::adaptiveChatWideWidth)
|
|
|
|
? Adaptive::ChatLayout::Normal
|
|
|
|
: Adaptive::ChatLayout::Wide;
|
|
|
|
if (layout != Global::AdaptiveChatLayout()) {
|
|
|
|
Global::SetAdaptiveChatLayout(layout);
|
|
|
|
Adaptive::Changed().notify(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-22 07:53:56 +00:00
|
|
|
void PinnedWidget::setMessagesCount(int count) {
|
|
|
|
if (_messagesCount == count) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_messagesCount = count;
|
|
|
|
_topBar->setCustomTitle(
|
|
|
|
tr::lng_pinned_messages_title(tr::now, lt_count, count));
|
|
|
|
refreshClearButtonText();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::refreshClearButtonText() {
|
|
|
|
const auto can = _history->peer->canPinMessages();
|
|
|
|
_clearButton->setText(can
|
|
|
|
? tr::lng_pinned_unpin_all(
|
|
|
|
tr::now,
|
|
|
|
lt_count,
|
|
|
|
std::max(_messagesCount, 1)).toUpper()
|
|
|
|
: tr::lng_pinned_hide_all(tr::now).toUpper());
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:29:24 +00:00
|
|
|
void PinnedWidget::updateControlsGeometry() {
|
|
|
|
const auto contentWidth = width();
|
|
|
|
|
|
|
|
const auto newScrollTop = _scroll->isHidden()
|
|
|
|
? std::nullopt
|
|
|
|
: base::make_optional(_scroll->scrollTop() + topDelta());
|
|
|
|
_topBar->resizeToWidth(contentWidth);
|
|
|
|
_topBarShadow->resize(contentWidth, st::lineWidth);
|
|
|
|
|
2020-10-22 07:53:56 +00:00
|
|
|
const auto bottom = height() - _clearButton->height();
|
|
|
|
_clearButton->resizeToWidth(width());
|
|
|
|
_clearButton->move(0, bottom);
|
2020-10-20 16:29:24 +00:00
|
|
|
const auto controlsHeight = 0;
|
|
|
|
const auto scrollY = _topBar->height();
|
|
|
|
const auto scrollHeight = bottom - scrollY - controlsHeight;
|
|
|
|
const auto scrollSize = QSize(contentWidth, scrollHeight);
|
|
|
|
if (_scroll->size() != scrollSize) {
|
|
|
|
_skipScrollEvent = true;
|
|
|
|
_scroll->resize(scrollSize);
|
|
|
|
_inner->resizeToWidth(scrollSize.width(), _scroll->height());
|
|
|
|
_skipScrollEvent = false;
|
|
|
|
}
|
|
|
|
_scroll->move(0, scrollY);
|
|
|
|
if (!_scroll->isHidden()) {
|
|
|
|
if (newScrollTop) {
|
|
|
|
_scroll->scrollToY(*newScrollTop);
|
|
|
|
}
|
|
|
|
updateInnerVisibleArea();
|
|
|
|
}
|
|
|
|
updateScrollDownPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
if (animating()) {
|
|
|
|
SectionWidget::paintEvent(e);
|
|
|
|
return;
|
|
|
|
} else if (Ui::skipPaintEvent(this, e)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto aboveHeight = _topBar->height();
|
|
|
|
const auto bg = e->rect().intersected(
|
|
|
|
QRect(0, aboveHeight, width(), height() - aboveHeight));
|
|
|
|
SectionWidget::PaintBackground(controller(), this, bg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::onScroll() {
|
|
|
|
if (_skipScrollEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
updateInnerVisibleArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::updateInnerVisibleArea() {
|
|
|
|
const auto scrollTop = _scroll->scrollTop();
|
|
|
|
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
|
|
|
updateScrollDownVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::showAnimatedHook(
|
|
|
|
const Window::SectionSlideParams ¶ms) {
|
|
|
|
_topBar->setAnimatingMode(true);
|
|
|
|
if (params.withTopBarShadow) {
|
|
|
|
_topBarShadow->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::showFinishedHook() {
|
|
|
|
_topBar->setAnimatingMode(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::floatPlayerHandleWheelEvent(QEvent *e) {
|
|
|
|
return _scroll->viewportEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect PinnedWidget::floatPlayerAvailableRect() {
|
|
|
|
return mapToGlobal(_scroll->geometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
Context PinnedWidget::listContext() {
|
2020-10-21 14:41:13 +00:00
|
|
|
return Context::Pinned;
|
2020-10-20 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::listScrollTo(int top) {
|
|
|
|
if (_scroll->scrollTop() != top) {
|
|
|
|
_scroll->scrollToY(top);
|
|
|
|
} else {
|
|
|
|
updateInnerVisibleArea();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::listCancelRequest() {
|
2020-10-26 08:54:59 +00:00
|
|
|
if (_inner && !_inner->getSelectedIds().empty()) {
|
2020-10-20 16:29:24 +00:00
|
|
|
clearSelected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
controller()->showBackFromStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::listDeleteRequest() {
|
|
|
|
confirmDeleteSelected();
|
|
|
|
}
|
|
|
|
|
2020-10-22 12:40:33 +00:00
|
|
|
rpl::producer<int> SharedMediaCountValue(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
PeerData *migrated,
|
|
|
|
Storage::SharedMediaType type) {
|
|
|
|
auto aroundId = 0;
|
|
|
|
auto limit = 0;
|
|
|
|
auto updated = SharedMediaMergedViewer(
|
|
|
|
&peer->session(),
|
|
|
|
SharedMediaMergedKey(
|
|
|
|
SparseIdsMergedSlice::Key(
|
|
|
|
peer->id,
|
|
|
|
migrated ? migrated->id : 0,
|
|
|
|
aroundId),
|
|
|
|
type),
|
|
|
|
limit,
|
|
|
|
limit
|
|
|
|
) | rpl::map([](const SparseIdsMergedSlice &slice) {
|
|
|
|
return slice.fullCount();
|
|
|
|
}) | rpl::filter_optional();
|
|
|
|
return rpl::single(0) | rpl::then(std::move(updated));
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:29:24 +00:00
|
|
|
rpl::producer<Data::MessagesSlice> PinnedWidget::listSource(
|
|
|
|
Data::MessagePosition aroundId,
|
|
|
|
int limitBefore,
|
|
|
|
int limitAfter) {
|
|
|
|
const auto channelId = peerToChannel(_history->peer->id);
|
|
|
|
const auto messageId = aroundId.fullId.msg
|
|
|
|
? aroundId.fullId.msg
|
|
|
|
: (ServerMaxMsgId - 1);
|
2020-10-22 12:40:33 +00:00
|
|
|
|
|
|
|
return SharedMediaMergedViewer(
|
2020-10-20 16:29:24 +00:00
|
|
|
&_history->session(),
|
2020-10-22 12:40:33 +00:00
|
|
|
SharedMediaMergedKey(
|
|
|
|
SparseIdsMergedSlice::Key(
|
|
|
|
_history->peer->id,
|
|
|
|
_migratedPeer ? _migratedPeer->id : 0,
|
|
|
|
messageId),
|
|
|
|
Storage::SharedMediaType::Pinned),
|
2020-10-20 16:29:24 +00:00
|
|
|
limitBefore,
|
|
|
|
limitAfter
|
2020-10-22 12:40:33 +00:00
|
|
|
) | rpl::filter([=](const SparseIdsMergedSlice &slice) {
|
2020-10-21 14:41:13 +00:00
|
|
|
const auto count = slice.fullCount();
|
|
|
|
if (!count.has_value()) {
|
|
|
|
return true;
|
|
|
|
} else if (*count != 0) {
|
2020-10-22 07:53:56 +00:00
|
|
|
setMessagesCount(*count);
|
2020-10-21 14:41:13 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
controller()->showBackFromStack();
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-22 12:40:33 +00:00
|
|
|
}) | rpl::map([=](SparseIdsMergedSlice &&slice) {
|
2020-10-20 16:29:24 +00:00
|
|
|
auto result = Data::MessagesSlice();
|
|
|
|
result.fullCount = slice.fullCount();
|
|
|
|
result.skippedAfter = slice.skippedAfter();
|
|
|
|
result.skippedBefore = slice.skippedBefore();
|
|
|
|
const auto count = slice.size();
|
|
|
|
result.ids.reserve(count);
|
|
|
|
if (const auto msgId = slice.nearest(messageId)) {
|
2020-10-22 12:40:33 +00:00
|
|
|
result.nearestToAround = *msgId;
|
2020-10-20 16:29:24 +00:00
|
|
|
}
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
2020-10-22 12:40:33 +00:00
|
|
|
result.ids.push_back(slice[i]);
|
2020-10-20 16:29:24 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::listAllowsMultiSelect() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::listIsItemGoodForSelection(
|
|
|
|
not_null<HistoryItem*> item) {
|
2020-10-26 08:54:59 +00:00
|
|
|
return IsServerMsgId(item->id);
|
2020-10-20 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::listIsLessInOrder(
|
|
|
|
not_null<HistoryItem*> first,
|
|
|
|
not_null<HistoryItem*> second) {
|
|
|
|
return first->position() < second->position();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::listSelectionChanged(SelectedItems &&items) {
|
|
|
|
HistoryView::TopBarWidget::SelectedState state;
|
|
|
|
state.count = items.size();
|
|
|
|
for (const auto item : items) {
|
|
|
|
if (item.canDelete) {
|
|
|
|
++state.canDeleteCount;
|
|
|
|
}
|
|
|
|
if (item.canForward) {
|
|
|
|
++state.canForwardCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_topBar->showSelected(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::listVisibleItemsChanged(HistoryItemsList &&items) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessagesBarData PinnedWidget::listMessagesBar(
|
|
|
|
const std::vector<not_null<Element*>> &elements) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::listContentRefreshed() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ClickHandlerPtr PinnedWidget::listDateLink(not_null<Element*> view) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::listElementHideReply(not_null<const Element*> view) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::listElementShownUnread(not_null<const Element*> view) {
|
|
|
|
return view->data()->unread();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedWidget::listIsGoodForAroundPosition(
|
|
|
|
not_null<const Element*> view) {
|
|
|
|
return IsServerMsgId(view->data()->id);
|
|
|
|
}
|
|
|
|
|
2020-11-10 16:38:21 +00:00
|
|
|
void PinnedWidget::listSendBotCommand(
|
|
|
|
const QString &command,
|
|
|
|
const FullMsgId &context) {
|
|
|
|
}
|
|
|
|
|
2020-11-10 18:51:20 +00:00
|
|
|
void PinnedWidget::listHandleViaClick(not_null<UserData*> bot) {
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:29:24 +00:00
|
|
|
void PinnedWidget::confirmDeleteSelected() {
|
2020-10-26 08:54:59 +00:00
|
|
|
ConfirmDeleteSelectedItems(_inner);
|
2020-10-20 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::confirmForwardSelected() {
|
2020-10-26 08:54:59 +00:00
|
|
|
ConfirmForwardSelectedItems(_inner);
|
2020-10-20 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinnedWidget::clearSelected() {
|
|
|
|
_inner->cancelSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace HistoryView
|