mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Added message counter to each peer in moderate box.
This commit is contained in:
parent
489c86dad8
commit
743c3c54a7
3 changed files with 96 additions and 31 deletions
|
@ -87,19 +87,35 @@ ModerateOptions CalculateModerateOptions(const HistoryItemsList &items) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<int> MessagesCountValue(
|
[[nodiscard]] rpl::producer<base::flat_map<PeerId, int>> MessagesCountValue(
|
||||||
not_null<History*> history,
|
not_null<History*> history,
|
||||||
not_null<PeerData*> from) {
|
std::vector<not_null<PeerData*>> from) {
|
||||||
return [=](auto consumer) {
|
return [=](auto consumer) {
|
||||||
auto lifetime = rpl::lifetime();
|
auto lifetime = rpl::lifetime();
|
||||||
auto search = lifetime.make_state<Api::MessagesSearch>(history);
|
struct State final {
|
||||||
consumer.put_next(0);
|
base::flat_map<PeerId, int> messagesCounts;
|
||||||
|
int index = 0;
|
||||||
search->messagesFounds(
|
rpl::lifetime apiLifetime;
|
||||||
) | rpl::start_with_next([=](const Api::FoundMessages &found) {
|
};
|
||||||
consumer.put_next_copy(found.total);
|
const auto search = lifetime.make_state<Api::MessagesSearch>(history);
|
||||||
}, lifetime);
|
const auto state = lifetime.make_state<State>();
|
||||||
search->searchMessages({ .from = from });
|
const auto send = [=](auto repeat) -> void {
|
||||||
|
if (state->index >= from.size()) {
|
||||||
|
consumer.put_next_copy(state->messagesCounts);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto peer = from[state->index];
|
||||||
|
const auto peerId = peer->id;
|
||||||
|
state->apiLifetime = search->messagesFounds(
|
||||||
|
) | rpl::start_with_next([=](const Api::FoundMessages &found) {
|
||||||
|
state->messagesCounts[peerId] = found.total;
|
||||||
|
state->index++;
|
||||||
|
repeat(repeat);
|
||||||
|
});
|
||||||
|
search->searchMessages({ .from = peer });
|
||||||
|
};
|
||||||
|
consumer.put_next({});
|
||||||
|
send(send);
|
||||||
|
|
||||||
return lifetime;
|
return lifetime;
|
||||||
};
|
};
|
||||||
|
@ -274,15 +290,50 @@ void CreateModerateMessagesBox(
|
||||||
false,
|
false,
|
||||||
st::defaultBoxCheckbox),
|
st::defaultBoxCheckbox),
|
||||||
st::boxRowPadding + buttonPadding);
|
st::boxRowPadding + buttonPadding);
|
||||||
if (isSingle) {
|
const auto history = items.front()->history();
|
||||||
const auto history = items.front()->history();
|
auto messagesCounts = MessagesCountValue(history, participants);
|
||||||
|
|
||||||
|
const auto controller = box->lifetime().make_state<Controller>(
|
||||||
|
Controller::Data{
|
||||||
|
.messagesCounts = rpl::duplicate(messagesCounts),
|
||||||
|
.participants = participants,
|
||||||
|
});
|
||||||
|
Ui::AddExpandablePeerList(deleteAll, controller, inner);
|
||||||
|
{
|
||||||
tr::lng_selected_delete_sure(
|
tr::lng_selected_delete_sure(
|
||||||
lt_count,
|
lt_count,
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
MessagesCountValue(history, participants.front()),
|
std::move(messagesCounts),
|
||||||
deleteAll->checkedValue()
|
isSingle
|
||||||
) | rpl::map([s = items.size()](int all, bool checked) {
|
? deleteAll->checkedValue()
|
||||||
return float64((checked && all) ? all : s);
|
: rpl::merge(
|
||||||
|
controller->toggleRequestsFromInner.events(),
|
||||||
|
controller->checkAllRequests.events())
|
||||||
|
) | rpl::map([=, s = items.size()](const auto &map, bool c) {
|
||||||
|
const auto checked = (isSingle && !c)
|
||||||
|
? Participants()
|
||||||
|
: controller->collectRequests
|
||||||
|
? controller->collectRequests()
|
||||||
|
: Participants();
|
||||||
|
auto result = 0;
|
||||||
|
for (const auto &[peerId, count] : map) {
|
||||||
|
for (const auto &peer : checked) {
|
||||||
|
if (peer->id == peerId) {
|
||||||
|
result += count;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto &item : items) {
|
||||||
|
for (const auto &peer : checked) {
|
||||||
|
if (peer->id == item->from()->id) {
|
||||||
|
result--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
return float64(result);
|
||||||
})
|
})
|
||||||
) | rpl::start_with_next([=](const QString &text) {
|
) | rpl::start_with_next([=](const QString &text) {
|
||||||
title->setText(text);
|
title->setText(text);
|
||||||
|
@ -290,10 +341,6 @@ void CreateModerateMessagesBox(
|
||||||
- rect::m::sum::h(st::boxRowPadding));
|
- rect::m::sum::h(st::boxRowPadding));
|
||||||
}, title->lifetime());
|
}, title->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto controller = box->lifetime().make_state<Controller>(
|
|
||||||
Controller::Data{ .participants = participants });
|
|
||||||
Ui::AddExpandablePeerList(deleteAll, controller, inner);
|
|
||||||
handleSubmition(deleteAll);
|
handleSubmition(deleteAll);
|
||||||
|
|
||||||
handleConfirmation(deleteAll, controller, [=](
|
handleConfirmation(deleteAll, controller, [=](
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/expandable_peer_list.h"
|
#include "ui/widgets/expandable_peer_list.h"
|
||||||
|
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
|
#include "info/profile/info_profile_values.h"
|
||||||
#include "ui/controls/userpic_button.h"
|
#include "ui/controls/userpic_button.h"
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
|
@ -148,19 +149,35 @@ void AddExpandablePeerList(
|
||||||
const auto &st = st::moderateBoxUserpic;
|
const auto &st = st::moderateBoxUserpic;
|
||||||
line->resize(line->width(), st.size.height());
|
line->resize(line->width(), st.size.height());
|
||||||
|
|
||||||
const auto userpic = Ui::CreateChild<Ui::UserpicButton>(
|
using namespace Info::Profile;
|
||||||
line,
|
auto name = controller->data.bold
|
||||||
peer,
|
? NameValue(peer) | rpl::map(Ui::Text::Bold)
|
||||||
st);
|
: NameValue(peer) | rpl::map(Ui::Text::WithEntities);
|
||||||
|
const auto userpic
|
||||||
|
= Ui::CreateChild<Ui::UserpicButton>(line, peer, st);
|
||||||
const auto checkbox = Ui::CreateChild<Ui::Checkbox>(
|
const auto checkbox = Ui::CreateChild<Ui::Checkbox>(
|
||||||
line,
|
line,
|
||||||
controller->data.bold
|
controller->data.messagesCounts
|
||||||
? Ui::Text::Bold(peer->name())
|
? rpl::combine(
|
||||||
: TextWithEntities{ .text = peer->name() },
|
std::move(name),
|
||||||
ranges::contains(controller->data.checked, peer->id),
|
rpl::duplicate(controller->data.messagesCounts)
|
||||||
st::defaultBoxCheckbox);
|
) | rpl::map([=](const auto &richName, const auto &map) {
|
||||||
line->widthValue(
|
const auto it = map.find(peer->id);
|
||||||
) | rpl::start_with_next([=](int width) {
|
return (it == map.end() || !it->second)
|
||||||
|
? richName
|
||||||
|
: TextWithEntities(
|
||||||
|
(u"(%1) "_q).arg(it->second)).append(richName);
|
||||||
|
})
|
||||||
|
: std::move(name),
|
||||||
|
st::defaultBoxCheckbox,
|
||||||
|
std::make_unique<Ui::CheckView>(
|
||||||
|
st::defaultCheck,
|
||||||
|
ranges::contains(controller->data.checked, peer->id)));
|
||||||
|
checkbox->setCheckAlignment(style::al_left);
|
||||||
|
rpl::combine(
|
||||||
|
line->widthValue(),
|
||||||
|
checkbox->widthValue()
|
||||||
|
) | rpl::start_with_next([=](int width, int) {
|
||||||
userpic->moveToLeft(
|
userpic->moveToLeft(
|
||||||
st::boxRowPadding.left()
|
st::boxRowPadding.left()
|
||||||
+ checkbox->checkRect().width()
|
+ checkbox->checkRect().width()
|
||||||
|
|
|
@ -18,6 +18,7 @@ class VerticalLayout;
|
||||||
|
|
||||||
struct ExpandablePeerListController final {
|
struct ExpandablePeerListController final {
|
||||||
struct Data final {
|
struct Data final {
|
||||||
|
rpl::producer<base::flat_map<PeerId, int>> messagesCounts = nullptr;
|
||||||
Participants participants;
|
Participants participants;
|
||||||
std::vector<PeerId> checked;
|
std::vector<PeerId> checked;
|
||||||
bool skipSingle = false;
|
bool skipSingle = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue