mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-01 23:00:58 +00:00
Allow creating discussion groups for channels.
This commit is contained in:
parent
b9d89cb4a0
commit
ee2c7fad78
@ -352,12 +352,6 @@ protected:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CreatingGroupType {
|
|
||||||
CreatingGroupNone,
|
|
||||||
CreatingGroupGroup,
|
|
||||||
CreatingGroupChannel,
|
|
||||||
};
|
|
||||||
|
|
||||||
class BoxPointer {
|
class BoxPointer {
|
||||||
public:
|
public:
|
||||||
BoxPointer() = default;
|
BoxPointer() = default;
|
||||||
|
@ -398,9 +398,14 @@ void AddContactBox::updateButtons() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupInfoBox::GroupInfoBox(QWidget*, CreatingGroupType creating, bool fromTypeChoose)
|
GroupInfoBox::GroupInfoBox(
|
||||||
: _creating(creating)
|
QWidget*,
|
||||||
, _fromTypeChoose(fromTypeChoose) {
|
Type type,
|
||||||
|
const QString &title,
|
||||||
|
Fn<void(not_null<ChannelData*>)> channelDone)
|
||||||
|
: _type(type)
|
||||||
|
, _initialTitle(title)
|
||||||
|
, _channelDone(std::move(channelDone)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupInfoBox::prepare() {
|
void GroupInfoBox::prepare() {
|
||||||
@ -408,7 +413,7 @@ void GroupInfoBox::prepare() {
|
|||||||
|
|
||||||
_photo.create(
|
_photo.create(
|
||||||
this,
|
this,
|
||||||
lang((_creating == CreatingGroupChannel)
|
lang((_type == Type::Channel)
|
||||||
? lng_create_channel_crop
|
? lng_create_channel_crop
|
||||||
: lng_create_group_crop),
|
: lng_create_group_crop),
|
||||||
Ui::UserpicButton::Role::ChangePhoto,
|
Ui::UserpicButton::Role::ChangePhoto,
|
||||||
@ -416,9 +421,10 @@ void GroupInfoBox::prepare() {
|
|||||||
_title.create(
|
_title.create(
|
||||||
this,
|
this,
|
||||||
st::defaultInputField,
|
st::defaultInputField,
|
||||||
langFactory(_creating == CreatingGroupChannel
|
langFactory((_type == Type::Channel)
|
||||||
? lng_dlg_new_channel_name
|
? lng_dlg_new_channel_name
|
||||||
: lng_dlg_new_group_name));
|
: lng_dlg_new_group_name),
|
||||||
|
_initialTitle);
|
||||||
_title->setMaxLength(kMaxGroupChannelTitle);
|
_title->setMaxLength(kMaxGroupChannelTitle);
|
||||||
_title->setInstantReplaces(Ui::InstantReplaces::Default());
|
_title->setInstantReplaces(Ui::InstantReplaces::Default());
|
||||||
_title ->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
|
_title ->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
|
||||||
@ -426,7 +432,7 @@ void GroupInfoBox::prepare() {
|
|||||||
getDelegate()->outerContainer(),
|
getDelegate()->outerContainer(),
|
||||||
_title);
|
_title);
|
||||||
|
|
||||||
if (_creating == CreatingGroupChannel) {
|
if (_type != Type::Group) {
|
||||||
_description.create(
|
_description.create(
|
||||||
this,
|
this,
|
||||||
st::newGroupDescription,
|
st::newGroupDescription,
|
||||||
@ -449,8 +455,8 @@ void GroupInfoBox::prepare() {
|
|||||||
|
|
||||||
connect(_title, &Ui::InputField::submitted, [=] { submitName(); });
|
connect(_title, &Ui::InputField::submitted, [=] { submitName(); });
|
||||||
|
|
||||||
addButton(langFactory(_creating == CreatingGroupChannel ? lng_create_group_create : lng_create_group_next), [this] { submit(); });
|
addButton(langFactory((_type != Type::Group) ? lng_create_group_create : lng_create_group_next), [this] { submit(); });
|
||||||
addButton(langFactory(_fromTypeChoose ? lng_create_group_back : lng_cancel), [this] { closeBox(); });
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||||
|
|
||||||
updateMaxHeight();
|
updateMaxHeight();
|
||||||
}
|
}
|
||||||
@ -590,7 +596,7 @@ void GroupInfoBox::submit() {
|
|||||||
_title->showError();
|
_title->showError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_creating != CreatingGroupGroup) {
|
if (_type != Type::Group) {
|
||||||
createChannel(title, description);
|
createChannel(title, description);
|
||||||
} else {
|
} else {
|
||||||
auto initBox = [title, weak = make_weak(this)](
|
auto initBox = [title, weak = make_weak(this)](
|
||||||
@ -619,8 +625,9 @@ void GroupInfoBox::submit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GroupInfoBox::createChannel(const QString &title, const QString &description) {
|
void GroupInfoBox::createChannel(const QString &title, const QString &description) {
|
||||||
bool mega = false;
|
const auto flags = (_type == Type::Megagroup)
|
||||||
auto flags = mega ? MTPchannels_CreateChannel::Flag::f_megagroup : MTPchannels_CreateChannel::Flag::f_broadcast;
|
? MTPchannels_CreateChannel::Flag::f_megagroup
|
||||||
|
: MTPchannels_CreateChannel::Flag::f_broadcast;
|
||||||
_creationRequestId = request(MTPchannels_CreateChannel(
|
_creationRequestId = request(MTPchannels_CreateChannel(
|
||||||
MTP_flags(flags),
|
MTP_flags(flags),
|
||||||
MTP_string(title),
|
MTP_string(title),
|
||||||
@ -628,7 +635,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
|
|||||||
)).done([=](const MTPUpdates &result) {
|
)).done([=](const MTPUpdates &result) {
|
||||||
Auth().api().applyUpdates(result);
|
Auth().api().applyUpdates(result);
|
||||||
|
|
||||||
auto success = base::make_optional(&result)
|
const auto success = base::make_optional(&result)
|
||||||
| [](auto updates) -> std::optional<const QVector<MTPChat>*> {
|
| [](auto updates) -> std::optional<const QVector<MTPChat>*> {
|
||||||
switch (updates->type()) {
|
switch (updates->type()) {
|
||||||
case mtpc_updates:
|
case mtpc_updates:
|
||||||
@ -663,7 +670,14 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
|
|||||||
auto link = qs(result.c_chatInviteExported().vlink);
|
auto link = qs(result.c_chatInviteExported().vlink);
|
||||||
_createdChannel->setInviteLink(link);
|
_createdChannel->setInviteLink(link);
|
||||||
}
|
}
|
||||||
Ui::show(Box<SetupChannelBox>(_createdChannel));
|
if (_channelDone) {
|
||||||
|
const auto callback = _channelDone;
|
||||||
|
const auto argument = _createdChannel;
|
||||||
|
closeBox();
|
||||||
|
callback(argument);
|
||||||
|
} else {
|
||||||
|
Ui::show(Box<SetupChannelBox>(_createdChannel));
|
||||||
|
}
|
||||||
}).send();
|
}).send();
|
||||||
};
|
};
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
@ -84,7 +84,16 @@ private:
|
|||||||
|
|
||||||
class GroupInfoBox : public BoxContent, private MTP::Sender {
|
class GroupInfoBox : public BoxContent, private MTP::Sender {
|
||||||
public:
|
public:
|
||||||
GroupInfoBox(QWidget*, CreatingGroupType creating, bool fromTypeChoose);
|
enum class Type {
|
||||||
|
Group,
|
||||||
|
Channel,
|
||||||
|
Megagroup,
|
||||||
|
};
|
||||||
|
GroupInfoBox(
|
||||||
|
QWidget*,
|
||||||
|
Type type,
|
||||||
|
const QString &title = QString(),
|
||||||
|
Fn<void(not_null<ChannelData*>)> channelDone = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
@ -101,8 +110,9 @@ private:
|
|||||||
void descriptionResized();
|
void descriptionResized();
|
||||||
void updateMaxHeight();
|
void updateMaxHeight();
|
||||||
|
|
||||||
CreatingGroupType _creating;
|
Type _type = Type::Group;
|
||||||
bool _fromTypeChoose = false;
|
QString _initialTitle;
|
||||||
|
Fn<void(not_null<ChannelData*>)> _channelDone;
|
||||||
|
|
||||||
object_ptr<Ui::UserpicButton> _photo = { nullptr };
|
object_ptr<Ui::UserpicButton> _photo = { nullptr };
|
||||||
object_ptr<Ui::InputField> _title = { nullptr };
|
object_ptr<Ui::InputField> _title = { nullptr };
|
||||||
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include "info/profile/info_profile_button.h"
|
#include "info/profile/info_profile_button.h"
|
||||||
#include "info/profile/info_profile_values.h"
|
#include "info/profile/info_profile_values.h"
|
||||||
#include "boxes/peer_list_box.h"
|
#include "boxes/peer_list_box.h"
|
||||||
|
#include "boxes/add_contact_box.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_info.h"
|
#include "styles/style_info.h"
|
||||||
|
|
||||||
@ -135,7 +136,10 @@ object_ptr<Ui::RpWidget> SetupAbout(
|
|||||||
|
|
||||||
object_ptr<Ui::RpWidget> SetupCreateGroup(
|
object_ptr<Ui::RpWidget> SetupCreateGroup(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
not_null<ChannelData*> channel) {
|
not_null<ChannelData*> channel,
|
||||||
|
Fn<void(ChannelData*)> callback) {
|
||||||
|
Expects(channel->isBroadcast());
|
||||||
|
|
||||||
auto result = object_ptr<Info::Profile::Button>(
|
auto result = object_ptr<Info::Profile::Button>(
|
||||||
parent,
|
parent,
|
||||||
Lang::Viewer(
|
Lang::Viewer(
|
||||||
@ -143,7 +147,13 @@ object_ptr<Ui::RpWidget> SetupCreateGroup(
|
|||||||
) | Info::Profile::ToUpperValue(),
|
) | Info::Profile::ToUpperValue(),
|
||||||
st::infoCreateLinkedChatButton);
|
st::infoCreateLinkedChatButton);
|
||||||
result->addClickHandler([=] {
|
result->addClickHandler([=] {
|
||||||
|
const auto guarded = crl::guard(parent, callback);
|
||||||
|
Ui::show(
|
||||||
|
Box<GroupInfoBox>(
|
||||||
|
GroupInfoBox::Type::Megagroup,
|
||||||
|
channel->name + " Chat",
|
||||||
|
guarded),
|
||||||
|
LayerOption::KeepOther);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -197,7 +207,7 @@ object_ptr<Ui::RpWidget> EditLinkedChatBox::setupContent(
|
|||||||
SetupAbout(result, channel, chat),
|
SetupAbout(result, channel, chat),
|
||||||
st::linkedChatAboutPadding);
|
st::linkedChatAboutPadding);
|
||||||
if (!chat) {
|
if (!chat) {
|
||||||
result->add(SetupCreateGroup(result, channel));
|
result->add(SetupCreateGroup(result, channel, callback));
|
||||||
}
|
}
|
||||||
result->add(SetupList(result, channel, chat, chats, callback));
|
result->add(SetupList(result, channel, chat, chats, callback));
|
||||||
if (chat) {
|
if (chat) {
|
||||||
|
@ -592,7 +592,7 @@ void MainWindow::onShowNewGroup() {
|
|||||||
|
|
||||||
if (AuthSession::Exists()) {
|
if (AuthSession::Exists()) {
|
||||||
Ui::show(
|
Ui::show(
|
||||||
Box<GroupInfoBox>(CreatingGroupGroup, false),
|
Box<GroupInfoBox>(GroupInfoBox::Type::Group),
|
||||||
LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -602,7 +602,7 @@ void MainWindow::onShowNewChannel() {
|
|||||||
|
|
||||||
if (_main) {
|
if (_main) {
|
||||||
Ui::show(
|
Ui::show(
|
||||||
Box<GroupInfoBox>(CreatingGroupChannel, false),
|
Box<GroupInfoBox>(GroupInfoBox::Type::Channel),
|
||||||
LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user