mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use recent requester userIds from API.
This commit is contained in:
parent
36271d6b85
commit
eb82664452
5 changed files with 32 additions and 136 deletions
|
@ -766,15 +766,6 @@ void InviteLinks::requestMoreLinks(
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InviteLinks::pushRecentRequests(RecentRequests &&requests) {
|
|
||||||
_recentRequestsLocal.fire(std::move(requests));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto InviteLinks::recentRequestsLocal() const
|
|
||||||
-> rpl::producer<RecentRequests> {
|
|
||||||
return _recentRequestsLocal.events();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InviteLinks::editPermanentLink(
|
void InviteLinks::editPermanentLink(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
const QString &link) {
|
const QString &link) {
|
||||||
|
|
|
@ -132,13 +132,6 @@ public:
|
||||||
bool revoked,
|
bool revoked,
|
||||||
Fn<void(Links)> done);
|
Fn<void(Links)> done);
|
||||||
|
|
||||||
struct RecentRequests {
|
|
||||||
not_null<PeerData*> peer;
|
|
||||||
std::vector<not_null<UserData*>> users;
|
|
||||||
};
|
|
||||||
void pushRecentRequests(RecentRequests &&requests);
|
|
||||||
[[nodiscard]] rpl::producer<RecentRequests> recentRequestsLocal() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct LinkKey {
|
struct LinkKey {
|
||||||
not_null<PeerData*> peer;
|
not_null<PeerData*> peer;
|
||||||
|
@ -223,7 +216,6 @@ private:
|
||||||
base::flat_map<
|
base::flat_map<
|
||||||
std::pair<not_null<PeerData*>, not_null<UserData*>>,
|
std::pair<not_null<PeerData*>, not_null<UserData*>>,
|
||||||
ProcessRequest> _processRequests;
|
ProcessRequest> _processRequests;
|
||||||
rpl::event_stream<RecentRequests> _recentRequestsLocal;
|
|
||||||
|
|
||||||
rpl::event_stream<Update> _updates;
|
rpl::event_stream<Update> _updates;
|
||||||
|
|
||||||
|
|
|
@ -377,7 +377,6 @@ void RequestsBoxController::processRequest(
|
||||||
}
|
}
|
||||||
static_cast<RequestsBoxSearchController*>(
|
static_cast<RequestsBoxSearchController*>(
|
||||||
searchController())->removeFromCache(user);
|
searchController())->removeFromCache(user);
|
||||||
pushRecentRequests();
|
|
||||||
};
|
};
|
||||||
const auto done = crl::guard(this, [=] {
|
const auto done = crl::guard(this, [=] {
|
||||||
remove();
|
remove();
|
||||||
|
@ -403,24 +402,6 @@ void RequestsBoxController::processRequest(
|
||||||
fail);
|
fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestsBoxController::pushRecentRequests() {
|
|
||||||
const auto count = std::min(
|
|
||||||
delegate()->peerListFullRowsCount(),
|
|
||||||
HistoryView::kRecentRequestsLimit);
|
|
||||||
if (!count) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto requests = std::vector<not_null<UserData*>>();
|
|
||||||
requests.reserve(count);
|
|
||||||
for (auto i = 0; i != count; ++i) {
|
|
||||||
requests.push_back(delegate()->peerListRowAt(i)->peer()->asUser());
|
|
||||||
}
|
|
||||||
session().api().inviteLinks().pushRecentRequests({
|
|
||||||
.peer = _peer,
|
|
||||||
.users = std::move(requests),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void RequestsBoxController::appendRow(
|
void RequestsBoxController::appendRow(
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
TimeId date) {
|
TimeId date) {
|
||||||
|
|
|
@ -53,7 +53,6 @@ private:
|
||||||
void appendRow(not_null<UserData*> user, TimeId date);
|
void appendRow(not_null<UserData*> user, TimeId date);
|
||||||
void refreshDescription();
|
void refreshDescription();
|
||||||
void processRequest(not_null<UserData*> user, bool approved);
|
void processRequest(not_null<UserData*> user, bool approved);
|
||||||
void pushRecentRequests();
|
|
||||||
|
|
||||||
void subscribeToMigration();
|
void subscribeToMigration();
|
||||||
void migrate(not_null<ChatData*> chat, not_null<ChannelData*> channel);
|
void migrate(not_null<ChatData*> chat, not_null<ChannelData*> channel);
|
||||||
|
|
|
@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/view/history_view_group_call_bar.h"
|
#include "history/view/history_view_group_call_bar.h"
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
#include "data/data_chat.h"
|
||||||
|
#include "data/data_channel.h"
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
@ -17,15 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/chat/group_call_userpics.h"
|
#include "ui/chat/group_call_userpics.h"
|
||||||
#include "info/profile/info_profile_values.h"
|
#include "info/profile/info_profile_values.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "api/api_invite_links.h"
|
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
namespace {
|
|
||||||
|
|
||||||
// If less than 10 requests we request userpics each time the count changes.
|
|
||||||
constexpr auto kRequestExactThreshold = 10;
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
rpl::producer<Ui::RequestsBarContent> RequestsBarContentByPeer(
|
rpl::producer<Ui::RequestsBarContent> RequestsBarContentByPeer(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
|
@ -35,18 +30,12 @@ rpl::producer<Ui::RequestsBarContent> RequestsBarContentByPeer(
|
||||||
: peer(peer) {
|
: peer(peer) {
|
||||||
current.isGroup = !peer->isBroadcast();
|
current.isGroup = !peer->isBroadcast();
|
||||||
}
|
}
|
||||||
~State() {
|
|
||||||
if (requestId) {
|
|
||||||
peer->session().api().request(requestId).cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
not_null<PeerData*> peer;
|
not_null<PeerData*> peer;
|
||||||
std::vector<UserpicInRow> userpics;
|
std::vector<UserpicInRow> userpics;
|
||||||
std::vector<not_null<UserData*>> users;
|
std::vector<not_null<UserData*>> users;
|
||||||
Ui::RequestsBarContent current;
|
Ui::RequestsBarContent current;
|
||||||
base::has_weak_ptr guard;
|
base::has_weak_ptr guard;
|
||||||
mtpRequestId requestId = 0;
|
|
||||||
bool someUserpicsNotLoaded = false;
|
bool someUserpicsNotLoaded = false;
|
||||||
bool pushScheduled = false;
|
bool pushScheduled = false;
|
||||||
};
|
};
|
||||||
|
@ -113,74 +102,6 @@ rpl::producer<Ui::RequestsBarContent> RequestsBarContentByPeer(
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const auto RequestExact = [](
|
|
||||||
not_null<State*> state,
|
|
||||||
int userpicSize,
|
|
||||||
Fn<void()> push,
|
|
||||||
auto requestExact) {
|
|
||||||
if (state->requestId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
using Flag = MTPmessages_GetChatInviteImporters::Flag;
|
|
||||||
state->requestId = state->peer->session().api().request(
|
|
||||||
MTPmessages_GetChatInviteImporters(
|
|
||||||
MTP_flags(Flag::f_requested),
|
|
||||||
state->peer->input,
|
|
||||||
MTPstring(), // link
|
|
||||||
MTPstring(), // q
|
|
||||||
MTP_int(0), // offset_date
|
|
||||||
MTP_inputUserEmpty(), // offset_user
|
|
||||||
MTP_int(kRecentRequestsLimit))
|
|
||||||
).done([=](const MTPmessages_ChatInviteImporters &result) {
|
|
||||||
state->requestId = 0;
|
|
||||||
|
|
||||||
result.match([&](
|
|
||||||
const MTPDmessages_chatInviteImporters &data) {
|
|
||||||
const auto count = data.vcount().v;
|
|
||||||
const auto &importers = data.vimporters().v;
|
|
||||||
auto &owner = state->peer->owner();
|
|
||||||
const auto old = base::take(state->users);
|
|
||||||
state->users = std::vector<not_null<UserData*>>();
|
|
||||||
const auto use = std::min(
|
|
||||||
importers.size(),
|
|
||||||
HistoryView::kRecentRequestsLimit);
|
|
||||||
state->users.reserve(use);
|
|
||||||
for (auto i = 0; i != use; ++i) {
|
|
||||||
importers[i].match([&](
|
|
||||||
const MTPDchatInviteImporter &data) {
|
|
||||||
state->users.push_back(
|
|
||||||
owner.user(data.vuser_id()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const auto changed = (state->current.count != count)
|
|
||||||
|| (count == 1
|
|
||||||
&& ((state->users.size() != old.size())
|
|
||||||
|| (old.size() == 1
|
|
||||||
&& state->users.front() != old.front())));
|
|
||||||
if (changed) {
|
|
||||||
state->current.count = count;
|
|
||||||
if (count == 1 && !state->users.empty()) {
|
|
||||||
const auto user = state->users.front();
|
|
||||||
state->current.nameShort = user->shortName();
|
|
||||||
state->current.nameFull = user->name;
|
|
||||||
} else {
|
|
||||||
state->current.nameShort
|
|
||||||
= state->current.nameFull
|
|
||||||
= QString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (RegenerateUserpics(state, userpicSize) || changed) {
|
|
||||||
push();
|
|
||||||
}
|
|
||||||
if (state->userpics.size() > state->current.count) {
|
|
||||||
requestExact(state, userpicSize, push, requestExact);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).fail([=](const MTP::Error &error) {
|
|
||||||
state->requestId = 0;
|
|
||||||
}).send();
|
|
||||||
};
|
|
||||||
|
|
||||||
return [=](auto consumer) {
|
return [=](auto consumer) {
|
||||||
const auto api = &peer->session().api();
|
const auto api = &peer->session().api();
|
||||||
|
|
||||||
|
@ -219,25 +140,37 @@ rpl::producer<Ui::RequestsBarContent> RequestsBarContentByPeer(
|
||||||
) | rpl::filter([=](int count) {
|
) | rpl::filter([=](int count) {
|
||||||
return (state->current.count != count);
|
return (state->current.count != count);
|
||||||
}) | rpl::start_with_next([=](int count) {
|
}) | rpl::start_with_next([=](int count) {
|
||||||
const auto was = state->current.count;
|
const auto &requesters = peer->isChat()
|
||||||
const auto requestUsersNeeded = (was < kRequestExactThreshold)
|
? peer->asChat()->recentRequesters()
|
||||||
|| (count < kRequestExactThreshold);
|
: peer->asChannel()->recentRequesters();
|
||||||
state->current.count = count;
|
auto &owner = state->peer->owner();
|
||||||
if (requestUsersNeeded) {
|
const auto old = base::take(state->users);
|
||||||
RequestExact(state, userpicSize, pushNext, RequestExact);
|
state->users = std::vector<not_null<UserData*>>();
|
||||||
|
const auto use = std::min(
|
||||||
|
int(requesters.size()),
|
||||||
|
HistoryView::kRecentRequestsLimit);
|
||||||
|
state->users.reserve(use);
|
||||||
|
for (auto i = 0; i != use; ++i) {
|
||||||
|
state->users.push_back(owner.user(requesters[i]));
|
||||||
}
|
}
|
||||||
pushNext();
|
const auto changed = (state->current.count != count)
|
||||||
}, lifetime);
|
|| (count == 1
|
||||||
|
&& ((state->users.size() != old.size())
|
||||||
using RecentRequests = Api::InviteLinks::RecentRequests;
|
|| (old.size() == 1
|
||||||
api->inviteLinks().recentRequestsLocal(
|
&& state->users.front() != old.front())));
|
||||||
) | rpl::filter([=](const RecentRequests &value) {
|
if (changed) {
|
||||||
return (value.peer == peer)
|
state->current.count = count;
|
||||||
&& (state->current.count >= kRequestExactThreshold)
|
if (count == 1 && !state->users.empty()) {
|
||||||
&& (value.users.size() == kRecentRequestsLimit);
|
const auto user = state->users.front();
|
||||||
}) | rpl::start_with_next([=](RecentRequests &&value) {
|
state->current.nameShort = user->shortName();
|
||||||
state->users = std::move(value.users);
|
state->current.nameFull = user->name;
|
||||||
if (RegenerateUserpics(state, userpicSize)) {
|
} else {
|
||||||
|
state->current.nameShort
|
||||||
|
= state->current.nameFull
|
||||||
|
= QString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (RegenerateUserpics(state, userpicSize) || changed) {
|
||||||
pushNext();
|
pushNext();
|
||||||
}
|
}
|
||||||
}, lifetime);
|
}, lifetime);
|
||||||
|
|
Loading…
Add table
Reference in a new issue