Unregister channel from shortpoll.

This commit is contained in:
John Preston 2024-09-13 12:40:17 +04:00
parent 6f71d21bb7
commit 1dc310586d
4 changed files with 27 additions and 11 deletions

View file

@ -417,13 +417,12 @@ void Updates::channelDifferenceDone(
"{ good - after not final channelDifference was received }%1"
).arg(_session->mtp().isTestMode() ? " TESTMODE" : ""));
getChannelDifference(channel);
} else if (ranges::contains(
_activeChats,
channel,
[](const auto &pair) { return pair.second.peer; })) {
channel->ptsWaitingForShortPoll(timeout
} else if (inActiveChats(channel)) {
channel->ptsSetWaitingForShortPoll(timeout
? (timeout * crl::time(1000))
: kWaitForChannelGetDifference);
} else {
channel->ptsSetWaitingForShortPoll(-1);
}
}
@ -743,16 +742,32 @@ void Updates::addActiveChat(rpl::producer<PeerData*> chat) {
std::move(
chat
) | rpl::start_with_next_done([=](PeerData *peer) {
_activeChats[key].peer = peer;
if (const auto channel = peer ? peer->asChannel() : nullptr) {
channel->ptsWaitingForShortPoll(
kWaitForChannelGetDifference);
auto &active = _activeChats[key];
const auto was = active.peer;
if (was != peer) {
active.peer = peer;
if (const auto channel = was ? was->asChannel() : nullptr) {
if (!inActiveChats(channel)) {
channel->ptsSetWaitingForShortPoll(-1);
}
}
if (const auto channel = peer ? peer->asChannel() : nullptr) {
channel->ptsSetWaitingForShortPoll(
kWaitForChannelGetDifference);
}
}
}, [=] {
_activeChats.erase(key);
}, _activeChats[key].lifetime);
}
bool Updates::inActiveChats(not_null<PeerData*> peer) const {
return ranges::contains(
_activeChats,
peer.get(),
[](const auto &pair) { return pair.second.peer; });
}
void Updates::requestChannelRangeDifference(not_null<History*> history) {
Expects(history->peer->isChannel());

View file

@ -63,6 +63,7 @@ public:
void requestChannelRangeDifference(not_null<History*> history);
void addActiveChat(rpl::producer<PeerData*> chat);
[[nodiscard]] bool inActiveChats(not_null<PeerData*> peer) const;
private:
enum class ChannelDifferenceRequest {

View file

@ -2028,7 +2028,7 @@ void ApiWrap::deleteHistory(
}
if (const auto channel = peer->asChannel()) {
if (!justClear && !revoke) {
channel->ptsWaitingForShortPoll(-1);
channel->ptsSetWaitingForShortPoll(-1);
leaveChannel(channel);
} else {
if (const auto migrated = peer->migrateFrom()) {

View file

@ -423,7 +423,7 @@ public:
return _ptsWaiter.setRequesting(isRequesting);
}
// < 0 - not waiting
void ptsWaitingForShortPoll(int32 ms) {
void ptsSetWaitingForShortPoll(int32 ms) {
return _ptsWaiter.setWaitingForShortPoll(this, ms);
}
[[nodiscard]] bool ptsWaitingForSkipped() const {