diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 22e116eaf..950debc82 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -442,6 +442,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_auto_night_warning" = "You have enabled auto-night mode. If you want to change the dark mode settings, you'll need to disable it first."; "lng_settings_auto_night_disable" = "Disable"; +"lng_suggest_hide_new_title" = "Hide new chats?"; +"lng_suggest_hide_new_about" = "You are receiving lots of new chats from users who are not in your ContactList. Do you want to have such chats **automatically muted** and **archived**?"; +"lng_suggest_hide_new_to_settings" = "Go to Settings"; + "lng_settings_spellchecker" = "Spell checker"; "lng_settings_system_spellchecker" = "Use system spell checker"; "lng_settings_custom_spellchecker" = "Use spell checker"; @@ -1290,6 +1294,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_new_contact_share_done" = "{user} can now see your phone number."; "lng_new_contact_add_name" = "Add {user} to contacts"; "lng_new_contact_add_done" = "{user} is now in your contact list."; +"lng_new_contact_unarchive" = "Unarchive"; "lng_cant_send_to_not_contact" = "Sorry, you can only send messages to\nmutual contacts at the moment.\n{more_info}"; "lng_cant_invite_not_contact" = "Sorry, you can only add mutual contacts\nto groups at the moment.\n{more_info}"; "lng_cant_more_info" = "More info ยป"; diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index a1179a9f9..356a91b70 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_chat.h" #include "data/data_channel.h" +#include "data/data_session.h" #include "window/window_peer_menu.h" #include "window/window_controller.h" #include "window/window_session_controller.h" @@ -62,6 +63,10 @@ ContactStatus::Bar::Bar(QWidget *parent, const QString &name) this, QString(), st::historyContactStatusButton) +, _unarchive( + this, + tr::lng_new_contact_unarchive(tr::now).toUpper(), + st::historyContactStatusButton) , _block( this, tr::lng_new_contact_block(tr::now).toUpper(), @@ -72,7 +77,7 @@ ContactStatus::Bar::Bar(QWidget *parent, const QString &name) st::historyContactStatusButton) , _report( this, - tr::lng_report_spam_and_leave(tr::now).toUpper(), + QString(), st::historyContactStatusBlock) , _close(this, st::historyReplyCancel) { resize(_close->size()); @@ -80,15 +85,26 @@ ContactStatus::Bar::Bar(QWidget *parent, const QString &name) void ContactStatus::Bar::showState(State state) { _add->setVisible(state == State::AddOrBlock || state == State::Add); - _block->setVisible(state == State::AddOrBlock); + _unarchive->setVisible(state == State::UnarchiveOrBlock + || state == State::UnarchiveOrReport); + _block->setVisible(state == State::AddOrBlock + || state == State::UnarchiveOrBlock); _share->setVisible(state == State::SharePhoneNumber); - _report->setVisible(state == State::ReportSpam); + _report->setVisible(state == State::ReportSpam + || state == State::UnarchiveOrReport); _add->setText((state == State::Add) ? tr::lng_new_contact_add_name(tr::now, lt_user, _name).toUpper() : tr::lng_new_contact_add(tr::now).toUpper()); + _report->setText((state == State::ReportSpam) + ? tr::lng_report_spam_and_leave(tr::now).toUpper() + : tr::lng_report_spam(tr::now).toUpper()); updateButtonsGeometry(); } +rpl::producer<> ContactStatus::Bar::unarchiveClicks() const { + return _unarchive->clicks() | rpl::to_empty; +} + rpl::producer<> ContactStatus::Bar::addClicks() const { return _add->clicks() | rpl::to_empty; } @@ -143,32 +159,34 @@ void ContactStatus::Bar::updateButtonsGeometry() { closeWidth); placeButton(button, full, margin); }; - if (!_add->isHidden() && !_block->isHidden()) { - const auto addWidth = buttonWidth(_add); - const auto blockWidth = buttonWidth(_block); + const auto &leftButton = _unarchive->isHidden() ? _add : _unarchive; + const auto &rightButton = _block->isHidden() ? _report : _block; + if (!leftButton->isHidden() && !rightButton->isHidden()) { + const auto leftWidth = buttonWidth(leftButton); + const auto rightWidth = buttonWidth(rightButton); const auto half = full / 2; - if (addWidth <= half - && blockWidth + 2 * closeWidth <= full - half) { - placeButton(_add, half); - placeButton(_block, full - half); - } else if (addWidth + blockWidth <= available) { + if (leftWidth <= half + && rightWidth + 2 * closeWidth <= full - half) { + placeButton(leftButton, half); + placeButton(rightButton, full - half); + } else if (leftWidth + rightWidth <= available) { const auto margin = std::clamp( - addWidth + blockWidth + closeWidth - available, + leftWidth + rightWidth + closeWidth - available, 0, closeWidth); - const auto realBlockWidth = blockWidth + 2 * closeWidth - margin; - if (addWidth > realBlockWidth) { - placeButton(_add, addWidth); - placeButton(_block, full - addWidth, margin); + const auto realBlockWidth = rightWidth + 2 * closeWidth - margin; + if (leftWidth > realBlockWidth) { + placeButton(leftButton, leftWidth); + placeButton(rightButton, full - leftWidth, margin); } else { - placeButton(_add, full - realBlockWidth); - placeButton(_block, realBlockWidth, margin); + placeButton(leftButton, full - realBlockWidth); + placeButton(rightButton, realBlockWidth, margin); } } else { - const auto forAdd = (available * addWidth) - / (addWidth + blockWidth); - placeButton(_add, forAdd); - placeButton(_block, full - forAdd, closeWidth); + const auto forLeft = (available * leftWidth) + / (leftWidth + rightWidth); + placeButton(leftButton, forLeft); + placeButton(rightButton, full - forLeft, closeWidth); } } else { placeOne(_add); @@ -245,6 +263,8 @@ auto ContactStatus::PeerState(not_null peer) } else { return State::None; } + } else if (settings.value & Setting::f_autoarchived) { + return State::UnarchiveOrBlock; } else if (settings.value & Setting::f_block_contact) { return State::AddOrBlock; } else if (settings.value & Setting::f_add_contact) { @@ -257,7 +277,9 @@ auto ContactStatus::PeerState(not_null peer) return peer->settingsValue( ) | rpl::map([=](SettingsChange settings) { - return (settings.value & Setting::f_report_spam) + return (settings.value & Setting::f_autoarchived) + ? State::UnarchiveOrReport + : (settings.value & Setting::f_report_spam) ? State::ReportSpam : State::None; }); @@ -287,6 +309,7 @@ void ContactStatus::setupHandlers(not_null peer) { setupBlockHandler(user); setupShareHandler(user); } + setupUnarchiveHandler(peer); setupReportHandler(peer); setupCloseHandler(peer); } @@ -340,6 +363,21 @@ void ContactStatus::setupShareHandler(not_null user) { }, _bar.lifetime()); } +void ContactStatus::setupUnarchiveHandler(not_null peer) { + _bar.entity()->unarchiveClicks( + ) | rpl::start_with_next([=] { + Window::ToggleHistoryArchived(peer->owner().history(peer), false); + peer->owner().updateNotifySettings(peer, 0); + if (const auto settings = peer->settings()) { + using Flag = MTPDpeerSettings::Flag; + const auto flags = Flag::f_autoarchived + | Flag::f_block_contact + | Flag::f_report_spam; + peer->setSettings(*settings & ~flags); + } + }, _bar.lifetime()); +} + void ContactStatus::setupReportHandler(not_null peer) { _bar.entity()->reportClicks( ) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.h b/Telegram/SourceFiles/history/view/history_view_contact_status.h index 4279ecdc9..3e258555f 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.h +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.h @@ -46,6 +46,8 @@ private: ReportSpam, Add, AddOrBlock, + UnarchiveOrBlock, + UnarchiveOrReport, SharePhoneNumber, }; @@ -55,6 +57,7 @@ private: void showState(State state); + rpl::producer<> unarchiveClicks() const; rpl::producer<> addClicks() const; rpl::producer<> blockClicks() const; rpl::producer<> shareClicks() const; @@ -69,6 +72,7 @@ private: QString _name; object_ptr _add; + object_ptr _unarchive; object_ptr _block; object_ptr _share; object_ptr _report; @@ -82,6 +86,7 @@ private: void setupAddHandler(not_null user); void setupBlockHandler(not_null user); void setupShareHandler(not_null user); + void setupUnarchiveHandler(not_null peer); void setupReportHandler(not_null peer); void setupCloseHandler(not_null peer);