2017-09-13 17:01:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
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"
|
|
|
|
#include "info/info_top_bar_override.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
#include "info/profile/info_profile_button.h"
|
|
|
|
#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-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"
|
2017-09-26 19:42:58 +00:00
|
|
|
#include "auth_session.h"
|
|
|
|
#include "apiwrap.h"
|
2017-10-03 13:05:58 +00:00
|
|
|
#include "window/main_window.h"
|
2017-09-15 17:34:41 +00:00
|
|
|
#include "window/window_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"
|
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-26 18:55:53 +00:00
|
|
|
#include "profile/profile_common_groups_section.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)
|
2017-10-31 18:25:22 +00:00
|
|
|
, _peer(_controller->peer())
|
|
|
|
, _migrated(_controller->migrated())
|
|
|
|
, _content(setupContent(this)) {
|
2017-09-25 09:02:55 +00:00
|
|
|
_content->heightValue()
|
2017-09-27 08:43:35 +00:00
|
|
|
| rpl::start_with_next([this](int height) {
|
2017-10-03 17:41:44 +00:00
|
|
|
resizeToWidth(width());
|
2017-09-26 17:57:01 +00:00
|
|
|
_desiredHeight.fire(countDesiredHeight());
|
2017-09-25 09:02:55 +00:00
|
|
|
}, lifetime());
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
bool InnerWidget::canHideDetailsEver() const {
|
|
|
|
return (_peer->isChat() || _peer->isMegagroup());
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> InnerWidget::canHideDetails() const {
|
|
|
|
using namespace rpl::mappers;
|
2017-09-25 09:02:55 +00:00
|
|
|
return MembersCountValue(_peer)
|
2017-09-21 19:21:33 +00:00
|
|
|
| rpl::map($1 > 0);
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:02:55 +00:00
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupContent(
|
2017-10-31 18:25:22 +00:00
|
|
|
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,
|
2017-10-03 17:41:44 +00:00
|
|
|
_peer));
|
|
|
|
_cover->setOnlineCount(rpl::single(0));
|
2017-09-25 09:02:55 +00:00
|
|
|
auto details = setupDetails(parent);
|
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-10-03 17:41:44 +00:00
|
|
|
)->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-10-31 18:25:22 +00:00
|
|
|
result->add(setupSharedMedia(result));
|
2017-09-25 09:02:55 +00:00
|
|
|
result->add(object_ptr<BoxContentDivider>(result));
|
2017-09-21 19:21:33 +00:00
|
|
|
if (auto user = _peer->asUser()) {
|
2017-09-25 09:02:55 +00:00
|
|
|
result->add(setupUserActions(result, user));
|
|
|
|
//} else if (auto channel = _peer->asChannel()) {
|
|
|
|
// if (!channel->isMegagroup()) {
|
|
|
|
// setupChannelActions(result, channel);
|
|
|
|
// }
|
2017-09-21 19:21:33 +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,
|
2017-09-26 17:57:01 +00:00
|
|
|
_controller,
|
|
|
|
_peer)
|
|
|
|
);
|
|
|
|
_members->scrollToRequests()
|
2017-09-27 08:43:35 +00:00
|
|
|
| rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
2017-09-26 17:57:01 +00:00
|
|
|
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
|
|
|
}
|
2017-09-25 09:02:55 +00:00
|
|
|
return std::move(result);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupDetails(
|
2017-09-13 17:01:23 +00:00
|
|
|
RpWidget *parent) const {
|
|
|
|
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
|
|
|
result->add(object_ptr<BoxContentDivider>(result));
|
2017-09-21 10:28:34 +00:00
|
|
|
result->add(createSkipWidget(result));
|
2017-09-21 19:21:33 +00:00
|
|
|
result->add(setupInfo(result));
|
2017-09-13 17:01:23 +00:00
|
|
|
result->add(setupMuteToggle(result));
|
|
|
|
if (auto user = _peer->asUser()) {
|
2017-09-21 19:21:33 +00:00
|
|
|
setupUserButtons(result, user);
|
|
|
|
//} else if (auto channel = _peer->asChannel()) {
|
|
|
|
// if (!channel->isMegagroup()) {
|
|
|
|
// setupChannelButtons(result, channel);
|
|
|
|
// }
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
2017-09-21 10:28:34 +00:00
|
|
|
result->add(createSkipWidget(result));
|
2017-09-18 17:04:45 +00:00
|
|
|
return std::move(result);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupInfo(
|
2017-09-13 17:01:23 +00:00
|
|
|
RpWidget *parent) const {
|
|
|
|
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
2017-10-04 12:39:59 +00:00
|
|
|
auto tracker = Ui::MultiSlideTracker();
|
2017-09-21 19:21:33 +00:00
|
|
|
auto addInfoLine = [&](
|
|
|
|
LangKey label,
|
|
|
|
rpl::producer<TextWithEntities> &&text,
|
|
|
|
bool selectByDoubleClick = false,
|
|
|
|
const style::FlatLabel &textSt = st::infoLabeled) {
|
2017-09-25 09:02:55 +00:00
|
|
|
auto line = result->add(CreateTextWithLabel(
|
2017-09-21 19:21:33 +00:00
|
|
|
result,
|
|
|
|
Lang::Viewer(label) | WithEmptyEntities(),
|
|
|
|
std::move(text),
|
|
|
|
textSt,
|
|
|
|
st::infoProfileLabeledPadding,
|
|
|
|
selectByDoubleClick));
|
|
|
|
tracker.track(line);
|
|
|
|
return line;
|
|
|
|
};
|
|
|
|
auto addInfoOneLine = [&](
|
|
|
|
LangKey label,
|
|
|
|
rpl::producer<TextWithEntities> &&text) {
|
|
|
|
addInfoLine(
|
|
|
|
label,
|
|
|
|
std::move(text),
|
|
|
|
true,
|
|
|
|
st::infoLabeledOneLine);
|
|
|
|
};
|
|
|
|
if (auto user = _peer->asUser()) {
|
2017-09-25 09:02:55 +00:00
|
|
|
addInfoOneLine(lng_info_mobile_label, PhoneValue(user));
|
|
|
|
addInfoLine(lng_info_bio_label, BioValue(user));
|
|
|
|
addInfoOneLine(lng_info_username_label, UsernameValue(user));
|
2017-09-21 19:21:33 +00:00
|
|
|
} else {
|
2017-09-25 09:02:55 +00:00
|
|
|
addInfoOneLine(lng_info_link_label, LinkValue(_peer));
|
|
|
|
addInfoLine(lng_info_about_label, AboutValue(_peer));
|
2017-09-21 19:21:33 +00:00
|
|
|
}
|
|
|
|
result->add(object_ptr<Ui::SlideWrap<>>(
|
|
|
|
result,
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::PlainShadow>(result),
|
2017-09-21 19:21:33 +00:00
|
|
|
st::infoProfileSeparatorPadding)
|
|
|
|
)->toggleOn(std::move(tracker).atLeastOneShownValue());
|
|
|
|
object_ptr<FloatingIcon>(
|
2017-09-13 17:01:23 +00:00
|
|
|
result,
|
2017-09-21 19:21:33 +00:00
|
|
|
st::infoIconInformation,
|
|
|
|
st::infoInformationIconPosition);
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupMuteToggle(
|
|
|
|
RpWidget *parent) const {
|
|
|
|
auto result = object_ptr<Button>(
|
|
|
|
parent,
|
2017-09-13 17:01:23 +00:00
|
|
|
Lang::Viewer(lng_profile_enable_notifications),
|
2017-09-21 19:21:33 +00:00
|
|
|
st::infoNotificationsButton);
|
|
|
|
result->toggleOn(
|
2017-09-25 09:02:55 +00:00
|
|
|
NotificationsEnabledValue(_peer)
|
2017-10-03 14:57:11 +00:00
|
|
|
)->addClickHandler([this] {
|
|
|
|
App::main()->updateNotifySetting(
|
|
|
|
_peer,
|
|
|
|
_peer->isMuted()
|
|
|
|
? NotifySettingSetNotify
|
|
|
|
: NotifySettingSetMuted);
|
|
|
|
});
|
2017-09-13 17:01:23 +00:00
|
|
|
object_ptr<FloatingIcon>(
|
|
|
|
result,
|
2017-09-21 10:28:34 +00:00
|
|
|
st::infoIconNotifications,
|
|
|
|
st::infoNotificationsIconPosition);
|
2017-09-18 17:04:45 +00:00
|
|
|
return std::move(result);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
void InnerWidget::setupUserButtons(
|
2017-09-13 17:01:23 +00:00
|
|
|
Ui::VerticalLayout *wrap,
|
|
|
|
not_null<UserData*> user) const {
|
2017-09-21 19:21:33 +00:00
|
|
|
using namespace rpl::mappers;
|
2017-10-04 12:39:59 +00:00
|
|
|
auto tracker = Ui::MultiSlideTracker();
|
2017-09-21 10:28:34 +00:00
|
|
|
auto topSkip = wrap->add(createSlideSkipWidget(wrap));
|
2017-09-27 12:04:19 +00:00
|
|
|
auto addButton = [&](auto &&text) {
|
2017-09-21 10:28:34 +00:00
|
|
|
auto result = wrap->add(object_ptr<Ui::SlideWrap<Button>>(
|
2017-09-20 18:40:23 +00:00
|
|
|
wrap,
|
2017-09-21 10:28:34 +00:00
|
|
|
object_ptr<Button>(
|
|
|
|
wrap,
|
|
|
|
std::move(text),
|
|
|
|
st::infoMainButton)));
|
|
|
|
tracker.track(result);
|
|
|
|
return result;
|
|
|
|
};
|
2017-09-21 19:21:33 +00:00
|
|
|
addButton(
|
|
|
|
Lang::Viewer(lng_profile_send_message) | ToUpperValue()
|
|
|
|
)->toggleOn(
|
2017-10-31 18:25:22 +00:00
|
|
|
_controller->window()->historyPeer.value()
|
2017-09-21 19:21:33 +00:00
|
|
|
| rpl::map($1 != user)
|
2017-10-03 14:57:11 +00:00
|
|
|
)->entity()->addClickHandler([this, user] {
|
2017-10-31 18:25:22 +00:00
|
|
|
_controller->window()->showPeerHistory(
|
2017-10-03 14:57:11 +00:00
|
|
|
user,
|
|
|
|
Window::SectionShow::Way::Forward);
|
|
|
|
});
|
2017-09-21 19:21:33 +00:00
|
|
|
|
|
|
|
addButton(
|
|
|
|
Lang::Viewer(lng_info_add_as_contact) | ToUpperValue()
|
|
|
|
)->toggleOn(
|
2017-09-25 09:02:55 +00:00
|
|
|
CanAddContactValue(user)
|
2017-10-03 14:57:11 +00:00
|
|
|
)->entity()->addClickHandler([user] {
|
|
|
|
auto firstName = user->firstName;
|
|
|
|
auto lastName = user->lastName;
|
|
|
|
auto phone = user->phone().isEmpty()
|
|
|
|
? App::phoneFromSharedContact(user->bareId())
|
|
|
|
: user->phone();
|
|
|
|
Ui::show(Box<AddContactBox>(firstName, lastName, phone));
|
|
|
|
});
|
2017-09-21 10:28:34 +00:00
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
topSkip->toggleOn(std::move(tracker).atLeastOneShownValue());
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
|
2017-10-31 18:25:22 +00:00
|
|
|
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-10-31 18:25:22 +00:00
|
|
|
_controller->window(),
|
|
|
|
_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-10-31 18:25:22 +00:00
|
|
|
_controller->window(),
|
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);
|
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
|
|
|
}
|
2017-10-20 17:54:51 +00:00
|
|
|
addMediaButton(MediaType::VoiceFile, st::infoIconMediaVoice);
|
|
|
|
// addMediaButton(MediaType::RoundFile, st::infoIconMediaRound);
|
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
|
|
|
|
|
|
|
using ToggledData = std::tuple<bool, Wrap, bool>;
|
|
|
|
rpl::combine(
|
|
|
|
tracker.atLeastOneShownValue(),
|
2017-10-31 18:25:22 +00:00
|
|
|
_controller->wrapValue(),
|
2017-10-20 17:54:51 +00:00
|
|
|
_isStackBottom.events())
|
|
|
|
| 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),
|
|
|
|
(wasOneShown == nowOneShown && wasWrap == nowWrap)
|
|
|
|
? anim::type::normal
|
|
|
|
: anim::type::instant);
|
|
|
|
}, result->lifetime());
|
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
auto layout = result->entity();
|
|
|
|
|
2017-10-04 12:39:59 +00:00
|
|
|
layout->add(object_ptr<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;
|
2017-09-21 19:21:33 +00:00
|
|
|
return std::move(result);
|
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::setupUserActions(
|
|
|
|
RpWidget *parent,
|
|
|
|
not_null<UserData*> user) const {
|
|
|
|
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
2017-09-26 19:42:58 +00:00
|
|
|
result->add(createSkipWidget(result));
|
|
|
|
auto addButton = [&](
|
2017-09-27 12:04:19 +00:00
|
|
|
auto &&text,
|
|
|
|
auto &&toggleOn,
|
2017-09-26 19:42:58 +00:00
|
|
|
auto &&callback,
|
|
|
|
const style::InfoProfileButton &st
|
|
|
|
= st::infoSharedMediaButton) {
|
|
|
|
return result->add(object_ptr<Ui::SlideWrap<Button>>(
|
2017-09-21 19:21:33 +00:00
|
|
|
result,
|
|
|
|
object_ptr<Button>(
|
|
|
|
result,
|
|
|
|
std::move(text),
|
2017-09-26 19:42:58 +00:00
|
|
|
st))
|
|
|
|
)->toggleOn(
|
|
|
|
std::move(toggleOn)
|
2017-10-03 14:57:11 +00:00
|
|
|
)->entity()->addClickHandler(std::move(callback));
|
2017-09-21 19:21:33 +00:00
|
|
|
};
|
2017-09-26 19:42:58 +00:00
|
|
|
|
|
|
|
addButton(
|
|
|
|
Lang::Viewer(lng_profile_share_contact),
|
|
|
|
CanShareContactValue(user),
|
2017-10-20 16:19:42 +00:00
|
|
|
[this, user] { shareContact(user); });
|
2017-09-26 19:42:58 +00:00
|
|
|
addButton(
|
|
|
|
Lang::Viewer(lng_info_edit_contact),
|
|
|
|
IsContactValue(user),
|
|
|
|
[user] { Ui::show(Box<AddContactBox>(user)); });
|
|
|
|
addButton(
|
|
|
|
Lang::Viewer(lng_profile_clear_history),
|
|
|
|
rpl::single(true),
|
|
|
|
[user] {
|
|
|
|
auto confirmation = lng_sure_delete_history(lt_contact, App::peerName(user));
|
|
|
|
Ui::show(Box<ConfirmBox>(confirmation, lang(lng_box_delete), st::attentionBoxButton, [user] {
|
|
|
|
Ui::hideLayer();
|
|
|
|
App::main()->clearHistory(user);
|
|
|
|
Ui::showPeerHistory(user, ShowAtUnreadMsgId);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
addButton(
|
|
|
|
Lang::Viewer(lng_profile_delete_conversation),
|
|
|
|
rpl::single(true),
|
|
|
|
[user] {
|
|
|
|
auto confirmation = lng_sure_delete_history(lt_contact, App::peerName(user));
|
|
|
|
auto confirmButton = lang(lng_box_delete);
|
|
|
|
Ui::show(Box<ConfirmBox>(confirmation, confirmButton, st::attentionBoxButton, [user] {
|
|
|
|
Ui::hideLayer();
|
|
|
|
Ui::showChatsList();
|
|
|
|
App::main()->deleteConversation(user);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!user->isSelf()) {
|
|
|
|
result->add(CreateSkipWidget(
|
|
|
|
result,
|
|
|
|
st::infoBlockButtonSkip));
|
|
|
|
|
2017-10-24 17:11:35 +00:00
|
|
|
auto text = Notify::PeerUpdateValue(
|
|
|
|
user,
|
|
|
|
Notify::PeerUpdate::Flag::UserIsBlocked)
|
2017-09-27 18:29:13 +00:00
|
|
|
| rpl::map([user]() -> rpl::producer<QString> {
|
2017-09-26 19:42:58 +00:00
|
|
|
switch (user->blockStatus()) {
|
|
|
|
case UserData::BlockStatus::Blocked:
|
|
|
|
return Lang::Viewer(lng_profile_unblock_user);
|
|
|
|
case UserData::BlockStatus::NotBlocked:
|
|
|
|
return Lang::Viewer(lng_profile_block_user);
|
|
|
|
default:
|
|
|
|
return rpl::single(QString());
|
|
|
|
}
|
|
|
|
})
|
|
|
|
| rpl::flatten_latest()
|
|
|
|
| rpl::start_spawning(result->lifetime());
|
|
|
|
addButton(
|
|
|
|
rpl::duplicate(text),
|
|
|
|
rpl::duplicate(text)
|
|
|
|
| rpl::map([](const QString &text) {
|
|
|
|
return !text.isEmpty();
|
|
|
|
}),
|
|
|
|
[user] {
|
|
|
|
if (user->isBlocked()) {
|
|
|
|
Auth().api().unblockUser(user);
|
|
|
|
} else {
|
|
|
|
Auth().api().blockUser(user);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
st::infoBlockButton);
|
|
|
|
}
|
|
|
|
result->add(createSkipWidget(result));
|
|
|
|
|
2017-09-21 19:21:33 +00:00
|
|
|
object_ptr<FloatingIcon>(
|
|
|
|
result,
|
|
|
|
st::infoIconActions,
|
|
|
|
st::infoIconPosition);
|
2017-09-18 17:04:45 +00:00
|
|
|
return std::move(result);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 16:19:42 +00:00
|
|
|
void InnerWidget::shareContact(not_null<UserData*> user) const {
|
|
|
|
auto callback = [user](not_null<PeerData*> peer) {
|
|
|
|
if (!peer->canWrite()) {
|
|
|
|
Ui::show(Box<InformBox>(
|
|
|
|
lang(lng_forward_share_cant)),
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto recipient = peer->isUser()
|
|
|
|
? peer->name
|
|
|
|
: '\xAB' + peer->name + '\xBB';
|
|
|
|
Ui::show(Box<ConfirmBox>(
|
|
|
|
lng_forward_share_contact(lt_recipient, recipient),
|
|
|
|
lang(lng_forward_send),
|
|
|
|
[peer, user] {
|
|
|
|
App::main()->onShareContact(
|
|
|
|
peer->id,
|
|
|
|
user);
|
|
|
|
Ui::hideLayer();
|
|
|
|
}), LayerOption::KeepOther);
|
|
|
|
};
|
|
|
|
Ui::show(Box<PeerListBox>(
|
|
|
|
std::make_unique<ChooseRecipientBoxController>(std::move(callback)),
|
|
|
|
[](not_null<PeerListBox*> box) {
|
|
|
|
box->addButton(langFactory(lng_cancel), [box] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2017-09-21 10:28:34 +00:00
|
|
|
object_ptr<Ui::RpWidget> InnerWidget::createSkipWidget(
|
|
|
|
RpWidget *parent) const {
|
|
|
|
return Ui::CreateSkipWidget(parent, st::infoProfileSkip);
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<Ui::SlideWrap<>> InnerWidget::createSlideSkipWidget(
|
|
|
|
RpWidget *parent) const {
|
|
|
|
return Ui::CreateSlideSkipWidget(parent, st::infoProfileSkip);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
_members->saveState(memento);
|
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
2017-10-03 17:41:44 +00:00
|
|
|
_cover->toggle(memento->infoExpanded());
|
2017-10-24 17:11:35 +00:00
|
|
|
if (_members) {
|
|
|
|
_members->restoreState(memento);
|
|
|
|
}
|
2017-10-03 17:41:44 +00:00
|
|
|
if (_infoWrap) {
|
|
|
|
_infoWrap->finishAnimating();
|
|
|
|
}
|
|
|
|
if (_sharedMediaWrap) {
|
|
|
|
_sharedMediaWrap->finishAnimating();
|
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int InnerWidget::resizeGetHeight(int newWidth) {
|
|
|
|
_content->resizeToWidth(newWidth);
|
2017-09-21 10:28:34 +00:00
|
|
|
_content->moveToLeft(0, 0);
|
2017-10-03 17:41:44 +00:00
|
|
|
return _content->heightNoMargins();
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Profile
|
|
|
|
} // namespace Info
|