2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Colorize bubbles according to a custom chat theme.

This commit is contained in:
John Preston
2021-08-27 23:44:47 +03:00
parent 5de83ef30c
commit beff635e45
38 changed files with 479 additions and 165 deletions

View File

@@ -61,22 +61,6 @@ namespace {
});
}
[[nodiscard]] auto ChatThemeValueFromPeer(
not_null<SessionController*> controller,
not_null<PeerData*> peer)
-> rpl::producer<std::shared_ptr<Ui::ChatTheme>> {
return MaybeCloudThemeValueFromPeer(
peer
) | rpl::map([=](std::optional<Data::CloudTheme> theme)
-> rpl::producer<std::shared_ptr<Ui::ChatTheme>> {
if (!theme) {
return rpl::single(controller->defaultChatTheme());
}
return controller->cachedChatThemeValue(*theme);
}) | rpl::flatten_latest(
) | rpl::distinct_until_changed();
}
} // namespace
AbstractSectionWidget::AbstractSectionWidget(
@@ -298,4 +282,20 @@ rpl::producer<int> SectionWidget::desiredHeight() const {
SectionWidget::~SectionWidget() = default;
auto ChatThemeValueFromPeer(
not_null<SessionController*> controller,
not_null<PeerData*> peer)
-> rpl::producer<std::shared_ptr<Ui::ChatTheme>> {
return MaybeCloudThemeValueFromPeer(
peer
) | rpl::map([=](std::optional<Data::CloudTheme> theme)
-> rpl::producer<std::shared_ptr<Ui::ChatTheme>> {
if (!theme) {
return rpl::single(controller->defaultChatTheme());
}
return controller->cachedChatThemeValue(*theme);
}) | rpl::flatten_latest(
) | rpl::distinct_until_changed();
}
} // namespace Window

View File

@@ -203,4 +203,9 @@ private:
};
[[nodiscard]] auto ChatThemeValueFromPeer(
not_null<SessionController*> controller,
not_null<PeerData*> peer)
-> rpl::producer<std::shared_ptr<Ui::ChatTheme>>;
} // namespace Window

View File

@@ -45,6 +45,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/text_utilities.h"
#include "ui/delayed_activation.h"
#include "ui/chat/message_bubble.h"
#include "ui/chat/chat_style.h"
#include "ui/chat/chat_theme.h"
#include "ui/toast/toast.h"
#include "ui/toasts/common_toasts.h"
@@ -79,6 +80,7 @@ constexpr auto kMaxChatEntryHistorySize = 50;
std::optional<QColor> accent) {
return [=](style::palette &palette) {
using namespace Theme;
palette.finalize();
if (dark) {
const auto &embedded = EmbeddedThemes();
const auto i = ranges::find(
@@ -506,9 +508,13 @@ SessionController::SessionController(
_window->widget(),
this))
, _invitePeekTimer([=] { checkInvitePeek(); })
, _defaultChatTheme(std::make_shared<Ui::ChatTheme>()) {
, _defaultChatTheme(std::make_shared<Ui::ChatTheme>())
, _chatStyle(std::make_unique<Ui::ChatStyle>()) {
init();
_chatStyleTheme = _defaultChatTheme;
_chatStyle->apply(_defaultChatTheme.get());
pushDefaultChatBackground();
Theme::Background()->updates(
) | rpl::start_with_next([=](const Theme::BackgroundUpdate &update) {
@@ -1378,6 +1384,15 @@ auto SessionController::cachedChatThemeValue(
}) | rpl::take(1));
}
void SessionController::setChatStyleTheme(
const std::shared_ptr<Ui::ChatTheme> &theme) {
if (_chatStyleTheme.lock() == theme) {
return;
}
_chatStyleTheme = theme;
_chatStyle->apply(theme.get());
}
void SessionController::pushDefaultChatBackground() {
const auto background = Theme::Background();
const auto &paper = background->paper();
@@ -1520,7 +1535,10 @@ HistoryView::PaintContext SessionController::preparePaintContext(
args.visibleAreaTop - visibleAreaTopLocal,
args.visibleAreaWidth,
content()->height());
return args.theme->preparePaintContext(viewport, args.clip);
return args.theme->preparePaintContext(
_chatStyle.get(),
viewport,
args.clip);
}
SessionController::~SessionController() {

View File

@@ -45,6 +45,7 @@ class FormController;
namespace Ui {
class LayerWidget;
enum class ReportReason;
class ChatStyle;
class ChatTheme;
struct ChatPaintContext;
struct ChatThemeBackground;
@@ -404,6 +405,7 @@ public:
[[nodiscard]] auto cachedChatThemeValue(
const Data::CloudTheme &data)
-> rpl::producer<std::shared_ptr<Ui::ChatTheme>>;
void setChatStyleTheme(const std::shared_ptr<Ui::ChatTheme> &theme);
struct PaintContextArgs {
not_null<Ui::ChatTheme*> theme;
@@ -484,6 +486,8 @@ private:
std::shared_ptr<Ui::ChatTheme> _defaultChatTheme;
base::flat_map<uint64, CachedTheme> _customChatThemes;
rpl::event_stream<std::shared_ptr<Ui::ChatTheme>> _cachedThemesStream;
std::unique_ptr<Ui::ChatStyle> _chatStyle;
std::weak_ptr<Ui::ChatTheme> _chatStyleTheme;
rpl::lifetime _lifetime;