mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-05 22:29:34 +00:00
Added ability to set TTL on creation groups.
This commit is contained in:
parent
11165abc09
commit
1cd4cb3baa
@ -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();
|
||||
|
@ -139,6 +139,7 @@ private:
|
||||
mtpRequestId _creationRequestId = 0;
|
||||
bool _creatingInviteLink = false;
|
||||
ChannelData *_createdChannel = nullptr;
|
||||
TimeId _ttlPeriod = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -190,7 +190,9 @@ void TTLBox(not_null<Ui::GenericBox*> box, Args args) {
|
||||
const auto pickerTtl = TimePickerBox(box, ttls, phrases, args.startTtl);
|
||||
|
||||
Ui::ConfirmBox(box, {
|
||||
.confirmed = [=] { args.callback(pickerTtl()); },
|
||||
.confirmed = [=](Fn<void()> close) {
|
||||
args.callback(pickerTtl(), std::move(close));
|
||||
},
|
||||
.confirmText = tr::lng_settings_save(),
|
||||
.cancelText = tr::lng_cancel(),
|
||||
});
|
||||
@ -199,7 +201,7 @@ void TTLBox(not_null<Ui::GenericBox*> box, Args args) {
|
||||
|
||||
if (args.startTtl && !args.hideDisable) {
|
||||
box->addLeftButton(tr::lng_manage_messages_ttl_disable(), [=] {
|
||||
args.callback(0);
|
||||
args.callback(0, [=] { box->closeBox(); });
|
||||
box->getDelegate()->hideLayer();
|
||||
});
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ struct Args {
|
||||
std::shared_ptr<Ui::Show> show;
|
||||
TimeId startTtl;
|
||||
rpl::producer<TextWithEntities> about;
|
||||
Fn<void(TimeId)> callback;
|
||||
Fn<void(TimeId, Fn<void()>)> callback;
|
||||
bool hideDisable = false;
|
||||
};
|
||||
|
||||
|
@ -68,7 +68,9 @@ Args TTLValidator::createArgs() const {
|
||||
mtpRequestId savingRequestId = 0;
|
||||
};
|
||||
const auto state = std::make_shared<State>();
|
||||
auto callback = [=, toastParent = show->toastParent()](TimeId period) {
|
||||
auto callback = [=, toastParent = show->toastParent()](
|
||||
TimeId period,
|
||||
Fn<void()>) {
|
||||
auto &api = peer->session().api();
|
||||
if (state->savingRequestId) {
|
||||
if (period == state->savingPeriod) {
|
||||
@ -84,11 +86,6 @@ Args TTLValidator::createArgs() const {
|
||||
peer->session().api().applyUpdates(result);
|
||||
ShowAutoDeleteToast(toastParent, peer);
|
||||
state->savingRequestId = 0;
|
||||
#if 0
|
||||
if (const auto strong = state->weak.data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
#endif
|
||||
}).fail([=] {
|
||||
state->savingRequestId = 0;
|
||||
}).send();
|
||||
|
@ -356,7 +356,7 @@ void GlobalTTL::setupContent() {
|
||||
show->showBox(Box(TTLMenu::TTLBox, TTLMenu::Args{
|
||||
.show = show,
|
||||
.startTtl = _group->value(),
|
||||
.callback = [=](TimeId ttl) { showSure(ttl, true); },
|
||||
.callback = [=](TimeId ttl, Fn<void()>) { showSure(ttl, true); },
|
||||
.hideDisable = true,
|
||||
}));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user