Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore supergroup convert #42

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
55 changes: 55 additions & 0 deletions Telegram/SourceFiles/boxes/confirm_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatData*> 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<PeerData*> peer,
Expand Down
19 changes: 19 additions & 0 deletions Telegram/SourceFiles/boxes/confirm_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ class MaxInviteBox : public Ui::BoxContent, private base::Subscriber {

};

class ConvertToSupergroupBox : public Ui::BoxContent, public RPCSender {
public:
ConvertToSupergroupBox(QWidget*, not_null<ChatData*> 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<ChatData*> _chat;
object_ptr<Ui::FlatLabel> _text = { nullptr };
};

class PinMessageBox : public Ui::BoxContent, public RPCSender {
public:
PinMessageBox(QWidget*, not_null<PeerData*> peer, MsgId msgId);
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/history/history_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down