Support sending albums to slowmode groups.

This commit is contained in:
John Preston 2019-07-18 18:09:50 +02:00
parent b23bfe8b02
commit 22f210ea8e
5 changed files with 66 additions and 43 deletions

View file

@ -1483,6 +1483,11 @@ void SendFilesBox::prepare() {
void SendFilesBox::initSendWay() { void SendFilesBox::initSendWay() {
refreshAlbumMediaCount(); refreshAlbumMediaCount();
const auto value = [&] { const auto value = [&] {
if (_sendLimit == SendLimit::One
&& _list.albumIsPossible
&& _list.files.size() > 1) {
return SendFilesWay::Album;
}
if (_compressConfirm == CompressConfirm::None) { if (_compressConfirm == CompressConfirm::None) {
return SendFilesWay::Files; return SendFilesWay::Files;
} else if (_compressConfirm == CompressConfirm::No) { } else if (_compressConfirm == CompressConfirm::No) {
@ -1571,7 +1576,8 @@ void SendFilesBox::setupSendWayControls() {
_sendAlbum.destroy(); _sendAlbum.destroy();
_sendPhotos.destroy(); _sendPhotos.destroy();
_sendFiles.destroy(); _sendFiles.destroy();
if (_compressConfirm == CompressConfirm::None) { if (_compressConfirm == CompressConfirm::None
|| _sendLimit == SendLimit::One) {
return; return;
} }
const auto addRadio = [&]( const auto addRadio = [&](

View file

@ -111,7 +111,8 @@ bool HasInlineItems(const HistoryItemsList &items) {
QString GetErrorTextForForward( QString GetErrorTextForForward(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const HistoryItemsList &items, const HistoryItemsList &items,
const TextWithTags &comment) { const TextWithTags &comment,
bool ignoreSlowmodeCountdown) {
if (!peer->canWrite()) { if (!peer->canWrite()) {
return tr::lng_forward_cant(tr::now); return tr::lng_forward_cant(tr::now);
} }
@ -131,9 +132,19 @@ QString GetErrorTextForForward(
return *error; return *error;
} }
if (peer->slowmodeApplied() && !comment.text.isEmpty()) { if (peer->slowmodeApplied()) {
if (const auto history = peer->owner().historyLoaded(peer)) {
if (!ignoreSlowmodeCountdown
&& (history->latestSendingMessage() != nullptr)
&& (!items.empty() || !comment.text.isEmpty())) {
return tr::lng_slowmode_no_many(tr::now); return tr::lng_slowmode_no_many(tr::now);
} else if (peer->slowmodeApplied() && items.size() > 1) { }
}
if (comment.text.size() > MaxMessageSize) {
return tr::lng_slowmode_no_many(tr::now);
} else if (!items.empty() && !comment.text.isEmpty()) {
return tr::lng_slowmode_no_many(tr::now);
} else if (items.size() > 1) {
const auto albumForward = [&] { const auto albumForward = [&] {
if (const auto groupId = items.front()->groupId()) { if (const auto groupId = items.front()->groupId()) {
for (const auto item : items) { for (const auto item : items) {
@ -149,13 +160,15 @@ QString GetErrorTextForForward(
return tr::lng_slowmode_no_many(tr::now); return tr::lng_slowmode_no_many(tr::now);
} }
} }
}
if (const auto left = peer->slowmodeSecondsLeft()) { if (const auto left = peer->slowmodeSecondsLeft()) {
if (!ignoreSlowmodeCountdown) {
return tr::lng_slowmode_enabled( return tr::lng_slowmode_enabled(
tr::now, tr::now,
lt_left, lt_left,
formatDurationWords(left)); formatDurationWords(left));
} }
}
return QString(); return QString();
} }
@ -327,8 +340,9 @@ MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer) {
QString GetErrorTextForForward( QString GetErrorTextForForward(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const HistoryItemsList &items) { const HistoryItemsList &items,
return GetErrorTextForForward(peer, items, TextWithTags()); bool ignoreSlowmodeCountdown) {
return GetErrorTextForForward(peer, items, {}, ignoreSlowmodeCountdown);
} }
struct HistoryMessage::CreateConfig { struct HistoryMessage::CreateConfig {

View file

@ -20,7 +20,13 @@ Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer); MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer);
QString GetErrorTextForForward( QString GetErrorTextForForward(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const HistoryItemsList &items); const HistoryItemsList &items,
bool ignoreSlowmodeCountdown = false);
QString GetErrorTextForForward(
not_null<PeerData*> peer,
const HistoryItemsList &items,
const TextWithTags &comment,
bool ignoreSlowmodeCountdown = false);
void FastShareMessage(not_null<HistoryItem*> item); void FastShareMessage(not_null<HistoryItem*> item);
class HistoryMessage class HistoryMessage

View file

@ -2836,15 +2836,14 @@ void HistoryWidget::send(Qt::KeyboardModifiers modifiers) {
message.webPageId = webPageId; message.webPageId = webPageId;
message.handleSupportSwitch = Support::HandleSwitch(modifiers); message.handleSupportSwitch = Support::HandleSwitch(modifiers);
if (_peer->slowmodeApplied()) { const auto error = GetErrorTextForForward(
if (_toForward.size() > 1 _peer,
|| (!_toForward.empty() _toForward,
&& !message.textWithTags.text.isEmpty()) message.textWithTags);
|| (message.textWithTags.text.size() > MaxMessageSize)) { if (!error.isEmpty()) {
ShowErrorToast(tr::lng_slowmode_no_many(tr::now)); ShowErrorToast(error);
return; return;
} }
}
session().api().sendMessage(std::move(message)); session().api().sendMessage(std::move(message));
@ -3055,10 +3054,7 @@ void HistoryWidget::chooseAttach() {
+ cImgExtensions().join(qsl(" *")) + cImgExtensions().join(qsl(" *"))
+ qsl(")"); + qsl(")");
const auto method = _peer->slowmodeApplied() FileDialog::GetOpenPaths(this, tr::lng_choose_files(tr::now), filter, crl::guard(this, [=](
? &FileDialog::GetOpenPath
: &FileDialog::GetOpenPaths;
method(this, tr::lng_choose_files(tr::now), filter, crl::guard(this, [=](
FileDialog::OpenResult &&result) { FileDialog::OpenResult &&result) {
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) { if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
return; return;
@ -4000,7 +3996,9 @@ bool HistoryWidget::showSendingFilesError(
} else if (!canWriteMessage()) { } else if (!canWriteMessage()) {
return tr::lng_forward_send_files_cant(tr::now); return tr::lng_forward_send_files_cant(tr::now);
} }
if (list.files.size() > 1 && _peer->slowmodeApplied()) { if (list.files.size() > 1
&& _peer->slowmodeApplied()
&& !list.albumIsPossible) {
return tr::lng_slowmode_no_many(tr::now); return tr::lng_slowmode_no_many(tr::now);
} else if (const auto left = _peer->slowmodeSecondsLeft()) { } else if (const auto left = _peer->slowmodeSecondsLeft()) {
return tr::lng_slowmode_enabled( return tr::lng_slowmode_enabled(
@ -4222,7 +4220,7 @@ void HistoryWidget::uploadFilesAfterConfirmation(
const auto isAlbum = (album != nullptr); const auto isAlbum = (album != nullptr);
const auto compressImages = (type == SendMediaType::Photo); const auto compressImages = (type == SendMediaType::Photo);
if (_peer->slowmodeApplied() if (_peer->slowmodeApplied()
&& (list.files.size() > 1 && ((list.files.size() > 1 && !album)
|| (!list.files.empty() || (!list.files.empty()
&& !caption.text.isEmpty() && !caption.text.isEmpty()
&& !list.canAddCaption(isAlbum, compressImages)))) { && !list.canAddCaption(isAlbum, compressImages)))) {

View file

@ -597,7 +597,8 @@ bool MainWidget::setForwardDraft(PeerId peerId, MessageIdsList &&items) {
const auto peer = session().data().peer(peerId); const auto peer = session().data().peer(peerId);
const auto error = GetErrorTextForForward( const auto error = GetErrorTextForForward(
peer, peer,
session().data().idsToItems(items)); session().data().idsToItems(items),
true);
if (!error.isEmpty()) { if (!error.isEmpty()) {
Ui::show(Box<InformBox>(error), LayerOption::KeepOther); Ui::show(Box<InformBox>(error), LayerOption::KeepOther);
return false; return false;
@ -681,10 +682,8 @@ void MainWidget::cancelForwarding(not_null<History*> history) {
void MainWidget::finishForwarding(not_null<History*> history) { void MainWidget::finishForwarding(not_null<History*> history) {
auto toForward = history->validateForwardDraft(); auto toForward = history->validateForwardDraft();
if (!toForward.empty()) { if (!toForward.empty()) {
if (history->peer->slowmodeSecondsLeft() const auto error = GetErrorTextForForward(history->peer, toForward);
|| (history->peer->slowmodeApplied() if (!error.isEmpty()) {
&& (toForward.size() > 1
|| history->latestSendingMessage() != nullptr))) {
return; return;
} }