mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Added ability to set TTL on creation groups.
This commit is contained in:
@@ -21,12 +21,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "chat_helpers/emoji_suggestions_widget.h"
|
||||
#include "countries/countries_instance.h" // Countries::ExtractPhoneCode.
|
||||
#include "window/window_session_controller.h"
|
||||
#include "menu/menu_ttl.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/special_buttons.h"
|
||||
#include "ui/widgets/fields/special_fields.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text/text_options.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/unread_badge.h"
|
||||
@@ -42,7 +45,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "api/api_invite_links.h"
|
||||
#include "api/api_peer_photo.h"
|
||||
#include "main/main_session.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
#include "styles/style_widgets.h"
|
||||
@@ -66,6 +71,7 @@ bool IsValidPhone(QString phone) {
|
||||
void ChatCreateDone(
|
||||
not_null<Window::SessionNavigation*> navigation,
|
||||
QImage image,
|
||||
TimeId ttlPeriod,
|
||||
const MTPUpdates &updates) {
|
||||
navigation->session().api().applyUpdates(updates);
|
||||
|
||||
@@ -97,6 +103,9 @@ void ChatCreateDone(
|
||||
chat,
|
||||
std::move(image));
|
||||
}
|
||||
if (ttlPeriod) {
|
||||
chat->setMessagesTTL(ttlPeriod);
|
||||
}
|
||||
navigation->showPeerHistory(chat);
|
||||
};
|
||||
if (!success) {
|
||||
@@ -516,6 +525,39 @@ void GroupInfoBox::prepare() {
|
||||
[=] { submit(); });
|
||||
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
||||
|
||||
if (_type == Type::Group) {
|
||||
const auto top = addTopButton(st::infoTopBarMenu);
|
||||
const auto menu =
|
||||
top->lifetime().make_state<base::unique_qptr<Ui::PopupMenu>>();
|
||||
top->setClickedCallback([=] {
|
||||
*menu = base::make_unique_q<Ui::PopupMenu>(
|
||||
top,
|
||||
st::popupMenuWithIcons);
|
||||
|
||||
const auto text = tr::lng_manage_messages_ttl_menu(tr::now)
|
||||
+ (_ttlPeriod
|
||||
? ('\t' + Ui::FormatTTLTiny(_ttlPeriod))
|
||||
: QString());
|
||||
(*menu)->addAction(
|
||||
text,
|
||||
[=, show = std::make_shared<Ui::BoxShow>(this)] {
|
||||
show->showBox(Box(TTLMenu::TTLBox, TTLMenu::Args{
|
||||
.show = show,
|
||||
.startTtl = _ttlPeriod,
|
||||
.about = nullptr,
|
||||
.callback = crl::guard(this, [=](
|
||||
TimeId t,
|
||||
Fn<void()> close) {
|
||||
_ttlPeriod = t;
|
||||
close();
|
||||
}),
|
||||
}));
|
||||
}, &st::menuIconTTL);
|
||||
(*menu)->popup(QCursor::pos());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
updateMaxHeight();
|
||||
}
|
||||
|
||||
@@ -593,16 +635,18 @@ void GroupInfoBox::createGroup(
|
||||
return;
|
||||
}
|
||||
_creationRequestId = _api.request(MTPmessages_CreateChat(
|
||||
MTP_flags(0),
|
||||
MTP_flags(_ttlPeriod
|
||||
? MTPmessages_CreateChat::Flag::f_ttl_period
|
||||
: MTPmessages_CreateChat::Flags(0)),
|
||||
MTP_vector<TLUsers>(inputs),
|
||||
MTP_string(title),
|
||||
MTPint() // ttl_period
|
||||
MTP_int(_ttlPeriod)
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
auto image = _photo->takeResultImage();
|
||||
const auto navigation = _navigation;
|
||||
|
||||
getDelegate()->hideLayer(); // Destroys 'this'.
|
||||
ChatCreateDone(navigation, std::move(image), result);
|
||||
ChatCreateDone(navigation, std::move(image), _ttlPeriod, result);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
const auto &type = error.type();
|
||||
_creationRequestId = 0;
|
||||
@@ -678,16 +722,19 @@ void GroupInfoBox::createChannel(
|
||||
const QString &description) {
|
||||
Expects(!_creationRequestId);
|
||||
|
||||
const auto flags = (_type == Type::Megagroup)
|
||||
? MTPchannels_CreateChannel::Flag::f_megagroup
|
||||
: MTPchannels_CreateChannel::Flag::f_broadcast;
|
||||
const auto flags = ((_type == Type::Megagroup)
|
||||
? MTPchannels_CreateChannel::Flag::f_megagroup
|
||||
: MTPchannels_CreateChannel::Flag::f_broadcast)
|
||||
| (_ttlPeriod
|
||||
? MTPchannels_CreateChannel::Flag::f_ttl_period
|
||||
: MTPchannels_CreateChannel::Flags(0));
|
||||
_creationRequestId = _api.request(MTPchannels_CreateChannel(
|
||||
MTP_flags(flags),
|
||||
MTP_string(title),
|
||||
MTP_string(description),
|
||||
MTPInputGeoPoint(), // geo_point
|
||||
MTPstring(), // address
|
||||
MTPint() // ttl_period
|
||||
MTP_int((_type == Type::Megagroup) ? _ttlPeriod : 0)
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
_navigation->session().api().applyUpdates(result);
|
||||
|
||||
@@ -720,6 +767,9 @@ void GroupInfoBox::createChannel(
|
||||
channel,
|
||||
std::move(image));
|
||||
}
|
||||
if (_ttlPeriod && channel->isMegagroup()) {
|
||||
channel->setMessagesTTL(_ttlPeriod);
|
||||
}
|
||||
channel->session().api().requestFullPeer(channel);
|
||||
_createdChannel = channel;
|
||||
checkInviteLink();
|
||||
|
Reference in New Issue
Block a user