mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Count senders / captions count correctly in forwards.
This commit is contained in:
parent
95d4e02ae1
commit
5f97d683df
8 changed files with 65 additions and 41 deletions
|
@ -495,7 +495,6 @@ void ShareBox::showMenu(not_null<Ui::RpWidget*> parent) {
|
||||||
};
|
};
|
||||||
Ui::FillForwardOptions(
|
Ui::FillForwardOptions(
|
||||||
std::move(createView),
|
std::move(createView),
|
||||||
_descriptor.forwardOptions.messagesCount,
|
|
||||||
_forwardOptions,
|
_forwardOptions,
|
||||||
[=](Ui::ForwardOptions value) { _forwardOptions = value; },
|
[=](Ui::ForwardOptions value) { _forwardOptions = value; },
|
||||||
_menu->lifetime());
|
_menu->lifetime());
|
||||||
|
@ -522,7 +521,10 @@ void ShareBox::createButtons() {
|
||||||
const auto send = addButton(tr::lng_share_confirm(), [=] {
|
const auto send = addButton(tr::lng_share_confirm(), [=] {
|
||||||
submit({});
|
submit({});
|
||||||
});
|
});
|
||||||
_forwardOptions.hasCaptions = _descriptor.forwardOptions.hasCaptions;
|
_forwardOptions.sendersCount
|
||||||
|
= _descriptor.forwardOptions.sendersCount;
|
||||||
|
_forwardOptions.captionsCount
|
||||||
|
= _descriptor.forwardOptions.captionsCount;
|
||||||
|
|
||||||
send->setAcceptBoth();
|
send->setAcceptBoth();
|
||||||
send->clicks(
|
send->clicks(
|
||||||
|
@ -575,7 +577,7 @@ void ShareBox::innerSelectedChanged(
|
||||||
|
|
||||||
void ShareBox::submit(Api::SendOptions options) {
|
void ShareBox::submit(Api::SendOptions options) {
|
||||||
if (const auto onstack = _descriptor.submitCallback) {
|
if (const auto onstack = _descriptor.submitCallback) {
|
||||||
const auto forwardOptions = (_forwardOptions.hasCaptions
|
const auto forwardOptions = (_forwardOptions.captionsCount
|
||||||
&& _forwardOptions.dropCaptions)
|
&& _forwardOptions.dropCaptions)
|
||||||
? Data::ForwardOptions::NoNamesAndCaptions
|
? Data::ForwardOptions::NoNamesAndCaptions
|
||||||
: _forwardOptions.dropNames
|
: _forwardOptions.dropNames
|
||||||
|
@ -1659,9 +1661,9 @@ void FastShareMessage(
|
||||||
msgIds),
|
msgIds),
|
||||||
.filterCallback = std::move(filterCallback),
|
.filterCallback = std::move(filterCallback),
|
||||||
.forwardOptions = {
|
.forwardOptions = {
|
||||||
.messagesCount = int(msgIds.size()),
|
.sendersCount = ItemsForwardSendersCount(items),
|
||||||
|
.captionsCount = ItemsForwardCaptionsCount(items),
|
||||||
.show = !hasOnlyForcedForwardedInfo,
|
.show = !hasOnlyForcedForwardedInfo,
|
||||||
.hasCaptions = hasCaptions,
|
|
||||||
},
|
},
|
||||||
.premiumRequiredError = SharePremiumRequiredError(),
|
.premiumRequiredError = SharePremiumRequiredError(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -100,9 +100,9 @@ public:
|
||||||
const style::PeerList *st = nullptr;
|
const style::PeerList *st = nullptr;
|
||||||
const style::InputField *stLabel = nullptr;
|
const style::InputField *stLabel = nullptr;
|
||||||
struct {
|
struct {
|
||||||
int messagesCount = 0;
|
int sendersCount = 0;
|
||||||
|
int captionsCount = 0;
|
||||||
bool show = false;
|
bool show = false;
|
||||||
bool hasCaptions = false;
|
|
||||||
} forwardOptions;
|
} forwardOptions;
|
||||||
HistoryView::ScheduleBoxStyleArgs scheduleBoxStyle;
|
HistoryView::ScheduleBoxStyleArgs scheduleBoxStyle;
|
||||||
|
|
||||||
|
|
|
@ -808,3 +808,29 @@ void ClearMediaAsExpired(not_null<HistoryItem*> item) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ItemsForwardSendersCount(const HistoryItemsList &list) {
|
||||||
|
auto peers = base::flat_set<not_null<PeerData*>>();
|
||||||
|
auto names = base::flat_set<QString>();
|
||||||
|
for (const auto &item : list) {
|
||||||
|
if (const auto peer = item->originalSender()) {
|
||||||
|
peers.emplace(peer);
|
||||||
|
} else {
|
||||||
|
names.emplace(item->originalHiddenSenderInfo()->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return int(peers.size()) + int(names.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
int ItemsForwardCaptionsCount(const HistoryItemsList &list) {
|
||||||
|
auto result = 0;
|
||||||
|
for (const auto &item : list) {
|
||||||
|
if (const auto media = item->media()) {
|
||||||
|
if (!item->originalText().text.isEmpty()
|
||||||
|
&& media->allowsEditCaption()) {
|
||||||
|
++result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -158,3 +158,6 @@ ClickHandlerPtr JumpToStoryClickHandler(
|
||||||
void ShowTrialTranscribesToast(int left, TimeId until);
|
void ShowTrialTranscribesToast(int left, TimeId until);
|
||||||
|
|
||||||
void ClearMediaAsExpired(not_null<HistoryItem*> item);
|
void ClearMediaAsExpired(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
|
[[nodiscard]] int ItemsForwardSendersCount(const HistoryItemsList &list);
|
||||||
|
[[nodiscard]] int ItemsForwardCaptionsCount(const HistoryItemsList &list);
|
||||||
|
|
|
@ -44,18 +44,6 @@ constexpr auto kUnknownVersion = -1;
|
||||||
constexpr auto kNameWithCaptionsVersion = -2;
|
constexpr auto kNameWithCaptionsVersion = -2;
|
||||||
constexpr auto kNameNoCaptionsVersion = -3;
|
constexpr auto kNameNoCaptionsVersion = -3;
|
||||||
|
|
||||||
[[nodiscard]] bool HasCaptions(const HistoryItemsList &list) {
|
|
||||||
for (const auto &item : list) {
|
|
||||||
if (const auto media = item->media()) {
|
|
||||||
if (!item->originalText().text.isEmpty()
|
|
||||||
&& media->allowsEditCaption()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool HasOnlyForcedForwardedInfo(const HistoryItemsList &list) {
|
[[nodiscard]] bool HasOnlyForcedForwardedInfo(const HistoryItemsList &list) {
|
||||||
for (const auto &item : list) {
|
for (const auto &item : list) {
|
||||||
if (const auto media = item->media()) {
|
if (const auto media = item->media()) {
|
||||||
|
@ -257,10 +245,10 @@ void ForwardPanel::editOptions(std::shared_ptr<ChatHelpers::Show> show) {
|
||||||
const auto now = _data.options;
|
const auto now = _data.options;
|
||||||
const auto count = _data.items.size();
|
const auto count = _data.items.size();
|
||||||
const auto dropNames = (now != Options::PreserveInfo);
|
const auto dropNames = (now != Options::PreserveInfo);
|
||||||
const auto hasCaptions = HasCaptions(_data.items);
|
const auto sendersCount = ItemsForwardSendersCount(_data.items);
|
||||||
const auto hasOnlyForcedForwardedInfo = hasCaptions
|
const auto captionsCount = ItemsForwardCaptionsCount(_data.items);
|
||||||
? false
|
const auto hasOnlyForcedForwardedInfo = !captionsCount
|
||||||
: HasOnlyForcedForwardedInfo(_data.items);
|
&& HasOnlyForcedForwardedInfo(_data.items);
|
||||||
const auto dropCaptions = (now == Options::NoNamesAndCaptions);
|
const auto dropCaptions = (now == Options::NoNamesAndCaptions);
|
||||||
const auto weak = base::make_weak(this);
|
const auto weak = base::make_weak(this);
|
||||||
const auto changeRecipient = crl::guard(this, [=] {
|
const auto changeRecipient = crl::guard(this, [=] {
|
||||||
|
@ -283,7 +271,7 @@ void ForwardPanel::editOptions(std::shared_ptr<ChatHelpers::Show> show) {
|
||||||
if (_data.items.empty()) {
|
if (_data.items.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto newOptions = (options.hasCaptions
|
const auto newOptions = (options.captionsCount
|
||||||
&& options.dropCaptions)
|
&& options.dropCaptions)
|
||||||
? Options::NoNamesAndCaptions
|
? Options::NoNamesAndCaptions
|
||||||
: options.dropNames
|
: options.dropNames
|
||||||
|
@ -302,8 +290,9 @@ void ForwardPanel::editOptions(std::shared_ptr<ChatHelpers::Show> show) {
|
||||||
Ui::ForwardOptionsBox,
|
Ui::ForwardOptionsBox,
|
||||||
count,
|
count,
|
||||||
Ui::ForwardOptions{
|
Ui::ForwardOptions{
|
||||||
|
.sendersCount = sendersCount,
|
||||||
|
.captionsCount = captionsCount,
|
||||||
.dropNames = dropNames,
|
.dropNames = dropNames,
|
||||||
.hasCaptions = hasCaptions,
|
|
||||||
.dropCaptions = dropCaptions,
|
.dropCaptions = dropCaptions,
|
||||||
},
|
},
|
||||||
optionsChanged,
|
optionsChanged,
|
||||||
|
@ -312,10 +301,9 @@ void ForwardPanel::editOptions(std::shared_ptr<ChatHelpers::Show> show) {
|
||||||
|
|
||||||
void ForwardPanel::editToNextOption() {
|
void ForwardPanel::editToNextOption() {
|
||||||
using Options = Data::ForwardOptions;
|
using Options = Data::ForwardOptions;
|
||||||
const auto hasCaptions = HasCaptions(_data.items);
|
const auto captionsCount = ItemsForwardCaptionsCount(_data.items);
|
||||||
const auto hasOnlyForcedForwardedInfo = hasCaptions
|
const auto hasOnlyForcedForwardedInfo = !captionsCount
|
||||||
? false
|
&& HasOnlyForcedForwardedInfo(_data.items);
|
||||||
: HasOnlyForcedForwardedInfo(_data.items);
|
|
||||||
if (hasOnlyForcedForwardedInfo) {
|
if (hasOnlyForcedForwardedInfo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -323,7 +311,7 @@ void ForwardPanel::editToNextOption() {
|
||||||
const auto now = _data.options;
|
const auto now = _data.options;
|
||||||
const auto next = (now == Options::PreserveInfo)
|
const auto next = (now == Options::PreserveInfo)
|
||||||
? Options::NoSenderNames
|
? Options::NoSenderNames
|
||||||
: ((now == Options::NoSenderNames) && hasCaptions)
|
: ((now == Options::NoSenderNames) && captionsCount)
|
||||||
? Options::NoNamesAndCaptions
|
? Options::NoNamesAndCaptions
|
||||||
: Options::PreserveInfo;
|
: Options::PreserveInfo;
|
||||||
|
|
||||||
|
|
|
@ -19,20 +19,19 @@ void FillForwardOptions(
|
||||||
Fn<not_null<AbstractCheckView*>(
|
Fn<not_null<AbstractCheckView*>(
|
||||||
rpl::producer<QString> &&,
|
rpl::producer<QString> &&,
|
||||||
bool)> createView,
|
bool)> createView,
|
||||||
int count,
|
|
||||||
ForwardOptions options,
|
ForwardOptions options,
|
||||||
Fn<void(ForwardOptions)> optionsChanged,
|
Fn<void(ForwardOptions)> optionsChanged,
|
||||||
rpl::lifetime &lifetime) {
|
rpl::lifetime &lifetime) {
|
||||||
Expects(optionsChanged != nullptr);
|
Expects(optionsChanged != nullptr);
|
||||||
|
|
||||||
const auto names = createView(
|
const auto names = createView(
|
||||||
(count == 1
|
(options.sendersCount == 1
|
||||||
? tr::lng_forward_show_sender
|
? tr::lng_forward_show_sender
|
||||||
: tr::lng_forward_show_senders)(),
|
: tr::lng_forward_show_senders)(),
|
||||||
!options.dropNames);
|
!options.dropNames);
|
||||||
const auto captions = options.hasCaptions
|
const auto captions = options.captionsCount
|
||||||
? createView(
|
? createView(
|
||||||
(count == 1
|
(options.captionsCount == 1
|
||||||
? tr::lng_forward_show_caption
|
? tr::lng_forward_show_caption
|
||||||
: tr::lng_forward_show_captions)(),
|
: tr::lng_forward_show_captions)(),
|
||||||
!options.dropCaptions).get()
|
!options.dropCaptions).get()
|
||||||
|
@ -40,8 +39,9 @@ void FillForwardOptions(
|
||||||
|
|
||||||
const auto notify = [=] {
|
const auto notify = [=] {
|
||||||
optionsChanged({
|
optionsChanged({
|
||||||
|
.sendersCount = options.sendersCount,
|
||||||
|
.captionsCount = options.captionsCount,
|
||||||
.dropNames = !names->checked(),
|
.dropNames = !names->checked(),
|
||||||
.hasCaptions = options.hasCaptions,
|
|
||||||
.dropCaptions = (captions && !captions->checked()),
|
.dropCaptions = (captions && !captions->checked()),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -118,7 +118,6 @@ void ForwardOptionsBox(
|
||||||
};
|
};
|
||||||
FillForwardOptions(
|
FillForwardOptions(
|
||||||
std::move(createView),
|
std::move(createView),
|
||||||
count,
|
|
||||||
options,
|
options,
|
||||||
std::move(optionsChanged),
|
std::move(optionsChanged),
|
||||||
box->lifetime());
|
box->lifetime());
|
||||||
|
|
|
@ -14,8 +14,9 @@ namespace Ui {
|
||||||
class AbstractCheckView;
|
class AbstractCheckView;
|
||||||
|
|
||||||
struct ForwardOptions {
|
struct ForwardOptions {
|
||||||
|
int sendersCount = 0;
|
||||||
|
int captionsCount = 0;
|
||||||
bool dropNames = false;
|
bool dropNames = false;
|
||||||
bool hasCaptions = false;
|
|
||||||
bool dropCaptions = false;
|
bool dropCaptions = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,7 +24,6 @@ void FillForwardOptions(
|
||||||
Fn<not_null<AbstractCheckView*>(
|
Fn<not_null<AbstractCheckView*>(
|
||||||
rpl::producer<QString> &&,
|
rpl::producer<QString> &&,
|
||||||
bool)> createView,
|
bool)> createView,
|
||||||
int count,
|
|
||||||
ForwardOptions options,
|
ForwardOptions options,
|
||||||
Fn<void(ForwardOptions)> optionsChanged,
|
Fn<void(ForwardOptions)> optionsChanged,
|
||||||
rpl::lifetime &lifetime);
|
rpl::lifetime &lifetime);
|
||||||
|
|
|
@ -1761,7 +1761,10 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
|
||||||
Fn<void()> &&successCallback) {
|
Fn<void()> &&successCallback) {
|
||||||
const auto session = &show->session();
|
const auto session = &show->session();
|
||||||
const auto owner = &session->data();
|
const auto owner = &session->data();
|
||||||
const auto msgIds = owner->itemsToIds(owner->idsToItems(draft.ids));
|
const auto itemsList = owner->idsToItems(draft.ids);
|
||||||
|
const auto msgIds = owner->itemsToIds(itemsList);
|
||||||
|
const auto sendersCount = ItemsForwardSendersCount(itemsList);
|
||||||
|
const auto captionsCount = ItemsForwardCaptionsCount(itemsList);
|
||||||
if (msgIds.empty()) {
|
if (msgIds.empty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1779,7 +1782,7 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] Data::ForwardOptions forwardOptionsData() const {
|
[[nodiscard]] Data::ForwardOptions forwardOptionsData() const {
|
||||||
return (_forwardOptions.hasCaptions
|
return (_forwardOptions.captionsCount
|
||||||
&& _forwardOptions.dropCaptions)
|
&& _forwardOptions.dropCaptions)
|
||||||
? Data::ForwardOptions::NoNamesAndCaptions
|
? Data::ForwardOptions::NoNamesAndCaptions
|
||||||
: _forwardOptions.dropNames
|
: _forwardOptions.dropNames
|
||||||
|
@ -1868,6 +1871,10 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
|
||||||
const auto controllerRaw = controller.get();
|
const auto controllerRaw = controller.get();
|
||||||
auto box = Box<ListBox>(std::move(controller), nullptr);
|
auto box = Box<ListBox>(std::move(controller), nullptr);
|
||||||
const auto boxRaw = box.data();
|
const auto boxRaw = box.data();
|
||||||
|
boxRaw->setForwardOptions({
|
||||||
|
.sendersCount = sendersCount,
|
||||||
|
.captionsCount = captionsCount,
|
||||||
|
});
|
||||||
show->showBox(std::move(box));
|
show->showBox(std::move(box));
|
||||||
auto state = State{ boxRaw, controllerRaw };
|
auto state = State{ boxRaw, controllerRaw };
|
||||||
return boxRaw->lifetime().make_state<State>(std::move(state));
|
return boxRaw->lifetime().make_state<State>(std::move(state));
|
||||||
|
@ -1988,7 +1995,6 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
|
||||||
};
|
};
|
||||||
Ui::FillForwardOptions(
|
Ui::FillForwardOptions(
|
||||||
std::move(createView),
|
std::move(createView),
|
||||||
msgIds.size(),
|
|
||||||
state->box->forwardOptions(),
|
state->box->forwardOptions(),
|
||||||
[=](Ui::ForwardOptions o) {
|
[=](Ui::ForwardOptions o) {
|
||||||
state->box->setForwardOptions(o);
|
state->box->setForwardOptions(o);
|
||||||
|
|
Loading…
Add table
Reference in a new issue