mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-03 21:54:05 +02:00
Added birthday suggestion to top bar in dialogs.
This commit is contained in:
parent
3a622f111a
commit
f3b6c7c09b
3 changed files with 88 additions and 10 deletions
|
@ -7,12 +7,32 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "dialogs/dialogs_top_bar_suggestion.h"
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "data/data_birthday.h"
|
||||
#include "data/data_user.h"
|
||||
#include "dialogs/ui/dialogs_top_bar_suggestion_content.h"
|
||||
#include "info/profile/info_profile_values.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "window/window_session_controller.h"
|
||||
|
||||
namespace Dialogs {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] Window::SessionController *FindSessionController(
|
||||
not_null<Ui::RpWidget*> widget) {
|
||||
const auto window = Core::App().findWindow(widget);
|
||||
return window ? window->sessionController() : nullptr;
|
||||
}
|
||||
|
||||
constexpr auto kSugSetBirthday = "BIRTHDAY_SETUP"_cs;
|
||||
|
||||
} // namespace
|
||||
|
||||
object_ptr<Ui::SlideWrap<Ui::RpWidget>> CreateTopBarSuggestion(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
|
@ -22,14 +42,57 @@ object_ptr<Ui::SlideWrap<Ui::RpWidget>> CreateTopBarSuggestion(
|
|||
parent,
|
||||
object_ptr<Ui::RpWidget>::fromRaw(content));
|
||||
const auto wrap = result.data();
|
||||
wrap->toggle(false, anim::type::instant);
|
||||
struct State {
|
||||
rpl::lifetime birthdayLifetime;
|
||||
};
|
||||
const auto state = content->lifetime().make_state<State>();
|
||||
|
||||
content->setContent(
|
||||
tr::lng_dialogs_top_bar_suggestions_birthday_title(
|
||||
tr::now,
|
||||
Ui::Text::Bold),
|
||||
tr::lng_dialogs_top_bar_suggestions_birthday_about(
|
||||
tr::now,
|
||||
TextWithEntities::Simple));
|
||||
const auto processCurrentSuggestion = [=](auto repeat) -> void {
|
||||
if (session->appConfig().suggestionCurrent(kSugSetBirthday.utf8())
|
||||
&& !Data::IsBirthdayToday(session->user()->birthday())) {
|
||||
content->setClickedCallback([=] {
|
||||
const auto controller = FindSessionController(parent);
|
||||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
Core::App().openInternalUrl(
|
||||
u"internal:edit_birthday"_q,
|
||||
QVariant::fromValue(ClickHandlerContext{
|
||||
.sessionWindow = base::make_weak(controller),
|
||||
}));
|
||||
|
||||
state->birthdayLifetime = Info::Profile::BirthdayValue(
|
||||
session->user()
|
||||
) | rpl::map(
|
||||
Data::IsBirthdayTodayValue
|
||||
) | rpl::flatten_latest(
|
||||
) | rpl::distinct_until_changed(
|
||||
) | rpl::start_with_next([=] {
|
||||
repeat(repeat);
|
||||
});
|
||||
});
|
||||
content->setHideCallback([=] {
|
||||
session->appConfig().dismissSuggestion(
|
||||
kSugSetBirthday.utf8());
|
||||
repeat(repeat);
|
||||
});
|
||||
content->setContent(
|
||||
tr::lng_dialogs_top_bar_suggestions_birthday_title(
|
||||
tr::now,
|
||||
Ui::Text::Bold),
|
||||
tr::lng_dialogs_top_bar_suggestions_birthday_about(
|
||||
tr::now,
|
||||
TextWithEntities::Simple));
|
||||
wrap->toggle(true, anim::type::normal);
|
||||
} else {
|
||||
wrap->toggle(false, anim::type::normal);
|
||||
}
|
||||
};
|
||||
|
||||
session->appConfig().refreshed() | rpl::start_with_next([=] {
|
||||
processCurrentSuggestion(processCurrentSuggestion);
|
||||
}, content->lifetime());
|
||||
|
||||
rpl::combine(
|
||||
parent->widthValue(),
|
||||
|
|
|
@ -18,7 +18,15 @@ TopBarSuggestionContent::TopBarSuggestionContent(not_null<Ui::RpWidget*> p)
|
|||
: Ui::RippleButton(p, st::defaultRippleAnimationBgOver)
|
||||
, _titleSt(st::semiboldTextStyle)
|
||||
, _contentTitleSt(st::semiboldTextStyle)
|
||||
, _contentTextSt(st::defaultTextStyle) {
|
||||
, _contentTextSt(st::defaultTextStyle)
|
||||
, _rightHide(
|
||||
base::make_unique_q<Ui::IconButton>(
|
||||
this,
|
||||
st::dialogsCancelSearchInPeer)) {
|
||||
const auto rightHide = _rightHide.get();
|
||||
sizeValue() | rpl::start_with_next([=](const QSize &s) {
|
||||
rightHide->moveToRight(st::buttonRadius, st::lineWidth);
|
||||
}, rightHide->lifetime());
|
||||
}
|
||||
|
||||
void TopBarSuggestionContent::draw(QPainter &p) {
|
||||
|
@ -29,7 +37,7 @@ void TopBarSuggestionContent::draw(QPainter &p) {
|
|||
const auto r = Ui::RpWidget::rect();
|
||||
p.fillRect(r, st::historyPinnedBg);
|
||||
Ui::RippleButton::paintRipple(p, 0, 0);
|
||||
const auto leftPadding = st::msgReplyBarSkip + st::msgReplyBarSkip;
|
||||
const auto leftPadding = st::defaultDialogRow.padding.left();
|
||||
const auto rightPadding = st::msgReplyBarSkip;
|
||||
const auto topPadding = st::msgReplyPadding.top();
|
||||
const auto availableWidthNoPhoto = r.width()
|
||||
|
@ -44,7 +52,7 @@ void TopBarSuggestionContent::draw(QPainter &p) {
|
|||
p.setPen(st::windowActiveTextFg);
|
||||
p.setPen(st::windowFg);
|
||||
{
|
||||
const auto left = hasSecondLineTitle ? leftPadding : titleRight;
|
||||
const auto left = leftPadding;
|
||||
const auto top = hasSecondLineTitle
|
||||
? (topPadding + _titleSt.font->height)
|
||||
: topPadding;
|
||||
|
@ -133,4 +141,8 @@ rpl::producer<int> TopBarSuggestionContent::desiredHeightValue() const {
|
|||
});
|
||||
}
|
||||
|
||||
void TopBarSuggestionContent::setHideCallback(Fn<void()> hideCallback) {
|
||||
_rightHide->setClickedCallback(std::move(hideCallback));
|
||||
}
|
||||
|
||||
} // namespace Dialogs
|
||||
|
|
|
@ -26,6 +26,8 @@ public:
|
|||
|
||||
[[nodiscard]] rpl::producer<int> desiredHeightValue() const override;
|
||||
|
||||
void setHideCallback(Fn<void()>);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
|
||||
|
@ -42,6 +44,7 @@ private:
|
|||
rpl::variable<int> _lastPaintedContentTop = 0;
|
||||
|
||||
base::unique_qptr<Ui::IconButton> _rightHide;
|
||||
Fn<void()> _hideCallback;
|
||||
|
||||
std::shared_ptr<Ui::DynamicImage> _rightPhoto;
|
||||
QImage _rightPhotoImage;
|
||||
|
|
Loading…
Add table
Reference in a new issue