Added toasts to quick dialog actions.

This commit is contained in:
23rd 2025-03-31 00:31:26 +03:00 committed by John Preston
parent 74b188fa46
commit 63578affa4
4 changed files with 53 additions and 7 deletions

View file

@ -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";

View file

@ -76,19 +76,41 @@ void PerformQuickDialogAction(
MuteMenu::ThreadDescriptor(history).updateMutePeriod(isMuted
? 0
: std::numeric_limits<TimeId>::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<void()>(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)();

View file

@ -390,7 +390,8 @@ bool PinnedLimitReached(
void TogglePinnedThread(
not_null<Window::SessionController*> controller,
not_null<Dialogs::Entry*> entry) {
not_null<Dialogs::Entry*> entry,
Fn<void()> 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<Window::SessionController*> controller,
not_null<Dialogs::Entry*> entry,
FilterId filterId) {
FilterId filterId,
Fn<void()> 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();
}
}
}

View file

@ -202,7 +202,8 @@ void ToggleMessagePinned(
void TogglePinnedThread(
not_null<Window::SessionController*> controller,
not_null<Dialogs::Entry*> entry,
FilterId filterId);
FilterId filterId,
Fn<void()> onToggled);
void HidePinnedBar(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,