From 63578affa42c7c43e848d00b7c2a23c241d81490 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 31 Mar 2025 00:31:26 +0300 Subject: [PATCH] Added toasts to quick dialog actions. --- Telegram/Resources/langs/lang.strings | 9 +++++++ .../dialogs/dialogs_quick_action.cpp | 26 +++++++++++++++++-- .../SourceFiles/window/window_peer_menu.cpp | 22 +++++++++++++--- .../SourceFiles/window/window_peer_menu.h | 3 ++- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 862ff5565f..bfadf60c39 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1195,6 +1195,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_quick_dialog_action_delete" = "Delete"; "lng_settings_quick_dialog_action_disabled" = "Change folder"; +"lng_quick_dialog_action_toast_mute_success" = "Notifications for this chat have been muted."; +"lng_quick_dialog_action_toast_unmute_success" = "Notifications enabled for this chat."; +"lng_quick_dialog_action_toast_pin_success" = "The chat has been pinned."; +"lng_quick_dialog_action_toast_unpin_success" = "The chat has been unpinned."; +"lng_quick_dialog_action_toast_read_success" = "The chat has been marked as read."; +"lng_quick_dialog_action_toast_unread_success" = "The chat has been marked as unread."; +"lng_quick_dialog_action_toast_archive_success" = "The chat has been archived."; +"lng_quick_dialog_action_toast_unarchive_success" = "The chat has been unarchived."; + "lng_settings_generic_subscribe" = "Subscribe to {link} to use this setting."; "lng_settings_generic_subscribe_link" = "Telegram Premium"; diff --git a/Telegram/SourceFiles/dialogs/dialogs_quick_action.cpp b/Telegram/SourceFiles/dialogs/dialogs_quick_action.cpp index 340a9f3b6e..a796b4721e 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_quick_action.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_quick_action.cpp @@ -76,19 +76,41 @@ void PerformQuickDialogAction( MuteMenu::ThreadDescriptor(history).updateMutePeriod(isMuted ? 0 : std::numeric_limits::max()); + controller->showToast(isMuted + ? tr::lng_quick_dialog_action_toast_unmute_success(tr::now) + : tr::lng_quick_dialog_action_toast_mute_success(tr::now)); } else if (action == Dialogs::Ui::QuickDialogAction::Pin) { const auto entry = (Dialogs::Entry*)(history); - Window::TogglePinnedThread(controller, entry, filterId); + const auto isPinned = entry->isPinnedDialog(filterId); + const auto onToggled = isPinned + ? Fn(nullptr) + : [=] { + controller->showToast( + tr::lng_quick_dialog_action_toast_pin_success(tr::now)); + }; + Window::TogglePinnedThread(controller, entry, filterId, onToggled); + if (isPinned) { + controller->showToast( + tr::lng_quick_dialog_action_toast_unpin_success(tr::now)); + } } else if (action == Dialogs::Ui::QuickDialogAction::Read) { if (Window::IsUnreadThread(history)) { Window::MarkAsReadThread(history); + controller->showToast( + tr::lng_quick_dialog_action_toast_read_success(tr::now)); } else if (history) { peer->owner().histories().changeDialogUnreadMark(history, true); + controller->showToast( + tr::lng_quick_dialog_action_toast_unread_success(tr::now)); } } else if (action == Dialogs::Ui::QuickDialogAction::Archive) { + const auto isArchived = Window::IsArchived(history); + controller->showToast(isArchived + ? tr::lng_quick_dialog_action_toast_unarchive_success(tr::now) + : tr::lng_quick_dialog_action_toast_archive_success(tr::now)); history->session().api().toggleHistoryArchived( history, - !Window::IsArchived(history), + !isArchived, [] {}); } else if (action == Dialogs::Ui::QuickDialogAction::Delete) { Window::DeleteAndLeaveHandler(controller, peer)(); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 996096e276..135985fb10 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -390,7 +390,8 @@ bool PinnedLimitReached( void TogglePinnedThread( not_null controller, - not_null entry) { + not_null entry, + Fn onToggled) { if (!entry->folderKnown()) { return; } @@ -410,6 +411,9 @@ void TogglePinnedThread( MTP_inputDialogPeer(history->peer->input) )).done([=] { owner->notifyPinnedDialogsOrderUpdated(); + if (onToggled) { + onToggled(); + } }).send(); if (isPinned) { controller->content()->dialogsToUp(); @@ -421,6 +425,9 @@ void TogglePinnedThread( MTP_bool(isPinned) )).done([=](const MTPUpdates &result) { owner->session().api().applyUpdates(result); + if (onToggled) { + onToggled(); + } }).send(); } else if (const auto sublist = entry->asSublist()) { const auto flags = isPinned @@ -431,6 +438,9 @@ void TogglePinnedThread( MTP_inputDialogPeer(sublist->peer()->input) )).done([=] { owner->notifyPinnedDialogsOrderUpdated(); + if (onToggled) { + onToggled(); + } }).send(); //if (isPinned) { // controller->content()->dialogsToUp(); @@ -499,7 +509,7 @@ void Filler::addTogglePin() { const auto weak = base::make_weak(entry); const auto pinToggle = [=] { if (const auto strong = weak.get()) { - TogglePinnedThread(controller, strong, filterId); + TogglePinnedThread(controller, strong, filterId, nullptr); } }; _addAction( @@ -3310,9 +3320,10 @@ void AddSeparatorAndShiftUp(const PeerMenuCallback &addAction) { void TogglePinnedThread( not_null controller, not_null entry, - FilterId filterId) { + FilterId filterId, + Fn onToggled) { if (!filterId) { - return TogglePinnedThread(controller, entry); + return TogglePinnedThread(controller, entry, onToggled); } const auto history = entry->asHistory(); if (!history) { @@ -3338,6 +3349,9 @@ void TogglePinnedThread( Api::SaveNewFilterPinned(&owner->session(), filterId); if (isPinned) { controller->content()->dialogsToUp(); + if (onToggled) { + onToggled(); + } } } diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index e2406d8ee7..a125c3c55d 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -202,7 +202,8 @@ void ToggleMessagePinned( void TogglePinnedThread( not_null controller, not_null entry, - FilterId filterId); + FilterId filterId, + Fn onToggled); void HidePinnedBar( not_null navigation, not_null peer,