From 69d433a5313c3f39ac2fad208613043b159f2ea7 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sat, 16 May 2020 09:29:51 +0300 Subject: [PATCH 1/6] Restore group migrate messages Hope that old translation phrase won't be deleted from platform. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/history/history_service.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) 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/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) { From 418c96d1cc1c293cc0d316fae88665a201c226d2 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sat, 16 May 2020 10:04:30 +0300 Subject: [PATCH 2/6] Remade supergroup convert box --- Telegram/SourceFiles/boxes/confirm_box.cpp | 56 ++++++++++++++++++++++ Telegram/SourceFiles/boxes/confirm_box.h | 20 ++++++++ 2 files changed, 76 insertions(+) diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 4839c52691..987c55cbaa 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -426,6 +426,62 @@ 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); + + _textWidth = st::boxWideWidth - st::boxPadding.left() - st::boxButtonPadding.right(); + _textHeight = _text.countHeight(_textWidth); + setDimensions(st::boxWideWidth, _textHeight + st::boxPadding.bottom()); +} + +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 PinMessageBox::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..c10d151437 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -124,6 +124,26 @@ class MaxInviteBox : public Ui::BoxContent, private base::Subscriber { }; +class ConvertToSupergroupBox : public 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 }; + int32 _textWidth, _textHeight; +}; + class PinMessageBox : public Ui::BoxContent, public RPCSender { public: PinMessageBox(QWidget*, not_null peer, MsgId msgId); From 123c748686a89962dc783bd7706bbfb93b1847c9 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sat, 16 May 2020 10:24:43 +0300 Subject: [PATCH 3/6] Fix missing Ui namespace --- Telegram/SourceFiles/boxes/confirm_box.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index c10d151437..ee42a8b7d9 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -124,7 +124,7 @@ class MaxInviteBox : public Ui::BoxContent, private base::Subscriber { }; -class ConvertToSupergroupBox : public BoxContent, public RPCSender { +class ConvertToSupergroupBox : public Ui::BoxContent, public RPCSender { public: ConvertToSupergroupBox(QWidget*, not_null chat); From b829065fcad83a4e697beeebf3e6f652d645c488 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sat, 16 May 2020 10:39:10 +0300 Subject: [PATCH 4/6] Fix redifinition Copy-pasting strikes back. --- Telegram/SourceFiles/boxes/confirm_box.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 987c55cbaa..2ec628091b 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -469,7 +469,7 @@ bool ConvertToSupergroupBox::convertFail(const RPCError &error) { return true; } -void PinMessageBox::resizeEvent(QResizeEvent *e) { +void ConvertToSupergroupBox::resizeEvent(QResizeEvent *e) { BoxContent::resizeEvent(e); _text->moveToLeft(st::boxPadding.left(), st::boxPadding.top()); } From fa098be02e5381dc54161b2901d8574a404af913 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sat, 16 May 2020 11:32:03 +0300 Subject: [PATCH 5/6] Fix countHeight usage --- Telegram/SourceFiles/boxes/confirm_box.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 2ec628091b..c4b712ca9f 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -450,7 +450,7 @@ void ConvertToSupergroupBox::prepare() { _text.create(this, rpl::single(std::move(details)), st::boxLabel); _textWidth = st::boxWideWidth - st::boxPadding.left() - st::boxButtonPadding.right(); - _textHeight = _text.countHeight(_textWidth); + _textHeight = _text->countHeight(_textWidth); setDimensions(st::boxWideWidth, _textHeight + st::boxPadding.bottom()); } From a0ec972c7ac7352b2858e4054953c88bd45c3fc3 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sat, 16 May 2020 12:54:26 +0300 Subject: [PATCH 6/6] Fixed height counting --- Telegram/SourceFiles/boxes/confirm_box.cpp | 5 ++--- Telegram/SourceFiles/boxes/confirm_box.h | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index c4b712ca9f..0fe8a85b19 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -449,9 +449,8 @@ void ConvertToSupergroupBox::prepare() { _text.create(this, rpl::single(std::move(details)), st::boxLabel); - _textWidth = st::boxWideWidth - st::boxPadding.left() - st::boxButtonPadding.right(); - _textHeight = _text->countHeight(_textWidth); - setDimensions(st::boxWideWidth, _textHeight + st::boxPadding.bottom()); + const auto fullHeight = st::boxPadding.top() + _text->height() + st::boxPadding.bottom(); + setDimensions(st::boxWideWidth, fullHeight); } void ConvertToSupergroupBox::convertToSupergroup() { diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index ee42a8b7d9..406b76bb67 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -141,7 +141,6 @@ class ConvertToSupergroupBox : public Ui::BoxContent, public RPCSender { not_null _chat; object_ptr _text = { nullptr }; - int32 _textWidth, _textHeight; }; class PinMessageBox : public Ui::BoxContent, public RPCSender {