mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Support sending albums to slowmode groups.
This commit is contained in:
parent
b23bfe8b02
commit
22f210ea8e
5 changed files with 66 additions and 43 deletions
|
@ -1483,6 +1483,11 @@ void SendFilesBox::prepare() {
|
|||
void SendFilesBox::initSendWay() {
|
||||
refreshAlbumMediaCount();
|
||||
const auto value = [&] {
|
||||
if (_sendLimit == SendLimit::One
|
||||
&& _list.albumIsPossible
|
||||
&& _list.files.size() > 1) {
|
||||
return SendFilesWay::Album;
|
||||
}
|
||||
if (_compressConfirm == CompressConfirm::None) {
|
||||
return SendFilesWay::Files;
|
||||
} else if (_compressConfirm == CompressConfirm::No) {
|
||||
|
@ -1571,7 +1576,8 @@ void SendFilesBox::setupSendWayControls() {
|
|||
_sendAlbum.destroy();
|
||||
_sendPhotos.destroy();
|
||||
_sendFiles.destroy();
|
||||
if (_compressConfirm == CompressConfirm::None) {
|
||||
if (_compressConfirm == CompressConfirm::None
|
||||
|| _sendLimit == SendLimit::One) {
|
||||
return;
|
||||
}
|
||||
const auto addRadio = [&](
|
||||
|
|
|
@ -111,7 +111,8 @@ bool HasInlineItems(const HistoryItemsList &items) {
|
|||
QString GetErrorTextForForward(
|
||||
not_null<PeerData*> peer,
|
||||
const HistoryItemsList &items,
|
||||
const TextWithTags &comment) {
|
||||
const TextWithTags &comment,
|
||||
bool ignoreSlowmodeCountdown) {
|
||||
if (!peer->canWrite()) {
|
||||
return tr::lng_forward_cant(tr::now);
|
||||
}
|
||||
|
@ -131,30 +132,42 @@ QString GetErrorTextForForward(
|
|||
return *error;
|
||||
}
|
||||
|
||||
if (peer->slowmodeApplied() && !comment.text.isEmpty()) {
|
||||
return tr::lng_slowmode_no_many(tr::now);
|
||||
} else if (peer->slowmodeApplied() && items.size() > 1) {
|
||||
const auto albumForward = [&] {
|
||||
if (const auto groupId = items.front()->groupId()) {
|
||||
for (const auto item : items) {
|
||||
if (item->groupId() != groupId) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
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 false;
|
||||
}();
|
||||
if (!albumForward) {
|
||||
}
|
||||
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 = [&] {
|
||||
if (const auto groupId = items.front()->groupId()) {
|
||||
for (const auto item : items) {
|
||||
if (item->groupId() != groupId) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}();
|
||||
if (!albumForward) {
|
||||
return tr::lng_slowmode_no_many(tr::now);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (const auto left = peer->slowmodeSecondsLeft()) {
|
||||
return tr::lng_slowmode_enabled(
|
||||
tr::now,
|
||||
lt_left,
|
||||
formatDurationWords(left));
|
||||
if (!ignoreSlowmodeCountdown) {
|
||||
return tr::lng_slowmode_enabled(
|
||||
tr::now,
|
||||
lt_left,
|
||||
formatDurationWords(left));
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
|
@ -327,8 +340,9 @@ MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer) {
|
|||
|
||||
QString GetErrorTextForForward(
|
||||
not_null<PeerData*> peer,
|
||||
const HistoryItemsList &items) {
|
||||
return GetErrorTextForForward(peer, items, TextWithTags());
|
||||
const HistoryItemsList &items,
|
||||
bool ignoreSlowmodeCountdown) {
|
||||
return GetErrorTextForForward(peer, items, {}, ignoreSlowmodeCountdown);
|
||||
}
|
||||
|
||||
struct HistoryMessage::CreateConfig {
|
||||
|
|
|
@ -20,7 +20,13 @@ Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
|
|||
MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer);
|
||||
QString GetErrorTextForForward(
|
||||
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);
|
||||
|
||||
class HistoryMessage
|
||||
|
|
|
@ -2836,14 +2836,13 @@ void HistoryWidget::send(Qt::KeyboardModifiers modifiers) {
|
|||
message.webPageId = webPageId;
|
||||
message.handleSupportSwitch = Support::HandleSwitch(modifiers);
|
||||
|
||||
if (_peer->slowmodeApplied()) {
|
||||
if (_toForward.size() > 1
|
||||
|| (!_toForward.empty()
|
||||
&& !message.textWithTags.text.isEmpty())
|
||||
|| (message.textWithTags.text.size() > MaxMessageSize)) {
|
||||
ShowErrorToast(tr::lng_slowmode_no_many(tr::now));
|
||||
return;
|
||||
}
|
||||
const auto error = GetErrorTextForForward(
|
||||
_peer,
|
||||
_toForward,
|
||||
message.textWithTags);
|
||||
if (!error.isEmpty()) {
|
||||
ShowErrorToast(error);
|
||||
return;
|
||||
}
|
||||
|
||||
session().api().sendMessage(std::move(message));
|
||||
|
@ -3055,10 +3054,7 @@ void HistoryWidget::chooseAttach() {
|
|||
+ cImgExtensions().join(qsl(" *"))
|
||||
+ qsl(")");
|
||||
|
||||
const auto method = _peer->slowmodeApplied()
|
||||
? &FileDialog::GetOpenPath
|
||||
: &FileDialog::GetOpenPaths;
|
||||
method(this, tr::lng_choose_files(tr::now), filter, crl::guard(this, [=](
|
||||
FileDialog::GetOpenPaths(this, tr::lng_choose_files(tr::now), filter, crl::guard(this, [=](
|
||||
FileDialog::OpenResult &&result) {
|
||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||
return;
|
||||
|
@ -4000,7 +3996,9 @@ bool HistoryWidget::showSendingFilesError(
|
|||
} else if (!canWriteMessage()) {
|
||||
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);
|
||||
} else if (const auto left = _peer->slowmodeSecondsLeft()) {
|
||||
return tr::lng_slowmode_enabled(
|
||||
|
@ -4222,7 +4220,7 @@ void HistoryWidget::uploadFilesAfterConfirmation(
|
|||
const auto isAlbum = (album != nullptr);
|
||||
const auto compressImages = (type == SendMediaType::Photo);
|
||||
if (_peer->slowmodeApplied()
|
||||
&& (list.files.size() > 1
|
||||
&& ((list.files.size() > 1 && !album)
|
||||
|| (!list.files.empty()
|
||||
&& !caption.text.isEmpty()
|
||||
&& !list.canAddCaption(isAlbum, compressImages)))) {
|
||||
|
|
|
@ -597,7 +597,8 @@ bool MainWidget::setForwardDraft(PeerId peerId, MessageIdsList &&items) {
|
|||
const auto peer = session().data().peer(peerId);
|
||||
const auto error = GetErrorTextForForward(
|
||||
peer,
|
||||
session().data().idsToItems(items));
|
||||
session().data().idsToItems(items),
|
||||
true);
|
||||
if (!error.isEmpty()) {
|
||||
Ui::show(Box<InformBox>(error), LayerOption::KeepOther);
|
||||
return false;
|
||||
|
@ -681,10 +682,8 @@ void MainWidget::cancelForwarding(not_null<History*> history) {
|
|||
void MainWidget::finishForwarding(not_null<History*> history) {
|
||||
auto toForward = history->validateForwardDraft();
|
||||
if (!toForward.empty()) {
|
||||
if (history->peer->slowmodeSecondsLeft()
|
||||
|| (history->peer->slowmodeApplied()
|
||||
&& (toForward.size() > 1
|
||||
|| history->latestSendingMessage() != nullptr))) {
|
||||
const auto error = GetErrorTextForForward(history->peer, toForward);
|
||||
if (!error.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue