2017-09-13 17:01:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-09-13 17:01:23 +00:00
|
|
|
*/
|
2017-09-24 15:46:37 +00:00
|
|
|
#include "info/profile/info_profile_widget.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2023-06-20 15:31:40 +00:00
|
|
|
#include "dialogs/ui/dialogs_stories_content.h"
|
2017-09-24 15:46:37 +00:00
|
|
|
#include "info/profile/info_profile_inner_widget.h"
|
2017-11-17 13:23:36 +00:00
|
|
|
#include "info/profile/info_profile_members.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2022-04-04 06:36:45 +00:00
|
|
|
#include "data/data_peer.h"
|
|
|
|
#include "data/data_channel.h"
|
2022-10-12 12:57:17 +00:00
|
|
|
#include "data/data_forum_topic.h"
|
2022-04-04 06:36:45 +00:00
|
|
|
#include "data/data_user.h"
|
|
|
|
#include "lang/lang_keys.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
#include "info/info_controller.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2022-09-27 12:05:47 +00:00
|
|
|
namespace Info::Profile {
|
2017-09-15 17:34:41 +00:00
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
Memento::Memento(not_null<Controller*> controller)
|
|
|
|
: Memento(
|
2020-06-08 09:06:50 +00:00
|
|
|
controller->peer(),
|
2022-10-12 12:57:17 +00:00
|
|
|
controller->topic(),
|
2024-02-01 13:29:53 +00:00
|
|
|
controller->migratedPeerId(),
|
|
|
|
{ v::null }) {
|
2017-10-31 18:25:22 +00:00
|
|
|
}
|
|
|
|
|
2024-02-01 13:29:53 +00:00
|
|
|
Memento::Memento(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
PeerId migratedPeerId,
|
|
|
|
Origin origin)
|
|
|
|
: Memento(peer, nullptr, migratedPeerId, origin) {
|
2022-10-12 12:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Memento::Memento(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Data::ForumTopic *topic,
|
2024-02-01 13:29:53 +00:00
|
|
|
PeerId migratedPeerId,
|
|
|
|
Origin origin)
|
|
|
|
: ContentMemento(peer, topic, migratedPeerId)
|
|
|
|
, _origin(origin) {
|
2018-01-22 19:51:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 12:05:47 +00:00
|
|
|
Memento::Memento(not_null<Data::ForumTopic*> topic)
|
2022-10-12 12:57:17 +00:00
|
|
|
: ContentMemento(topic->channel(), topic, 0) {
|
2022-09-27 12:05:47 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
Section Memento::section() const {
|
|
|
|
return Section(Section::Type::Profile);
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
object_ptr<ContentWidget> Memento::createWidget(
|
|
|
|
QWidget *parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<Controller*> controller,
|
2017-09-13 17:01:23 +00:00
|
|
|
const QRect &geometry) {
|
2024-02-01 13:29:53 +00:00
|
|
|
auto result = object_ptr<Widget>(parent, controller, _origin);
|
2017-09-13 17:01:23 +00:00
|
|
|
result->setInternalState(geometry, this);
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 13:23:36 +00:00
|
|
|
void Memento::setMembersState(std::unique_ptr<MembersState> state) {
|
|
|
|
_membersState = std::move(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<MembersState> Memento::membersState() {
|
|
|
|
return std::move(_membersState);
|
|
|
|
}
|
|
|
|
|
|
|
|
Memento::~Memento() = default;
|
|
|
|
|
2024-02-01 13:29:53 +00:00
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Controller*> controller,
|
|
|
|
Origin origin)
|
2017-10-31 18:25:22 +00:00
|
|
|
: ContentWidget(parent, controller) {
|
2017-11-17 13:23:36 +00:00
|
|
|
controller->setSearchEnabledByContent(false);
|
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
_inner = setInnerWidget(object_ptr<InnerWidget>(
|
|
|
|
this,
|
2024-02-01 13:29:53 +00:00
|
|
|
controller,
|
|
|
|
origin));
|
2017-09-13 17:01:23 +00:00
|
|
|
_inner->move(0, 0);
|
2017-12-22 07:05:20 +00:00
|
|
|
_inner->scrollToRequests(
|
|
|
|
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
|
|
|
if (request.ymin < 0) {
|
|
|
|
scrollTopRestore(
|
|
|
|
qMin(scrollTopSave(), request.ymax));
|
|
|
|
} else {
|
|
|
|
scrollTo(request);
|
|
|
|
}
|
|
|
|
}, lifetime());
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setInnerFocus() {
|
|
|
|
_inner->setFocus();
|
|
|
|
}
|
|
|
|
|
2022-04-04 06:36:45 +00:00
|
|
|
rpl::producer<QString> Widget::title() {
|
2022-09-27 12:05:47 +00:00
|
|
|
if (const auto topic = controller()->key().topic()) {
|
2022-10-14 13:25:05 +00:00
|
|
|
return tr::lng_info_topic_title();
|
2022-09-27 12:05:47 +00:00
|
|
|
}
|
2022-04-04 06:36:45 +00:00
|
|
|
const auto peer = controller()->key().peer();
|
|
|
|
if (const auto user = peer->asUser()) {
|
|
|
|
return (user->isBot() && !user->isSupport())
|
|
|
|
? tr::lng_info_bot_title()
|
|
|
|
: tr::lng_info_user_title();
|
|
|
|
} else if (const auto channel = peer->asChannel()) {
|
|
|
|
return channel->isMegagroup()
|
|
|
|
? tr::lng_info_group_title()
|
|
|
|
: tr::lng_info_channel_title();
|
|
|
|
} else if (peer->isChat()) {
|
|
|
|
return tr::lng_info_group_title();
|
|
|
|
}
|
|
|
|
Unexpected("Bad peer type in Info::TitleValue()");
|
2023-06-20 15:31:40 +00:00
|
|
|
}
|
2022-04-04 06:36:45 +00:00
|
|
|
|
2023-06-20 15:31:40 +00:00
|
|
|
rpl::producer<Dialogs::Stories::Content> Widget::titleStories() {
|
|
|
|
const auto peer = controller()->key().peer();
|
2023-09-01 11:20:55 +00:00
|
|
|
if (peer && !peer->isChat()) {
|
|
|
|
return Dialogs::Stories::LastForPeer(peer);
|
2023-06-20 15:31:40 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
2022-04-04 06:36:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
2017-10-31 18:25:22 +00:00
|
|
|
if (!controller()->validateMementoPeer(memento)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
if (auto profileMemento = dynamic_cast<Memento*>(memento.get())) {
|
2017-10-31 18:25:22 +00:00
|
|
|
restoreState(profileMemento);
|
|
|
|
return true;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-17 13:23:36 +00:00
|
|
|
void Widget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<Memento*> memento) {
|
2017-09-13 17:01:23 +00:00
|
|
|
setGeometry(geometry);
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
2017-09-13 17:01:23 +00:00
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
2020-12-14 14:48:10 +00:00
|
|
|
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
|
|
|
auto result = std::make_shared<Memento>(controller());
|
2017-09-13 17:01:23 +00:00
|
|
|
saveState(result.get());
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2022-09-27 12:05:47 +00:00
|
|
|
} // namespace Info::Profile
|