Check if it is possible to 'Send now.'

This commit is contained in:
John Preston 2019-08-30 16:17:46 +03:00
parent 470b67f557
commit d95e54cb1a
7 changed files with 40 additions and 20 deletions

View File

@ -114,7 +114,7 @@ bool HasInlineItems(const HistoryItemsList &items) {
} // namespace } // namespace
QString GetErrorTextForForward( QString GetErrorTextForSending(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const HistoryItemsList &items, const HistoryItemsList &items,
const TextWithTags &comment, const TextWithTags &comment,
@ -234,7 +234,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
const auto error = [&] { const auto error = [&] {
for (const auto peer : result) { for (const auto peer : result) {
const auto error = GetErrorTextForForward( const auto error = GetErrorTextForSending(
peer, peer,
items, items,
comment); comment);
@ -354,11 +354,11 @@ MTPDmessage_ClientFlags NewMessageClientFlags() {
return MTPDmessage_ClientFlag::f_sending; return MTPDmessage_ClientFlag::f_sending;
} }
QString GetErrorTextForForward( QString GetErrorTextForSending(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const HistoryItemsList &items, const HistoryItemsList &items,
bool ignoreSlowmodeCountdown) { bool ignoreSlowmodeCountdown) {
return GetErrorTextForForward(peer, items, {}, ignoreSlowmodeCountdown); return GetErrorTextForSending(peer, items, {}, ignoreSlowmodeCountdown);
} }
struct HistoryMessage::CreateConfig { struct HistoryMessage::CreateConfig {

View File

@ -19,11 +19,11 @@ Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
const FullMsgId &msgId); const FullMsgId &msgId);
MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer); MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer);
MTPDmessage_ClientFlags NewMessageClientFlags(); MTPDmessage_ClientFlags NewMessageClientFlags();
QString GetErrorTextForForward( QString GetErrorTextForSending(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const HistoryItemsList &items, const HistoryItemsList &items,
bool ignoreSlowmodeCountdown = false); bool ignoreSlowmodeCountdown = false);
QString GetErrorTextForForward( QString GetErrorTextForSending(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const HistoryItemsList &items, const HistoryItemsList &items,
const TextWithTags &comment, const TextWithTags &comment,

View File

@ -2937,7 +2937,7 @@ void HistoryWidget::send(Api::SendOptions options) {
message.webPageId = webPageId; message.webPageId = webPageId;
if (_canSendMessages) { if (_canSendMessages) {
const auto error = GetErrorTextForForward( const auto error = GetErrorTextForSending(
_peer, _peer,
_toForward, _toForward,
message.textWithTags); message.textWithTags);

View File

@ -2330,12 +2330,18 @@ std::unique_ptr<QMimeData> ListWidget::prepareDrag() {
? _pressItemExact ? _pressItemExact
: pressedItem; : pressedItem;
if (_mouseCursorState == CursorState::Date) { if (_mouseCursorState == CursorState::Date) {
forwardIds = session().data().itemOrItsGroup(_overElement->data()); if (_overElement->data()->allowsForward()) {
forwardIds = session().data().itemOrItsGroup(
_overElement->data());
}
} else if (_pressState.pointState == PointState::GroupPart) { } else if (_pressState.pointState == PointState::GroupPart) {
forwardIds = MessageIdsList(1, exactItem->fullId()); if (exactItem->allowsForward()) {
forwardIds = MessageIdsList(1, exactItem->fullId());
}
} else if (const auto media = pressedView->media()) { } else if (const auto media = pressedView->media()) {
if (media->dragItemByHandler(pressedHandler) if (pressedView->data()->allowsForward()
|| media->dragItem()) { && (media->dragItemByHandler(pressedHandler)
|| media->dragItem())) {
forwardIds = MessageIdsList(1, exactItem->fullId()); forwardIds = MessageIdsList(1, exactItem->fullId());
} }
} }

View File

@ -400,7 +400,7 @@ void ScheduledWidget::send(Api::SendOptions options) {
//message.action.replyTo = replyToId(); //message.action.replyTo = replyToId();
message.webPageId = webPageId; message.webPageId = webPageId;
//const auto error = GetErrorTextForForward( //const auto error = GetErrorTextForSending(
// _peer, // _peer,
// _toForward, // _toForward,
// message.textWithTags); // message.textWithTags);

View File

@ -597,7 +597,7 @@ bool MainWidget::setForwardDraft(PeerId peerId, MessageIdsList &&items) {
Expects(peerId != 0); Expects(peerId != 0);
const auto peer = session().data().peer(peerId); const auto peer = session().data().peer(peerId);
const auto error = GetErrorTextForForward( const auto error = GetErrorTextForSending(
peer, peer,
session().data().idsToItems(items), session().data().idsToItems(items),
true); true);
@ -685,7 +685,7 @@ void MainWidget::finishForwarding(Api::SendAction action) {
const auto history = action.history; const auto history = action.history;
auto toForward = history->validateForwardDraft(); auto toForward = history->validateForwardDraft();
if (!toForward.empty()) { if (!toForward.empty()) {
const auto error = GetErrorTextForForward(history->peer, toForward); const auto error = GetErrorTextForSending(history->peer, toForward);
if (!error.isEmpty()) { if (!error.isEmpty()) {
return; return;
} }

View File

@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_common.h" #include "api/api_common.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_message.h" // GetErrorTextForSending.
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "support/support_helper.h" #include "support/support_helper.h"
@ -868,6 +869,19 @@ QPointer<Ui::RpWidget> ShowSendNowMessagesBox(
const auto text = (items.size() > 1) const auto text = (items.size() > 1)
? tr::lng_scheduled_send_now_many(tr::now, lt_count, items.size()) ? tr::lng_scheduled_send_now_many(tr::now, lt_count, items.size())
: tr::lng_scheduled_send_now(tr::now); : tr::lng_scheduled_send_now(tr::now);
const auto error = GetErrorTextForSending(
history->peer,
session->data().idsToItems(items),
TextWithTags());
if (!error.isEmpty()) {
auto config = Ui::Toast::Config();
config.multiline = true;
config.minWidth = st::msgMinWidth;
config.text = error;
Ui::Toast::Show(config);
return { nullptr };
}
const auto box = std::make_shared<QPointer<BoxContent>>(); const auto box = std::make_shared<QPointer<BoxContent>>();
auto done = [ auto done = [
=, =,
@ -878,12 +892,10 @@ QPointer<Ui::RpWidget> ShowSendNowMessagesBox(
(*box)->closeBox(); (*box)->closeBox();
} }
auto ids = QVector<MTPint>(); auto ids = QVector<MTPint>();
for (const auto &itemId : list) { for (const auto item : session->data().idsToItems(list)) {
if (const auto item = session->data().message(itemId)) { if (item->allowsSendNow()) {
if (item->allowsSendNow()) { ids.push_back(MTP_int(
ids.push_back(MTP_int( session->data().scheduledMessages().lookupId(item)));
session->data().scheduledMessages().lookupId(item)));
}
} }
} }
session->api().request(MTPmessages_SendScheduledMessages( session->api().request(MTPmessages_SendScheduledMessages(
@ -891,6 +903,8 @@ QPointer<Ui::RpWidget> ShowSendNowMessagesBox(
MTP_vector<MTPint>(ids) MTP_vector<MTPint>(ids)
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
session->api().applyUpdates(result); session->api().applyUpdates(result);
}).fail([=](const RPCError &error) {
session->api().sendMessageFail(error, history->peer);
}).send(); }).send();
if (callback) { if (callback) {
callback(); callback();