mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Implement restrictions on topics enabling.
This commit is contained in:
@@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/text/text_utilities.h" // Ui::Text::ToUpper
|
||||
#include "boxes/peer_list_box.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/toasts/common_toasts.h"
|
||||
#include "boxes/add_contact_box.h"
|
||||
#include "apiwrap.h"
|
||||
#include "main/main_session.h"
|
||||
@@ -32,6 +33,7 @@ constexpr auto kEnableSearchRowsCount = 10;
|
||||
class Controller : public PeerListController, public base::has_weak_ptr {
|
||||
public:
|
||||
Controller(
|
||||
not_null<Window::SessionNavigation*> navigation,
|
||||
not_null<ChannelData*> channel,
|
||||
ChannelData *chat,
|
||||
const std::vector<not_null<PeerData*>> &chats,
|
||||
@@ -47,6 +49,7 @@ private:
|
||||
void choose(not_null<ChannelData*> chat);
|
||||
void choose(not_null<ChatData*> chat);
|
||||
|
||||
not_null<Window::SessionNavigation*> _navigation;
|
||||
not_null<ChannelData*> _channel;
|
||||
ChannelData *_chat = nullptr;
|
||||
std::vector<not_null<PeerData*>> _chats;
|
||||
@@ -59,12 +62,14 @@ private:
|
||||
};
|
||||
|
||||
Controller::Controller(
|
||||
not_null<Window::SessionNavigation*> navigation,
|
||||
not_null<ChannelData*> channel,
|
||||
ChannelData *chat,
|
||||
const std::vector<not_null<PeerData*>> &chats,
|
||||
Fn<void(ChannelData*)> callback,
|
||||
Fn<void(not_null<PeerData*>)> showHistoryCallback)
|
||||
: _channel(channel)
|
||||
: _navigation(navigation)
|
||||
, _channel(channel)
|
||||
, _chat(chat)
|
||||
, _chats(std::move(chats))
|
||||
, _callback(std::move(callback))
|
||||
@@ -131,6 +136,10 @@ void Controller::rowClicked(not_null<PeerListRow*> row) {
|
||||
}
|
||||
|
||||
void Controller::choose(not_null<ChannelData*> chat) {
|
||||
if (chat->isForum()) {
|
||||
ShowForumForDiscussionError(_navigation);
|
||||
return;
|
||||
}
|
||||
auto text = tr::lng_manage_discussion_group_sure(
|
||||
tr::now,
|
||||
lt_group,
|
||||
@@ -324,6 +333,7 @@ object_ptr<Ui::BoxContent> EditLinkedChatBox(
|
||||
ShowAtUnreadMsgId);
|
||||
};
|
||||
auto controller = std::make_unique<Controller>(
|
||||
navigation,
|
||||
channel,
|
||||
chat,
|
||||
std::move(chats),
|
||||
@@ -362,3 +372,13 @@ object_ptr<Ui::BoxContent> EditLinkedChatBox(
|
||||
canEdit,
|
||||
callback);
|
||||
}
|
||||
|
||||
void ShowForumForDiscussionError(
|
||||
not_null<Window::SessionNavigation*> navigation) {
|
||||
Ui::ShowMultilineToast({
|
||||
.parentOverride = Window::Show(navigation).toastParent(),
|
||||
.text = tr::lng_forum_topics_no_discussion(
|
||||
tr::now,
|
||||
Ui::Text::RichLangValue),
|
||||
});
|
||||
}
|
||||
|
@@ -29,3 +29,6 @@ object_ptr<Ui::BoxContent> EditLinkedChatBox(
|
||||
not_null<ChannelData*> channel,
|
||||
std::vector<not_null<PeerData*>> &&chats,
|
||||
Fn<void(ChannelData*)> callback);
|
||||
|
||||
void ShowForumForDiscussionError(
|
||||
not_null<Window::SessionNavigation*> navigation);
|
||||
|
@@ -39,10 +39,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "info/profile/info_profile_values.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "mtproto/sender.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/special_buttons.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/toasts/common_toasts.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
@@ -67,6 +72,12 @@ namespace {
|
||||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] int EnableForumMinMembers(not_null<PeerData*> peer) {
|
||||
return peer->session().account().appConfig().get<int>(
|
||||
u"forum_upgrade_participants_min"_q,
|
||||
200);
|
||||
}
|
||||
|
||||
void AddSkip(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
int top = st::editPeerTopButtonsLayoutSkip,
|
||||
@@ -253,6 +264,8 @@ private:
|
||||
Ui::UserpicButton *photo = nullptr;
|
||||
rpl::lifetime initialPhotoImageWaiting;
|
||||
Ui::VerticalLayout *buttonsLayout = nullptr;
|
||||
Ui::SettingsButton *forumToggle = nullptr;
|
||||
bool forumToggleLocked = false;
|
||||
Ui::SlideWrap<> *historyVisibilityWrap = nullptr;
|
||||
};
|
||||
struct Saving {
|
||||
@@ -279,6 +292,7 @@ private:
|
||||
[[nodiscard]] bool canEditInformation() const;
|
||||
[[nodiscard]] bool canEditReactions() const;
|
||||
void refreshHistoryVisibility();
|
||||
void refreshForumToggleLocked();
|
||||
void showEditPeerTypeBox(
|
||||
std::optional<rpl::producer<QString>> error = {});
|
||||
void showEditLinkedChatBox();
|
||||
@@ -614,7 +628,8 @@ void Controller::refreshHistoryVisibility() {
|
||||
_controls.historyVisibilityWrap->toggle(
|
||||
(!withUsername
|
||||
&& !_channelHasLocationOriginalValue
|
||||
&& (!_linkedChatSavedValue || !*_linkedChatSavedValue)),
|
||||
&& (!_linkedChatSavedValue || !*_linkedChatSavedValue)
|
||||
&& (!_forumSavedValue || !*_forumSavedValue)),
|
||||
anim::type::instant);
|
||||
}
|
||||
|
||||
@@ -645,6 +660,11 @@ void Controller::showEditPeerTypeBox(
|
||||
void Controller::showEditLinkedChatBox() {
|
||||
Expects(_peer->isChannel());
|
||||
|
||||
if (_forumSavedValue && *_forumSavedValue) {
|
||||
ShowForumForDiscussionError(_navigation);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto box = std::make_shared<QPointer<Ui::BoxContent>>();
|
||||
const auto channel = _peer->asChannel();
|
||||
const auto callback = [=](ChannelData *result) {
|
||||
@@ -654,6 +674,7 @@ void Controller::showEditLinkedChatBox() {
|
||||
*_linkedChatSavedValue = result;
|
||||
_linkedChatUpdates.fire_copy(result);
|
||||
refreshHistoryVisibility();
|
||||
refreshForumToggleLocked();
|
||||
};
|
||||
const auto canEdit = channel->isBroadcast()
|
||||
? channel->canEditInformation()
|
||||
@@ -675,8 +696,14 @@ void Controller::showEditLinkedChatBox() {
|
||||
} else if (!canEdit || _linkedChatsRequestId) {
|
||||
return;
|
||||
} else if (channel->isMegagroup()) {
|
||||
// Restore original linked channel.
|
||||
callback(_linkedChatOriginalValue);
|
||||
if (_forumSavedValue
|
||||
&& *_forumSavedValue
|
||||
&& _linkedChatOriginalValue) {
|
||||
ShowForumForDiscussionError(_navigation);
|
||||
} else {
|
||||
// Restore original linked channel.
|
||||
callback(_linkedChatOriginalValue);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_linkedChatsRequestId = _api.request(
|
||||
@@ -817,22 +844,58 @@ void Controller::fillLinkedChatButton() {
|
||||
void Controller::fillForumButton() {
|
||||
Expects(_controls.buttonsLayout != nullptr);
|
||||
|
||||
const auto channel = _peer->asChannel();
|
||||
if (!channel || !channel->amCreator()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AddButtonWithText(
|
||||
_controls.buttonsLayout,
|
||||
tr::lng_forum_topics_switch(),
|
||||
rpl::single(QString()),
|
||||
[] {},
|
||||
{ &st::settingsIconGroup, Settings::kIconPurple }
|
||||
)->toggleOn(rpl::single(channel->isForum())
|
||||
const auto button = _controls.forumToggle = _controls.buttonsLayout->add(
|
||||
EditPeerInfoBox::CreateButton(
|
||||
_controls.buttonsLayout,
|
||||
tr::lng_forum_topics_switch(),
|
||||
rpl::single(QString()),
|
||||
[] {},
|
||||
st::manageGroupTopicsButton,
|
||||
{ &st::settingsIconGroup, Settings::kIconPurple }));
|
||||
const auto unlocks = std::make_shared<rpl::event_stream<bool>>();
|
||||
button->toggleOn(
|
||||
rpl::single(_peer->isForum()) | rpl::then(unlocks->events())
|
||||
)->toggledValue(
|
||||
) | rpl::start_with_next([=](bool toggled) {
|
||||
_forumSavedValue = toggled;
|
||||
if (_controls.forumToggleLocked && toggled) {
|
||||
unlocks->fire(false);
|
||||
if (_linkedChatSavedValue && *_linkedChatSavedValue) {
|
||||
ShowForumForDiscussionError(_navigation);
|
||||
} else {
|
||||
Ui::ShowMultilineToast({
|
||||
.parentOverride = Window::Show(
|
||||
_navigation).toastParent(),
|
||||
.text = tr::lng_forum_topics_not_enough(
|
||||
tr::now,
|
||||
lt_count,
|
||||
EnableForumMinMembers(_peer),
|
||||
Ui::Text::RichLangValue),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
_forumSavedValue = toggled;
|
||||
if (toggled) {
|
||||
_savingData.hiddenPreHistory = false;
|
||||
}
|
||||
refreshHistoryVisibility();
|
||||
}
|
||||
}, _controls.buttonsLayout->lifetime());
|
||||
refreshForumToggleLocked();
|
||||
}
|
||||
|
||||
void Controller::refreshForumToggleLocked() {
|
||||
if (!_controls.forumToggle) {
|
||||
return;
|
||||
}
|
||||
const auto limit = EnableForumMinMembers(_peer);
|
||||
const auto chat = _peer->asChat();
|
||||
const auto channel = _peer->asChannel();
|
||||
const auto notenough = !_peer->isForum()
|
||||
&& ((chat ? chat->count : channel->membersCount()) < limit);
|
||||
const auto linked = _linkedChatSavedValue
|
||||
&& *_linkedChatSavedValue;
|
||||
const auto locked = _controls.forumToggleLocked = notenough || linked;
|
||||
_controls.forumToggle->setToggleLocked(locked);
|
||||
}
|
||||
|
||||
void Controller::fillSignaturesButton() {
|
||||
@@ -943,8 +1006,8 @@ void Controller::fillManageSection() {
|
||||
: chat->canEditPreHistoryHidden();
|
||||
}();
|
||||
const auto canEditForum = isChannel
|
||||
&& channel->isMegagroup()
|
||||
&& channel->canEditInformation();
|
||||
? (channel->isMegagroup() && channel->amCreator())
|
||||
: chat->amCreator();
|
||||
|
||||
const auto canEditPermissions = [&] {
|
||||
return isChannel
|
||||
@@ -1703,9 +1766,20 @@ void Controller::togglePreHistoryHidden(
|
||||
void Controller::saveForum() {
|
||||
const auto channel = _peer->asChannel();
|
||||
if (!_savingData.forum
|
||||
|| !channel
|
||||
|| *_savingData.forum == channel->isForum()) {
|
||||
|| *_savingData.forum == _peer->isForum()) {
|
||||
return continueSave();
|
||||
} else if (!channel) {
|
||||
const auto saveForChannel = [=](not_null<ChannelData*> channel) {
|
||||
if (_peer->asChannel() == channel) {
|
||||
saveForum();
|
||||
} else {
|
||||
cancelSave();
|
||||
}
|
||||
};
|
||||
_peer->session().api().migrateChat(
|
||||
_peer->asChat(),
|
||||
crl::guard(this, saveForChannel));
|
||||
return;
|
||||
}
|
||||
_api.request(MTPchannels_ToggleForum(
|
||||
channel->inputChannel,
|
||||
|
Reference in New Issue
Block a user