2017-09-25 09:02:55 +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-25 09:02:55 +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-25 09:02:55 +00:00
|
|
|
*/
|
|
|
|
#include "info/profile/info_profile_cover.h"
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_photo.h"
|
2017-12-17 08:13:26 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
2022-08-09 17:15:42 +00:00
|
|
|
#include "data/data_user.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2022-08-09 17:15:42 +00:00
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_document.h"
|
2022-08-30 15:21:14 +00:00
|
|
|
#include "data/data_emoji_statuses.h"
|
2022-08-09 17:15:42 +00:00
|
|
|
#include "data/stickers/data_custom_emoji.h"
|
2021-02-22 02:10:27 +00:00
|
|
|
#include "editor/photo_editor_layer_widget.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
#include "info/profile/info_profile_values.h"
|
2017-11-13 15:50:10 +00:00
|
|
|
#include "info/info_controller.h"
|
2017-11-17 17:02:49 +00:00
|
|
|
#include "info/info_memento.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2022-09-01 19:24:46 +00:00
|
|
|
#include "menu/menu_send.h" // SendMenu::Type.
|
|
|
|
#include "ui/boxes/confirm_box.h"
|
|
|
|
#include "ui/boxes/time_picker_box.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2022-06-03 12:11:44 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2022-09-01 19:24:46 +00:00
|
|
|
#include "ui/text/format_values.h"
|
2022-01-04 21:26:13 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2017-11-13 15:50:10 +00:00
|
|
|
#include "ui/special_buttons.h"
|
2019-06-23 12:18:33 +00:00
|
|
|
#include "ui/unread_badge.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2022-08-09 17:15:42 +00:00
|
|
|
#include "window/window_controller.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2022-06-03 12:11:44 +00:00
|
|
|
#include "settings/settings_premium.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
#include "apiwrap.h"
|
2022-08-09 17:15:42 +00:00
|
|
|
#include "mainwindow.h"
|
2021-10-20 16:54:22 +00:00
|
|
|
#include "api/api_peer_photo.h"
|
2022-08-09 17:15:42 +00:00
|
|
|
#include "chat_helpers/tabbed_panel.h"
|
|
|
|
#include "chat_helpers/tabbed_selector.h"
|
2019-09-18 08:05:37 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_info.h"
|
2022-08-09 17:15:42 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Profile {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
auto MembersStatusText(int count) {
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_chat_status_members(tr::now, lt_count_decimal, count);
|
2017-09-25 09:02:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto OnlineStatusText(int count) {
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_chat_status_online(tr::now, lt_count_decimal, count);
|
2017-09-25 09:02:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto ChatStatusText(int fullCount, int onlineCount, bool isGroup) {
|
2017-10-22 12:07:57 +00:00
|
|
|
if (onlineCount > 1 && onlineCount <= fullCount) {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_chat_status_members_online(
|
|
|
|
tr::now,
|
|
|
|
lt_members_count,
|
|
|
|
MembersStatusText(fullCount),
|
|
|
|
lt_online_count,
|
|
|
|
OnlineStatusText(onlineCount));
|
2017-09-25 09:02:55 +00:00
|
|
|
} else if (fullCount > 0) {
|
2020-05-01 11:20:57 +00:00
|
|
|
return isGroup
|
|
|
|
? tr::lng_chat_status_members(
|
|
|
|
tr::now,
|
|
|
|
lt_count_decimal,
|
|
|
|
fullCount)
|
|
|
|
: tr::lng_chat_status_subscribers(
|
|
|
|
tr::now,
|
|
|
|
lt_count_decimal,
|
|
|
|
fullCount);
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
return isGroup
|
|
|
|
? tr::lng_group_status(tr::now)
|
|
|
|
: tr::lng_channel_status(tr::now);
|
2017-09-25 09:02:55 +00:00
|
|
|
};
|
|
|
|
|
2022-09-01 19:24:46 +00:00
|
|
|
void PickUntilBox(not_null<Ui::GenericBox*> box, Fn<void(TimeId)> callback) {
|
|
|
|
box->setTitle(tr::lng_emoji_status_for_title());
|
|
|
|
|
|
|
|
const auto seconds = Ui::DefaultTimePickerValues();
|
|
|
|
const auto phrases = ranges::views::all(
|
|
|
|
seconds
|
|
|
|
) | ranges::views::transform(Ui::FormatMuteFor) | ranges::to_vector;
|
|
|
|
|
|
|
|
const auto pickerCallback = Ui::TimePickerBox(box, seconds, phrases, 0);
|
|
|
|
|
|
|
|
Ui::ConfirmBox(box, {
|
|
|
|
.confirmed = [=] {
|
|
|
|
callback(pickerCallback());
|
|
|
|
box->closeBox();
|
|
|
|
},
|
|
|
|
.confirmText = tr::lng_emoji_status_for_submit(),
|
|
|
|
.cancelText = tr::lng_cancel(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:02:55 +00:00
|
|
|
} // namespace
|
|
|
|
|
2022-08-11 17:22:21 +00:00
|
|
|
BadgeView::BadgeView(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
const style::InfoPeerBadge &st,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Fn<bool()> animationPaused,
|
2022-08-31 14:37:31 +00:00
|
|
|
int customStatusLoopsLimit,
|
2022-08-11 17:22:21 +00:00
|
|
|
base::flags<Badge> allowed)
|
|
|
|
: _parent(parent)
|
|
|
|
, _st(st)
|
|
|
|
, _peer(peer)
|
2022-08-31 14:37:31 +00:00
|
|
|
, _customStatusLoopsLimit(customStatusLoopsLimit)
|
2022-08-11 17:22:21 +00:00
|
|
|
, _allowed(allowed)
|
|
|
|
, _animationPaused(std::move(animationPaused)) {
|
|
|
|
rpl::combine(
|
|
|
|
BadgeValue(peer),
|
|
|
|
EmojiStatusIdValue(peer)
|
|
|
|
) | rpl::start_with_next([=](Badge badge, DocumentId emojiStatusId) {
|
|
|
|
setBadge(badge, emojiStatusId);
|
|
|
|
}, _lifetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ui::RpWidget *BadgeView::widget() const {
|
|
|
|
return _view.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BadgeView::setBadge(Badge badge, DocumentId emojiStatusId) {
|
|
|
|
if ((!_peer->session().premiumBadgesShown() && badge == Badge::Premium)
|
|
|
|
|| !(_allowed & badge)) {
|
|
|
|
badge = Badge::None;
|
|
|
|
}
|
|
|
|
if (!(_allowed & badge)) {
|
|
|
|
badge = Badge::None;
|
|
|
|
}
|
|
|
|
if (badge != Badge::Premium) {
|
|
|
|
emojiStatusId = 0;
|
|
|
|
}
|
|
|
|
if (_badge == badge && _emojiStatusId == emojiStatusId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_badge = badge;
|
|
|
|
_emojiStatusId = emojiStatusId;
|
|
|
|
_emojiStatus = nullptr;
|
2022-08-31 08:29:09 +00:00
|
|
|
_emojiStatusColored = nullptr;
|
2022-08-11 17:22:21 +00:00
|
|
|
_view.destroy();
|
|
|
|
if (_badge == Badge::None) {
|
|
|
|
_updated.fire({});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_view.create(_parent);
|
|
|
|
_view->show();
|
|
|
|
switch (_badge) {
|
|
|
|
case Badge::Verified:
|
|
|
|
case Badge::Premium: {
|
|
|
|
if (_emojiStatusId) {
|
|
|
|
using SizeTag = Data::CustomEmojiManager::SizeTag;
|
|
|
|
const auto tag = (_st.sizeTag == 2)
|
|
|
|
? SizeTag::Isolated
|
|
|
|
: (_st.sizeTag == 1)
|
|
|
|
? SizeTag::Large
|
|
|
|
: SizeTag::Normal;
|
|
|
|
_emojiStatus = _peer->owner().customEmojiManager().create(
|
|
|
|
_emojiStatusId,
|
2022-08-20 10:18:31 +00:00
|
|
|
[raw = _view.data()] { raw->update(); },
|
2022-08-11 17:22:21 +00:00
|
|
|
tag);
|
2022-08-31 14:37:31 +00:00
|
|
|
if (_customStatusLoopsLimit > 0) {
|
|
|
|
_emojiStatus = std::make_unique<Ui::Text::LimitedLoopsEmoji>(
|
|
|
|
std::move(_emojiStatus),
|
|
|
|
_customStatusLoopsLimit);
|
|
|
|
}
|
2022-08-31 08:29:09 +00:00
|
|
|
_emojiStatusColored = std::make_unique<
|
|
|
|
Ui::Text::CustomEmojiColored
|
|
|
|
>();
|
2022-08-11 17:22:21 +00:00
|
|
|
const auto emoji = Data::FrameSizeFromTag(tag)
|
|
|
|
/ style::DevicePixelRatio();
|
|
|
|
_view->resize(emoji, emoji);
|
|
|
|
_view->paintRequest(
|
|
|
|
) | rpl::start_with_next([=, check = _view.data()]{
|
|
|
|
Painter p(check);
|
2022-08-31 08:29:09 +00:00
|
|
|
_emojiStatusColored->color = _st.premiumFg->c;
|
2022-08-23 14:47:26 +00:00
|
|
|
_emojiStatus->paint(p, {
|
|
|
|
.preview = st::windowBgOver->c,
|
2022-08-31 08:29:09 +00:00
|
|
|
.colored = _emojiStatusColored.get(),
|
2022-08-23 14:47:26 +00:00
|
|
|
.now = crl::now(),
|
|
|
|
.paused = _animationPaused && _animationPaused(),
|
|
|
|
});
|
2022-08-11 17:22:21 +00:00
|
|
|
}, _view->lifetime());
|
|
|
|
} else {
|
|
|
|
const auto icon = (_badge == Badge::Verified)
|
|
|
|
? &_st.verified
|
|
|
|
: &_st.premium;
|
|
|
|
_view->resize(icon->size());
|
|
|
|
_view->paintRequest(
|
|
|
|
) | rpl::start_with_next([=, check = _view.data()]{
|
|
|
|
Painter p(check);
|
|
|
|
icon->paint(p, 0, 0, check->width());
|
|
|
|
}, _view->lifetime());
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Badge::Scam:
|
|
|
|
case Badge::Fake: {
|
|
|
|
const auto fake = (_badge == Badge::Fake);
|
|
|
|
const auto size = Ui::ScamBadgeSize(fake);
|
|
|
|
const auto skip = st::infoVerifiedCheckPosition.x();
|
|
|
|
_view->resize(
|
|
|
|
size.width() + 2 * skip,
|
|
|
|
size.height() + 2 * skip);
|
|
|
|
_view->paintRequest(
|
|
|
|
) | rpl::start_with_next([=, badge = _view.data()]{
|
|
|
|
Painter p(badge);
|
|
|
|
Ui::DrawScamBadge(
|
|
|
|
fake,
|
|
|
|
p,
|
|
|
|
badge->rect().marginsRemoved({ skip, skip, skip, skip }),
|
|
|
|
badge->width(),
|
|
|
|
st::attentionButtonFg);
|
|
|
|
}, _view->lifetime());
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_badge != Badge::Premium || !_premiumClickCallback) {
|
|
|
|
_view->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
} else {
|
|
|
|
_view->setClickedCallback(_premiumClickCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
_updated.fire({});
|
|
|
|
}
|
|
|
|
|
|
|
|
void BadgeView::setPremiumClickCallback(Fn<void()> callback) {
|
|
|
|
_premiumClickCallback = std::move(callback);
|
|
|
|
if (_view && _badge == Badge::Premium) {
|
|
|
|
if (!_premiumClickCallback) {
|
|
|
|
_view->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
} else {
|
|
|
|
_view->setAttribute(Qt::WA_TransparentForMouseEvents, false);
|
|
|
|
_view->setClickedCallback(_premiumClickCallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> BadgeView::updated() const {
|
|
|
|
return _updated.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BadgeView::move(int left, int top, int bottom) {
|
|
|
|
if (!_view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto star = !_emojiStatus
|
|
|
|
&& (_badge == Badge::Premium || _badge == Badge::Verified);
|
|
|
|
const auto fake = !_emojiStatus && !star;
|
|
|
|
const auto skip = fake ? 0 : _st.position.x();
|
|
|
|
const auto badgeLeft = left + skip;
|
|
|
|
const auto badgeTop = top
|
|
|
|
+ (star
|
2022-08-11 17:56:07 +00:00
|
|
|
? _st.position.y()
|
2022-08-11 17:22:21 +00:00
|
|
|
: (bottom - top - _view->height()) / 2);
|
|
|
|
_view->moveToLeft(badgeLeft, badgeTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiStatusPanel::show(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<QWidget*> button) {
|
2022-08-30 15:21:14 +00:00
|
|
|
const auto self = controller->session().user();
|
|
|
|
const auto &statuses = controller->session().data().emojiStatuses();
|
2022-09-02 11:17:52 +00:00
|
|
|
const auto &recent = statuses.list(Data::EmojiStatuses::Type::Recent);
|
2022-08-30 15:21:14 +00:00
|
|
|
const auto &other = statuses.list(Data::EmojiStatuses::Type::Default);
|
2022-09-02 11:17:52 +00:00
|
|
|
auto list = statuses.list(Data::EmojiStatuses::Type::Colored);
|
2022-08-30 15:21:14 +00:00
|
|
|
list.insert(begin(list), 0);
|
2022-09-02 11:17:52 +00:00
|
|
|
list.reserve(list.size() + recent.size() + other.size() + 1);
|
|
|
|
for (const auto &id : ranges::views::concat(recent, other)) {
|
|
|
|
if (!ranges::contains(list, id)) {
|
|
|
|
list.push_back(id);
|
2022-08-30 15:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ranges::contains(list, self->emojiStatusId())) {
|
|
|
|
list.push_back(self->emojiStatusId());
|
|
|
|
}
|
2022-08-11 17:22:21 +00:00
|
|
|
if (!_panel) {
|
|
|
|
create(controller);
|
|
|
|
|
2022-08-11 17:56:07 +00:00
|
|
|
const auto weak = Ui::MakeWeak(button.get());
|
2022-08-11 17:22:21 +00:00
|
|
|
_panel->shownValue(
|
2022-08-11 17:56:07 +00:00
|
|
|
) | rpl::filter([=](bool shown) {
|
|
|
|
return !shown && weak;
|
|
|
|
}) | rpl::start_with_next([=] {
|
2022-08-11 17:22:21 +00:00
|
|
|
button->removeEventFilter(_panel.get());
|
|
|
|
}, _panel->lifetime());
|
|
|
|
}
|
2022-08-30 15:21:14 +00:00
|
|
|
_panel->selector()->provideRecentEmoji(list);
|
2022-08-11 17:22:21 +00:00
|
|
|
const auto parent = _panel->parentWidget();
|
2022-08-16 06:47:17 +00:00
|
|
|
const auto global = button->mapToGlobal(QPoint());
|
2022-08-11 17:22:21 +00:00
|
|
|
const auto local = parent->mapFromGlobal(global);
|
|
|
|
_panel->moveTopRight(
|
|
|
|
local.y() + button->height(),
|
|
|
|
local.x() + button->width() * 3);
|
|
|
|
_panel->toggleAnimated();
|
|
|
|
button->installEventFilter(_panel.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiStatusPanel::create(
|
|
|
|
not_null<Window::SessionController*> controller) {
|
|
|
|
using Selector = ChatHelpers::TabbedSelector;
|
|
|
|
_panel = base::make_unique_q<ChatHelpers::TabbedPanel>(
|
|
|
|
controller->window().widget()->bodyWidget(),
|
|
|
|
controller,
|
|
|
|
object_ptr<Selector>(
|
|
|
|
nullptr,
|
|
|
|
controller,
|
|
|
|
Window::GifPauseReason::Layer,
|
|
|
|
ChatHelpers::TabbedSelector::Mode::EmojiStatus));
|
|
|
|
_panel->setDropDown(true);
|
|
|
|
_panel->setDesiredHeightValues(
|
|
|
|
1.,
|
|
|
|
st::emojiPanMinHeight / 2,
|
|
|
|
st::emojiPanMinHeight);
|
|
|
|
_panel->hide();
|
|
|
|
_panel->selector()->setAllowEmojiWithoutPremium(false);
|
|
|
|
|
2022-09-01 19:24:46 +00:00
|
|
|
struct Chosen {
|
|
|
|
DocumentId id = 0;
|
|
|
|
TimeId until = 0;
|
2022-09-06 13:08:20 +00:00
|
|
|
Ui::MessageSendingAnimationFrom animation;
|
2022-09-01 19:24:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_panel->selector()->contextMenuRequested(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_panel->selector()->showMenuWithType(SendMenu::Type::Scheduled);
|
|
|
|
}, _panel->lifetime());
|
|
|
|
|
2022-08-11 17:22:21 +00:00
|
|
|
auto statusChosen = _panel->selector()->customEmojiChosen(
|
|
|
|
) | rpl::map([=](Selector::FileChosen data) {
|
2022-09-06 13:08:20 +00:00
|
|
|
return Chosen{
|
|
|
|
.id = data.document->id,
|
|
|
|
.until = data.options.scheduled,
|
|
|
|
.animation = data.messageSendingFrom,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
auto emojiChosen = _panel->selector()->emojiChosen(
|
|
|
|
) | rpl::map([=](Selector::EmojiChosen data) {
|
|
|
|
return Chosen{ .animation = data.messageSendingFrom };
|
2022-08-11 17:22:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
rpl::merge(
|
|
|
|
std::move(statusChosen),
|
2022-09-06 13:08:20 +00:00
|
|
|
std::move(emojiChosen)
|
2022-09-01 19:24:46 +00:00
|
|
|
) | rpl::start_with_next([=](const Chosen chosen) {
|
|
|
|
if (chosen.until == ChatHelpers::TabbedSelector::kPickCustomTimeId) {
|
|
|
|
controller->show(Box(PickUntilBox, [=](TimeId seconds) {
|
|
|
|
controller->session().data().emojiStatuses().set(
|
|
|
|
chosen.id,
|
|
|
|
base::unixtime::now() + seconds);
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
controller->session().data().emojiStatuses().set(
|
|
|
|
chosen.id,
|
|
|
|
chosen.until);
|
|
|
|
_panel->hideAnimated();
|
|
|
|
}
|
2022-08-11 17:22:21 +00:00
|
|
|
}, _panel->lifetime());
|
|
|
|
|
|
|
|
_panel->selector()->showPromoForPremiumEmoji();
|
|
|
|
}
|
|
|
|
|
2017-11-13 15:50:10 +00:00
|
|
|
Cover::Cover(
|
|
|
|
QWidget *parent,
|
2018-09-05 19:39:35 +00:00
|
|
|
not_null<PeerData*> peer,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller)
|
2019-06-10 15:47:22 +00:00
|
|
|
: Cover(parent, peer, controller, NameValue(
|
|
|
|
peer
|
|
|
|
) | rpl::map([=](const TextWithEntities &name) {
|
|
|
|
return name.text;
|
|
|
|
})) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Cover::Cover(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
rpl::producer<QString> title)
|
2022-05-30 13:09:36 +00:00
|
|
|
: FixedHeightWidget(
|
2017-09-25 09:02:55 +00:00
|
|
|
parent,
|
|
|
|
st::infoProfilePhotoTop
|
2017-11-13 15:50:10 +00:00
|
|
|
+ st::infoProfilePhoto.size.height()
|
2017-09-25 09:02:55 +00:00
|
|
|
+ st::infoProfilePhotoBottom)
|
2022-06-03 12:11:44 +00:00
|
|
|
, _controller(controller)
|
2018-09-05 19:39:35 +00:00
|
|
|
, _peer(peer)
|
2022-08-11 17:22:21 +00:00
|
|
|
, _badge(
|
|
|
|
this,
|
|
|
|
st::infoPeerBadge,
|
|
|
|
peer,
|
|
|
|
[=] {
|
|
|
|
return controller->isGifPausedAtLeastFor(
|
|
|
|
Window::GifPauseReason::Layer);
|
|
|
|
})
|
2017-11-13 15:50:10 +00:00
|
|
|
, _userpic(
|
|
|
|
this,
|
2018-09-05 19:39:35 +00:00
|
|
|
controller,
|
2017-11-13 15:50:10 +00:00
|
|
|
_peer,
|
|
|
|
Ui::UserpicButton::Role::OpenPhoto,
|
|
|
|
st::infoProfilePhoto)
|
2017-09-25 09:02:55 +00:00
|
|
|
, _name(this, st::infoProfileNameLabel)
|
2017-11-17 17:02:49 +00:00
|
|
|
, _status(
|
|
|
|
this,
|
|
|
|
_peer->isMegagroup()
|
|
|
|
? st::infoProfileMegagroupStatusLabel
|
2017-11-24 15:51:47 +00:00
|
|
|
: st::infoProfileStatusLabel)
|
|
|
|
, _refreshStatusTimer([this] { refreshStatusText(); }) {
|
2017-09-25 09:02:55 +00:00
|
|
|
_peer->updateFull();
|
|
|
|
|
|
|
|
_name->setSelectable(true);
|
2019-06-19 15:09:03 +00:00
|
|
|
_name->setContextCopyText(tr::lng_profile_copy_fullname(tr::now));
|
2017-11-17 17:02:49 +00:00
|
|
|
|
|
|
|
if (!_peer->isMegagroup()) {
|
|
|
|
_status->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
}
|
2017-09-25 09:02:55 +00:00
|
|
|
|
2022-08-11 17:22:21 +00:00
|
|
|
_badge.setPremiumClickCallback([=] {
|
|
|
|
if (_peer->isSelf()) {
|
|
|
|
_emojiStatusPanel.show(_controller, _badge.widget());
|
|
|
|
} else {
|
2022-08-20 10:18:31 +00:00
|
|
|
::Settings::ShowEmojiStatusPremium(_controller, _peer);
|
2022-08-11 17:22:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
_badge.updated() | rpl::start_with_next([=] {
|
|
|
|
refreshNameGeometry(width());
|
|
|
|
}, _name->lifetime());
|
|
|
|
|
2019-06-10 15:47:22 +00:00
|
|
|
initViewers(std::move(title));
|
2017-09-25 09:02:55 +00:00
|
|
|
setupChildGeometry();
|
2021-02-22 02:10:27 +00:00
|
|
|
|
|
|
|
_userpic->uploadPhotoRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
2021-10-20 16:54:22 +00:00
|
|
|
_peer->session().api().peerPhoto().upload(
|
2021-02-22 02:10:27 +00:00
|
|
|
_peer,
|
|
|
|
_userpic->takeResultImage());
|
|
|
|
}, _userpic->lifetime());
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Cover::setupChildGeometry() {
|
2022-05-30 13:09:36 +00:00
|
|
|
widthValue(
|
2018-05-17 08:15:52 +00:00
|
|
|
) | rpl::start_with_next([this](int newWidth) {
|
2017-12-22 07:05:20 +00:00
|
|
|
_userpic->moveToLeft(
|
|
|
|
st::infoProfilePhotoLeft,
|
|
|
|
st::infoProfilePhotoTop,
|
|
|
|
newWidth);
|
|
|
|
refreshNameGeometry(newWidth);
|
|
|
|
refreshStatusGeometry(newWidth);
|
|
|
|
}, lifetime());
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Cover *Cover::setOnlineCount(rpl::producer<int> &&count) {
|
2017-12-22 07:05:20 +00:00
|
|
|
std::move(
|
|
|
|
count
|
|
|
|
) | rpl::start_with_next([this](int count) {
|
|
|
|
_onlineCount = count;
|
|
|
|
refreshStatusText();
|
|
|
|
}, lifetime());
|
2017-09-25 09:02:55 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-06-10 15:47:22 +00:00
|
|
|
void Cover::initViewers(rpl::producer<QString> title) {
|
2020-06-12 12:12:34 +00:00
|
|
|
using Flag = Data::PeerUpdate::Flag;
|
2019-06-10 15:47:22 +00:00
|
|
|
std::move(
|
|
|
|
title
|
|
|
|
) | rpl::start_with_next([=](const QString &title) {
|
|
|
|
_name->setText(title);
|
2018-09-09 17:38:08 +00:00
|
|
|
refreshNameGeometry(width());
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
_peer->session().changes().peerFlagsValue(
|
2017-12-22 07:05:20 +00:00
|
|
|
_peer,
|
2020-06-12 12:12:34 +00:00
|
|
|
Flag::OnlineStatus | Flag::Members
|
2017-12-22 07:05:20 +00:00
|
|
|
) | rpl::start_with_next(
|
2019-01-05 10:50:04 +00:00
|
|
|
[=] { refreshStatusText(); },
|
2017-12-22 07:05:20 +00:00
|
|
|
lifetime());
|
2017-11-13 17:12:36 +00:00
|
|
|
if (!_peer->isUser()) {
|
2020-06-12 12:12:34 +00:00
|
|
|
_peer->session().changes().peerFlagsValue(
|
2017-12-22 07:05:20 +00:00
|
|
|
_peer,
|
2020-06-12 12:12:34 +00:00
|
|
|
Flag::Rights
|
2017-12-22 07:05:20 +00:00
|
|
|
) | rpl::start_with_next(
|
2019-01-05 10:50:04 +00:00
|
|
|
[=] { refreshUploadPhotoOverlay(); },
|
2017-09-25 09:02:55 +00:00
|
|
|
lifetime());
|
2018-09-13 20:09:26 +00:00
|
|
|
} else if (_peer->isSelf()) {
|
|
|
|
refreshUploadPhotoOverlay();
|
2017-12-22 07:05:20 +00:00
|
|
|
}
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 17:12:36 +00:00
|
|
|
void Cover::refreshUploadPhotoOverlay() {
|
|
|
|
_userpic->switchChangePhotoOverlay([&] {
|
2018-09-13 20:09:26 +00:00
|
|
|
if (const auto chat = _peer->asChat()) {
|
2019-01-03 14:39:19 +00:00
|
|
|
return chat->canEditInformation();
|
2018-09-13 20:09:26 +00:00
|
|
|
} else if (const auto channel = _peer->asChannel()) {
|
2017-11-13 17:12:36 +00:00
|
|
|
return channel->canEditInformation();
|
|
|
|
}
|
2018-09-13 20:09:26 +00:00
|
|
|
return _peer->isSelf();
|
2017-11-13 17:12:36 +00:00
|
|
|
}());
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:02:55 +00:00
|
|
|
void Cover::refreshStatusText() {
|
2017-11-17 17:02:49 +00:00
|
|
|
auto hasMembersLink = [&] {
|
|
|
|
if (auto megagroup = _peer->asMegagroup()) {
|
|
|
|
return megagroup->canViewMembers();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}();
|
2022-01-04 21:26:13 +00:00
|
|
|
auto statusText = [&]() -> TextWithEntities {
|
|
|
|
using namespace Ui::Text;
|
2019-07-10 17:28:33 +00:00
|
|
|
auto currentTime = base::unixtime::now();
|
2017-09-25 09:02:55 +00:00
|
|
|
if (auto user = _peer->asUser()) {
|
2017-12-17 08:13:26 +00:00
|
|
|
const auto result = Data::OnlineTextFull(user, currentTime);
|
|
|
|
const auto showOnline = Data::OnlineTextActive(user, currentTime);
|
|
|
|
const auto updateIn = Data::OnlineChangeTimeout(user, currentTime);
|
2017-11-24 15:51:47 +00:00
|
|
|
if (showOnline) {
|
2017-12-17 08:13:26 +00:00
|
|
|
_refreshStatusTimer.callOnce(updateIn);
|
2017-11-24 15:51:47 +00:00
|
|
|
}
|
|
|
|
return showOnline
|
2022-01-04 21:26:13 +00:00
|
|
|
? PlainLink(result)
|
|
|
|
: TextWithEntities{ .text = result };
|
2017-09-25 09:02:55 +00:00
|
|
|
} else if (auto chat = _peer->asChat()) {
|
|
|
|
if (!chat->amIn()) {
|
2022-01-04 21:26:13 +00:00
|
|
|
return tr::lng_chat_status_unaccessible({}, WithEntities);
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
2017-12-01 18:38:44 +00:00
|
|
|
auto fullCount = std::max(
|
2017-09-25 09:02:55 +00:00
|
|
|
chat->count,
|
2017-12-01 18:38:44 +00:00
|
|
|
int(chat->participants.size()));
|
2022-01-04 21:26:13 +00:00
|
|
|
return { .text = ChatStatusText(fullCount, _onlineCount, true) };
|
2017-09-25 09:02:55 +00:00
|
|
|
} else if (auto channel = _peer->asChannel()) {
|
|
|
|
auto fullCount = qMax(channel->membersCount(), 1);
|
2017-11-17 17:02:49 +00:00
|
|
|
auto result = ChatStatusText(
|
2017-09-25 09:02:55 +00:00
|
|
|
fullCount,
|
|
|
|
_onlineCount,
|
|
|
|
channel->isMegagroup());
|
2022-01-04 21:26:13 +00:00
|
|
|
return hasMembersLink
|
|
|
|
? PlainLink(result)
|
|
|
|
: TextWithEntities{ .text = result };
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
2022-01-04 21:26:13 +00:00
|
|
|
return tr::lng_chat_status_unaccessible(tr::now, WithEntities);
|
2017-09-25 09:02:55 +00:00
|
|
|
}();
|
2022-01-04 21:26:13 +00:00
|
|
|
_status->setMarkedText(statusText);
|
2017-11-17 17:02:49 +00:00
|
|
|
if (hasMembersLink) {
|
2017-12-18 09:07:18 +00:00
|
|
|
_status->setLink(1, std::make_shared<LambdaClickHandler>([=] {
|
2018-09-05 19:39:35 +00:00
|
|
|
_showSection.fire(Section::Type::Members);
|
2017-11-17 17:02:49 +00:00
|
|
|
}));
|
|
|
|
}
|
2017-09-25 09:02:55 +00:00
|
|
|
refreshStatusGeometry(width());
|
|
|
|
}
|
|
|
|
|
2017-10-25 16:32:22 +00:00
|
|
|
Cover::~Cover() {
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:02:55 +00:00
|
|
|
void Cover::refreshNameGeometry(int newWidth) {
|
2017-11-06 14:13:56 +00:00
|
|
|
auto nameLeft = st::infoProfileNameLeft;
|
|
|
|
auto nameTop = st::infoProfileNameTop;
|
2017-09-25 09:02:55 +00:00
|
|
|
auto nameWidth = newWidth
|
2017-11-06 14:13:56 +00:00
|
|
|
- nameLeft
|
2022-05-30 13:09:36 +00:00
|
|
|
- st::infoProfileNameRight;
|
2022-08-11 17:22:21 +00:00
|
|
|
if (const auto width = _badge.widget() ? _badge.widget()->width() : 0) {
|
|
|
|
nameWidth -= st::infoVerifiedCheckPosition.x() + width;
|
2017-11-06 14:13:56 +00:00
|
|
|
}
|
|
|
|
_name->resizeToNaturalWidth(nameWidth);
|
|
|
|
_name->moveToLeft(nameLeft, nameTop, newWidth);
|
2022-08-11 17:22:21 +00:00
|
|
|
const auto badgeLeft = nameLeft + _name->width();
|
|
|
|
const auto badgeTop = nameTop;
|
|
|
|
const auto badgeBottom = nameTop + _name->height();
|
|
|
|
_badge.move(badgeLeft, badgeTop, badgeBottom);
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Cover::refreshStatusGeometry(int newWidth) {
|
|
|
|
auto statusWidth = newWidth
|
|
|
|
- st::infoProfileStatusLeft
|
2022-05-30 13:09:36 +00:00
|
|
|
- st::infoProfileStatusRight;
|
2017-09-25 09:02:55 +00:00
|
|
|
_status->resizeToWidth(statusWidth);
|
|
|
|
_status->moveToLeft(
|
|
|
|
st::infoProfileStatusLeft,
|
|
|
|
st::infoProfileStatusTop,
|
|
|
|
newWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Profile
|
|
|
|
} // namespace Info
|