From f65a35b15e76245b9eba24eeeefe66bc1e7e9693 Mon Sep 17 00:00:00 2001 From: c0re100 Date: Fri, 10 Jul 2020 06:05:14 +0800 Subject: [PATCH] Support Forward Message without quote --- Telegram/Resources/langs/lang.strings | 1 + .../history/history_inner_widget.cpp | 18 +++ .../history/history_inner_widget.h | 2 + .../SourceFiles/window/window_peer_menu.cpp | 116 ++++++++++++++++++ .../SourceFiles/window/window_peer_menu.h | 5 + 5 files changed, 142 insertions(+) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 1fa1395991..69f678470f 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2404,6 +2404,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_show_messages_from" = "Messages From User"; "lng_context_repeat_msg" = "Repeat This Message"; "lng_context_repeat_msg_no_fwd" = "Repeat This Message(!Forward)"; +"lng_context_forward_msg_no_quote" = "Forward Message(W/O quote)"; "lng_message_id" = "Message ID: "; "lng_admin_log_banned_send_stickers2" = "Send stickers"; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 9da9831812..a120ae4200 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1659,6 +1659,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(tr::lng_context_forward_msg(tr::now), [=] { forwardItem(itemId); }); + _menu->addAction(tr::lng_context_forward_msg_no_quote(tr::now), [=] { + forwardItemNoQuote(itemId); + }); if (!item->emptyText() && item->media() == nullptr && (item->history()->peer->isMegagroup() || item->history()->peer->isChat() || item->history()->peer->isUser())) { _menu->addAction(tr::lng_context_repeat_msg(tr::now), [=] { const auto api = &item->history()->peer->session().api(); @@ -1817,6 +1820,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(tr::lng_context_forward_msg(tr::now), [=] { forwardAsGroup(itemId); }); + _menu->addAction(tr::lng_context_forward_msg_no_quote(tr::now), [=] { + forwardAsGroupNoQuote(itemId); + }); if (!item->emptyText() && item->media() == nullptr && (item->history()->peer->isMegagroup() || item->history()->peer->isChat() || item->history()->peer->isUser())) { _menu->addAction(tr::lng_context_repeat_msg(tr::now), [=] { const auto api = &item->history()->peer->session().api(); @@ -3137,6 +3143,18 @@ void HistoryInner::forwardAsGroup(FullMsgId itemId) { } } +void HistoryInner::forwardItemNoQuote(FullMsgId itemId) { + Window::ShowForwardNoQuoteMessagesBox(_controller, { 1, itemId }); +} + +void HistoryInner::forwardAsGroupNoQuote(FullMsgId itemId) { + if (const auto item = session().data().message(itemId)) { + Window::ShowForwardNoQuoteMessagesBox( + _controller, + session().data().itemOrItsGroup(item)); + } +} + void HistoryInner::deleteItem(FullMsgId itemId) { if (const auto item = session().data().message(itemId)) { deleteItem(item); diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 89aa3d2a6c..349095ca06 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -301,6 +301,8 @@ public slots: SelectAction action) const; void forwardItem(FullMsgId itemId); void forwardAsGroup(FullMsgId itemId); + void forwardItemNoQuote(FullMsgId itemId); + void forwardAsGroupNoQuote(FullMsgId itemId); void deleteItem(not_null item); void deleteItem(FullMsgId itemId); void deleteAsGroup(FullMsgId itemId); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 8347cd6c47..13775bc8e8 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -29,6 +29,7 @@ For license and copyright information please follow this link: #include "mainwindow.h" #include "api/api_common.h" #include "api/api_chat_filters.h" +#include "api/api_sending.h" #include "mtproto/mtproto_config.h" #include "history/history.h" #include "history/history_item.h" @@ -1047,6 +1048,121 @@ QPointer ShowForwardMessagesBox( return weak->data(); } +QPointer ShowForwardNoQuoteMessagesBox( + not_null navigation, + MessageIdsList &&items, + FnMut &&successCallback) { + struct ShareData { + ShareData(not_null peer, MessageIdsList &&ids) + : peer(peer) + , msgIds(std::move(ids)) { + } + not_null peer; + MessageIdsList msgIds; + base::flat_set requests; + }; + const auto weak = std::make_shared>(); + const auto item = App::wnd()->sessionController()->session().data().message(items[0]); + const auto history = item->history(); + const auto owner = &history->owner(); + const auto session = &history->session(); + const auto isGroup = (owner->groups().find(item) != nullptr); + const auto data = std::make_shared(history->peer, std::move(items)); + + auto submitCallback = [=]( + std::vector> &&result, + TextWithTags &&comment, + Api::SendOptions options) { + if (!data->requests.empty()) { + return; // Share clicked already. + } + auto items = history->owner().idsToItems(data->msgIds); + if (items.empty() || result.empty()) { + return; + } + + const auto error = [&] { + for (const auto peer : result) { + const auto error = GetErrorTextForSending( + peer, + items, + comment); + if (!error.isEmpty()) { + return std::make_pair(error, peer); + } + } + return std::make_pair(QString(), result.front()); + }(); + if (!error.first.isEmpty()) { + auto text = TextWithEntities(); + if (result.size() > 1) { + text.append( + Ui::Text::Bold(error.second->name) + ).append("\n\n"); + } + text.append(error.first); + Ui::show( + Box(text), + Ui::LayerOption::KeepOther); + return; + } + + auto &api = owner->session().api(); + auto &histories = owner->histories(); + const auto requestType = Data::Histories::RequestType::Send; + for (const auto peer : result) { + const auto history = owner->history(peer); + if (!comment.text.isEmpty()) { + auto message = ApiWrap::MessageToSend(history); + message.textWithTags = comment; + message.action.options = options; + message.action.clearDraft = false; + api.sendMessage(std::move(message)); + } + + histories.sendRequest(history, requestType, [=](Fn finish) { + const auto api = &item->history()->peer->session().api(); + for (const auto item : items) { + if (item->media() != nullptr) { + if (item->media()->document() != nullptr) { + const auto document = item->media()->document(); + auto message = ApiWrap::MessageToSend(history); + message.textWithTags = { item->originalText().text, TextUtilities::ConvertEntitiesToTextTags(item->originalText().entities) }; + message.action = Api::SendAction(history); + Api::SendExistingDocument(std::move(message), document); + } + else if (item->media()->photo() != nullptr) { + const auto photo = item->media()->photo(); + auto message = ApiWrap::MessageToSend(history); + message.textWithTags = { item->originalText().text, TextUtilities::ConvertEntitiesToTextTags(item->originalText().entities) }; + message.action = Api::SendAction(history); + Api::SendExistingPhoto(std::move(message), photo); + } + } else { + auto message = ApiWrap::MessageToSend(history); + message.textWithTags = { item->originalText().text, TextUtilities::ConvertEntitiesToTextTags(item->originalText().entities) }; + message.action = Api::SendAction(history); + api->sendMessage(std::move(message)); + } + } + Ui::Toast::Show(tr::lng_share_done(tr::now)); + Ui::hideLayer(); + finish(); + return 0; + }); + } + }; + auto filterCallback = [](PeerData *peer) { + return peer->canWrite(); + }; + *weak = Ui::show(Box( + App::wnd()->sessionController(), + nullptr, + std::move(submitCallback), + std::move(filterCallback))); + return weak->data(); +} + QPointer ShowSendNowMessagesBox( not_null navigation, not_null history, diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index e68bdb1382..129f139646 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -82,6 +82,11 @@ QPointer ShowForwardMessagesBox( MessageIdsList &&items, FnMut &&successCallback = nullptr); +QPointer ShowForwardNoQuoteMessagesBox( + not_null navigation, + MessageIdsList &&items, + FnMut &&successCallback = nullptr); + QPointer ShowSendNowMessagesBox( not_null navigation, not_null history,