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_inner_widget.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-09-18 16:39:45 +00:00
|
|
|
#include <rpl/combine.h>
|
2017-10-20 17:54:51 +00:00
|
|
|
#include <rpl/combine_previous.h>
|
2017-09-26 19:42:58 +00:00
|
|
|
#include <rpl/flatten_latest.h>
|
2017-10-03 17:41:44 +00:00
|
|
|
#include "info/info_memento.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
#include "info/info_controller.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
#include "info/profile/info_profile_widget.h"
|
|
|
|
#include "info/profile/info_profile_text.h"
|
|
|
|
#include "info/profile/info_profile_values.h"
|
|
|
|
#include "info/profile/info_profile_cover.h"
|
|
|
|
#include "info/profile/info_profile_icon.h"
|
2017-09-25 16:06:53 +00:00
|
|
|
#include "info/profile/info_profile_members.h"
|
2017-11-07 11:53:05 +00:00
|
|
|
#include "info/profile/info_profile_actions.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "info/media/info_media_buttons.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2017-09-20 10:23:57 +00:00
|
|
|
#include "boxes/add_contact_box.h"
|
2017-09-26 19:42:58 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "mainwidget.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2017-09-26 19:42:58 +00:00
|
|
|
#include "apiwrap.h"
|
2017-10-03 13:05:58 +00:00
|
|
|
#include "window/main_window.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-09-21 19:21:33 +00:00
|
|
|
#include "storage/storage_shared_media.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "styles/style_info.h"
|
2017-09-26 19:42:58 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/checkbox.h"
|
2017-09-26 17:57:01 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/widgets/box_content_divider.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2017-11-06 07:31:18 +00:00
|
|
|
#include "data/data_shared_media.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Profile {
|
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
InnerWidget::InnerWidget(
|
|
|
|
QWidget *parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<Controller*> controller)
|
2017-09-13 17:01:23 +00:00
|
|
|
: RpWidget(parent)
|
2017-09-15 17:34:41 +00:00
|
|
|
, _controller(controller)
|
2018-01-22 19:51:38 +00:00
|
|
|
, _peer(_controller->key().peer())
|
2017-10-31 18:25:22 +00:00
|
|
|
, _migrated(_controller->migrated())
|
|
|
|
, _content(setupContent(this)) {
|
2017-12-22 07:05:20 +00:00
|
|
|
_content->heightValue(
|
|
|
|
) | rpl::start_with_next([this](int height) {
|
|
|
|
if (!_inResize) {
|
|
|
|
resizeToWidth(width());
|
|
|
|
updateDesiredHeight();
|
|
|
|
}
|
|
|
|
}, lifetime());
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
bool InnerWidget::canHideDetailsEver() const {
|
2017-11-16 09:13:17 +00:00
|
|
|
return false;// (_peer->isChat() || _peer->isMegagroup());
|
2017-09-21 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> InnerWidget::canHideDetails() const {
|
|
|
|
using namespace rpl::mappers;
|
2017-09-25 09:02:55 +00:00
|
|
|
return MembersCountValue(_peer)
|
2017-11-20 12:32:55 +00:00
|
|
|
| rpl::map(_1 > 0);
|
2017-09-21 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 09:02:55 +00:00
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupContent(
|
2017-11-07 11:53:05 +00:00
|
|
|
not_null<RpWidget*> parent) {
|
2017-09-25 09:02:55 +00:00
|
|
|
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
2017-10-03 17:41:44 +00:00
|
|
|
_cover = result->add(object_ptr<Cover>(
|
2017-09-25 09:02:55 +00:00
|
|
|
result,
|
2018-09-05 19:39:35 +00:00
|
|
|
_peer,
|
|
|
|
_controller->parentController()));
|
|
|
|
_cover->showSection(
|
|
|
|
) | rpl::start_with_next([=](Section section) {
|
2020-11-21 22:37:05 +00:00
|
|
|
_controller->showSection(
|
2020-12-14 14:48:10 +00:00
|
|
|
std::make_shared<Info::Memento>(_peer, section));
|
2018-09-05 19:39:35 +00:00
|
|
|
}, _cover->lifetime());
|
2017-10-03 17:41:44 +00:00
|
|
|
_cover->setOnlineCount(rpl::single(0));
|
2017-11-07 11:53:05 +00:00
|
|
|
auto details = SetupDetails(_controller, parent, _peer);
|
2017-09-21 19:21:33 +00:00
|
|
|
if (canHideDetailsEver()) {
|
2017-10-03 17:41:44 +00:00
|
|
|
_cover->setToggleShown(canHideDetails());
|
|
|
|
_infoWrap = result->add(object_ptr<Ui::SlideWrap<>>(
|
2017-09-25 09:02:55 +00:00
|
|
|
result,
|
2017-09-21 19:21:33 +00:00
|
|
|
std::move(details))
|
2017-11-19 11:37:15 +00:00
|
|
|
)->setDuration(
|
|
|
|
st::infoSlideDuration
|
|
|
|
)->toggleOn(
|
|
|
|
_cover->toggledValue()
|
|
|
|
);
|
2017-09-13 17:01:23 +00:00
|
|
|
} else {
|
2017-09-25 09:02:55 +00:00
|
|
|
result->add(std::move(details));
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
2017-11-07 11:53:05 +00:00
|
|
|
result->add(setupSharedMedia(result.data()));
|
2017-11-10 19:19:43 +00:00
|
|
|
if (auto members = SetupChannelMembers(_controller, result.data(), _peer)) {
|
|
|
|
result->add(std::move(members));
|
|
|
|
}
|
2019-09-18 11:19:05 +00:00
|
|
|
result->add(object_ptr<Ui::BoxContentDivider>(result));
|
2017-11-07 11:53:05 +00:00
|
|
|
if (auto actions = SetupActions(_controller, result.data(), _peer)) {
|
|
|
|
result->add(std::move(actions));
|
2017-09-21 19:21:33 +00:00
|
|
|
}
|
2017-11-07 11:53:05 +00:00
|
|
|
|
2017-09-25 16:06:53 +00:00
|
|
|
if (_peer->isChat() || _peer->isMegagroup()) {
|
2017-09-26 17:57:01 +00:00
|
|
|
_members = result->add(object_ptr<Members>(
|
2017-09-25 16:06:53 +00:00
|
|
|
result,
|
2018-01-22 19:51:38 +00:00
|
|
|
_controller));
|
2017-12-22 07:05:20 +00:00
|
|
|
_members->scrollToRequests(
|
|
|
|
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
|
|
|
auto min = (request.ymin < 0)
|
|
|
|
? request.ymin
|
|
|
|
: mapFromGlobal(_members->mapToGlobal({ 0, request.ymin })).y();
|
|
|
|
auto max = (request.ymin < 0)
|
|
|
|
? mapFromGlobal(_members->mapToGlobal({ 0, 0 })).y()
|
|
|
|
: (request.ymax < 0)
|
|
|
|
? request.ymax
|
|
|
|
: mapFromGlobal(_members->mapToGlobal({ 0, request.ymax })).y();
|
|
|
|
_scrollToRequests.fire({ min, max });
|
|
|
|
}, _members->lifetime());
|
2017-10-22 12:07:57 +00:00
|
|
|
_cover->setOnlineCount(_members->onlineCountValue());
|
2017-09-25 16:06:53 +00:00
|
|
|
}
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
|
2017-11-07 11:53:05 +00:00
|
|
|
not_null<RpWidget*> parent) {
|
2017-09-21 19:21:33 +00:00
|
|
|
using namespace rpl::mappers;
|
2017-10-04 12:39:59 +00:00
|
|
|
using MediaType = Media::Type;
|
2017-09-21 19:21:33 +00:00
|
|
|
|
|
|
|
auto content = object_ptr<Ui::VerticalLayout>(parent);
|
2017-10-04 12:39:59 +00:00
|
|
|
auto tracker = Ui::MultiSlideTracker();
|
2017-10-20 17:54:51 +00:00
|
|
|
auto addMediaButton = [&](
|
|
|
|
MediaType type,
|
|
|
|
const style::icon &icon) {
|
|
|
|
auto result = Media::AddButton(
|
2017-10-04 12:39:59 +00:00
|
|
|
content,
|
2017-12-04 07:33:33 +00:00
|
|
|
_controller,
|
2017-10-31 18:25:22 +00:00
|
|
|
_peer,
|
|
|
|
_migrated,
|
2017-10-04 12:39:59 +00:00
|
|
|
type,
|
|
|
|
tracker);
|
2017-10-20 17:54:51 +00:00
|
|
|
object_ptr<Profile::FloatingIcon>(
|
|
|
|
result,
|
|
|
|
icon,
|
|
|
|
st::infoSharedMediaButtonIconPosition);
|
2017-09-21 19:21:33 +00:00
|
|
|
};
|
2017-10-20 17:54:51 +00:00
|
|
|
auto addCommonGroupsButton = [&](
|
|
|
|
not_null<UserData*> user,
|
|
|
|
const style::icon &icon) {
|
|
|
|
auto result = Media::AddCommonGroupsButton(
|
2017-10-04 12:39:59 +00:00
|
|
|
content,
|
2017-12-04 07:33:33 +00:00
|
|
|
_controller,
|
2017-10-04 12:39:59 +00:00
|
|
|
user,
|
|
|
|
tracker);
|
2017-10-20 17:54:51 +00:00
|
|
|
object_ptr<Profile::FloatingIcon>(
|
|
|
|
result,
|
|
|
|
icon,
|
|
|
|
st::infoSharedMediaButtonIconPosition);
|
2017-09-21 19:21:33 +00:00
|
|
|
};
|
2017-10-04 12:39:59 +00:00
|
|
|
|
2017-10-20 17:54:51 +00:00
|
|
|
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);
|
2020-05-04 12:50:46 +00:00
|
|
|
addMediaButton(MediaType::RoundVoiceFile, st::infoIconMediaVoice);
|
2020-08-23 19:42:28 +00:00
|
|
|
addMediaButton(MediaType::GIF, st::infoIconMediaGif);
|
2017-10-31 18:25:22 +00:00
|
|
|
if (auto user = _peer->asUser()) {
|
2017-10-20 17:54:51 +00:00
|
|
|
addCommonGroupsButton(user, st::infoIconMediaGroup);
|
2017-09-21 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
parent,
|
|
|
|
object_ptr<Ui::VerticalLayout>(parent)
|
|
|
|
);
|
2017-10-20 17:54:51 +00:00
|
|
|
|
2017-11-16 09:13:17 +00:00
|
|
|
// Allows removing shared media links in third column.
|
|
|
|
// Was done for tabs support.
|
|
|
|
//
|
|
|
|
//using ToggledData = std::tuple<bool, Wrap, bool>;
|
|
|
|
//rpl::combine(
|
|
|
|
// tracker.atLeastOneShownValue(),
|
|
|
|
// _controller->wrapValue(),
|
2017-12-22 07:05:20 +00:00
|
|
|
// _isStackBottom.value()
|
|
|
|
//) | rpl::combine_previous(
|
|
|
|
// ToggledData()
|
|
|
|
//) | rpl::start_with_next([wrap = result.data()](
|
|
|
|
// const ToggledData &was,
|
|
|
|
// const ToggledData &now) {
|
|
|
|
// bool wasOneShown, wasStackBottom, nowOneShown, nowStackBottom;
|
|
|
|
// Wrap wasWrap, nowWrap;
|
|
|
|
// std::tie(wasOneShown, wasWrap, wasStackBottom) = was;
|
|
|
|
// std::tie(nowOneShown, nowWrap, nowStackBottom) = now;
|
|
|
|
// // MSVC Internal Compiler Error
|
|
|
|
// //auto [wasOneShown, wasWrap, wasStackBottom] = was;
|
|
|
|
// //auto [nowOneShown, nowWrap, nowStackBottom] = now;
|
|
|
|
// wrap->toggle(
|
|
|
|
// nowOneShown && (nowWrap != Wrap::Side || !nowStackBottom),
|
|
|
|
// (wasStackBottom == nowStackBottom && wasWrap == nowWrap)
|
|
|
|
// ? anim::type::normal
|
|
|
|
// : anim::type::instant);
|
|
|
|
//}, result->lifetime());
|
2017-11-16 09:13:17 +00:00
|
|
|
//
|
|
|
|
// Using that instead
|
2017-11-19 11:37:15 +00:00
|
|
|
result->setDuration(
|
|
|
|
st::infoSlideDuration
|
|
|
|
)->toggleOn(
|
|
|
|
tracker.atLeastOneShownValue()
|
|
|
|
);
|
2017-10-20 17:54:51 +00:00
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
auto layout = result->entity();
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
layout->add(object_ptr<Ui::BoxContentDivider>(layout));
|
2017-09-21 19:21:33 +00:00
|
|
|
layout->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
layout,
|
|
|
|
st::infoSharedMediaBottomSkip)
|
|
|
|
)->setAttribute(Qt::WA_TransparentForMouseEvents);
|
2017-10-20 17:54:51 +00:00
|
|
|
layout->add(std::move(content));
|
|
|
|
layout->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
layout,
|
|
|
|
st::infoSharedMediaBottomSkip)
|
|
|
|
)->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
|
|
|
_sharedMediaWrap = result;
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-21 19:21:33 +00:00
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-09-26 17:57:01 +00:00
|
|
|
int InnerWidget::countDesiredHeight() const {
|
|
|
|
return _content->height() + (_members
|
|
|
|
? (_members->desiredHeight() - _members->height())
|
|
|
|
: 0);
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
void InnerWidget::visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
2017-09-25 16:06:53 +00:00
|
|
|
setChildVisibleTopBottom(_content, visibleTop, visibleBottom);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::saveState(not_null<Memento*> memento) {
|
2017-10-03 17:41:44 +00:00
|
|
|
memento->setInfoExpanded(_cover->toggled());
|
2017-10-24 17:11:35 +00:00
|
|
|
if (_members) {
|
2017-11-17 13:23:36 +00:00
|
|
|
memento->setMembersState(_members->saveState());
|
2017-10-24 17:11:35 +00:00
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
2017-11-12 17:46:20 +00:00
|
|
|
_cover->toggle(memento->infoExpanded(), anim::type::instant);
|
2017-10-24 17:11:35 +00:00
|
|
|
if (_members) {
|
2017-11-17 13:23:36 +00:00
|
|
|
_members->restoreState(memento->membersState());
|
2017-10-24 17:11:35 +00:00
|
|
|
}
|
2017-10-03 17:41:44 +00:00
|
|
|
if (_infoWrap) {
|
|
|
|
_infoWrap->finishAnimating();
|
|
|
|
}
|
|
|
|
if (_sharedMediaWrap) {
|
|
|
|
_sharedMediaWrap->finishAnimating();
|
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const {
|
|
|
|
return _scrollToRequests.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<int> InnerWidget::desiredHeightValue() const {
|
|
|
|
return _desiredHeight.events_starting_with(countDesiredHeight());
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
int InnerWidget::resizeGetHeight(int newWidth) {
|
2017-11-16 07:45:55 +00:00
|
|
|
_inResize = true;
|
|
|
|
auto guard = gsl::finally([&] { _inResize = false; });
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
_content->resizeToWidth(newWidth);
|
2017-09-21 10:28:34 +00:00
|
|
|
_content->moveToLeft(0, 0);
|
2017-11-16 07:45:55 +00:00
|
|
|
updateDesiredHeight();
|
2017-10-03 17:41:44 +00:00
|
|
|
return _content->heightNoMargins();
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Profile
|
|
|
|
} // namespace Info
|