Started gift collections.

This commit is contained in:
John Preston
2025-07-17 17:31:38 +04:00
parent 1cb4413869
commit 66e8f9865a
9 changed files with 200 additions and 4 deletions
+2
View File
@@ -1007,6 +1007,8 @@ PRIVATE
info/media/info_media_widget.h
info/members/info_members_widget.cpp
info/members/info_members_widget.h
info/peer_gifts/info_peer_gifts_collections.cpp
info/peer_gifts/info_peer_gifts_collections.h
info/peer_gifts/info_peer_gifts_common.cpp
info/peer_gifts/info_peer_gifts_common.h
info/peer_gifts/info_peer_gifts_widget.cpp
+17
View File
@@ -3751,6 +3751,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_resale_early" = "You will be able to resell this gift in {duration}.";
"lng_gift_transfer_early" = "You will be able to transfer this gift in {duration}.";
"lng_gift_resale_transfer_early_title" = "Try Later";
"lng_gift_collection_add" = "Add Collection";
"lng_gift_collection_new_title" = "Create a New Collection";
"lng_gift_collection_new_button" = "New Collection";
"lng_gift_collection_new_text" = "Choose a name for your collection and start adding your gifts there.";
"lng_gift_collection_new_ph" = "Title";
"lng_gift_collection_new_create" = "Create";
"lng_gift_collection_empty_title" = "Organize Your Gifts";
"lng_gift_collection_empty_text" = "Add some of your gifts to this collection.";
"lng_gift_collection_empty_button" = "Add to Collection";
"lng_gift_collection_all" = "All Gifts";
"lng_gift_collection_add_title" = "Add Gifts";
"lng_gift_collection_edit" = "Edit Name";
"lng_gift_collection_limit_title" = "Limit Reached";
"lng_gift_collection_limit_text" = "Please remove one of the existing collections to add a new one.";
"lng_gift_collection_delete" = "Delete Collection";
"lng_gift_collection_add_to" = "Add to Collection";
"lng_gift_collection_reorder" = "Reorder";
"lng_accounts_limit_title" = "Limit Reached";
"lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected account.";
@@ -1487,9 +1487,6 @@ editTagField: InputField(defaultInputField) {
heightMin: 36px;
}
editTagLimit: FlatLabel(defaultFlatLabel) {
textFg: windowSubTextFg;
}
editStickerSetNameField: InputField(defaultInputField) {
textMargins: margins(0px, 8px, 26px, 4px);
+16
View File
@@ -1227,3 +1227,19 @@ infoStarsRatingLearn: RoundButton(defaultActiveButton) {
ripple: emptyRippleAnimation;
}
infoStarsRatingTooltip: defaultImportantTooltip;
collectionAbout: FlatLabel(defaultFlatLabel) {
minWidth: 256px;
}
collectionNameField: InputField(defaultInputField) {
textBg: transparent;
textMargins: margins(2px, 10px, 32px, 2px);
placeholderFg: placeholderFg;
placeholderFgActive: placeholderFgActive;
placeholderFgError: placeholderFgActive;
placeholderMargins: margins(2px, 0px, 2px, 0px);
placeholderScale: 0.;
heightMin: 36px;
}
@@ -0,0 +1,107 @@
/*
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 "info/peer_gifts/info_peer_gifts_collections.h"
#include "api/api_credits.h" //
#include "apiwrap.h"
#include "data/data_peer.h"
#include "data/data_star_gift.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
#include "ui/boxes/confirm_box.h"
#include "ui/layers/generic_box.h"
#include "ui/widgets/fields/input_field.h"
#include "window/window_session_controller.h"
#include "styles/style_layers.h"
#include "styles/style_info.h"
namespace Info::PeerGifts {
namespace {
constexpr auto kCollectionNameLimit = 12;
} // namespace
void NewCollectionBox(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Data::SavedStarGiftId addId) {
box->setTitle(tr::lng_gift_collection_new_title());
box->addRow(
object_ptr<Ui::FlatLabel>(
box,
tr::lng_gift_collection_new_text(),
st::collectionAbout));
const auto title = box->addRow(
object_ptr<Ui::InputField>(
box,
st::collectionNameField,
tr::lng_gift_collection_new_ph()));
title->setMaxLength(kCollectionNameLimit * 2);
box->setFocusCallback([=] {
title->setFocusFast();
});
Ui::AddLengthLimitLabel(title, kCollectionNameLimit);
const auto show = navigation->uiShow();
const auto session = &peer->session();
const auto creating = std::make_shared<bool>(false);
box->addButton(tr::lng_gift_collection_new_create(), [=] {
if (*creating) {
return;
}
const auto text = title->getLastText().trimmed();
if (text.isEmpty()) {
title->showError();
return;
}
*creating = true;
auto ids = QVector<MTPInputSavedStarGift>();
if (addId) {
ids.push_back(Api::InputSavedStarGiftId(addId));
}
const auto weak = base::make_weak(box);
session->api().request(MTPpayments_CreateStarGiftCollection(
peer->input,
MTP_string(text),
MTP_vector<MTPInputSavedStarGift>(ids)
)).done([=](const MTPStarGiftCollection &result) {
*creating = false;
if (const auto strong = weak.get()) {
strong->closeBox();
}
}).fail([=](const MTP::Error &error) {
*creating = false;
const auto &type = error.type();
if (type == u""_q) {
show->show(Ui::MakeInformBox({
.text = tr::lng_gift_collection_limit_text(),
.confirmText = tr::lng_box_ok(),
.title = tr::lng_gift_collection_limit_title(),
}));
if (const auto strong = weak.get()) {
strong->closeBox();
}
} else {
show->showToast(error.type());
}
}).send();
});
box->addButton(tr::lng_cancel(), [=] {
box->closeBox();
});
}
} // namespace Info::PeerGifts
@@ -0,0 +1,30 @@
/*
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
*/
#pragma once
namespace Data {
class SavedStarGiftId;
} // namespace Data
namespace Ui {
class GenericBox;
} // namespace Ui
namespace Window {
class SessionNavigation;
} // namespace Window
namespace Info::PeerGifts {
void NewCollectionBox(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Data::SavedStarGiftId addId);
} // namespace Info::PeerGifts
@@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_credits.h"
#include "data/data_session.h"
#include "data/data_user.h"
#include "info/peer_gifts/info_peer_gifts_collections.h"
#include "info/peer_gifts/info_peer_gifts_common.h"
#include "info/info_controller.h"
#include "ui/layers/generic_box.h"
@@ -807,6 +808,8 @@ void Widget::setupNotifyCheckbox(bool enabled) {
}
void Widget::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) {
const auto peer = _inner->peer();
const auto canManage = peer->canManageGifts();
const auto filter = _filter.current();
const auto change = [=](Fn<void(Filter&)> update) {
auto now = _filter.current();
@@ -824,6 +827,20 @@ void Widget::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) {
}, &st::menuIconEarn);
}
if (canManage) {
const auto weak = base::make_weak(
(Window::SessionNavigation*)controller());
addAction(tr::lng_gift_collection_add(tr::now), [=] {
if (const auto strong = weak.get()) {
strong->uiShow()->show(Box(
NewCollectionBox,
strong,
peer,
Data::SavedStarGiftId()));
}
}, &st::menuIconAddToFolder);
}
addAction({ .isSeparator = true });
addAction(tr::lng_peer_gifts_filter_unlimited(tr::now), [=] {
@@ -857,7 +874,7 @@ void Widget::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) {
});
}, filter.skipUnique ? nullptr : &st::mediaPlayerMenuCheck);
if (_inner->peer()->canManageGifts()) {
if (canManage) {
addAction({ .isSeparator = true });
addAction(tr::lng_peer_gifts_filter_saved(tr::now), [=] {
@@ -121,6 +121,14 @@ int AppConfig::pinnedGiftsLimit() const {
return get<int>(u"stargifts_pinned_to_top_limit"_q, 6);
}
int AppConfig::giftCollectionsLimit() const {
return get<int>(u"stargifts_collections_limit"_q, 10);
}
int AppConfig::giftCollectionGiftsLimit() const {
return get<int>(u"stargifts_collection_gifts_limit"_q, 500);
}
bool AppConfig::callsDisabledForSession() const {
const auto authorizations = _account->sessionExists()
? &_account->session().api().authorizations()
@@ -78,6 +78,8 @@ public:
[[nodiscard]] int paidMessageChannelStarsDefault() const;
[[nodiscard]] int pinnedGiftsLimit() const;
[[nodiscard]] int giftCollectionsLimit() const;
[[nodiscard]] int giftCollectionGiftsLimit() const;
[[nodiscard]] bool callsDisabledForSession() const;
[[nodiscard]] int confcallSizeLimit() const;