Show verified/premium badge in chat preview.

This commit is contained in:
John Preston 2024-12-12 10:23:52 +04:00
parent c6cf8be8d4
commit 8ddb13d6e2
2 changed files with 26 additions and 4 deletions

View file

@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "info/profile/info_profile_badge.h"
#include "info/profile/info_profile_cover.h"
#include "info/profile/info_profile_values.h"
#include "lang/lang_keys.h"
@ -38,11 +39,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/shadow.h"
#include "ui/ui_utility.h"
#include "ui/unread_badge.h"
#include "window/themes/window_theme.h"
#include "window/section_widget.h"
#include "window/window_session_controller.h"
#include "styles/style_chat.h"
#include "styles/style_chat_helpers.h"
#include "styles/style_settings.h"
#ifdef Q_OS_WIN
#include "ui/platform/win/ui_windows_direct_manipulation.h"
@ -191,6 +194,8 @@ private:
const std::unique_ptr<Ui::ElasticScroll> _scroll;
const std::unique_ptr<Ui::FlatButton> _markRead;
Info::Profile::Badge _badge;
QPointer<ListWidget> _inner;
std::unique_ptr<CornerButtons> _cornerButtons;
rpl::event_stream<ChatPreviewAction> _actions;
@ -265,7 +270,14 @@ Item::Item(not_null<Ui::RpWidget*> parent, not_null<Data::Thread*> thread)
std::make_unique<Ui::FlatButton>(
this,
tr::lng_context_mark_read(tr::now),
st::previewMarkRead)) {
st::previewMarkRead))
, _badge(
_top.get(),
st::settingsInfoPeerBadge,
_peer,
nullptr,
nullptr,
1) {
_chatStyle->apply(_theme.get());
setPointerCursor(false);
setMinWidth(st::previewMenu.menu.widthMin);
@ -359,12 +371,14 @@ void Item::setupTop() {
const auto shadow = Ui::CreateChild<Ui::PlainShadow>(this);
rpl::combine(
_top->widthValue(),
std::move(nameValue)
) | rpl::start_with_next([=](int width, const auto &) {
std::move(nameValue),
rpl::single(rpl::empty) | rpl::then(_badge.updated())
) | rpl::start_with_next([=](int width, const auto &, const auto &) {
const auto &st = st::previewTop;
name->resizeToNaturalWidth(width
- st.namePosition.x()
- st.photoPosition.x());
- st.photoPosition.x()
- (_badge.widget() ? _badge.widget()->width() : 0));
if (status) {
name->move(st::previewTop.namePosition);
} else {
@ -372,6 +386,10 @@ void Item::setupTop() {
st::previewTop.namePosition.x(),
(st::previewTop.height - name->height()) / 2);
}
_badge.move(
name->x() + name->width() + st::normalFont->spacew,
name->y(),
name->y() + name->height());
}, name->lifetime());
_top->geometryValue() | rpl::start_with_next([=](QRect geometry) {

View file

@ -197,6 +197,10 @@ settingsInfoPhotoSkip: 7px;
settingsInfoNameSkip: -1px;
settingsInfoUploadLeft: 6px;
settingsInfoPeerBadge: InfoPeerBadge {
verified: icon {
{ "dialogs/dialogs_verified_star", dialogsVerifiedIconBg },
{ "dialogs/dialogs_verified_check", dialogsVerifiedIconFg },
};
premium: icon {{ "dialogs/dialogs_premium", dialogsVerifiedIconBg }};
premiumFg: dialogsVerifiedIconBg;
sizeTag: 0; // Normal