mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 15:04:57 +00:00
456 lines
12 KiB
C++
456 lines
12 KiB
C++
/*
|
|
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/profile/info_profile_inner_widget.h"
|
|
|
|
#include "info/info_controller.h"
|
|
#include "info/info_memento.h"
|
|
#include "info/profile/info_profile_widget.h"
|
|
#include "info/profile/info_profile_icon.h"
|
|
#include "info/profile/info_profile_members.h"
|
|
#include "info/profile/info_profile_music_button.h"
|
|
#include "info/profile/info_profile_top_bar.h"
|
|
#include "info/profile/info_profile_actions.h"
|
|
#include "info/media/info_media_buttons.h"
|
|
#include "info/saved/info_saved_music_widget.h"
|
|
#include "data/data_changes.h"
|
|
#include "data/data_channel.h"
|
|
#include "data/data_document.h"
|
|
#include "data/data_forum_topic.h"
|
|
#include "data/data_peer.h"
|
|
#include "data/data_photo.h"
|
|
#include "data/data_file_origin.h"
|
|
#include "data/data_user.h"
|
|
#include "data/data_saved_music.h"
|
|
#include "data/data_saved_sublist.h"
|
|
#include "info_profile_actions.h"
|
|
#include "main/main_session.h"
|
|
#include "apiwrap.h"
|
|
#include "api/api_peer_photo.h"
|
|
#include "lang/lang_keys.h"
|
|
#include "ui/text/format_song_document_name.h"
|
|
#include "ui/widgets/buttons.h"
|
|
#include "ui/widgets/checkbox.h"
|
|
#include "ui/widgets/scroll_area.h"
|
|
#include "ui/widgets/shadow.h"
|
|
#include "ui/wrap/fade_wrap.h"
|
|
#include "ui/wrap/vertical_layout.h"
|
|
#include "ui/wrap/slide_wrap.h"
|
|
#include "ui/vertical_list.h"
|
|
#include "ui/ui_utility.h"
|
|
#include "styles/style_info.h"
|
|
|
|
namespace Info {
|
|
namespace Profile {
|
|
|
|
namespace {
|
|
|
|
[[nodiscard]] MusicButtonData DocumentMusicButtonData(
|
|
not_null<DocumentData*> document) {
|
|
return { Ui::Text::FormatSongNameFor(document) };
|
|
}
|
|
|
|
void AddAboutVerification(
|
|
not_null<Ui::VerticalLayout*> layout,
|
|
not_null<PeerData*> peer) {
|
|
const auto inner = layout->add(object_ptr<Ui::VerticalLayout>(layout));
|
|
peer->session().changes().peerFlagsValue(
|
|
peer,
|
|
Data::PeerUpdate::Flag::VerifyInfo
|
|
) | rpl::start_with_next([=] {
|
|
const auto info = peer->botVerifyDetails();
|
|
while (inner->count()) {
|
|
delete inner->widgetAt(0);
|
|
}
|
|
if (!info) {
|
|
Ui::AddDivider(inner);
|
|
} else if (!info->description.empty()) {
|
|
Ui::AddDividerText(inner, rpl::single(info->description));
|
|
}
|
|
inner->resizeToWidth(inner->width());
|
|
}, inner->lifetime());
|
|
}
|
|
|
|
} // namespace
|
|
|
|
InnerWidget::InnerWidget(
|
|
QWidget *parent,
|
|
not_null<Controller*> controller,
|
|
Origin origin)
|
|
: RpWidget(parent)
|
|
, _controller(controller)
|
|
, _peer(_controller->key().peer())
|
|
, _migrated(_controller->migrated())
|
|
, _topic(_controller->key().topic())
|
|
, _sublist(_controller->key().sublist())
|
|
, _content(setupContent(this, origin)) {
|
|
_content->heightValue(
|
|
) | rpl::start_with_next([this](int height) {
|
|
if (!_inResize) {
|
|
resizeToWidth(width());
|
|
updateDesiredHeight();
|
|
}
|
|
}, lifetime());
|
|
}
|
|
|
|
rpl::producer<> InnerWidget::backRequest() const {
|
|
return _backClicks.events();
|
|
}
|
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupContent(
|
|
not_null<RpWidget*> parent,
|
|
Origin origin) {
|
|
if (const auto user = _peer->asUser()) {
|
|
user->session().changes().peerFlagsValue(
|
|
user,
|
|
Data::PeerUpdate::Flag::FullInfo
|
|
) | rpl::start_with_next([=] {
|
|
auto &photos = user->session().api().peerPhoto();
|
|
if (const auto original = photos.nonPersonalPhoto(user)) {
|
|
// Preload it for the edit contact box.
|
|
_nonPersonalView = original->createMediaView();
|
|
const auto id = peerToUser(user->id);
|
|
original->load(Data::FileOriginFullUser{ id });
|
|
}
|
|
}, lifetime());
|
|
}
|
|
|
|
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
|
setupSavedMusic(result);
|
|
if (_topic && _topic->creating()) {
|
|
return result;
|
|
}
|
|
|
|
AddDetails(result, _controller, _peer, _topic, _sublist, origin);
|
|
result->add(setupSharedMedia(result.data()));
|
|
if (_topic || _sublist) {
|
|
return result;
|
|
}
|
|
{
|
|
auto buttons = SetupChannelMembersAndManage(
|
|
_controller,
|
|
result.data(),
|
|
_peer);
|
|
if (buttons) {
|
|
result->add(std::move(buttons));
|
|
}
|
|
}
|
|
if (auto actions = SetupActions(_controller, result.data(), _peer)) {
|
|
addAboutVerificationOrDivider(result);
|
|
result->add(std::move(actions));
|
|
}
|
|
if (_peer->isChat() || _peer->isMegagroup()) {
|
|
if (!_peer->isMonoforum()) {
|
|
setupMembers(result.data());
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void InnerWidget::setupMembers(not_null<Ui::VerticalLayout*> container) {
|
|
auto wrap = container->add(object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
container,
|
|
object_ptr<Ui::VerticalLayout>(container)));
|
|
const auto inner = wrap->entity();
|
|
addAboutVerificationOrDivider(inner);
|
|
_members = inner->add(object_ptr<Members>(inner, _controller));
|
|
_members->scrollToRequests(
|
|
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
|
auto min = (request.ymin < 0)
|
|
? request.ymin
|
|
: MapFrom(this, _members, QPoint(0, request.ymin)).y();
|
|
auto max = (request.ymin < 0)
|
|
? MapFrom(this, _members, QPoint()).y()
|
|
: (request.ymax < 0)
|
|
? request.ymax
|
|
: MapFrom(this, _members, QPoint(0, request.ymax)).y();
|
|
_scrollToRequests.fire({ min, max });
|
|
}, _members->lifetime());
|
|
_members->onlineCountValue(
|
|
) | rpl::start_with_next([=](int count) {
|
|
_onlineCount.fire_copy(count);
|
|
}, _members->lifetime());
|
|
|
|
using namespace rpl::mappers;
|
|
wrap->toggleOn(
|
|
_members->fullCountValue() | rpl::map(_1 > 0),
|
|
anim::type::instant);
|
|
}
|
|
|
|
void InnerWidget::setupSavedMusic(not_null<Ui::VerticalLayout*> container) {
|
|
auto musicValue = Data::SavedMusic::Supported(_peer->id)
|
|
? Data::SavedMusicList(
|
|
_peer,
|
|
nullptr,
|
|
1
|
|
) | rpl::map([=](const Data::SavedMusicSlice &data) {
|
|
return data.size() ? data[0].get() : nullptr;
|
|
}) | rpl::type_erased()
|
|
: rpl::single<HistoryItem*>((HistoryItem*)(nullptr));
|
|
|
|
const auto divider = container->add(
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
container,
|
|
object_ptr<Ui::VerticalLayout>(container)));
|
|
|
|
rpl::combine(
|
|
std::move(musicValue),
|
|
_topBarColor.value()
|
|
) | rpl::start_with_next([=](
|
|
HistoryItem *item,
|
|
std::optional<QColor> color) {
|
|
while (divider->entity()->count()) {
|
|
delete divider->entity()->widgetAt(0);
|
|
}
|
|
if (item) {
|
|
if (const auto document = item->media()
|
|
? item->media()->document()
|
|
: nullptr) {
|
|
const auto music = divider->entity()->add(
|
|
object_ptr<MusicButton>(
|
|
divider->entity(),
|
|
DocumentMusicButtonData(document),
|
|
[window = _controller, peer = _peer] {
|
|
window->showSection(Info::Saved::MakeMusic(peer));
|
|
}));
|
|
music->setOverrideBg(color);
|
|
}
|
|
divider->toggle(true, anim::type::normal);
|
|
}
|
|
}, lifetime());
|
|
divider->finishAnimating();
|
|
}
|
|
|
|
void InnerWidget::addAboutVerificationOrDivider(
|
|
not_null<Ui::VerticalLayout*> content) {
|
|
if (_aboutVerificationAdded) {
|
|
Ui::AddDivider(content);
|
|
} else {
|
|
AddAboutVerification(content, _peer);
|
|
_aboutVerificationAdded = true;
|
|
}
|
|
}
|
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
|
|
not_null<RpWidget*> parent) {
|
|
using namespace rpl::mappers;
|
|
using MediaType = Media::Type;
|
|
|
|
auto content = object_ptr<Ui::VerticalLayout>(parent);
|
|
auto tracker = Ui::MultiSlideTracker();
|
|
auto addMediaButton = [&](
|
|
MediaType type,
|
|
const style::icon &icon) {
|
|
auto result = Media::AddButton(
|
|
content,
|
|
_controller,
|
|
_peer,
|
|
_topic ? _topic->rootId() : MsgId(),
|
|
_sublist ? _sublist->sublistPeer()->id : PeerId(),
|
|
_migrated,
|
|
type,
|
|
tracker);
|
|
object_ptr<Profile::FloatingIcon>(
|
|
result,
|
|
icon,
|
|
st::infoSharedMediaButtonIconPosition);
|
|
};
|
|
auto addCommonGroupsButton = [&](
|
|
not_null<UserData*> user,
|
|
const style::icon &icon) {
|
|
auto result = Media::AddCommonGroupsButton(
|
|
content,
|
|
_controller,
|
|
user,
|
|
tracker);
|
|
object_ptr<Profile::FloatingIcon>(
|
|
result,
|
|
icon,
|
|
st::infoSharedMediaButtonIconPosition);
|
|
};
|
|
const auto addSimilarPeersButton = [&](
|
|
not_null<PeerData*> peer,
|
|
const style::icon &icon) {
|
|
auto result = Media::AddSimilarPeersButton(
|
|
content,
|
|
_controller,
|
|
peer,
|
|
tracker);
|
|
object_ptr<Profile::FloatingIcon>(
|
|
result,
|
|
icon,
|
|
st::infoSharedMediaButtonIconPosition);
|
|
};
|
|
auto addStoriesButton = [&](
|
|
not_null<PeerData*> peer,
|
|
const style::icon &icon) {
|
|
if (peer->isChat()) {
|
|
return;
|
|
}
|
|
auto result = Media::AddStoriesButton(
|
|
content,
|
|
_controller,
|
|
peer,
|
|
tracker);
|
|
object_ptr<Profile::FloatingIcon>(
|
|
result,
|
|
icon,
|
|
st::infoSharedMediaButtonIconPosition);
|
|
};
|
|
auto addSavedSublistButton = [&](
|
|
not_null<PeerData*> peer,
|
|
const style::icon &icon) {
|
|
auto result = Media::AddSavedSublistButton(
|
|
content,
|
|
_controller,
|
|
peer,
|
|
tracker);
|
|
object_ptr<Profile::FloatingIcon>(
|
|
result,
|
|
icon,
|
|
st::infoSharedMediaButtonIconPosition);
|
|
};
|
|
auto addPeerGiftsButton = [&](
|
|
not_null<PeerData*> peer,
|
|
const style::icon &icon) {
|
|
auto result = Media::AddPeerGiftsButton(
|
|
content,
|
|
_controller,
|
|
peer,
|
|
tracker);
|
|
object_ptr<Profile::FloatingIcon>(
|
|
result,
|
|
icon,
|
|
st::infoSharedMediaButtonIconPosition);
|
|
};
|
|
|
|
if (!_topic) {
|
|
addStoriesButton(_peer, st::infoIconMediaStories);
|
|
addPeerGiftsButton(_peer, st::infoIconMediaGifts);
|
|
addSavedSublistButton(_peer, st::infoIconMediaSaved);
|
|
}
|
|
addMediaButton(MediaType::Photo, st::infoIconMediaPhoto);
|
|
addMediaButton(MediaType::Video, st::infoIconMediaVideo);
|
|
addMediaButton(MediaType::File, st::infoIconMediaFile);
|
|
addMediaButton(MediaType::MusicFile, st::infoIconMediaAudio);
|
|
addMediaButton(MediaType::Link, st::infoIconMediaLink);
|
|
addMediaButton(MediaType::RoundVoiceFile, st::infoIconMediaVoice);
|
|
addMediaButton(MediaType::GIF, st::infoIconMediaGif);
|
|
if (const auto bot = _peer->asBot()) {
|
|
addCommonGroupsButton(bot, st::infoIconMediaGroup);
|
|
addSimilarPeersButton(bot, st::infoIconMediaBot);
|
|
} else if (const auto channel = _peer->asBroadcast()) {
|
|
addSimilarPeersButton(channel, st::infoIconMediaChannel);
|
|
} else if (const auto user = _peer->asUser()) {
|
|
addCommonGroupsButton(user, st::infoIconMediaGroup);
|
|
}
|
|
|
|
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
parent,
|
|
object_ptr<Ui::VerticalLayout>(parent)
|
|
);
|
|
|
|
result->setDuration(
|
|
st::infoSlideDuration
|
|
)->toggleOn(
|
|
tracker.atLeastOneShownValue()
|
|
);
|
|
|
|
auto layout = result->entity();
|
|
|
|
addAboutVerificationOrDivider(layout);
|
|
Ui::AddSkip(layout, st::infoSharedMediaBottomSkip);
|
|
layout->add(std::move(content));
|
|
Ui::AddSkip(layout, st::infoSharedMediaBottomSkip);
|
|
|
|
_sharedMediaWrap = result;
|
|
return result;
|
|
}
|
|
|
|
int InnerWidget::countDesiredHeight() const {
|
|
return _content->height() + (_members
|
|
? (_members->desiredHeight() - _members->height())
|
|
: 0);
|
|
}
|
|
|
|
void InnerWidget::visibleTopBottomUpdated(
|
|
int visibleTop,
|
|
int visibleBottom) {
|
|
setChildVisibleTopBottom(_content, visibleTop, visibleBottom);
|
|
}
|
|
|
|
void InnerWidget::saveState(not_null<Memento*> memento) {
|
|
if (_members) {
|
|
memento->setMembersState(_members->saveState());
|
|
}
|
|
}
|
|
|
|
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
|
if (_members) {
|
|
_members->restoreState(memento->membersState());
|
|
}
|
|
if (_sharedMediaWrap) {
|
|
_sharedMediaWrap->finishAnimating();
|
|
}
|
|
}
|
|
|
|
rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const {
|
|
return _scrollToRequests.events();
|
|
}
|
|
|
|
rpl::producer<int> InnerWidget::desiredHeightValue() const {
|
|
return _desiredHeight.events_starting_with(countDesiredHeight());
|
|
}
|
|
|
|
int InnerWidget::resizeGetHeight(int newWidth) {
|
|
_inResize = true;
|
|
auto guard = gsl::finally([&] { _inResize = false; });
|
|
|
|
_content->resizeToWidth(newWidth);
|
|
_content->moveToLeft(0, 0);
|
|
updateDesiredHeight();
|
|
return _content->heightNoMargins();
|
|
}
|
|
|
|
void InnerWidget::enableBackButton() {
|
|
_backToggles.force_assign(true);
|
|
}
|
|
|
|
void InnerWidget::showFinished() {
|
|
_showFinished.fire({});
|
|
}
|
|
|
|
bool InnerWidget::hasFlexibleTopBar() const {
|
|
return true;
|
|
}
|
|
|
|
base::weak_qptr<Ui::RpWidget> InnerWidget::createPinnedToTop(
|
|
not_null<Ui::RpWidget*> parent) {
|
|
const auto content = Ui::CreateChild<TopBar>(
|
|
parent,
|
|
TopBar::Descriptor{
|
|
.controller = _controller->parentController(),
|
|
.key = _controller->key(),
|
|
.wrap = _controller->wrapValue(),
|
|
.backToggles = _backToggles.value(),
|
|
.showFinished = _showFinished.events(),
|
|
});
|
|
content->backRequest(
|
|
) | rpl::start_to_stream(_backClicks, content->lifetime());
|
|
content->setOnlineCount(_onlineCount.events());
|
|
_topBarColor = content->edgeColor();
|
|
return base::make_weak(not_null<Ui::RpWidget*>{ content });
|
|
}
|
|
|
|
base::weak_qptr<Ui::RpWidget> InnerWidget::createPinnedToBottom(
|
|
not_null<Ui::RpWidget*> parent) {
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace Profile
|
|
} // namespace Info
|