Replaced default toast text for shared messages with complex phrases.

This commit is contained in:
23rd 2023-11-20 02:47:58 +03:00
parent df3ae2c5f8
commit ac6765ebdb
5 changed files with 112 additions and 9 deletions

View File

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

View File

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

View File

@ -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 <QtGui/QGuiApplication>
@ -1330,6 +1325,18 @@ QString AppendShareGameScoreUrl(
return url + shareComponent;
}
ChatHelpers::ForwardedMessagePhraseArgs CreateForwardedMessagePhraseArgs(
const std::vector<not_null<Data::Thread*>> &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<Ui::Show> show,
not_null<History*> 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<TextWithEntities>(
ChatHelpers::ForwardedMessagePhrase(
donePhraseArgs)).current();
show->showToast(std::move(phrase));
show->hideLayer();
}
}

View File

@ -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<TextWithEntities> 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

View File

@ -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<TextWithEntities> ForwardedMessagePhrase(
const ForwardedMessagePhraseArgs &args);
} // namespace ChatHelpers