Implement topics pin limit box.

This commit is contained in:
John Preston 2022-11-08 18:49:53 +04:00
parent 8a288476b8
commit 248337daf5
4 changed files with 37 additions and 5 deletions

View file

@ -204,6 +204,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_filter_pin_limit2#one" = "Unpin some of the currently pinned ones or subscribe to **Telegram Premium** to double the limit to **{count}** chat.";
"lng_filter_pin_limit2#other" = "Unpin some of the currently pinned ones or subscribe to **Telegram Premium** to double the limit to **{count}** chats.";
"lng_forum_pin_limit#one" = "Sorry, you can't pin more than **{count}** topic to the top.";
"lng_forum_pin_limit#other" = "Sorry, you can't pin more than **{count}** topics to the top.";
"lng_fave_sticker_limit_title#one" = "The Limit of {count} Stickers Reached";
"lng_fave_sticker_limit_title#other" = "The Limit of {count} Stickers Reached";
"lng_fave_sticker_limit_more#one" = "An older sticker was replaced with this one.\nYou can {link} to {count} sticker.";

View file

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_chat_filters.h"
#include "data/data_user.h"
#include "data/data_channel.h"
#include "data/data_forum.h"
#include "data/data_session.h"
#include "data/data_folder.h"
#include "data/data_premium_limits.h"
@ -800,6 +801,28 @@ void PinsLimitBox(
PinsCount(session->data().chatsList()));
}
void ForumPinsLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Data::Forum*> forum) {
const auto premium = false;
const auto premiumPossible = false;
const auto current = forum->owner().pinnedChatsLimit(forum) * 1.;
auto text = tr::lng_forum_pin_limit(
lt_count,
rpl::single(current),
Ui::Text::RichLangValue);
SimpleLimitBox(
box,
&forum->session(),
false,
tr::lng_filter_pin_limit_title(),
std::move(text),
QString(),
{ current, current, current * 2, &st::premiumIconPins });
}
void CaptionLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session,

View file

@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/layers/generic_box.h"
namespace Data {
class Forum;
} // namespace Data
namespace Main {
class Session;
} // namespace Main
@ -41,6 +45,9 @@ void FolderPinsLimitBox(
void PinsLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session);
void ForumPinsLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Data::Forum*> forum);
void CaptionLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session,

View file

@ -344,6 +344,7 @@ bool PinnedLimitReached(
// Some old chat, that was converted, maybe is still pinned.
const auto history = thread->asHistory();
if (!history) {
controller->show(Box(ForumPinsLimitBox, thread->asTopic()->forum()));
return true;
}
const auto folder = history->folder();
@ -380,11 +381,9 @@ void TogglePinnedThread(
return;
}
const auto owner = &thread->owner();
const auto isPinned = !thread->isPinnedDialog(0);
if (const auto history = thread->asHistory()) {
if (isPinned && PinnedLimitReached(controller, history, 0)) {
return;
}
const auto isPinned = !thread->isPinnedDialog(FilterId());
if (isPinned && PinnedLimitReached(controller, thread)) {
return;
}
owner->setChatPinned(thread, FilterId(), isPinned);