From c1d948ef6346d949f58b704db15206f9fe2470bc Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 3 Jan 2022 18:16:19 +0300 Subject: [PATCH] Reshuffle chat menus. --- Telegram/Resources/langs/lang.strings | 9 +- .../SourceFiles/window/window_peer_menu.cpp | 640 ++++++++++-------- 2 files changed, 353 insertions(+), 296 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 5376862b6..7362ce1d2 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -440,7 +440,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_phone_label" = "Phone number"; "lng_settings_username_add" = "Add username"; "lng_settings_close_sure" = "Are you sure you want to close this page? You didn't save your changes."; -//"lng_settings_peer_to_peer" = "Peer-to-Peer"; "lng_settings_peer_to_peer_about" = "Disabling peer-to-peer will relay all calls through Telegram servers to avoid revealing your IP address, but may slightly decrease audio quality."; "lng_settings_advanced" = "Advanced"; "lng_settings_stickers_emoji" = "Stickers and emoji"; @@ -917,8 +916,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_profile_files_header" = "Files"; "lng_profile_audios#one" = "{count} voice message"; "lng_profile_audios#other" = "{count} voice messages"; -//"lng_profile_rounds#one" = "{count} video message"; -//"lng_profile_rounds#other" = "{count} video messages"; "lng_profile_audios_header" = "Voice messages"; "lng_profile_shared_links#one" = "{count} shared link"; "lng_profile_shared_links#other" = "{count} shared links"; @@ -978,8 +975,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_media_selected_file#other" = "{count} Files"; "lng_media_selected_audio#one" = "{count} Voice message"; "lng_media_selected_audio#other" = "{count} Voice messages"; -//"lng_media_selected_round#one" = "{count} Video message"; -//"lng_media_selected_round#other" = "{count} Video messages"; "lng_media_selected_link#one" = "{count} Shared link"; "lng_media_selected_link#other" = "{count} Shared links"; "lng_media_photo_empty" = "No photos here yet"; @@ -1729,7 +1724,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_send_message" = "Send message"; "lng_context_view_group" = "View group info"; "lng_context_view_channel" = "View channel info"; -//"lng_context_view_feed_info" = "View feed info"; "lng_context_hide_psa" = "Hide this announcement"; "lng_context_pin_to_top" = "Pin to top"; "lng_context_unpin_from_top" = "Unpin from top"; @@ -1745,6 +1739,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_archive_to_list" = "Move to chats list"; "lng_context_archive_to_menu_info" = "Archive moved to the main menu!\nYou can return it from the context menu of the archive button."; +"lng_context_mute" = "Mute notifications"; +"lng_context_unmute" = "Unmute"; + "lng_context_promote_admin" = "Promote to admin"; "lng_context_edit_permissions" = "Edit permissions"; "lng_context_restrict_user" = "Restrict user"; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index e5985d149..3fba63a00 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -121,23 +121,40 @@ public: private: using Section = Dialogs::EntryState::Section; - [[nodiscard]] bool showInfo(); - [[nodiscard]] bool showHidePromotion(); - [[nodiscard]] bool showToggleArchived(); - [[nodiscard]] bool showTogglePin(); + void fillChatsListActions(); + void fillHistoryActions(); + void fillProfileActions(); + void fillRepliesActions(); + void fillScheduledActions(); + void fillArchiveActions(); + void addHidePromotion(); void addTogglePin(); + void addToggleMute(); + void addSupportInfo(); void addInfo(); - //void addSearch(); + //void addToFolder(); void addToggleUnreadMark(); void addToggleArchive(); - void addUserActions(not_null user); - void addBlockUser(not_null user); + void addClearHistory(); + void addDeleteChat(); + void addLeaveChat(); + void addManageChat(); + void addCreatePoll(); + void addThemeEdit(); + void addBlockUser(); + void addViewDiscussion(); + void addExportChat(); + void addReport(); + void addNewContact(); + void addShareContact(); + void addEditContact(); + void addBotToGroup(); + void addNewMembers(); + void addDeleteContact(); + void addChatActions(not_null chat); void addChannelActions(not_null channel); - void addTogglesForArchive(); - - void addPollAction(not_null peer); not_null _controller; Dialogs::EntryState _request; @@ -271,55 +288,13 @@ Filler::Filler( , _addAction(addAction) { } -bool Filler::showInfo() { - if (_request.section == Section::Profile - || _peer->isSelf() - || _peer->isRepliesChat()) { - return false; - } else if (_controller->activeChatCurrent().peer() != _peer) { - return true; - } else if (!_controller->adaptive().isThreeColumn()) { - return true; - } else if (!Core::App().settings().thirdSectionInfoEnabled() - && !Core::App().settings().tabbedReplacedWithInfo()) { - return true; - } - return false; -} - -bool Filler::showHidePromotion() { - if (_request.section != Section::ChatsList) { - return false; - } - const auto history = _peer->owner().historyLoaded(_peer); - return history - && history->useTopPromotion() - && !history->topPromotionType().isEmpty(); -} - -bool Filler::showToggleArchived() { - if (_request.section != Section::ChatsList) { - return false; - } - const auto history = _peer->owner().historyLoaded(_peer); - if (history && history->useTopPromotion()) { - return false; - } else if (!_peer->isNotificationsUser() && !_peer->isSelf()) { - return true; - } - return history && (history->folder() != nullptr); -} - -bool Filler::showTogglePin() { - if (_request.section != Section::ChatsList) { - return false; - } - const auto history = _peer->owner().historyLoaded(_peer); - return history && !history->fixedOnTopIndex(); -} - void Filler::addHidePromotion() { - const auto history = _peer->owner().history(_peer); + const auto history = _peer->owner().historyLoaded(_peer); + if (!history + || !history->useTopPromotion() + || history->topPromotionType().isEmpty()) { + return; + } _addAction(tr::lng_context_hide_psa(tr::now), [=] { history->cacheTopPromotion(false, QString(), QString()); history->session().api().request(MTPhelp_HidePromoData( @@ -332,7 +307,10 @@ void Filler::addTogglePin() { const auto controller = _controller; const auto filterId = _request.filterId; const auto peer = _peer; - const auto history = peer->owner().history(peer); + const auto history = peer->owner().historyLoaded(peer); + if (!history || history->fixedOnTopIndex()) { + return; + } const auto pinText = [=] { return history->isPinnedDialog(filterId) ? tr::lng_context_unpin_from_top(tr::now) @@ -355,7 +333,36 @@ void Filler::addTogglePin() { SetActionText(pinAction, std::move(actionText)); } +void Filler::addToggleMute() { + if (_peer->isSelf()) { + return; + } + PeerMenuAddMuteAction(_peer, _addAction); +} + +void Filler::addSupportInfo() { + if (!_peer->session().supportMode()) { + return; + } + const auto user = _peer->asUser(); + if (!user) { + return; + } + const auto controller = _controller; + _addAction("Edit support info", [=] { + user->session().supportHelper().editInfo(controller, user); + }, &st::menuIconEdit); +} + void Filler::addInfo() { + if (_peer->isSelf() || _peer->isRepliesChat()) { + return; + } else if (_controller->adaptive().isThreeColumn()) { + if (Core::App().settings().thirdSectionInfoEnabled() + || Core::App().settings().tabbedReplacedWithInfo()) { + return; + } + } const auto controller = _controller; const auto peer = _peer; const auto text = (peer->isChat() || peer->isMegagroup()) @@ -368,12 +375,7 @@ void Filler::addInfo() { }, peer->isUser() ? &st::menuIconProfile : &st::menuIconInfo); } -//void Filler::addSearch() { -// const auto controller = _controller; -// const auto peer = _peer; -// _addAction(tr::lng_profile_search_messages(tr::now), [=] { -// controller->content()->searchInChat(peer->owner().history(peer)); -// }, &st::menuIconSearch); +//void Filler::addToFolder() { //} void Filler::addToggleUnreadMark() { @@ -406,7 +408,14 @@ void Filler::addToggleUnreadMark() { void Filler::addToggleArchive() { const auto peer = _peer; - const auto history = peer->owner().history(peer); + const auto history = peer->owner().historyLoaded(peer); + if (history && history->useTopPromotion()) { + return; + } else if (peer->isNotificationsUser() || peer->isSelf()) { + if (!history || !history->folder()) { + return; + } + } const auto isArchived = [=] { return (history->folder() != nullptr); }; @@ -430,7 +439,56 @@ void Filler::addToggleArchive() { SetActionText(archiveAction, std::move(actionText)); } -void Filler::addBlockUser(not_null user) { +void Filler::addClearHistory() { + const auto channel = _peer->asChannel(); + const auto isGroup = _peer->isChat() || _peer->isMegagroup(); + if (channel) { + if (!channel->amIn()) { + return; + } else if (!channel->canDeleteMessages() + && (!isGroup || channel->isPublic())) { + return; + } + } + _addAction( + tr::lng_profile_clear_history(tr::now), + ClearHistoryHandler(_peer), + &st::menuIconClear); +} + +void Filler::addDeleteChat() { + if (_peer->isChannel()) { + return; + } + _addAction( + (_peer->isUser() + ? tr::lng_profile_delete_conversation(tr::now) + : tr::lng_profile_clear_and_exit(tr::now)), + DeleteAndLeaveHandler(_peer), + &st::menuIconDelete); +} + +void Filler::addLeaveChat() { + const auto channel = _peer->asChannel(); + if (!channel || !channel->amIn()) { + return; + } + _addAction( + (_peer->isMegagroup() + ? tr::lng_profile_leave_group(tr::now) + : tr::lng_profile_leave_channel(tr::now)), + DeleteAndLeaveHandler(_peer), + &st::menuIconLeave); +} + +void Filler::addBlockUser() { + const auto user = _peer->asUser(); + if (!user + || user->isInaccessible() + || user->isSelf() + || user->isRepliesChat()) { + return; + } const auto window = &_controller->window(); const auto blockText = [](not_null user) { return user->isBlocked() @@ -471,197 +529,154 @@ void Filler::addBlockUser(not_null user) { } } -void Filler::addUserActions(not_null user) { - const auto controller = _controller; - const auto window = &_controller->window(); - if (_request.section != Section::ChatsList) { - if (user->session().supportMode()) { - _addAction("Edit support info", [=] { - user->session().supportHelper().editInfo(controller, user); - }, &st::menuIconEdit); - } - if (!user->isContact() && !user->isSelf() && !user->isBot()) { - _addAction( - tr::lng_info_add_as_contact(tr::now), - [=] { window->show(Box(EditContactBox, controller, user)); }, - &st::menuIconInvite); - } - if (user->canShareThisContact()) { - _addAction( - tr::lng_info_share_contact(tr::now), - [=] { PeerMenuShareContactBox(controller, user); }, - &st::menuIconShare); - } - if (user->isContact() && !user->isSelf()) { - _addAction( - tr::lng_info_edit_contact(tr::now), - [=] { window->show(Box(EditContactBox, controller, user)); }, - &st::menuIconEdit); - _addAction( - tr::lng_info_delete_contact(tr::now), - [=] { PeerMenuDeleteContact(user); }, - &st::menuIconRemove); - } - if (user->isBot() - && !user->isRepliesChat() - && !user->botInfo->cantJoinGroups) { - using AddBotToGroup = AddBotToGroupBoxController; - _addAction( - tr::lng_profile_invite_to_group(tr::now), - [=] { AddBotToGroup::Start(user); }, - &st::menuIconInvite); - } - addPollAction(user); - if (!user->isBot() && _request.section == Section::History) { - _addAction( - tr::lng_chat_theme_change(tr::now), - [=] { controller->toggleChooseChatTheme(user); }, - &st::menuIconChangeColors); - } - if (user->canExportChatHistory()) { - _addAction( - tr::lng_profile_export_chat(tr::now), - [=] { PeerMenuExportChat(user); }, - &st::menuIconExport); - } - } - _addAction( - tr::lng_profile_delete_conversation(tr::now), - DeleteAndLeaveHandler(user), - &st::menuIconDelete); - _addAction( - tr::lng_profile_clear_history(tr::now), - ClearHistoryHandler(user), - &st::menuIconClear); - if (!user->isInaccessible() - && user != user->session().user() - && !user->isRepliesChat() - && _request.section != Section::ChatsList) { - addBlockUser(user); - } -} - -void Filler::addChatActions(not_null chat) { - const auto navigation = _controller; - if (_request.section != Section::ChatsList) { - if (EditPeerInfoBox::Available(chat)) { - const auto text = tr::lng_manage_group_title(tr::now); - _addAction(text, [=] { - navigation->showEditPeerBox(chat); - }, &st::menuIconManage); - } - if (chat->canAddMembers()) { - _addAction( - tr::lng_channel_add_members(tr::now), - [=] { AddChatMembers(navigation, chat); }, - &st::menuIconInvite); - } - addPollAction(chat); - if (chat->canExportChatHistory()) { - _addAction( - tr::lng_profile_export_chat(tr::now), - [=] { PeerMenuExportChat(chat); }, - &st::menuIconExport); - } - } - _addAction( - tr::lng_profile_clear_and_exit(tr::now), - DeleteAndLeaveHandler(_peer), - &st::menuIconDelete); - _addAction( - tr::lng_profile_clear_history(tr::now), - ClearHistoryHandler(_peer), - &st::menuIconClear); - if (_request.section != Section::ChatsList) { - if (!chat->amCreator()) { - _addAction(tr::lng_profile_report(tr::now), [=] { - HistoryView::ShowReportPeerBox(navigation, chat); - }, &st::menuIconReport); - } - } -} - -void Filler::addChannelActions(not_null channel) { - const auto isGroup = channel->isMegagroup(); - const auto navigation = _controller; - if (_request.section != Section::ChatsList) { - if (channel->isBroadcast()) { - if (const auto chat = channel->linkedChat()) { - _addAction(tr::lng_profile_view_discussion(tr::now), [=] { - if (channel->invitePeekExpires()) { - Ui::Toast::Show( - tr::lng_channel_invite_private(tr::now)); - return; - } - navigation->showPeerHistory( - chat, - Window::SectionShow::Way::Forward); - }, &st::menuIconDiscussion); - } - } - if (EditPeerInfoBox::Available(channel)) { - const auto text = isGroup - ? tr::lng_manage_group_title(tr::now) - : tr::lng_manage_channel_title(tr::now); - _addAction(text, [=] { - navigation->showEditPeerBox(channel); - }, &st::menuIconManage); - } - if (channel->canAddMembers()) { - _addAction( - (channel->isMegagroup() - ? tr::lng_channel_add_members(tr::now) - : tr::lng_channel_add_users(tr::now)), - [=] { PeerMenuAddChannelMembers(navigation, channel); }, - &st::menuIconInvite); - } - addPollAction(channel); - if (channel->canExportChatHistory()) { - _addAction( - (isGroup - ? tr::lng_profile_export_chat(tr::now) - : tr::lng_profile_export_channel(tr::now)), - [=] { PeerMenuExportChat(channel); }, - &st::menuIconExport); - } - } - if (channel->amIn()) { - auto text = isGroup - ? tr::lng_profile_leave_group(tr::now) - : tr::lng_profile_leave_channel(tr::now); - _addAction( - text, - DeleteAndLeaveHandler(channel), - &st::menuIconLeave); - if ((isGroup && !channel->isPublic()) - || channel->canDeleteMessages()) { - _addAction( - tr::lng_profile_clear_history(tr::now), - ClearHistoryHandler(channel), - &st::menuIconClear); - } - } else { - auto text = isGroup - ? tr::lng_profile_join_group(tr::now) - : tr::lng_profile_join_channel(tr::now); - _addAction( - text, - [=] { channel->session().api().joinChannel(channel); }, - &st::menuIconInvite); // #TODO icons - } - if (_request.section != Section::ChatsList) { - if (!channel->amCreator()) { - _addAction(tr::lng_profile_report(tr::now), [=] { - HistoryView::ShowReportPeerBox(navigation, channel); - }, &st::menuIconReport); - } - } -} - -void Filler::addPollAction(not_null peer) { - if (!peer->canSendPolls()) { +void Filler::addViewDiscussion() { + const auto channel = _peer->asBroadcast(); + if (!channel) { return; } + const auto chat = channel->linkedChat(); + if (!chat) { + return; + } + const auto navigation = _controller; + _addAction(tr::lng_profile_view_discussion(tr::now), [=] { + if (channel->invitePeekExpires()) { + Ui::Toast::Show( + tr::lng_channel_invite_private(tr::now)); + return; + } + navigation->showPeerHistory( + chat, + Window::SectionShow::Way::Forward); + }, &st::menuIconDiscussion); +} + +void Filler::addExportChat() { + if (!_peer->canExportChatHistory()) { + return; + } + const auto peer = _peer; + _addAction( + tr::lng_profile_export_chat(tr::now), + [=] { PeerMenuExportChat(peer); }, + &st::menuIconExport); +} + +void Filler::addReport() { + const auto chat = _peer->asChat(); + const auto channel = _peer->asChannel(); + if ((!chat || chat->amCreator()) + && (!channel || channel->amCreator())) { + return; + } + const auto peer = _peer; + const auto navigation = _controller; + _addAction(tr::lng_profile_report(tr::now), [=] { + HistoryView::ShowReportPeerBox(navigation, peer); + }, &st::menuIconReport); +} + +void Filler::addNewContact() { + const auto user = _peer->asUser(); + if (!user || user->isContact() || user->isSelf() || user->isBot()) { + return; + } + const auto controller = _controller; + _addAction( + tr::lng_info_add_as_contact(tr::now), + [=] { controller->show(Box(EditContactBox, controller, user)); }, + &st::menuIconInvite); +} + +void Filler::addShareContact() { + const auto user = _peer->asUser(); + if (!user || !user->canShareThisContact()) { + return; + } + const auto controller = _controller; + _addAction( + tr::lng_info_share_contact(tr::now), + [=] { PeerMenuShareContactBox(controller, user); }, + &st::menuIconShare); +} + +void Filler::addEditContact() { + const auto user = _peer->asUser(); + if (!user || !user->isContact() || user->isSelf()) { + return; + } + const auto controller = _controller; + _addAction( + tr::lng_info_edit_contact(tr::now), + [=] { controller->show(Box(EditContactBox, controller, user)); }, + &st::menuIconEdit); +} + +void Filler::addBotToGroup() { + const auto user = _peer->asUser(); + if (!user + || !user->isBot() + || user->isRepliesChat() + || user->botInfo->cantJoinGroups) { + return; + } + using AddBotToGroup = AddBotToGroupBoxController; + _addAction( + tr::lng_profile_invite_to_group(tr::now), + [=] { AddBotToGroup::Start(user); }, + &st::menuIconInvite); +} + +void Filler::addNewMembers() { + const auto chat = _peer->asChat(); + const auto channel = _peer->asChannel(); + if ((!chat || !chat->canAddMembers()) + && (!channel || !channel->canAddMembers())) { + return; + } + const auto peer = _peer; + const auto navigation = _controller; + const auto callback = chat + ? Fn([=] { AddChatMembers(navigation, chat); }) + : [=] { PeerMenuAddChannelMembers(navigation, channel); }; + _addAction( + ((chat || channel->isMegagroup()) + ? tr::lng_channel_add_members(tr::now) + : tr::lng_channel_add_users(tr::now)), + callback, + &st::menuIconInvite); +} + +void Filler::addDeleteContact() { + const auto user = _peer->asUser(); + if (!user || !user->isContact() || user->isSelf()) { + return; + } + _addAction( + tr::lng_info_delete_contact(tr::now), + [=] { PeerMenuDeleteContact(user); }, + &st::menuIconDelete); +} + +void Filler::addManageChat() { + if (!EditPeerInfoBox::Available(_peer)) { + return; + } + const auto peer = _peer; + const auto navigation = _controller; + const auto text = (peer->isChat() || peer->isMegagroup()) + ? tr::lng_manage_group_title(tr::now) + : tr::lng_manage_channel_title(tr::now); + _addAction(text, [=] { + navigation->showEditPeerBox(peer); + }, &st::menuIconManage); +} + +void Filler::addCreatePoll() { + if (!_peer->canSendPolls()) { + return; + } + const auto peer = _peer; const auto controller = _controller; const auto source = (_request.section == Section::Scheduled) ? Api::SendType::Scheduled @@ -691,45 +706,90 @@ void Filler::addPollAction(not_null peer) { &st::menuIconCreatePoll); } +void Filler::addThemeEdit() { + const auto user = _peer->asUser(); + if (!user || user->isBot()) { + return; + } + const auto controller = _controller; + _addAction( + tr::lng_chat_theme_change(tr::now), + [=] { controller->toggleChooseChatTheme(user); }, + &st::menuIconChangeColors); +} + void Filler::fill() { if (_folder) { - addTogglesForArchive(); - return; - } else if (_request.section == Section::Scheduled - || _request.section == Section::Replies) { - addPollAction(_peer); + fillArchiveActions(); return; } - if (showHidePromotion()) { - addHidePromotion(); - } - if (showToggleArchived()) { - addToggleArchive(); - } - if (showTogglePin()) { - addTogglePin(); - } - if (showInfo()) { - addInfo(); - } - if (_request.section != Section::Profile && !_peer->isSelf()) { - PeerMenuAddMuteAction(_peer, _addAction); - } - if (_request.section == Section::ChatsList) { - //addSearch(); - addToggleUnreadMark(); - } - - if (const auto user = _peer->asUser()) { - addUserActions(user); - } else if (const auto chat = _peer->asChat()) { - addChatActions(chat); - } else if (const auto channel = _peer->asChannel()) { - addChannelActions(channel); + switch (_request.section) { + case Section::ChatsList: fillChatsListActions(); break; + case Section::History: fillHistoryActions(); break; + case Section::Profile: fillProfileActions(); break; + case Section::Replies: fillRepliesActions(); break; + case Section::Scheduled: fillScheduledActions(); break; + default: Unexpected("_request.section in Filler::fill."); } } -void Filler::addTogglesForArchive() { +void Filler::fillChatsListActions() { + addHidePromotion(); + addToggleArchive(); + addTogglePin(); + addToggleMute(); + addToggleUnreadMark(); + // addToFolder(); + if (const auto user = _peer->asUser()) { + if (!user->isContact()) { + addBlockUser(); + } + } + addClearHistory(); + addDeleteChat(); + addLeaveChat(); +} + +void Filler::fillHistoryActions() { + addInfo(); + addToggleMute(); + addSupportInfo(); + addManageChat(); + addCreatePoll(); + addThemeEdit(); + addViewDiscussion(); + addExportChat(); + addReport(); + addClearHistory(); + addDeleteChat(); + addLeaveChat(); +} + +void Filler::fillProfileActions() { + addSupportInfo(); + addNewContact(); + addShareContact(); + addEditContact(); + addBotToGroup(); + addNewMembers(); + addManageChat(); + addViewDiscussion(); + addExportChat(); + addBlockUser(); + addReport(); + addLeaveChat(); + addDeleteContact(); +} + +void Filler::fillRepliesActions() { + addCreatePoll(); +} + +void Filler::fillScheduledActions() { + addCreatePoll(); +} + +void Filler::fillArchiveActions() { Expects(_folder != nullptr); if (_folder->id() != Data::Folder::kId) { @@ -1244,8 +1304,8 @@ void PeerMenuAddMuteAction( peer->owner().requestNotifySettings(peer); const auto muteText = [](bool isUnmuted) { return isUnmuted - ? tr::lng_disable_notifications_from_tray(tr::now) - : tr::lng_enable_notifications_from_tray(tr::now); + ? tr::lng_context_mute(tr::now) + : tr::lng_context_unmute(tr::now); }; const auto muteAction = addAction(QString("-"), [=] { if (!peer->owner().notifyIsMuted(peer)) {