2022-04-12 21:05:21 +00:00
|
|
|
/*
|
|
|
|
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 "boxes/reactions_settings_box.h"
|
|
|
|
|
|
|
|
#include "base/unixtime.h"
|
2022-04-21 15:34:00 +00:00
|
|
|
#include "data/data_user.h"
|
2022-04-12 21:05:21 +00:00
|
|
|
#include "data/data_document.h"
|
|
|
|
#include "data/data_document_media.h"
|
|
|
|
#include "data/data_message_reactions.h"
|
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "history/admin_log/history_admin_log_item.h"
|
|
|
|
#include "history/history.h"
|
2022-12-14 12:15:46 +00:00
|
|
|
#include "history/history_item.h"
|
2022-04-12 21:05:21 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
2022-08-19 12:08:11 +00:00
|
|
|
#include "history/view/reactions/history_view_reactions_strip.h"
|
2022-04-12 21:05:21 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2022-05-27 15:42:05 +00:00
|
|
|
#include "boxes/premium_preview_box.h"
|
2022-04-12 21:05:21 +00:00
|
|
|
#include "main/main_session.h"
|
2022-05-20 13:12:56 +00:00
|
|
|
#include "settings/settings_premium.h"
|
2022-04-12 21:05:21 +00:00
|
|
|
#include "ui/chat/chat_style.h"
|
|
|
|
#include "ui/chat/chat_theme.h"
|
2022-04-13 10:22:10 +00:00
|
|
|
#include "ui/effects/scroll_content_shadow.h"
|
2022-04-12 21:05:21 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2022-08-29 12:34:21 +00:00
|
|
|
#include "ui/animated_icon.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2023-11-14 19:12:53 +00:00
|
|
|
#include "ui/vertical_list.h"
|
2022-04-12 21:05:21 +00:00
|
|
|
#include "window/section_widget.h"
|
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_chat.h"
|
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_media_player.h" // mediaPlayerMenuCheck
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
PeerId GenerateUser(not_null<History*> history, const QString &name) {
|
|
|
|
Expects(history->peer->isUser());
|
2022-04-16 16:58:13 +00:00
|
|
|
|
2022-04-12 21:05:21 +00:00
|
|
|
const auto peerId = Data::FakePeerIdForJustName(name);
|
|
|
|
history->owner().processUser(MTP_user(
|
|
|
|
MTP_flags(MTPDuser::Flag::f_first_name | MTPDuser::Flag::f_min),
|
|
|
|
peerToBareMTPInt(peerId),
|
|
|
|
MTP_long(0),
|
|
|
|
MTP_string(tr::lng_settings_chat_message_reply_from(tr::now)),
|
|
|
|
MTPstring(), // last name
|
|
|
|
MTPstring(), // username
|
|
|
|
MTPstring(), // phone
|
|
|
|
MTPUserProfilePhoto(), // profile photo
|
|
|
|
MTPUserStatus(), // status
|
|
|
|
MTP_int(0), // bot info version
|
|
|
|
MTPVector<MTPRestrictionReason>(), // restrictions
|
|
|
|
MTPstring(), // bot placeholder
|
2022-08-09 11:15:21 +00:00
|
|
|
MTPstring(), // lang code
|
2022-10-04 04:55:43 +00:00
|
|
|
MTPEmojiStatus(),
|
2023-07-03 07:40:29 +00:00
|
|
|
MTPVector<MTPUsername>(),
|
2023-10-13 12:17:02 +00:00
|
|
|
MTPint(), // stories_max_id
|
2023-11-22 08:16:39 +00:00
|
|
|
MTPPeerColor(), // color
|
|
|
|
MTPPeerColor())); // profile_color
|
2022-04-12 21:05:21 +00:00
|
|
|
return peerId;
|
|
|
|
}
|
|
|
|
|
|
|
|
AdminLog::OwnedItem GenerateItem(
|
|
|
|
not_null<HistoryView::ElementDelegate*> delegate,
|
|
|
|
not_null<History*> history,
|
|
|
|
PeerId from,
|
2023-10-10 06:49:22 +00:00
|
|
|
FullMsgId replyTo,
|
2022-04-12 21:05:21 +00:00
|
|
|
const QString &text) {
|
|
|
|
Expects(history->peer->isUser());
|
|
|
|
|
|
|
|
const auto item = history->addNewLocalMessage(
|
|
|
|
history->nextNonHistoryEntryId(),
|
2023-05-25 09:32:13 +00:00
|
|
|
(MessageFlag::FakeHistoryItem
|
2022-04-12 21:05:21 +00:00
|
|
|
| MessageFlag::HasFromId
|
2023-05-25 09:32:13 +00:00
|
|
|
| MessageFlag::HasReplyInfo),
|
2022-04-12 21:05:21 +00:00
|
|
|
UserId(), // via
|
2023-10-10 06:49:22 +00:00
|
|
|
FullReplyTo{ .messageId = replyTo },
|
2022-04-12 21:05:21 +00:00
|
|
|
base::unixtime::now(), // date
|
|
|
|
from,
|
|
|
|
QString(), // postAuthor
|
|
|
|
TextWithEntities{ .text = text },
|
|
|
|
MTP_messageMediaEmpty(),
|
|
|
|
HistoryMessageMarkupData(),
|
|
|
|
uint64(0)); // groupedId
|
|
|
|
|
|
|
|
return AdminLog::OwnedItem(delegate, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddMessage(
|
2022-04-30 23:38:49 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2022-04-12 21:05:21 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2022-09-16 07:16:59 +00:00
|
|
|
rpl::producer<Data::ReactionId> &&idValue,
|
2022-04-30 23:38:49 +00:00
|
|
|
int width) {
|
2022-04-12 21:05:21 +00:00
|
|
|
|
2022-04-30 23:38:49 +00:00
|
|
|
const auto widget = container->add(
|
|
|
|
object_ptr<Ui::RpWidget>(container),
|
2022-04-12 21:05:21 +00:00
|
|
|
style::margins(
|
|
|
|
0,
|
2023-11-15 00:27:13 +00:00
|
|
|
st::defaultVerticalListSkip,
|
2022-04-12 21:05:21 +00:00
|
|
|
0,
|
|
|
|
st::settingsPrivacySkipTop));
|
|
|
|
|
|
|
|
class Delegate final : public HistoryView::SimpleElementDelegate {
|
|
|
|
public:
|
|
|
|
using HistoryView::SimpleElementDelegate::SimpleElementDelegate;
|
|
|
|
private:
|
|
|
|
HistoryView::Context elementContext() override {
|
|
|
|
return HistoryView::Context::ContactPreview;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct State {
|
|
|
|
AdminLog::OwnedItem reply;
|
|
|
|
AdminLog::OwnedItem item;
|
|
|
|
std::unique_ptr<Delegate> delegate;
|
|
|
|
std::unique_ptr<Ui::ChatStyle> style;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
std::vector<rpl::lifetime> lifetimes;
|
|
|
|
bool flag = false;
|
|
|
|
} icons;
|
|
|
|
};
|
2022-04-30 23:38:49 +00:00
|
|
|
const auto state = container->lifetime().make_state<State>();
|
2022-04-12 21:05:21 +00:00
|
|
|
state->delegate = std::make_unique<Delegate>(
|
|
|
|
controller,
|
|
|
|
crl::guard(widget, [=] { widget->update(); }));
|
2023-10-26 19:40:53 +00:00
|
|
|
state->style = std::make_unique<Ui::ChatStyle>(
|
|
|
|
controller->session().colorIndicesValue());
|
2022-04-15 09:23:10 +00:00
|
|
|
state->style->apply(controller->defaultChatTheme().get());
|
2022-04-12 21:05:21 +00:00
|
|
|
state->icons.lifetimes = std::vector<rpl::lifetime>(2);
|
|
|
|
|
|
|
|
const auto history = controller->session().data().history(
|
|
|
|
PeerData::kServiceNotificationsId);
|
|
|
|
state->reply = GenerateItem(
|
|
|
|
state->delegate.get(),
|
|
|
|
history,
|
|
|
|
GenerateUser(
|
|
|
|
history,
|
|
|
|
tr::lng_settings_chat_message_reply_from(tr::now)),
|
2023-10-10 06:49:22 +00:00
|
|
|
FullMsgId(),
|
2022-04-12 21:05:21 +00:00
|
|
|
tr::lng_settings_chat_message_reply(tr::now));
|
|
|
|
auto message = GenerateItem(
|
|
|
|
state->delegate.get(),
|
|
|
|
history,
|
|
|
|
history->peer->id,
|
2023-10-10 06:49:22 +00:00
|
|
|
state->reply->data()->fullId(),
|
2022-04-12 21:05:21 +00:00
|
|
|
tr::lng_settings_chat_message(tr::now));
|
|
|
|
const auto view = message.get();
|
|
|
|
state->item = std::move(message);
|
|
|
|
|
|
|
|
const auto padding = st::settingsForwardPrivacyPadding;
|
|
|
|
|
2022-04-30 23:38:49 +00:00
|
|
|
const auto updateWidgetSize = [=](int width) {
|
2022-04-12 21:05:21 +00:00
|
|
|
const auto height = view->resizeGetHeight(width);
|
|
|
|
const auto top = view->marginTop();
|
|
|
|
const auto bottom = view->marginBottom();
|
|
|
|
const auto full = padding + top + height + bottom + padding;
|
|
|
|
widget->resize(width, full);
|
2022-04-30 23:38:49 +00:00
|
|
|
};
|
|
|
|
widget->widthValue(
|
|
|
|
) | rpl::filter(
|
|
|
|
rpl::mappers::_1 >= (st::historyMinimalWidth / 2)
|
|
|
|
) | rpl::start_with_next(updateWidgetSize, widget->lifetime());
|
|
|
|
updateWidgetSize(width);
|
2022-04-12 21:05:21 +00:00
|
|
|
|
|
|
|
const auto rightSize = st::settingsReactionCornerSize;
|
|
|
|
const auto rightRect = [=] {
|
|
|
|
const auto viewInner = view->innerGeometry();
|
|
|
|
return QRect(
|
|
|
|
viewInner.x() + viewInner.width(),
|
|
|
|
padding
|
|
|
|
+ view->marginTop()
|
|
|
|
+ view->resizeGetHeight(widget->width())
|
|
|
|
- rightSize.height(),
|
|
|
|
rightSize.width(),
|
|
|
|
rightSize.height()).translated(st::settingsReactionCornerSkip);
|
|
|
|
};
|
|
|
|
|
|
|
|
widget->paintRequest(
|
|
|
|
) | rpl::start_with_next([=](const QRect &rect) {
|
|
|
|
Window::SectionWidget::PaintBackground(
|
|
|
|
controller,
|
|
|
|
controller->defaultChatTheme().get(), // #TODO themes
|
|
|
|
widget,
|
|
|
|
rect);
|
|
|
|
|
|
|
|
Painter p(widget);
|
|
|
|
auto hq = PainterHighQualityEnabler(p);
|
|
|
|
const auto theme = controller->defaultChatTheme().get();
|
|
|
|
auto context = theme->preparePaintContext(
|
|
|
|
state->style.get(),
|
|
|
|
widget->rect(),
|
2022-09-09 16:09:51 +00:00
|
|
|
widget->rect(),
|
|
|
|
controller->isGifPausedAtLeastFor(
|
|
|
|
Window::GifPauseReason::Layer));
|
2022-04-12 21:05:21 +00:00
|
|
|
context.outbg = view->hasOutLayout();
|
|
|
|
|
|
|
|
{
|
|
|
|
const auto radius = rightSize.height() / 2;
|
|
|
|
const auto r = rightRect();
|
|
|
|
const auto &st = context.st->messageStyle(
|
|
|
|
context.outbg,
|
|
|
|
context.selected());
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st.msgShadow);
|
|
|
|
p.drawRoundedRect(r.translated(0, st::msgShadow), radius, radius);
|
|
|
|
p.setBrush(st.msgBg);
|
|
|
|
p.drawRoundedRect(r, radius, radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
p.translate(padding / 2, padding + view->marginBottom());
|
|
|
|
view->draw(p, context);
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
2022-09-16 07:16:59 +00:00
|
|
|
auto selectedId = rpl::duplicate(idValue);
|
2022-04-14 05:45:52 +00:00
|
|
|
std::move(
|
2022-09-16 07:16:59 +00:00
|
|
|
selectedId
|
2022-04-14 05:45:52 +00:00
|
|
|
) | rpl::start_with_next([
|
|
|
|
=,
|
2022-09-16 07:16:59 +00:00
|
|
|
idValue = std::move(idValue),
|
2022-04-14 05:45:52 +00:00
|
|
|
iconSize = st::settingsReactionMessageSize
|
2022-09-16 07:16:59 +00:00
|
|
|
](const Data::ReactionId &id) {
|
|
|
|
const auto index = state->icons.flag ? 1 : 0;
|
|
|
|
state->icons.flag = !state->icons.flag;
|
|
|
|
state->icons.lifetimes[index] = rpl::lifetime();
|
2022-04-12 21:05:21 +00:00
|
|
|
const auto &reactions = controller->session().data().reactions();
|
2022-09-16 07:16:59 +00:00
|
|
|
auto iconPositionValue = widget->geometryValue(
|
|
|
|
) | rpl::map([=](const QRect &r) {
|
|
|
|
return widget->pos()
|
|
|
|
+ rightRect().topLeft()
|
|
|
|
+ QPoint(
|
|
|
|
(rightSize.width() - iconSize) / 2,
|
|
|
|
(rightSize.height() - iconSize) / 2);
|
|
|
|
});
|
|
|
|
auto destroys = rpl::duplicate(
|
|
|
|
idValue
|
|
|
|
) | rpl::skip(1) | rpl::to_empty;
|
|
|
|
if (const auto customId = id.custom()) {
|
|
|
|
AddReactionCustomIcon(
|
|
|
|
container,
|
|
|
|
std::move(iconPositionValue),
|
|
|
|
iconSize,
|
|
|
|
controller,
|
|
|
|
customId,
|
|
|
|
std::move(destroys),
|
|
|
|
&state->icons.lifetimes[index]);
|
|
|
|
return;
|
|
|
|
}
|
2022-04-15 05:26:58 +00:00
|
|
|
for (const auto &r : reactions.list(Data::Reactions::Type::Active)) {
|
2022-08-16 11:28:17 +00:00
|
|
|
if (r.id != id) {
|
2022-04-12 21:05:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-08-29 12:34:21 +00:00
|
|
|
AddReactionAnimatedIcon(
|
2022-04-30 23:38:49 +00:00
|
|
|
container,
|
2022-09-16 07:16:59 +00:00
|
|
|
std::move(iconPositionValue),
|
2022-04-12 21:05:21 +00:00
|
|
|
iconSize,
|
|
|
|
r,
|
|
|
|
rpl::never<>(),
|
2022-09-16 07:16:59 +00:00
|
|
|
std::move(destroys),
|
2022-04-12 21:05:21 +00:00
|
|
|
&state->icons.lifetimes[index]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}, widget->lifetime());
|
|
|
|
}
|
|
|
|
|
2022-08-30 09:21:58 +00:00
|
|
|
not_null<Ui::RpWidget*> AddReactionIconWrap(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
rpl::producer<QPoint> iconPositionValue,
|
|
|
|
int iconSize,
|
|
|
|
Fn<void(not_null<QWidget*>, QPainter&)> paintCallback,
|
|
|
|
rpl::producer<> &&destroys,
|
|
|
|
not_null<rpl::lifetime*> stateLifetime) {
|
|
|
|
struct State {
|
|
|
|
base::unique_qptr<Ui::RpWidget> widget;
|
|
|
|
Ui::Animations::Simple finalAnimation;
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto state = stateLifetime->make_state<State>();
|
|
|
|
state->widget = base::make_unique_q<Ui::RpWidget>(parent);
|
|
|
|
|
|
|
|
const auto widget = state->widget.get();
|
|
|
|
widget->resize(iconSize, iconSize);
|
|
|
|
widget->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
|
|
|
std::move(
|
|
|
|
iconPositionValue
|
|
|
|
) | rpl::start_with_next([=](const QPoint &point) {
|
|
|
|
widget->moveToLeft(point.x(), point.y());
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
|
|
|
const auto update = crl::guard(widget, [=] { widget->update(); });
|
|
|
|
|
|
|
|
widget->paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
auto p = QPainter(widget);
|
|
|
|
|
|
|
|
if (state->finalAnimation.animating()) {
|
|
|
|
const auto progress = 1. - state->finalAnimation.value(0.);
|
|
|
|
const auto size = widget->size();
|
|
|
|
const auto scaledSize = size * progress;
|
|
|
|
const auto scaledCenter = QPoint(
|
|
|
|
(size.width() - scaledSize.width()) / 2.,
|
|
|
|
(size.height() - scaledSize.height()) / 2.);
|
|
|
|
p.setOpacity(progress);
|
|
|
|
p.translate(scaledCenter);
|
|
|
|
p.scale(progress, progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
paintCallback(widget, p);
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
|
|
|
std::move(
|
|
|
|
destroys
|
|
|
|
) | rpl::take(1) | rpl::start_with_next([=, from = 0., to = 1.] {
|
|
|
|
state->finalAnimation.start(
|
|
|
|
[=](float64 value) {
|
|
|
|
update();
|
|
|
|
if (value == to) {
|
|
|
|
stateLifetime->destroy();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
from,
|
|
|
|
to,
|
|
|
|
st::defaultPopupMenu.showDuration);
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
|
|
|
widget->raise();
|
|
|
|
widget->show();
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2022-04-12 21:05:21 +00:00
|
|
|
} // namespace
|
|
|
|
|
2022-08-29 12:34:21 +00:00
|
|
|
void AddReactionAnimatedIcon(
|
2022-04-13 16:20:30 +00:00
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
rpl::producer<QPoint> iconPositionValue,
|
|
|
|
int iconSize,
|
|
|
|
const Data::Reaction &reaction,
|
|
|
|
rpl::producer<> &&selects,
|
|
|
|
rpl::producer<> &&destroys,
|
|
|
|
not_null<rpl::lifetime*> stateLifetime) {
|
|
|
|
struct State {
|
|
|
|
struct Entry {
|
|
|
|
std::shared_ptr<Data::DocumentMedia> media;
|
2022-08-29 12:34:21 +00:00
|
|
|
std::shared_ptr<Ui::AnimatedIcon> icon;
|
2022-04-13 16:20:30 +00:00
|
|
|
};
|
|
|
|
Entry appear;
|
|
|
|
Entry select;
|
|
|
|
bool appearAnimated = false;
|
|
|
|
rpl::lifetime loadingLifetime;
|
|
|
|
};
|
|
|
|
const auto state = stateLifetime->make_state<State>();
|
|
|
|
|
|
|
|
state->appear.media = reaction.appearAnimation->createMediaView();
|
|
|
|
state->select.media = reaction.selectAnimation->createMediaView();
|
|
|
|
state->appear.media->checkStickerLarge();
|
|
|
|
state->select.media->checkStickerLarge();
|
|
|
|
rpl::single() | rpl::then(
|
2022-04-17 09:33:29 +00:00
|
|
|
reaction.appearAnimation->session().downloaderTaskFinished()
|
2022-04-13 16:20:30 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
const auto check = [&](State::Entry &entry) {
|
|
|
|
if (!entry.media) {
|
|
|
|
return true;
|
|
|
|
} else if (!entry.media->loaded()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
entry.icon = HistoryView::Reactions::DefaultIconFactory(
|
|
|
|
entry.media.get(),
|
|
|
|
iconSize);
|
|
|
|
entry.media = nullptr;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
if (check(state->select) && check(state->appear)) {
|
|
|
|
state->loadingLifetime.destroy();
|
|
|
|
}
|
|
|
|
}, state->loadingLifetime);
|
|
|
|
|
2022-08-30 09:21:58 +00:00
|
|
|
const auto paintCallback = [=](not_null<QWidget*> widget, QPainter &p) {
|
2022-08-29 12:34:21 +00:00
|
|
|
const auto paintFrame = [&](not_null<Ui::AnimatedIcon*> animation) {
|
2023-04-24 16:59:19 +00:00
|
|
|
const auto frame = animation->frame(st::windowFg->c);
|
2022-04-13 16:20:30 +00:00
|
|
|
p.drawImage(
|
|
|
|
QRect(
|
2022-04-14 05:45:52 +00:00
|
|
|
(widget->width() - iconSize) / 2,
|
|
|
|
(widget->height() - iconSize) / 2,
|
|
|
|
iconSize,
|
|
|
|
iconSize),
|
2022-04-13 16:20:30 +00:00
|
|
|
frame);
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto appear = state->appear.icon.get();
|
|
|
|
if (appear && !state->appearAnimated) {
|
|
|
|
state->appearAnimated = true;
|
2022-08-30 09:21:58 +00:00
|
|
|
appear->animate(crl::guard(widget, [=] { widget->update(); }));
|
2022-04-13 16:20:30 +00:00
|
|
|
}
|
|
|
|
if (appear && appear->animating()) {
|
|
|
|
paintFrame(appear);
|
|
|
|
} else if (const auto select = state->select.icon.get()) {
|
|
|
|
paintFrame(select);
|
|
|
|
}
|
2022-08-30 09:21:58 +00:00
|
|
|
};
|
|
|
|
const auto widget = AddReactionIconWrap(
|
|
|
|
parent,
|
|
|
|
std::move(iconPositionValue),
|
|
|
|
iconSize,
|
|
|
|
paintCallback,
|
|
|
|
std::move(destroys),
|
|
|
|
stateLifetime);
|
2022-04-13 16:20:30 +00:00
|
|
|
|
|
|
|
std::move(
|
|
|
|
selects
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
const auto select = state->select.icon.get();
|
|
|
|
if (select && !select->animating()) {
|
2022-08-30 09:21:58 +00:00
|
|
|
select->animate(crl::guard(widget, [=] { widget->update(); }));
|
2022-04-13 16:20:30 +00:00
|
|
|
}
|
|
|
|
}, widget->lifetime());
|
2022-08-30 09:21:58 +00:00
|
|
|
}
|
2022-04-13 16:20:30 +00:00
|
|
|
|
2022-08-30 09:21:58 +00:00
|
|
|
void AddReactionCustomIcon(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
rpl::producer<QPoint> iconPositionValue,
|
|
|
|
int iconSize,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
DocumentId customId,
|
|
|
|
rpl::producer<> &&destroys,
|
|
|
|
not_null<rpl::lifetime*> stateLifetime) {
|
|
|
|
struct State {
|
|
|
|
std::unique_ptr<Ui::Text::CustomEmoji> custom;
|
|
|
|
Fn<void()> repaint;
|
|
|
|
};
|
|
|
|
const auto state = stateLifetime->make_state<State>();
|
2022-08-30 15:21:14 +00:00
|
|
|
static constexpr auto tag = Data::CustomEmojiManager::SizeTag::Normal;
|
2022-08-30 09:21:58 +00:00
|
|
|
state->custom = controller->session().data().customEmojiManager().create(
|
|
|
|
customId,
|
|
|
|
[=] { state->repaint(); },
|
|
|
|
tag);
|
|
|
|
|
|
|
|
const auto paintCallback = [=](not_null<QWidget*> widget, QPainter &p) {
|
|
|
|
const auto ratio = style::DevicePixelRatio();
|
|
|
|
const auto size = Data::FrameSizeFromTag(tag) / ratio;
|
|
|
|
state->custom->paint(p, {
|
2022-12-15 15:10:51 +00:00
|
|
|
.textColor = st::windowFg->c,
|
2022-08-30 09:21:58 +00:00
|
|
|
.now = crl::now(),
|
|
|
|
.position = QPoint(
|
|
|
|
(widget->width() - size) / 2,
|
|
|
|
(widget->height() - size) / 2),
|
|
|
|
.paused = controller->isGifPausedAtLeastFor(
|
|
|
|
Window::GifPauseReason::Layer),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const auto widget = AddReactionIconWrap(
|
|
|
|
parent,
|
|
|
|
std::move(iconPositionValue),
|
|
|
|
iconSize,
|
|
|
|
paintCallback,
|
|
|
|
std::move(destroys),
|
|
|
|
stateLifetime);
|
2022-08-30 15:21:14 +00:00
|
|
|
state->repaint = crl::guard(widget, [=] { widget->update(); });
|
2022-04-13 16:20:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 21:05:21 +00:00
|
|
|
void ReactionsSettingsBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
not_null<Window::SessionController*> controller) {
|
|
|
|
|
|
|
|
struct State {
|
2022-09-16 07:16:59 +00:00
|
|
|
rpl::variable<Data::ReactionId> selectedId;
|
2022-04-12 21:05:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto &reactions = controller->session().data().reactions();
|
|
|
|
const auto state = box->lifetime().make_state<State>();
|
2022-09-16 07:16:59 +00:00
|
|
|
state->selectedId = reactions.favoriteId();
|
2022-04-12 21:05:21 +00:00
|
|
|
|
2022-04-30 23:38:49 +00:00
|
|
|
const auto pinnedToTop = box->setPinnedToTopContent(
|
|
|
|
object_ptr<Ui::VerticalLayout>(box));
|
|
|
|
|
2022-09-16 07:16:59 +00:00
|
|
|
auto idValue = state->selectedId.value();
|
|
|
|
AddMessage(pinnedToTop, controller, std::move(idValue), box->width());
|
2022-04-12 21:05:21 +00:00
|
|
|
|
2023-11-14 19:12:53 +00:00
|
|
|
Ui::AddSubsectionTitle(
|
2022-04-30 23:38:49 +00:00
|
|
|
pinnedToTop,
|
2022-04-12 21:05:21 +00:00
|
|
|
tr::lng_settings_chat_reactions_subtitle());
|
|
|
|
|
2022-04-30 23:38:49 +00:00
|
|
|
const auto container = box->verticalLayout();
|
|
|
|
|
|
|
|
const auto check = Ui::CreateChild<Ui::RpWidget>(container.get());
|
2022-04-12 21:05:21 +00:00
|
|
|
check->resize(st::settingsReactionCornerSize);
|
|
|
|
check->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
check->paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Painter p(check);
|
|
|
|
st::mediaPlayerMenuCheck.paintInCenter(p, check->rect());
|
|
|
|
}, check->lifetime());
|
|
|
|
const auto checkButton = [=](not_null<const Ui::RpWidget*> button) {
|
|
|
|
check->moveToRight(
|
|
|
|
st::settingsButtonRightSkip,
|
|
|
|
button->y() + (button->height() - check->height()) / 2);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto firstCheckedButton = (Ui::RpWidget*)(nullptr);
|
2022-09-16 07:16:59 +00:00
|
|
|
auto list = reactions.list(Data::Reactions::Type::Active);
|
|
|
|
if (const auto favorite = reactions.favorite()) {
|
|
|
|
if (favorite->id.custom()) {
|
|
|
|
list.insert(begin(list), *favorite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto &r : list) {
|
2023-11-14 20:59:21 +00:00
|
|
|
const auto button = container->add(object_ptr<Ui::SettingsButton>(
|
2022-04-30 23:38:49 +00:00
|
|
|
container,
|
2022-04-12 21:05:21 +00:00
|
|
|
rpl::single<QString>(base::duplicate(r.title)),
|
2023-11-14 20:59:21 +00:00
|
|
|
st::settingsButton));
|
2022-04-12 21:05:21 +00:00
|
|
|
|
|
|
|
const auto iconSize = st::settingsReactionSize;
|
2022-09-16 07:16:59 +00:00
|
|
|
const auto left = button->st().iconLeft;
|
|
|
|
auto iconPositionValue = button->sizeValue(
|
|
|
|
) | rpl::map([=](const QSize &s) {
|
|
|
|
return QPoint(
|
|
|
|
left + st::settingsReactionRightSkip,
|
|
|
|
(s.height() - iconSize) / 2);
|
|
|
|
});
|
|
|
|
if (const auto customId = r.id.custom()) {
|
|
|
|
AddReactionCustomIcon(
|
|
|
|
button,
|
|
|
|
std::move(iconPositionValue),
|
|
|
|
iconSize,
|
|
|
|
controller,
|
|
|
|
customId,
|
|
|
|
rpl::never<>(),
|
|
|
|
&button->lifetime());
|
|
|
|
} else {
|
|
|
|
AddReactionAnimatedIcon(
|
|
|
|
button,
|
|
|
|
std::move(iconPositionValue),
|
|
|
|
iconSize,
|
|
|
|
r,
|
|
|
|
button->events(
|
|
|
|
) | rpl::filter([=](not_null<QEvent*> event) {
|
|
|
|
return event->type() == QEvent::Enter;
|
|
|
|
}) | rpl::to_empty,
|
|
|
|
rpl::never<>(),
|
|
|
|
&button->lifetime());
|
|
|
|
}
|
2022-08-16 11:28:17 +00:00
|
|
|
button->setClickedCallback([=, id = r.id] {
|
2022-04-12 21:05:21 +00:00
|
|
|
checkButton(button);
|
2022-09-16 07:16:59 +00:00
|
|
|
state->selectedId = id;
|
2022-04-12 21:05:21 +00:00
|
|
|
});
|
2022-09-16 07:16:59 +00:00
|
|
|
if (r.id == state->selectedId.current()) {
|
2022-04-12 21:05:21 +00:00
|
|
|
firstCheckedButton = button;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (firstCheckedButton) {
|
|
|
|
firstCheckedButton->geometryValue(
|
|
|
|
) | rpl::filter([=](const QRect &r) {
|
|
|
|
return r.isValid();
|
|
|
|
}) | rpl::take(1) | rpl::start_with_next([=] {
|
|
|
|
checkButton(firstCheckedButton);
|
|
|
|
}, firstCheckedButton->lifetime());
|
|
|
|
}
|
|
|
|
check->raise();
|
|
|
|
|
|
|
|
box->setTitle(tr::lng_settings_chat_reactions_title());
|
|
|
|
box->setWidth(st::boxWideWidth);
|
|
|
|
box->addButton(tr::lng_settings_save(), [=] {
|
|
|
|
const auto &data = controller->session().data();
|
2022-09-16 07:16:59 +00:00
|
|
|
const auto selectedId = state->selectedId.current();
|
|
|
|
if (data.reactions().favoriteId() != selectedId) {
|
|
|
|
data.reactions().setFavorite(selectedId);
|
2022-04-12 21:05:21 +00:00
|
|
|
}
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
|
|
|
}
|