init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
This commit is contained in:
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
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 "info/common_groups/info_common_groups_inner_widget.h"
|
||||
|
||||
#include "base/weak_ptr.h"
|
||||
#include "info/common_groups/info_common_groups_widget.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "mtproto/sender.h"
|
||||
#include "main/main_session.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/search_field_controller.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/data_session.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
||||
namespace Info {
|
||||
namespace CommonGroups {
|
||||
namespace {
|
||||
|
||||
constexpr auto kCommonGroupsPerPage = 40;
|
||||
constexpr auto kCommonGroupsSearchAfter = 20;
|
||||
|
||||
class ListController final
|
||||
: public PeerListController
|
||||
, public base::has_weak_ptr {
|
||||
public:
|
||||
ListController(
|
||||
not_null<Controller*> controller,
|
||||
not_null<UserData*> user);
|
||||
|
||||
Main::Session &session() const override;
|
||||
void prepare() override;
|
||||
void rowClicked(not_null<PeerListRow*> row) override;
|
||||
void loadMoreRows() override;
|
||||
|
||||
std::unique_ptr<PeerListRow> createRestoredRow(
|
||||
not_null<PeerData*> peer) override {
|
||||
return createRow(peer);
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListState> saveState() const override;
|
||||
void restoreState(std::unique_ptr<PeerListState> state) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<PeerListRow> createRow(not_null<PeerData*> peer);
|
||||
|
||||
struct SavedState : SavedStateBase {
|
||||
PeerId preloadGroupId = 0;
|
||||
bool allLoaded = false;
|
||||
bool wasLoading = false;
|
||||
};
|
||||
const not_null<Controller*> _controller;
|
||||
MTP::Sender _api;
|
||||
not_null<UserData*> _user;
|
||||
mtpRequestId _preloadRequestId = 0;
|
||||
bool _allLoaded = false;
|
||||
PeerId _preloadGroupId = 0;
|
||||
|
||||
};
|
||||
|
||||
ListController::ListController(
|
||||
not_null<Controller*> controller,
|
||||
not_null<UserData*> user)
|
||||
: PeerListController()
|
||||
, _controller(controller)
|
||||
, _api(&_controller->session().mtp())
|
||||
, _user(user) {
|
||||
_controller->setSearchEnabledByContent(false);
|
||||
}
|
||||
|
||||
Main::Session &ListController::session() const {
|
||||
return _user->session();
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListRow> ListController::createRow(
|
||||
not_null<PeerData*> peer) {
|
||||
auto result = std::make_unique<PeerListRow>(peer);
|
||||
result->setCustomStatus(QString());
|
||||
return result;
|
||||
}
|
||||
|
||||
void ListController::prepare() {
|
||||
setSearchNoResultsText(tr::lng_bot_groups_not_found(tr::now));
|
||||
delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled);
|
||||
delegate()->peerListSetTitle(tr::lng_profile_common_groups_section());
|
||||
}
|
||||
|
||||
void ListController::loadMoreRows() {
|
||||
if (_preloadRequestId || _allLoaded) {
|
||||
return;
|
||||
}
|
||||
_preloadRequestId = _api.request(MTPmessages_GetCommonChats(
|
||||
_user->inputUser(),
|
||||
MTP_long(peerIsChat(_preloadGroupId)
|
||||
? peerToChat(_preloadGroupId).bare
|
||||
: peerToChannel(_preloadGroupId).bare),
|
||||
MTP_int(kCommonGroupsPerPage)
|
||||
)).done([this](const MTPmessages_Chats &result) {
|
||||
_preloadRequestId = 0;
|
||||
_preloadGroupId = 0;
|
||||
_allLoaded = true;
|
||||
const auto &chats = result.match([](const auto &data) {
|
||||
return data.vchats().v;
|
||||
});
|
||||
if (!chats.empty()) {
|
||||
auto add = std::vector<not_null<PeerData*>>();
|
||||
auto allLoaded = _allLoaded;
|
||||
auto preloadGroupId = _preloadGroupId;
|
||||
const auto owner = &_user->owner();
|
||||
const auto weak = base::make_weak(this);
|
||||
for (const auto &chat : chats) {
|
||||
if (const auto peer = owner->processChat(chat)) {
|
||||
if (!peer->migrateTo()) {
|
||||
add.push_back(peer);
|
||||
}
|
||||
preloadGroupId = peer->id;
|
||||
allLoaded = false;
|
||||
}
|
||||
}
|
||||
if (!weak) {
|
||||
return;
|
||||
}
|
||||
for (const auto &peer : add) {
|
||||
if (!delegate()->peerListFindRow(peer->id.value)) {
|
||||
delegate()->peerListAppendRow(createRow(peer));
|
||||
}
|
||||
}
|
||||
_preloadGroupId = preloadGroupId;
|
||||
_allLoaded = allLoaded;
|
||||
delegate()->peerListRefreshRows();
|
||||
}
|
||||
auto fullCount = delegate()->peerListFullRowsCount();
|
||||
if (fullCount > kCommonGroupsSearchAfter) {
|
||||
_controller->setSearchEnabledByContent(true);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListState> ListController::saveState() const {
|
||||
auto result = PeerListController::saveState();
|
||||
auto my = std::make_unique<SavedState>();
|
||||
my->preloadGroupId = _preloadGroupId;
|
||||
my->allLoaded = _allLoaded;
|
||||
my->wasLoading = (_preloadRequestId != 0);
|
||||
result->controllerState = std::move(my);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ListController::restoreState(
|
||||
std::unique_ptr<PeerListState> state) {
|
||||
auto typeErasedState = state
|
||||
? state->controllerState.get()
|
||||
: nullptr;
|
||||
if (auto my = dynamic_cast<SavedState*>(typeErasedState)) {
|
||||
if (auto requestId = base::take(_preloadRequestId)) {
|
||||
_api.request(requestId).cancel();
|
||||
}
|
||||
_allLoaded = my->allLoaded;
|
||||
_preloadGroupId = my->preloadGroupId;
|
||||
if (my->wasLoading) {
|
||||
loadMoreRows();
|
||||
}
|
||||
PeerListController::restoreState(std::move(state));
|
||||
auto fullCount = delegate()->peerListFullRowsCount();
|
||||
if (fullCount > kCommonGroupsSearchAfter) {
|
||||
_controller->setSearchEnabledByContent(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ListController::rowClicked(not_null<PeerListRow*> row) {
|
||||
const auto peer = row->peer();
|
||||
const auto controller = _controller->parentController();
|
||||
if (const auto forum = peer->forum()) {
|
||||
controller->showForum(forum);
|
||||
} else {
|
||||
controller->showPeerHistory(
|
||||
peer,
|
||||
Window::SectionShow::Way::Forward);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
InnerWidget::InnerWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<UserData*> user)
|
||||
: RpWidget(parent)
|
||||
, _show(controller->uiShow())
|
||||
, _controller(controller)
|
||||
, _user(user)
|
||||
, _listController(std::make_unique<ListController>(controller, _user))
|
||||
, _list(setupList(this, _listController.get())) {
|
||||
setContent(_list.data());
|
||||
_listController->setDelegate(static_cast<PeerListDelegate*>(this));
|
||||
|
||||
_controller->searchFieldController()->queryValue(
|
||||
) | rpl::on_next([this](QString &&query) {
|
||||
peerListScrollToTop();
|
||||
content()->searchQueryChanged(std::move(query));
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void InnerWidget::visibleTopBottomUpdated(
|
||||
int visibleTop,
|
||||
int visibleBottom) {
|
||||
setChildVisibleTopBottom(_list, visibleTop, visibleBottom);
|
||||
}
|
||||
|
||||
void InnerWidget::saveState(not_null<Memento*> memento) {
|
||||
memento->setListState(_listController->saveState());
|
||||
}
|
||||
|
||||
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
||||
_listController->restoreState(memento->listState());
|
||||
}
|
||||
|
||||
rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const {
|
||||
return _scrollToRequests.events();
|
||||
}
|
||||
|
||||
int InnerWidget::desiredHeight() const {
|
||||
auto desired = 0;
|
||||
auto count = qMax(_user->commonChatsCount(), 1);
|
||||
desired += qMax(count, _list->fullRowsCount())
|
||||
* st::infoCommonGroupsList.item.height;
|
||||
return qMax(height(), desired);
|
||||
}
|
||||
|
||||
object_ptr<InnerWidget::ListWidget> InnerWidget::setupList(
|
||||
RpWidget *parent,
|
||||
not_null<PeerListController*> controller) const {
|
||||
controller->setStyleOverrides(&st::infoCommonGroupsList);
|
||||
auto result = object_ptr<ListWidget>(
|
||||
parent,
|
||||
controller);
|
||||
result->scrollToRequests(
|
||||
) | rpl::on_next([this](Ui::ScrollToRequest request) {
|
||||
auto addmin = (request.ymin < 0)
|
||||
? 0
|
||||
: st::infoCommonGroupsMargin.top();
|
||||
auto addmax = (request.ymax < 0)
|
||||
? 0
|
||||
: st::infoCommonGroupsMargin.top();
|
||||
_scrollToRequests.fire({
|
||||
request.ymin + addmin,
|
||||
request.ymax + addmax });
|
||||
}, result->lifetime());
|
||||
result->moveToLeft(0, st::infoCommonGroupsMargin.top());
|
||||
parent->widthValue(
|
||||
) | rpl::on_next([list = result.data()](int newWidth) {
|
||||
list->resizeToWidth(newWidth);
|
||||
}, result->lifetime());
|
||||
result->heightValue(
|
||||
) | rpl::on_next([parent](int listHeight) {
|
||||
auto newHeight = st::infoCommonGroupsMargin.top()
|
||||
+ listHeight
|
||||
+ st::infoCommonGroupsMargin.bottom();
|
||||
parent->resize(parent->width(), newHeight);
|
||||
}, result->lifetime());
|
||||
return result;
|
||||
}
|
||||
|
||||
void InnerWidget::peerListSetTitle(rpl::producer<QString> title) {
|
||||
}
|
||||
|
||||
void InnerWidget::peerListSetAdditionalTitle(rpl::producer<QString> title) {
|
||||
}
|
||||
|
||||
bool InnerWidget::peerListIsRowChecked(not_null<PeerListRow*> row) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int InnerWidget::peerListSelectedRowsCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InnerWidget::peerListScrollToTop() {
|
||||
_scrollToRequests.fire({ -1, -1 });
|
||||
}
|
||||
|
||||
void InnerWidget::peerListAddSelectedPeerInBunch(not_null<PeerData*> peer) {
|
||||
Unexpected("Item selection in Info::Profile::Members.");
|
||||
}
|
||||
|
||||
void InnerWidget::peerListAddSelectedRowInBunch(not_null<PeerListRow*> row) {
|
||||
Unexpected("Item selection in Info::Profile::Members.");
|
||||
}
|
||||
|
||||
void InnerWidget::peerListFinishSelectedRowsBunch() {
|
||||
}
|
||||
|
||||
void InnerWidget::peerListSetDescription(
|
||||
object_ptr<Ui::FlatLabel> description) {
|
||||
description.destroy();
|
||||
}
|
||||
|
||||
std::shared_ptr<Main::SessionShow> InnerWidget::peerListUiShow() {
|
||||
return _show;
|
||||
}
|
||||
|
||||
} // namespace CommonGroups
|
||||
} // namespace Info
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
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 <rpl/producer.h>
|
||||
#include "ui/rp_widget.h"
|
||||
#include "boxes/peer_list_box.h"
|
||||
|
||||
namespace Ui {
|
||||
class Show;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Info {
|
||||
|
||||
class Controller;
|
||||
|
||||
namespace CommonGroups {
|
||||
|
||||
class Memento;
|
||||
|
||||
class InnerWidget final
|
||||
: public Ui::RpWidget
|
||||
, private PeerListContentDelegate {
|
||||
public:
|
||||
InnerWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<UserData*> user);
|
||||
|
||||
not_null<UserData*> user() const {
|
||||
return _user;
|
||||
}
|
||||
|
||||
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const;
|
||||
|
||||
int desiredHeight() const;
|
||||
|
||||
void saveState(not_null<Memento*> memento);
|
||||
void restoreState(not_null<Memento*> memento);
|
||||
|
||||
protected:
|
||||
void visibleTopBottomUpdated(
|
||||
int visibleTop,
|
||||
int visibleBottom) override;
|
||||
|
||||
private:
|
||||
using ListWidget = PeerListContent;
|
||||
|
||||
// PeerListContentDelegate interface.
|
||||
void peerListSetTitle(rpl::producer<QString> title) override;
|
||||
void peerListSetAdditionalTitle(rpl::producer<QString> title) override;
|
||||
bool peerListIsRowChecked(not_null<PeerListRow*> row) override;
|
||||
int peerListSelectedRowsCount() override;
|
||||
void peerListScrollToTop() override;
|
||||
void peerListAddSelectedPeerInBunch(
|
||||
not_null<PeerData*> peer) override;
|
||||
void peerListAddSelectedRowInBunch(
|
||||
not_null<PeerListRow*> row) override;
|
||||
void peerListFinishSelectedRowsBunch() override;
|
||||
void peerListSetDescription(
|
||||
object_ptr<Ui::FlatLabel> description) override;
|
||||
std::shared_ptr<Main::SessionShow> peerListUiShow() override;
|
||||
|
||||
object_ptr<ListWidget> setupList(
|
||||
RpWidget *parent,
|
||||
not_null<PeerListController*> controller) const;
|
||||
|
||||
std::shared_ptr<Main::SessionShow> _show;
|
||||
not_null<Controller*> _controller;
|
||||
not_null<UserData*> _user;
|
||||
std::unique_ptr<PeerListController> _listController;
|
||||
object_ptr<ListWidget> _list;
|
||||
|
||||
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
|
||||
|
||||
};
|
||||
|
||||
} // namespace CommonGroups
|
||||
} // namespace Info
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
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 "info/common_groups/info_common_groups_widget.h"
|
||||
|
||||
#include "info/common_groups/info_common_groups_inner_widget.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/data_session.h"
|
||||
#include "main/main_session.h"
|
||||
#include "styles/style_info.h"
|
||||
|
||||
namespace Info {
|
||||
namespace CommonGroups {
|
||||
|
||||
Memento::Memento(not_null<UserData*> user)
|
||||
: ContentMemento(user, nullptr, nullptr, PeerId()) {
|
||||
}
|
||||
|
||||
Section Memento::section() const {
|
||||
return Section(Section::Type::CommonGroups);
|
||||
}
|
||||
|
||||
not_null<UserData*> Memento::user() const {
|
||||
return peer()->asUser();
|
||||
}
|
||||
|
||||
object_ptr<ContentWidget> Memento::createWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
const QRect &geometry) {
|
||||
auto result = object_ptr<Widget>(parent, controller, user());
|
||||
result->setInternalState(geometry, this);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Memento::setListState(std::unique_ptr<PeerListState> state) {
|
||||
_listState = std::move(state);
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListState> Memento::listState() {
|
||||
return std::move(_listState);
|
||||
}
|
||||
|
||||
Memento::~Memento() = default;
|
||||
|
||||
Widget::Widget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<UserData*> user)
|
||||
: ContentWidget(parent, controller) {
|
||||
_inner = setInnerWidget(object_ptr<InnerWidget>(
|
||||
this,
|
||||
controller,
|
||||
user));
|
||||
}
|
||||
|
||||
rpl::producer<QString> Widget::title() {
|
||||
return tr::lng_profile_common_groups_section();
|
||||
}
|
||||
|
||||
not_null<UserData*> Widget::user() const {
|
||||
return _inner->user();
|
||||
}
|
||||
|
||||
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
||||
if (!controller()->validateMementoPeer(memento)) {
|
||||
return false;
|
||||
}
|
||||
if (auto groupsMemento = dynamic_cast<Memento*>(memento.get())) {
|
||||
if (groupsMemento->user() == user()) {
|
||||
restoreState(groupsMemento);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Widget::setInternalState(
|
||||
const QRect &geometry,
|
||||
not_null<Memento*> memento) {
|
||||
setGeometry(geometry);
|
||||
Ui::SendPendingMoveResizeEvents(this);
|
||||
restoreState(memento);
|
||||
}
|
||||
|
||||
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
||||
auto result = std::make_shared<Memento>(user());
|
||||
saveState(result.get());
|
||||
return result;
|
||||
}
|
||||
|
||||
void Widget::saveState(not_null<Memento*> memento) {
|
||||
memento->setScrollTop(scrollTopSave());
|
||||
_inner->saveState(memento);
|
||||
}
|
||||
|
||||
void Widget::restoreState(not_null<Memento*> memento) {
|
||||
_inner->restoreState(memento);
|
||||
scrollTopRestore(memento->scrollTop());
|
||||
}
|
||||
|
||||
} // namespace CommonGroups
|
||||
} // namespace Info
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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 <rpl/producer.h>
|
||||
#include "info/info_content_widget.h"
|
||||
|
||||
struct PeerListState;
|
||||
|
||||
namespace Ui {
|
||||
class SearchFieldController;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Info {
|
||||
namespace CommonGroups {
|
||||
|
||||
class InnerWidget;
|
||||
|
||||
class Memento final : public ContentMemento {
|
||||
public:
|
||||
explicit Memento(not_null<UserData*> user);
|
||||
|
||||
object_ptr<ContentWidget> createWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
const QRect &geometry) override;
|
||||
|
||||
Section section() const override;
|
||||
|
||||
not_null<UserData*> user() const;
|
||||
|
||||
void setListState(std::unique_ptr<PeerListState> state);
|
||||
std::unique_ptr<PeerListState> listState();
|
||||
|
||||
~Memento();
|
||||
|
||||
private:
|
||||
std::unique_ptr<PeerListState> _listState;
|
||||
|
||||
};
|
||||
|
||||
class Widget final : public ContentWidget {
|
||||
public:
|
||||
Widget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<UserData*> user);
|
||||
|
||||
not_null<UserData*> user() const;
|
||||
|
||||
bool showInternal(
|
||||
not_null<ContentMemento*> memento) override;
|
||||
|
||||
void setInternalState(
|
||||
const QRect &geometry,
|
||||
not_null<Memento*> memento);
|
||||
|
||||
rpl::producer<QString> title() override;
|
||||
|
||||
private:
|
||||
void saveState(not_null<Memento*> memento);
|
||||
void restoreState(not_null<Memento*> memento);
|
||||
|
||||
std::shared_ptr<ContentMemento> doCreateMemento() override;
|
||||
|
||||
InnerWidget *_inner = nullptr;
|
||||
|
||||
};
|
||||
|
||||
} // namespace CommonGroups
|
||||
} // namespace Info
|
||||
|
||||
Reference in New Issue
Block a user