From ac6765ebdb7818fd2319fc2f9d6e055a451f4b81 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 20 Nov 2023 02:47:58 +0300 Subject: [PATCH] Replaced default toast text for shared messages with complex phrases. --- Telegram/CMakeLists.txt | 6 ++- Telegram/Resources/langs/lang.strings | 10 ++++ Telegram/SourceFiles/boxes/share_box.cpp | 27 +++++++--- .../share_message_phrase_factory.cpp | 54 +++++++++++++++++++ .../share_message_phrase_factory.h | 24 +++++++++ 5 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 Telegram/SourceFiles/chat_helpers/share_message_phrase_factory.cpp create mode 100644 Telegram/SourceFiles/chat_helpers/share_message_phrase_factory.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index bd1035359b..3917feff02 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -380,16 +380,18 @@ PRIVATE chat_helpers/gifs_list_widget.h chat_helpers/message_field.cpp chat_helpers/message_field.h + chat_helpers/share_message_phrase_factory.cpp + chat_helpers/share_message_phrase_factory.h chat_helpers/spellchecker_common.cpp chat_helpers/spellchecker_common.h + chat_helpers/stickers_dice_pack.cpp + chat_helpers/stickers_dice_pack.h chat_helpers/stickers_emoji_image_loader.cpp chat_helpers/stickers_emoji_image_loader.h chat_helpers/stickers_emoji_pack.cpp chat_helpers/stickers_emoji_pack.h chat_helpers/stickers_gift_box_pack.cpp chat_helpers/stickers_gift_box_pack.h - chat_helpers/stickers_dice_pack.cpp - chat_helpers/stickers_dice_pack.h chat_helpers/stickers_list_footer.cpp chat_helpers/stickers_list_footer.h chat_helpers/stickers_list_widget.cpp diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index fc0ca0d221..429addc840 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2746,6 +2746,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_share_wrong_user" = "This game was opened from a different user."; "lng_share_game_link_copied" = "Game link copied to clipboard."; "lng_share_done" = "Done!"; +"lng_share_message_to_saved_messages" = "Message forwarded to **Saved Messages**."; +"lng_share_messages_to_saved_messages" = "Messages forwarded to **Saved Messages**."; +"lng_share_message_to_chat" = "Message forwarded to **{chat}**."; +"lng_share_messages_to_chat" = "Messages forwarded to **{chat}**."; +"lng_share_message_to_two_chats" = "Message forwarded to **{user}** and **{chat}**."; +"lng_share_messages_to_two_chats" = "Messages forwarded to **{user}** and **{chat}**."; +"lng_share_message_to_many_chats#one" = "Message forwarded to **{count} chat**."; +"lng_share_message_to_many_chats#other" = "Message forwarded to **{count} chats**."; +"lng_share_messages_to_many_chats#one" = "Messages forwarded to **{count} chat**."; +"lng_share_messages_to_many_chats#other" = "Messages forwarded to **{count} chats**."; "lng_contact_phone" = "Phone Number"; "lng_enter_contact_data" = "New Contact"; diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index ad992b525f..d7f958240f 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -8,14 +8,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/share_box.h" #include "base/random.h" -#include "dialogs/dialogs_indexed_list.h" #include "lang/lang_keys.h" #include "base/qthelp_url.h" #include "storage/storage_account.h" #include "ui/boxes/confirm_box.h" #include "apiwrap.h" -#include "ui/chat/forward_options_box.h" -#include "ui/toast/toast.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/multi_select.h" #include "ui/widgets/scroll_area.h" @@ -31,12 +28,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" #include "history/history_item_helpers.h" -#include "history/view/history_view_element.h" // HistoryView::Context. #include "history/view/history_view_context_menu.h" // CopyPostLink. -#include "history/view/history_view_schedule_box.h" #include "window/window_session_controller.h" #include "boxes/peer_list_controllers.h" #include "chat_helpers/emoji_suggestions_widget.h" +#include "chat_helpers/share_message_phrase_factory.h" #include "data/data_channel.h" #include "data/data_game.h" #include "data/data_histories.h" @@ -51,7 +47,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/core_settings.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" -#include "styles/style_chat.h" #include "styles/style_menu_icons.h" #include @@ -1330,6 +1325,18 @@ QString AppendShareGameScoreUrl( return url + shareComponent; } +ChatHelpers::ForwardedMessagePhraseArgs CreateForwardedMessagePhraseArgs( + const std::vector> &result, + const MessageIdsList &msgIds) { + const auto toCount = result.size(); + return { + .toCount = result.size(), + .singleMessage = (msgIds.size() <= 1), + .to1 = (toCount > 0) ? result.front()->peer().get() : nullptr, + .to2 = (toCount > 1) ? result[1]->peer().get() : nullptr, + }; +} + ShareBox::SubmitCallback ShareBox::DefaultForwardCallback( std::shared_ptr show, not_null history, @@ -1399,6 +1406,9 @@ ShareBox::SubmitCallback ShareBox::DefaultForwardCallback( }; auto &api = history->owner().session().api(); auto &histories = history->owner().histories(); + const auto donePhraseArgs = CreateForwardedMessagePhraseArgs( + result, + msgIds); const auto requestType = Data::Histories::RequestType::Send; for (const auto thread : result) { if (!comment.text.isEmpty()) { @@ -1438,7 +1448,10 @@ ShareBox::SubmitCallback ShareBox::DefaultForwardCallback( state->requests.remove(reqId); if (state->requests.empty()) { if (show->valid()) { - show->showToast(tr::lng_share_done(tr::now)); + auto phrase = rpl::variable( + ChatHelpers::ForwardedMessagePhrase( + donePhraseArgs)).current(); + show->showToast(std::move(phrase)); show->hideLayer(); } } diff --git a/Telegram/SourceFiles/chat_helpers/share_message_phrase_factory.cpp b/Telegram/SourceFiles/chat_helpers/share_message_phrase_factory.cpp new file mode 100644 index 0000000000..3d08fb958f --- /dev/null +++ b/Telegram/SourceFiles/chat_helpers/share_message_phrase_factory.cpp @@ -0,0 +1,54 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "chat_helpers/share_message_phrase_factory.h" + +#include "data/data_peer.h" +#include "lang/lang_keys.h" +#include "ui/text/text_utilities.h" + +namespace ChatHelpers { + +rpl::producer ForwardedMessagePhrase( + const ForwardedMessagePhraseArgs &args) { + if (args.toCount <= 1) { + Assert(args.to1); + + if (args.to1->isSelf()) { + return (args.singleMessage + ? tr::lng_share_message_to_saved_messages + : tr::lng_share_messages_to_saved_messages)( + Ui::Text::RichLangValue); + } else { + return (args.singleMessage + ? tr::lng_share_message_to_chat + : tr::lng_share_messages_to_chat)( + lt_chat, + rpl::single(TextWithEntities{ args.to1->name() }), + Ui::Text::RichLangValue); + } + } else if ((args.toCount == 2) && (args.to1 && args.to2)) { + return (args.singleMessage + ? tr::lng_share_message_to_two_chats + : tr::lng_share_messages_to_two_chats)( + lt_user, + rpl::single(TextWithEntities{ args.to1->name() }), + lt_chat, + rpl::single(TextWithEntities{ args.to2->name() }), + Ui::Text::RichLangValue); + } else { + return (args.singleMessage + ? tr::lng_share_message_to_many_chats + : tr::lng_share_messages_to_many_chats)( + lt_count, + rpl::single(args.toCount) | tr::to_count(), + Ui::Text::RichLangValue); + } +} + + +} // namespace ChatHelpers diff --git a/Telegram/SourceFiles/chat_helpers/share_message_phrase_factory.h b/Telegram/SourceFiles/chat_helpers/share_message_phrase_factory.h new file mode 100644 index 0000000000..a97addadee --- /dev/null +++ b/Telegram/SourceFiles/chat_helpers/share_message_phrase_factory.h @@ -0,0 +1,24 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +class PeerData; + +namespace ChatHelpers { + +struct ForwardedMessagePhraseArgs final { + size_t toCount = 0; + bool singleMessage = false; + PeerData *to1 = nullptr; + PeerData *to2 = nullptr; +}; + +rpl::producer ForwardedMessagePhrase( + const ForwardedMessagePhraseArgs &args); + +} // namespace ChatHelpers