diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 6e4bd6f68e..4adfb46122 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1049,6 +1049,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_action_changed_title_channel" = "Channel name was changed to «{title}»"; "lng_action_created_chat" = "{from} created group «{title}»"; "lng_action_created_channel" = "Channel created"; +"lng_action_group_migrate" = "The group was upgraded to a supergroup"; "lng_action_pinned_message" = "{from} pinned «{text}»"; "lng_action_pinned_media" = "{from} pinned {media}"; "lng_action_pinned_media_photo" = "a photo"; diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 4839c52691..0fe8a85b19 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -426,6 +426,61 @@ void MaxInviteBox::resizeEvent(QResizeEvent *e) { _invitationLink = myrtlrect(st::boxPadding.left(), st::boxPadding.top() + _textHeight + st::boxTextFont->height, width() - st::boxPadding.left() - st::boxPadding.right(), 2 * st::boxTextFont->height); } +ConvertToSupergroupBox::ConvertToSupergroupBox(QWidget*, not_null chat) +: _chat(chat) { +} + +void ConvertToSupergroupBox::prepare() { + setTitle(tr::lng_profile_convert_title()); + + addButton(tr::lng_profile_convert_confirm(), [=] { convertToSupergroup(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); + + auto details = TextWithEntities(); + const auto appendDetails = [&](TextWithEntities &&text) { + details.append(qs("\n")).append(std::move(text)); + }; + + details.text = tr::lng_profile_convert_feature1(tr::now); + appendDetails({ tr::lng_profile_convert_feature2(tr::now) }); + appendDetails({ tr::lng_profile_convert_feature3(tr::now) }); + appendDetails({ tr::lng_profile_convert_feature4(tr::now) }); + appendDetails({ qs("\n") + tr::lng_profile_convert_warning(tr::now, lt_bold_start, textcmdStartSemibold(), lt_bold_end, textcmdStopSemibold()) }); + + _text.create(this, rpl::single(std::move(details)), st::boxLabel); + + const auto fullHeight = st::boxPadding.top() + _text->height() + st::boxPadding.bottom(); + setDimensions(st::boxWideWidth, fullHeight); +} + +void ConvertToSupergroupBox::convertToSupergroup() { + MTP::send(MTPmessages_MigrateChat(_chat->inputChat), rpcDone(&ConvertToSupergroupBox::convertDone), rpcFail(&ConvertToSupergroupBox::convertFail)); +} + +void ConvertToSupergroupBox::convertDone(const MTPUpdates &updates) { + _chat->session().api().applyUpdates(updates); + Ui::hideLayer(); +} + +bool ConvertToSupergroupBox::convertFail(const RPCError &error) { + if (MTP::isDefaultHandledError(error)) return false; + Ui::hideLayer(); + return true; +} + +void ConvertToSupergroupBox::resizeEvent(QResizeEvent *e) { + BoxContent::resizeEvent(e); + _text->moveToLeft(st::boxPadding.left(), st::boxPadding.top()); +} + +void ConvertToSupergroupBox::keyPressEvent(QKeyEvent *e) { + if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { + convertToSupergroup(); + } else { + BoxContent::keyPressEvent(e); + } +} + PinMessageBox::PinMessageBox( QWidget*, not_null peer, diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index d3c53edda3..406b76bb67 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -124,6 +124,25 @@ class MaxInviteBox : public Ui::BoxContent, private base::Subscriber { }; +class ConvertToSupergroupBox : public Ui::BoxContent, public RPCSender { +public: + ConvertToSupergroupBox(QWidget*, not_null chat); + +protected: + void prepare() override; + + void resizeEvent(QResizeEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; + +private: + void convertToSupergroup(); + void convertDone(const MTPUpdates &updates); + bool convertFail(const RPCError &error); + + not_null _chat; + object_ptr _text = { nullptr }; +}; + class PinMessageBox : public Ui::BoxContent, public RPCSender { public: PinMessageBox(QWidget*, not_null peer, MsgId msgId); diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 7c45e16914..83a0acff1d 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -232,9 +232,9 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { }, [&](const MTPDmessageActionChatCreate &data) { return prepareChatCreate(data); }, [](const MTPDmessageActionChatMigrateTo &) { - return PreparedText(); + return PreparedText{ tr::lng_action_group_migrate(tr::now) }; }, [](const MTPDmessageActionChannelMigrateFrom &) { - return PreparedText(); + return PreparedText{ tr::lng_action_group_migrate(tr::now) }; }, [](const MTPDmessageActionHistoryClear &) { return PreparedText(); }, [&](const MTPDmessageActionChannelCreate &data) {