Skip to content

Commit

Permalink
Support Forward Message without quote
Browse files Browse the repository at this point in the history
  • Loading branch information
c0re100 committed Jul 9, 2020
1 parent 0ef5295 commit f65a35b
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
18 changes: 18 additions & 0 deletions Telegram/SourceFiles/history/history_inner_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/history/history_inner_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<HistoryItem*> item);
void deleteItem(FullMsgId itemId);
void deleteAsGroup(FullMsgId itemId);
Expand Down
116 changes: 116 additions & 0 deletions Telegram/SourceFiles/window/window_peer_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1047,6 +1048,121 @@ QPointer<Ui::RpWidget> ShowForwardMessagesBox(
return weak->data();
}

QPointer<Ui::RpWidget> ShowForwardNoQuoteMessagesBox(
not_null<Window::SessionNavigation*> navigation,
MessageIdsList &&items,
FnMut<void()> &&successCallback) {
struct ShareData {
ShareData(not_null<PeerData*> peer, MessageIdsList &&ids)
: peer(peer)
, msgIds(std::move(ids)) {
}
not_null<PeerData*> peer;
MessageIdsList msgIds;
base::flat_set<mtpRequestId> requests;
};
const auto weak = std::make_shared<QPointer<ShareBox>>();
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<ShareData>(history->peer, std::move(items));

auto submitCallback = [=](
std::vector<not_null<PeerData*>> &&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<InformBox>(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<void()> 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<ShareBox>(
App::wnd()->sessionController(),
nullptr,
std::move(submitCallback),
std::move(filterCallback)));
return weak->data();
}

QPointer<Ui::RpWidget> ShowSendNowMessagesBox(
not_null<Window::SessionNavigation*> navigation,
not_null<History*> history,
Expand Down
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/window/window_peer_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ QPointer<Ui::RpWidget> ShowForwardMessagesBox(
MessageIdsList &&items,
FnMut<void()> &&successCallback = nullptr);

QPointer<Ui::RpWidget> ShowForwardNoQuoteMessagesBox(
not_null<Window::SessionNavigation*> navigation,
MessageIdsList &&items,
FnMut<void()> &&successCallback = nullptr);

QPointer<Ui::RpWidget> ShowSendNowMessagesBox(
not_null<Window::SessionNavigation*> navigation,
not_null<History*> history,
Expand Down

0 comments on commit f65a35b

Please sign in to comment.