mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-03 21:54:05 +02:00
Initial saved sublist section implementation.
This commit is contained in:
parent
18c4d210e5
commit
fd417024fb
12 changed files with 939 additions and 11 deletions
|
@ -800,6 +800,8 @@ PRIVATE
|
|||
history/view/history_view_sponsored_click_handler.h
|
||||
history/view/history_view_sticker_toast.cpp
|
||||
history/view/history_view_sticker_toast.h
|
||||
history/view/history_view_sublist_section.cpp
|
||||
history/view/history_view_sublist_section.h
|
||||
history/view/history_view_transcribe_button.cpp
|
||||
history/view/history_view_transcribe_button.h
|
||||
history/view/history_view_translate_bar.cpp
|
||||
|
|
|
@ -2493,6 +2493,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_saved_short" = "Save";
|
||||
"lng_saved_forward_here" = "Forward messages here for quick access";
|
||||
"lng_saved_quote_here" = "Quote here to save";
|
||||
"lng_saved_open_chat" = "Open Chat";
|
||||
"lng_saved_open_channel" = "Open Channel";
|
||||
"lng_saved_open_group" = "Open Group";
|
||||
"lng_saved_about_hidden" = "Senders of this messages restricted to link their name when forwarding.";
|
||||
|
||||
"lng_scheduled_messages" = "Scheduled Messages";
|
||||
"lng_scheduled_messages_empty" = "No scheduled messages here yet...";
|
||||
|
|
|
@ -138,6 +138,7 @@ void SavedMessages::loadMore(not_null<SavedSublist*> sublist) {
|
|||
MTP_int(0), // min_id
|
||||
MTP_long(0)) // hash
|
||||
).done([=](const MTPmessages_Messages &result) {
|
||||
auto count = 0;
|
||||
auto list = (const QVector<MTPMessage>*)nullptr;
|
||||
result.match([](const MTPDmessages_channelMessages &) {
|
||||
LOG(("API Error: messages.channelMessages in sublist."));
|
||||
|
@ -147,6 +148,11 @@ void SavedMessages::loadMore(not_null<SavedSublist*> sublist) {
|
|||
owner().processUsers(data.vusers());
|
||||
owner().processChats(data.vchats());
|
||||
list = &data.vmessages().v;
|
||||
if constexpr (MTPDmessages_messages::Is<decltype(data)>()) {
|
||||
count = int(list->size());
|
||||
} else {
|
||||
count = data.vcount().v;
|
||||
}
|
||||
});
|
||||
|
||||
_loadMoreRequests.remove(sublist);
|
||||
|
@ -165,7 +171,7 @@ void SavedMessages::loadMore(not_null<SavedSublist*> sublist) {
|
|||
items.push_back(item);
|
||||
}
|
||||
}
|
||||
sublist->append(std::move(items));
|
||||
sublist->append(std::move(items), count);
|
||||
if (result.type() == mtpc_messages_messages) {
|
||||
sublist->setFullLoaded();
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ auto SavedSublist::messages() const
|
|||
return _items;
|
||||
}
|
||||
|
||||
void SavedSublist::applyMaybeLast(not_null<HistoryItem*> item) {
|
||||
void SavedSublist::applyMaybeLast(not_null<HistoryItem*> item, bool added) {
|
||||
const auto before = [](
|
||||
not_null<HistoryItem*> a,
|
||||
not_null<HistoryItem*> b) {
|
||||
|
@ -58,22 +58,28 @@ void SavedSublist::applyMaybeLast(not_null<HistoryItem*> item) {
|
|||
_items.push_back(item);
|
||||
} else if (_items.front() == item) {
|
||||
return;
|
||||
} else if (_items.size() == 1 && before(_items.front(), item)) {
|
||||
} else if (!isFullLoaded()
|
||||
&& _items.size() == 1
|
||||
&& before(_items.front(), item)) {
|
||||
_items[0] = item;
|
||||
} else if (before(_items.back(), item)) {
|
||||
for (auto i = begin(_items); i != end(_items); ++i) {
|
||||
if (item == *i) {
|
||||
break;
|
||||
return;
|
||||
} else if (before(*i, item)) {
|
||||
_items.insert(i, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (added && _fullCount) {
|
||||
++*_fullCount;
|
||||
}
|
||||
if (_items.front() == item) {
|
||||
setChatListTimeId(item->date());
|
||||
resolveChatListMessageGroup();
|
||||
}
|
||||
_changed.fire({});
|
||||
}
|
||||
|
||||
void SavedSublist::removeOne(not_null<HistoryItem*> item) {
|
||||
|
@ -81,7 +87,14 @@ void SavedSublist::removeOne(not_null<HistoryItem*> item) {
|
|||
return;
|
||||
}
|
||||
const auto last = (_items.front() == item);
|
||||
_items.erase(ranges::remove(_items, item), end(_items));
|
||||
const auto from = ranges::remove(_items, item);
|
||||
const auto removed = end(_items) - from;
|
||||
if (removed) {
|
||||
_items.erase(from, end(_items));
|
||||
}
|
||||
if (_fullCount) {
|
||||
--*_fullCount;
|
||||
}
|
||||
if (last) {
|
||||
if (_items.empty()) {
|
||||
if (isFullLoaded()) {
|
||||
|
@ -96,16 +109,38 @@ void SavedSublist::removeOne(not_null<HistoryItem*> item) {
|
|||
setChatListTimeId(_items.front()->date());
|
||||
}
|
||||
}
|
||||
if (removed || _fullCount) {
|
||||
_changed.fire({});
|
||||
}
|
||||
}
|
||||
|
||||
void SavedSublist::append(std::vector<not_null<HistoryItem*>> &&items) {
|
||||
rpl::producer<> SavedSublist::changes() const {
|
||||
return _changed.events();
|
||||
}
|
||||
|
||||
std::optional<int> SavedSublist::fullCount() const {
|
||||
return isFullLoaded() ? int(_items.size()) : _fullCount;
|
||||
}
|
||||
|
||||
rpl::producer<int> SavedSublist::fullCountValue() const {
|
||||
return _changed.events_starting_with({}) | rpl::map([=] {
|
||||
return fullCount();
|
||||
}) | rpl::filter_optional();
|
||||
}
|
||||
|
||||
void SavedSublist::append(
|
||||
std::vector<not_null<HistoryItem*>> &&items,
|
||||
int fullCount) {
|
||||
_fullCount = fullCount;
|
||||
if (items.empty()) {
|
||||
setFullLoaded();
|
||||
} else if (!_items.empty()) {
|
||||
_items.insert(end(_items), begin(items), end(items));
|
||||
_changed.fire({});
|
||||
} else {
|
||||
_items = std::move(items);
|
||||
setChatListTimeId(_items.front()->date());
|
||||
_changed.fire({});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,6 +154,7 @@ void SavedSublist::setFullLoaded(bool loaded) {
|
|||
} else {
|
||||
_flags &= ~Flag::FullLoaded;
|
||||
}
|
||||
_changed.fire({});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,11 +29,15 @@ public:
|
|||
|
||||
[[nodiscard]] auto messages() const
|
||||
-> const std::vector<not_null<HistoryItem*>> &;
|
||||
void applyMaybeLast(not_null<HistoryItem*> item);
|
||||
void applyMaybeLast(not_null<HistoryItem*> item, bool added = false);
|
||||
void removeOne(not_null<HistoryItem*> item);
|
||||
void append(std::vector<not_null<HistoryItem*>> &&items);
|
||||
void append(std::vector<not_null<HistoryItem*>> &&items, int fullCount);
|
||||
void setFullLoaded(bool loaded = true);
|
||||
|
||||
[[nodiscard]] rpl::producer<> changes() const;
|
||||
[[nodiscard]] std::optional<int> fullCount() const;
|
||||
[[nodiscard]] rpl::producer<int> fullCountValue() const;
|
||||
|
||||
[[nodiscard]] Dialogs::Ui::MessageView &lastItemDialogsView() {
|
||||
return _lastItemDialogsView;
|
||||
}
|
||||
|
@ -71,6 +75,8 @@ private:
|
|||
const not_null<History*> _history;
|
||||
|
||||
std::vector<not_null<HistoryItem*>> _items;
|
||||
std::optional<int> _fullCount;
|
||||
rpl::event_stream<> _changed;
|
||||
Dialogs::Ui::MessageView _lastItemDialogsView;
|
||||
Flags _flags;
|
||||
|
||||
|
|
|
@ -106,6 +106,7 @@ struct EntryState {
|
|||
Scheduled,
|
||||
Pinned,
|
||||
Replies,
|
||||
SavedSublist,
|
||||
ContextMenu,
|
||||
};
|
||||
|
||||
|
|
|
@ -612,7 +612,7 @@ not_null<HistoryItem*> History::addNewItem(
|
|||
}
|
||||
|
||||
if (const auto sublist = item->savedSublist()) {
|
||||
sublist->applyMaybeLast(item);
|
||||
sublist->applyMaybeLast(item, unread);
|
||||
}
|
||||
|
||||
return item;
|
||||
|
|
|
@ -374,7 +374,6 @@ private:
|
|||
|
||||
};
|
||||
|
||||
|
||||
class RepliesMemento final : public Window::SectionMemento {
|
||||
public:
|
||||
RepliesMemento(
|
||||
|
|
|
@ -0,0 +1,644 @@
|
|||
/*
|
||||
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_sublist_section.h"
|
||||
|
||||
//#include "base/timer_rpl.h"
|
||||
//#include "apiwrap.h"
|
||||
//#include "base/event_filter.h"
|
||||
//#include "base/call_delayed.h"
|
||||
//#include "base/qt/qt_key_modifiers.h"
|
||||
//#include "core/file_utilities.h"
|
||||
#include "main/main_session.h"
|
||||
//#include "data/data_chat.h"
|
||||
//#include "data/data_channel.h"
|
||||
//#include "data/data_changes.h"
|
||||
#include "data/data_saved_messages.h"
|
||||
#include "data/data_saved_sublist.h"
|
||||
#include "data/data_session.h"
|
||||
//#include "data/data_sparse_ids.h"
|
||||
//#include "data/data_shared_media.h"
|
||||
#include "data/data_peer_values.h"
|
||||
#include "data/data_user.h"
|
||||
#include "history/view/history_view_top_bar_widget.h"
|
||||
#include "history/view/history_view_translate_bar.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 "storage/storage_account.h"
|
||||
//#include "platform/platform_specific.h"
|
||||
#include "lang/lang_keys.h"
|
||||
//#include "ui/boxes/confirm_box.h"
|
||||
//#include "ui/layers/generic_box.h"
|
||||
//#include "ui/item_text_options.h"
|
||||
#include "ui/chat/chat_style.h"
|
||||
//#include "ui/toast/toast.h"
|
||||
//#include "ui/text/format_values.h"
|
||||
//#include "ui/text/text_utilities.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
//#include "ui/ui_utility.h"
|
||||
//#include "window/window_adaptive.h"
|
||||
#include "window/window_session_controller.h"
|
||||
//#include "window/window_peer_menu.h"
|
||||
#include "styles/style_chat.h"
|
||||
#include "styles/style_chat_helpers.h"
|
||||
#include "styles/style_window.h"
|
||||
//#include "styles/style_info.h"
|
||||
//#include "styles/style_boxes.h"
|
||||
//
|
||||
//#include <QtCore/QMimeData>
|
||||
|
||||
namespace HistoryView {
|
||||
namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
SublistMemento::SublistMemento(not_null<Data::SavedSublist*> sublist)
|
||||
: _sublist(sublist) {
|
||||
const auto selfId = sublist->session().userPeerId();
|
||||
_list.setAroundPosition({
|
||||
.fullId = FullMsgId(selfId, ShowAtUnreadMsgId),
|
||||
.date = TimeId(0),
|
||||
});
|
||||
}
|
||||
|
||||
object_ptr<Window::SectionWidget> SublistMemento::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<SublistWidget>(
|
||||
parent,
|
||||
controller,
|
||||
_sublist);
|
||||
result->setInternalState(geometry, this);
|
||||
return result;
|
||||
}
|
||||
|
||||
SublistWidget::SublistWidget(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Data::SavedSublist*> sublist)
|
||||
: Window::SectionWidget(parent, controller, sublist->peer())
|
||||
, _sublist(sublist)
|
||||
, _history(sublist->owner().history(sublist->session().user()))
|
||||
, _topBar(this, controller)
|
||||
, _topBarShadow(this)
|
||||
, _translateBar(std::make_unique<TranslateBar>(this, controller, _history))
|
||||
, _scroll(std::make_unique<Ui::ScrollArea>(
|
||||
this,
|
||||
controller->chatStyle()->value(lifetime(), st::historyScroll),
|
||||
false))
|
||||
, _openChatButton(std::make_unique<Ui::FlatButton>(
|
||||
this,
|
||||
(_sublist->peer()->isBroadcast()
|
||||
? tr::lng_saved_open_channel(tr::now)
|
||||
: _sublist->peer()->isUser()
|
||||
? tr::lng_saved_open_chat(tr::now)
|
||||
: tr::lng_saved_open_group(tr::now)),
|
||||
st::historyComposeButton))
|
||||
, _cornerButtons(
|
||||
_scroll.get(),
|
||||
controller->chatStyle(),
|
||||
static_cast<HistoryView::CornerButtonsDelegate*>(this)) {
|
||||
controller->chatStyle()->paletteChanged(
|
||||
) | rpl::start_with_next([=] {
|
||||
_scroll->updateBars();
|
||||
}, _scroll->lifetime());
|
||||
|
||||
Window::ChatThemeValueFromPeer(
|
||||
controller,
|
||||
sublist->peer()
|
||||
) | rpl::start_with_next([=](std::shared_ptr<Ui::ChatTheme> &&theme) {
|
||||
_theme = std::move(theme);
|
||||
controller->setChatStyleTheme(_theme);
|
||||
}, lifetime());
|
||||
|
||||
_topBar->setActiveChat(
|
||||
TopBarWidget::ActiveChat{
|
||||
.key = sublist,
|
||||
.section = Dialogs::EntryState::Section::SavedSublist,
|
||||
},
|
||||
nullptr);
|
||||
|
||||
_topBar->move(0, 0);
|
||||
_topBar->resizeToWidth(width());
|
||||
_topBar->show();
|
||||
_topBar->setCustomTitle(tr::lng_contacts_loading(tr::now));
|
||||
|
||||
_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());
|
||||
|
||||
_translateBar->raise();
|
||||
_topBarShadow->raise();
|
||||
controller->adaptive().value(
|
||||
) | rpl::start_with_next([=] {
|
||||
updateAdaptiveLayout();
|
||||
}, lifetime());
|
||||
|
||||
_inner = _scroll->setOwnedWidget(object_ptr<ListWidget>(
|
||||
this,
|
||||
controller,
|
||||
static_cast<ListDelegate*>(this)));
|
||||
_scroll->move(0, _topBar->height());
|
||||
_scroll->show();
|
||||
_scroll->scrolls(
|
||||
) | rpl::start_with_next([=] {
|
||||
onScroll();
|
||||
}, lifetime());
|
||||
|
||||
setupOpenChatButton();
|
||||
setupTranslateBar();
|
||||
}
|
||||
|
||||
SublistWidget::~SublistWidget() = default;
|
||||
|
||||
void SublistWidget::setupOpenChatButton() {
|
||||
_openChatButton->setClickedCallback([=] {
|
||||
controller()->showPeerHistory(
|
||||
_sublist->peer(),
|
||||
Window::SectionShow::Way::Forward);
|
||||
});
|
||||
}
|
||||
|
||||
void SublistWidget::setupTranslateBar() {
|
||||
controller()->adaptive().oneColumnValue(
|
||||
) | rpl::start_with_next([=, raw = _translateBar.get()](bool one) {
|
||||
raw->setShadowGeometryPostprocess([=](QRect geometry) {
|
||||
if (!one) {
|
||||
geometry.setLeft(geometry.left() + st::lineWidth);
|
||||
}
|
||||
return geometry;
|
||||
});
|
||||
}, _translateBar->lifetime());
|
||||
|
||||
_translateBarHeight = 0;
|
||||
_translateBar->heightValue(
|
||||
) | rpl::start_with_next([=](int height) {
|
||||
if (const auto delta = height - _translateBarHeight) {
|
||||
_translateBarHeight = height;
|
||||
setGeometryWithTopMoved(geometry(), delta);
|
||||
}
|
||||
}, _translateBar->lifetime());
|
||||
|
||||
_translateBar->finishAnimating();
|
||||
}
|
||||
|
||||
void SublistWidget::cornerButtonsShowAtPosition(
|
||||
Data::MessagePosition position) {
|
||||
showAtPosition(position);
|
||||
}
|
||||
|
||||
Data::Thread *SublistWidget::cornerButtonsThread() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FullMsgId SublistWidget::cornerButtonsCurrentId() {
|
||||
return {};
|
||||
}
|
||||
|
||||
bool SublistWidget::cornerButtonsIgnoreVisibility() {
|
||||
return animatingShow();
|
||||
}
|
||||
|
||||
std::optional<bool> SublistWidget::cornerButtonsDownShown() {
|
||||
const auto top = _scroll->scrollTop() + st::historyToDownShownAfter;
|
||||
if (top < _scroll->scrollTopMax() || _cornerButtons.replyReturn()) {
|
||||
return true;
|
||||
} else if (_inner->loadedAtBottomKnown()) {
|
||||
return !_inner->loadedAtBottom();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool SublistWidget::cornerButtonsUnreadMayBeShown() {
|
||||
return _inner->loadedAtBottomKnown();
|
||||
}
|
||||
|
||||
bool SublistWidget::cornerButtonsHas(CornerButtonType type) {
|
||||
return (type == CornerButtonType::Down);
|
||||
}
|
||||
|
||||
void SublistWidget::showAtPosition(
|
||||
Data::MessagePosition position,
|
||||
FullMsgId originId) {
|
||||
_inner->showAtPosition(
|
||||
position,
|
||||
{},
|
||||
_cornerButtons.doneJumpFrom(position.fullId, originId));
|
||||
}
|
||||
|
||||
void SublistWidget::updateAdaptiveLayout() {
|
||||
_topBarShadow->moveToLeft(
|
||||
controller()->adaptive().isOneColumn() ? 0 : st::lineWidth,
|
||||
_topBar->height());
|
||||
}
|
||||
|
||||
not_null<Data::SavedSublist*> SublistWidget::sublist() const {
|
||||
return _sublist;
|
||||
}
|
||||
|
||||
Dialogs::RowDescriptor SublistWidget::activeChat() const {
|
||||
return {
|
||||
_history,
|
||||
FullMsgId(_history->peer->id, ShowAtUnreadMsgId)
|
||||
};
|
||||
}
|
||||
|
||||
QPixmap SublistWidget::grabForShowAnimation(const Window::SectionSlideParams ¶ms) {
|
||||
_topBar->updateControlsVisibility();
|
||||
if (params.withTopBarShadow) _topBarShadow->hide();
|
||||
auto result = Ui::GrabWidget(this);
|
||||
if (params.withTopBarShadow) _topBarShadow->show();
|
||||
_translateBar->hide();
|
||||
return result;
|
||||
}
|
||||
|
||||
void SublistWidget::checkActivation() {
|
||||
_inner->checkActivation();
|
||||
}
|
||||
|
||||
void SublistWidget::doSetInnerFocus() {
|
||||
_inner->setFocus();
|
||||
}
|
||||
|
||||
bool SublistWidget::showInternal(
|
||||
not_null<Window::SectionMemento*> memento,
|
||||
const Window::SectionShow ¶ms) {
|
||||
if (auto logMemento = dynamic_cast<SublistMemento*>(memento.get())) {
|
||||
if (logMemento->getSublist() == sublist()) {
|
||||
restoreState(logMemento);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SublistWidget::setInternalState(
|
||||
const QRect &geometry,
|
||||
not_null<SublistMemento*> memento) {
|
||||
setGeometry(geometry);
|
||||
Ui::SendPendingMoveResizeEvents(this);
|
||||
restoreState(memento);
|
||||
}
|
||||
|
||||
std::shared_ptr<Window::SectionMemento> SublistWidget::createMemento() {
|
||||
auto result = std::make_shared<SublistMemento>(sublist());
|
||||
saveState(result.get());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SublistWidget::showMessage(
|
||||
PeerId peerId,
|
||||
const Window::SectionShow ¶ms,
|
||||
MsgId messageId) {
|
||||
return false; // We want 'Go to original' to work.
|
||||
}
|
||||
|
||||
void SublistWidget::saveState(not_null<SublistMemento*> memento) {
|
||||
_inner->saveState(memento->list());
|
||||
}
|
||||
|
||||
void SublistWidget::restoreState(not_null<SublistMemento*> memento) {
|
||||
_inner->restoreState(memento->list());
|
||||
}
|
||||
|
||||
void SublistWidget::resizeEvent(QResizeEvent *e) {
|
||||
if (!width() || !height()) {
|
||||
return;
|
||||
}
|
||||
recountChatWidth();
|
||||
updateControlsGeometry();
|
||||
}
|
||||
|
||||
void SublistWidget::recountChatWidth() {
|
||||
auto layout = (width() < st::adaptiveChatWideWidth)
|
||||
? Window::Adaptive::ChatLayout::Normal
|
||||
: Window::Adaptive::ChatLayout::Wide;
|
||||
controller()->adaptive().setChatLayout(layout);
|
||||
}
|
||||
|
||||
void SublistWidget::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);
|
||||
|
||||
const auto bottom = height() - _openChatButton->height();
|
||||
_openChatButton->resizeToWidth(width());
|
||||
_openChatButton->move(0, bottom);
|
||||
const auto controlsHeight = 0;
|
||||
auto top = _topBar->height();
|
||||
_translateBar->move(0, top);
|
||||
_translateBar->resizeToWidth(contentWidth);
|
||||
top += _translateBarHeight;
|
||||
const auto scrollHeight = bottom - top - 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, top);
|
||||
if (!_scroll->isHidden()) {
|
||||
if (newScrollTop) {
|
||||
_scroll->scrollToY(*newScrollTop);
|
||||
}
|
||||
updateInnerVisibleArea();
|
||||
}
|
||||
|
||||
_cornerButtons.updatePositions();
|
||||
}
|
||||
|
||||
void SublistWidget::paintEvent(QPaintEvent *e) {
|
||||
if (animatingShow()) {
|
||||
SectionWidget::paintEvent(e);
|
||||
return;
|
||||
} else if (controller()->contentOverlapped(this, e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto aboveHeight = _topBar->height();
|
||||
const auto bg = e->rect().intersected(
|
||||
QRect(0, aboveHeight, width(), height() - aboveHeight));
|
||||
SectionWidget::PaintBackground(controller(), _theme.get(), this, bg);
|
||||
}
|
||||
|
||||
void SublistWidget::onScroll() {
|
||||
if (_skipScrollEvent) {
|
||||
return;
|
||||
}
|
||||
updateInnerVisibleArea();
|
||||
}
|
||||
|
||||
void SublistWidget::updateInnerVisibleArea() {
|
||||
const auto scrollTop = _scroll->scrollTop();
|
||||
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
||||
_cornerButtons.updateJumpDownVisibility();
|
||||
_cornerButtons.updateUnreadThingsVisibility();
|
||||
}
|
||||
|
||||
void SublistWidget::showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) {
|
||||
_topBar->setAnimatingMode(true);
|
||||
if (params.withTopBarShadow) {
|
||||
_topBarShadow->show();
|
||||
}
|
||||
}
|
||||
|
||||
void SublistWidget::showFinishedHook() {
|
||||
_topBar->setAnimatingMode(false);
|
||||
_inner->showFinished();
|
||||
_translateBar->show();
|
||||
}
|
||||
|
||||
bool SublistWidget::floatPlayerHandleWheelEvent(QEvent *e) {
|
||||
return _scroll->viewportEvent(e);
|
||||
}
|
||||
|
||||
QRect SublistWidget::floatPlayerAvailableRect() {
|
||||
return mapToGlobal(_scroll->geometry());
|
||||
}
|
||||
|
||||
Context SublistWidget::listContext() {
|
||||
return Context::Pinned;
|
||||
}
|
||||
|
||||
bool SublistWidget::listScrollTo(int top, bool syntetic) {
|
||||
top = std::clamp(top, 0, _scroll->scrollTopMax());
|
||||
if (_scroll->scrollTop() == top) {
|
||||
updateInnerVisibleArea();
|
||||
return false;
|
||||
}
|
||||
_scroll->scrollToY(top);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SublistWidget::listCancelRequest() {
|
||||
if (_inner && !_inner->getSelectedIds().empty()) {
|
||||
clearSelected();
|
||||
return;
|
||||
}
|
||||
controller()->showBackFromStack();
|
||||
}
|
||||
|
||||
void SublistWidget::listDeleteRequest() {
|
||||
confirmDeleteSelected();
|
||||
}
|
||||
|
||||
void SublistWidget::listTryProcessKeyInput(not_null<QKeyEvent*> e) {
|
||||
}
|
||||
|
||||
rpl::producer<Data::MessagesSlice> SublistWidget::listSource(
|
||||
Data::MessagePosition aroundId,
|
||||
int limitBefore,
|
||||
int limitAfter) {
|
||||
const auto messageId = aroundId.fullId.msg
|
||||
? aroundId.fullId.msg
|
||||
: (ServerMaxMsgId - 1);
|
||||
return [=](auto consumer) {
|
||||
const auto pushSlice = [=] {
|
||||
auto result = Data::MessagesSlice();
|
||||
result.fullCount = _sublist->fullCount();
|
||||
const auto &messages = _sublist->messages();
|
||||
const auto i = ranges::lower_bound(
|
||||
messages,
|
||||
messageId,
|
||||
ranges::greater(),
|
||||
[](not_null<HistoryItem*> item) { return item->id; });
|
||||
const auto before = int(end(messages) - i);
|
||||
const auto useBefore = std::min(before, limitBefore);
|
||||
const auto after = int(i - begin(messages));
|
||||
const auto useAfter = std::min(after, limitAfter);
|
||||
const auto from = i - useAfter;
|
||||
const auto till = i + useBefore;
|
||||
auto nearestDistance = std::numeric_limits<int>::max();
|
||||
result.ids.reserve(useAfter + useBefore);
|
||||
for (auto j = till; j != from;) {
|
||||
const auto item = *--j;
|
||||
result.ids.push_back(item->fullId());
|
||||
const auto distance = std::abs((messageId - item->id).bare);
|
||||
if (nearestDistance > distance) {
|
||||
nearestDistance = distance;
|
||||
result.nearestToAround = result.ids.back();
|
||||
}
|
||||
}
|
||||
result.skippedAfter = after - useAfter;
|
||||
result.skippedBefore = result.fullCount
|
||||
? (*result.fullCount - after - useBefore)
|
||||
: std::optional<int>();
|
||||
if (!result.fullCount || useBefore < limitBefore) {
|
||||
_sublist->owner().savedMessages().loadMore(_sublist);
|
||||
}
|
||||
consumer.put_next(std::move(result));
|
||||
};
|
||||
auto lifetime = rpl::lifetime();
|
||||
_sublist->changes() | rpl::start_with_next(pushSlice, lifetime);
|
||||
pushSlice();
|
||||
return lifetime;
|
||||
};
|
||||
}
|
||||
|
||||
bool SublistWidget::listAllowsMultiSelect() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SublistWidget::listIsItemGoodForSelection(
|
||||
not_null<HistoryItem*> item) {
|
||||
return item->isRegular() && !item->isService();
|
||||
}
|
||||
|
||||
bool SublistWidget::listIsLessInOrder(
|
||||
not_null<HistoryItem*> first,
|
||||
not_null<HistoryItem*> second) {
|
||||
return first->id < second->id;
|
||||
}
|
||||
|
||||
void SublistWidget::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 SublistWidget::listMarkReadTill(not_null<HistoryItem*> item) {
|
||||
}
|
||||
|
||||
void SublistWidget::listMarkContentsRead(
|
||||
const base::flat_set<not_null<HistoryItem*>> &items) {
|
||||
}
|
||||
|
||||
MessagesBarData SublistWidget::listMessagesBar(
|
||||
const std::vector<not_null<Element*>> &elements) {
|
||||
return {};
|
||||
}
|
||||
|
||||
void SublistWidget::listContentRefreshed() {
|
||||
}
|
||||
|
||||
void SublistWidget::listUpdateDateLink(
|
||||
ClickHandlerPtr &link,
|
||||
not_null<Element*> view) {
|
||||
}
|
||||
|
||||
bool SublistWidget::listElementHideReply(not_null<const Element*> view) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SublistWidget::listElementShownUnread(not_null<const Element*> view) {
|
||||
return view->data()->unread(view->data()->history());
|
||||
}
|
||||
|
||||
bool SublistWidget::listIsGoodForAroundPosition(
|
||||
not_null<const Element*> view) {
|
||||
return view->data()->isRegular();
|
||||
}
|
||||
|
||||
void SublistWidget::listSendBotCommand(
|
||||
const QString &command,
|
||||
const FullMsgId &context) {
|
||||
}
|
||||
|
||||
void SublistWidget::listHandleViaClick(not_null<UserData*> bot) {
|
||||
}
|
||||
|
||||
not_null<Ui::ChatTheme*> SublistWidget::listChatTheme() {
|
||||
return _theme.get();
|
||||
}
|
||||
|
||||
CopyRestrictionType SublistWidget::listCopyRestrictionType(
|
||||
HistoryItem *item) {
|
||||
return CopyRestrictionTypeFor(_history->peer, item);
|
||||
}
|
||||
|
||||
CopyRestrictionType SublistWidget::listCopyMediaRestrictionType(
|
||||
not_null<HistoryItem*> item) {
|
||||
return CopyMediaRestrictionTypeFor(_history->peer, item);
|
||||
}
|
||||
|
||||
CopyRestrictionType SublistWidget::listSelectRestrictionType() {
|
||||
return SelectRestrictionTypeFor(_history->peer);
|
||||
}
|
||||
|
||||
auto SublistWidget::listAllowedReactionsValue()
|
||||
-> rpl::producer<Data::AllowedReactions> {
|
||||
return Data::PeerAllowedReactionsValue(_history->peer);
|
||||
}
|
||||
|
||||
void SublistWidget::listShowPremiumToast(not_null<DocumentData*> document) {
|
||||
}
|
||||
|
||||
void SublistWidget::listOpenPhoto(
|
||||
not_null<PhotoData*> photo,
|
||||
FullMsgId context) {
|
||||
controller()->openPhoto(photo, { context });
|
||||
}
|
||||
|
||||
void SublistWidget::listOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView) {
|
||||
controller()->openDocument(document, showInMediaView, { context });
|
||||
}
|
||||
|
||||
void SublistWidget::listPaintEmpty(
|
||||
Painter &p,
|
||||
const Ui::ChatPaintContext &context) {
|
||||
}
|
||||
|
||||
QString SublistWidget::listElementAuthorRank(not_null<const Element*> view) {
|
||||
return {};
|
||||
}
|
||||
|
||||
History *SublistWidget::listTranslateHistory() {
|
||||
return _history;
|
||||
}
|
||||
|
||||
void SublistWidget::listAddTranslatedItems(
|
||||
not_null<TranslateTracker*> tracker) {
|
||||
}
|
||||
|
||||
void SublistWidget::confirmDeleteSelected() {
|
||||
ConfirmDeleteSelectedItems(_inner);
|
||||
}
|
||||
|
||||
void SublistWidget::confirmForwardSelected() {
|
||||
ConfirmForwardSelectedItems(_inner);
|
||||
}
|
||||
|
||||
void SublistWidget::clearSelected() {
|
||||
_inner->cancelSelection();
|
||||
}
|
||||
|
||||
} // namespace HistoryView
|
215
Telegram/SourceFiles/history/view/history_view_sublist_section.h
Normal file
215
Telegram/SourceFiles/history/view/history_view_sublist_section.h
Normal file
|
@ -0,0 +1,215 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "window/section_widget.h"
|
||||
#include "window/section_memento.h"
|
||||
#include "history/view/history_view_list_widget.h"
|
||||
#include "history/view/history_view_corner_buttons.h"
|
||||
#include "data/data_messages.h"
|
||||
#include "base/weak_ptr.h"
|
||||
#include "base/timer.h"
|
||||
|
||||
class History;
|
||||
|
||||
namespace Ui {
|
||||
class ScrollArea;
|
||||
class PlainShadow;
|
||||
class FlatButton;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Profile {
|
||||
class BackButton;
|
||||
} // namespace Profile
|
||||
|
||||
namespace HistoryView {
|
||||
|
||||
class Element;
|
||||
class TopBarWidget;
|
||||
class SublistMemento;
|
||||
class TranslateBar;
|
||||
|
||||
class SublistWidget final
|
||||
: public Window::SectionWidget
|
||||
, private ListDelegate
|
||||
, private CornerButtonsDelegate {
|
||||
public:
|
||||
SublistWidget(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Data::SavedSublist*> sublist);
|
||||
~SublistWidget();
|
||||
|
||||
[[nodiscard]] not_null<Data::SavedSublist*> sublist() const;
|
||||
Dialogs::RowDescriptor activeChat() const override;
|
||||
|
||||
bool hasTopBarShadow() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
QPixmap grabForShowAnimation(
|
||||
const Window::SectionSlideParams ¶ms) override;
|
||||
|
||||
bool showInternal(
|
||||
not_null<Window::SectionMemento*> memento,
|
||||
const Window::SectionShow ¶ms) override;
|
||||
std::shared_ptr<Window::SectionMemento> createMemento() override;
|
||||
bool showMessage(
|
||||
PeerId peerId,
|
||||
const Window::SectionShow ¶ms,
|
||||
MsgId messageId) override;
|
||||
|
||||
void setInternalState(
|
||||
const QRect &geometry,
|
||||
not_null<SublistMemento*> memento);
|
||||
|
||||
Window::SectionActionResult sendBotCommand(
|
||||
Bot::SendCommandRequest request) override {
|
||||
return Window::SectionActionResult::Fallback;
|
||||
}
|
||||
|
||||
// Float player interface.
|
||||
bool floatPlayerHandleWheelEvent(QEvent *e) override;
|
||||
QRect floatPlayerAvailableRect() override;
|
||||
|
||||
// ListDelegate interface.
|
||||
Context listContext() override;
|
||||
bool listScrollTo(int top, bool syntetic = true) override;
|
||||
void listCancelRequest() override;
|
||||
void listDeleteRequest() override;
|
||||
void listTryProcessKeyInput(not_null<QKeyEvent*> e) override;
|
||||
rpl::producer<Data::MessagesSlice> listSource(
|
||||
Data::MessagePosition aroundId,
|
||||
int limitBefore,
|
||||
int limitAfter) override;
|
||||
bool listAllowsMultiSelect() override;
|
||||
bool listIsItemGoodForSelection(not_null<HistoryItem*> item) override;
|
||||
bool listIsLessInOrder(
|
||||
not_null<HistoryItem*> first,
|
||||
not_null<HistoryItem*> second) override;
|
||||
void listSelectionChanged(SelectedItems &&items) override;
|
||||
void listMarkReadTill(not_null<HistoryItem*> item) override;
|
||||
void listMarkContentsRead(
|
||||
const base::flat_set<not_null<HistoryItem*>> &items) override;
|
||||
MessagesBarData listMessagesBar(
|
||||
const std::vector<not_null<Element*>> &elements) override;
|
||||
void listContentRefreshed() override;
|
||||
void listUpdateDateLink(
|
||||
ClickHandlerPtr &link,
|
||||
not_null<Element*> view) override;
|
||||
bool listElementHideReply(not_null<const Element*> view) override;
|
||||
bool listElementShownUnread(not_null<const Element*> view) override;
|
||||
bool listIsGoodForAroundPosition(not_null<const Element*> view) override;
|
||||
void listSendBotCommand(
|
||||
const QString &command,
|
||||
const FullMsgId &context) override;
|
||||
void listHandleViaClick(not_null<UserData*> bot) override;
|
||||
not_null<Ui::ChatTheme*> listChatTheme() override;
|
||||
CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override;
|
||||
CopyRestrictionType listCopyMediaRestrictionType(
|
||||
not_null<HistoryItem*> item) override;
|
||||
CopyRestrictionType listSelectRestrictionType() override;
|
||||
auto listAllowedReactionsValue()
|
||||
-> rpl::producer<Data::AllowedReactions> override;
|
||||
void listShowPremiumToast(not_null<DocumentData*> document) override;
|
||||
void listOpenPhoto(
|
||||
not_null<PhotoData*> photo,
|
||||
FullMsgId context) override;
|
||||
void listOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView) override;
|
||||
void listPaintEmpty(
|
||||
Painter &p,
|
||||
const Ui::ChatPaintContext &context) override;
|
||||
QString listElementAuthorRank(not_null<const Element*> view) override;
|
||||
History *listTranslateHistory() override;
|
||||
void listAddTranslatedItems(
|
||||
not_null<TranslateTracker*> tracker) override;
|
||||
|
||||
// CornerButtonsDelegate delegate.
|
||||
void cornerButtonsShowAtPosition(
|
||||
Data::MessagePosition position) override;
|
||||
Data::Thread *cornerButtonsThread() override;
|
||||
FullMsgId cornerButtonsCurrentId() override;
|
||||
bool cornerButtonsIgnoreVisibility() override;
|
||||
std::optional<bool> cornerButtonsDownShown() override;
|
||||
bool cornerButtonsUnreadMayBeShown() override;
|
||||
bool cornerButtonsHas(CornerButtonType type) override;
|
||||
|
||||
private:
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
void showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) override;
|
||||
void showFinishedHook() override;
|
||||
void doSetInnerFocus() override;
|
||||
void checkActivation() override;
|
||||
|
||||
void onScroll();
|
||||
void updateInnerVisibleArea();
|
||||
void updateControlsGeometry();
|
||||
void updateAdaptiveLayout();
|
||||
void saveState(not_null<SublistMemento*> memento);
|
||||
void restoreState(not_null<SublistMemento*> memento);
|
||||
void showAtPosition(
|
||||
Data::MessagePosition position,
|
||||
FullMsgId originId = {});
|
||||
|
||||
void setupOpenChatButton();
|
||||
void setupTranslateBar();
|
||||
|
||||
void confirmDeleteSelected();
|
||||
void confirmForwardSelected();
|
||||
void clearSelected();
|
||||
void recountChatWidth();
|
||||
|
||||
const not_null<Data::SavedSublist*> _sublist;
|
||||
const not_null<History*> _history;
|
||||
std::shared_ptr<Ui::ChatTheme> _theme;
|
||||
QPointer<ListWidget> _inner;
|
||||
object_ptr<TopBarWidget> _topBar;
|
||||
object_ptr<Ui::PlainShadow> _topBarShadow;
|
||||
|
||||
std::unique_ptr<TranslateBar> _translateBar;
|
||||
int _translateBarHeight = 0;
|
||||
|
||||
bool _skipScrollEvent = false;
|
||||
std::unique_ptr<Ui::ScrollArea> _scroll;
|
||||
std::unique_ptr<Ui::FlatButton> _openChatButton;
|
||||
|
||||
CornerButtons _cornerButtons;
|
||||
|
||||
};
|
||||
|
||||
class SublistMemento : public Window::SectionMemento {
|
||||
public:
|
||||
explicit SublistMemento(not_null<Data::SavedSublist*> sublist);
|
||||
|
||||
object_ptr<Window::SectionWidget> createWidget(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Window::Column column,
|
||||
const QRect &geometry) override;
|
||||
|
||||
[[nodiscard]] not_null<Data::SavedSublist*> getSublist() const {
|
||||
return _sublist;
|
||||
}
|
||||
|
||||
[[nodiscard]] not_null<ListMemento*> list() {
|
||||
return &_list;
|
||||
}
|
||||
|
||||
private:
|
||||
const not_null<Data::SavedSublist*> _sublist;
|
||||
ListMemento _list;
|
||||
|
||||
};
|
||||
|
||||
} // namespace HistoryView
|
|
@ -469,6 +469,7 @@ void TopBarWidget::paintTopBar(Painter &p) {
|
|||
const auto now = crl::now();
|
||||
const auto history = _activeChat.key.owningHistory();
|
||||
const auto folder = _activeChat.key.folder();
|
||||
const auto sublist = _activeChat.key.sublist();
|
||||
const auto topic = _activeChat.key.topic();
|
||||
if (topic && _activeChat.section == Section::Replies) {
|
||||
p.setPen(st::dialogsNameFg);
|
||||
|
@ -491,8 +492,9 @@ void TopBarWidget::paintTopBar(Painter &p) {
|
|||
p.setPen(st::historyStatusFg);
|
||||
p.drawTextLeft(nameleft, statustop, width(), _customTitleText);
|
||||
}
|
||||
} else if (sublist) {
|
||||
} else if (folder
|
||||
|| history->peer->sharedMediaInfo()
|
||||
|| (history && history->peer->sharedMediaInfo())
|
||||
|| (_activeChat.section == Section::Scheduled)
|
||||
|| (_activeChat.section == Section::Pinned)) {
|
||||
auto text = (_activeChat.section == Section::Scheduled)
|
||||
|
@ -689,6 +691,10 @@ void TopBarWidget::infoClicked() {
|
|||
return;
|
||||
} else if (const auto topic = key.topic()) {
|
||||
_controller->showSection(std::make_shared<Info::Memento>(topic));
|
||||
} else if (const auto sublist = key.sublist()) {
|
||||
_controller->showSection(std::make_shared<Info::Memento>(
|
||||
_controller->session().user(),
|
||||
Info::Section(Storage::SharedMediaType::Photo)));
|
||||
} else if (key.peer()->savedSublistsInfo()) {
|
||||
_controller->showSection(std::make_shared<Info::Memento>(
|
||||
key.peer(),
|
||||
|
|
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "dialogs/dialogs_inner_widget.h"
|
||||
#include "history/view/history_view_sublist_section.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "info/info_memento.h"
|
||||
#include "main/main_session.h"
|
||||
|
@ -48,6 +49,14 @@ SublistsWidget::SublistsWidget(
|
|||
_inner->showSavedSublists();
|
||||
_inner->setNarrowRatio(0.);
|
||||
|
||||
_inner->chosenRow() | rpl::start_with_next([=](Dialogs::ChosenRow row) {
|
||||
if (const auto sublist = row.key.sublist()) {
|
||||
controller->showSection(
|
||||
std::make_shared<HistoryView::SublistMemento>(sublist),
|
||||
Window::SectionShow::Way::Forward);
|
||||
}
|
||||
}, _inner->lifetime());
|
||||
|
||||
const auto saved = &controller->session().data().savedMessages();
|
||||
_inner->heightValue() | rpl::start_with_next([=] {
|
||||
if (!saved->supported()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue