mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Reload topics on channelDifferenceTooLong.
This commit is contained in:
parent
08ba277327
commit
5356f6cd2c
6 changed files with 103 additions and 20 deletions
|
@ -395,6 +395,9 @@ void Updates::channelDifferenceDone(
|
||||||
data.vmessages().v,
|
data.vmessages().v,
|
||||||
QVector<MTPDialog>(1, data.vdialog()));
|
QVector<MTPDialog>(1, data.vdialog()));
|
||||||
session().data().channelDifferenceTooLong(channel);
|
session().data().channelDifferenceTooLong(channel);
|
||||||
|
if (const auto forum = channel->forum()) {
|
||||||
|
forum->reloadTopics();
|
||||||
|
}
|
||||||
}, [&](const MTPDupdates_channelDifference &data) {
|
}, [&](const MTPDupdates_channelDifference &data) {
|
||||||
feedChannelDifference(data);
|
feedChannelDifference(data);
|
||||||
channel->ptsInit(data.vpts().v);
|
channel->ptsInit(data.vpts().v);
|
||||||
|
@ -2210,7 +2213,9 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
||||||
}
|
}
|
||||||
const auto history = channel->owner().history(channel);
|
const auto history = channel->owner().history(channel);
|
||||||
history->requestChatListMessage();
|
history->requestChatListMessage();
|
||||||
if (!history->unreadCountKnown()) {
|
if (!history->folderKnown()
|
||||||
|
|| (!history->unreadCountKnown()
|
||||||
|
&& !history->peer->isForum())) {
|
||||||
history->owner().histories().requestDialogEntry(history);
|
history->owner().histories().requestDialogEntry(history);
|
||||||
}
|
}
|
||||||
if (!channel->amCreator()) {
|
if (!channel->amCreator()) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace {
|
||||||
constexpr auto kTopicsFirstLoad = 20;
|
constexpr auto kTopicsFirstLoad = 20;
|
||||||
constexpr auto kLoadedTopicsMinCount = 20;
|
constexpr auto kLoadedTopicsMinCount = 20;
|
||||||
constexpr auto kTopicsPerPage = 500;
|
constexpr auto kTopicsPerPage = 500;
|
||||||
|
constexpr auto kStalePerRequest = 100;
|
||||||
constexpr auto kGeneralColorId = 0xA9A9A9;
|
constexpr auto kGeneralColorId = 0xA9A9A9;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -47,12 +48,17 @@ Forum::Forum(not_null<History*> history)
|
||||||
}
|
}
|
||||||
|
|
||||||
Forum::~Forum() {
|
Forum::~Forum() {
|
||||||
|
for (const auto &request : _topicRequests) {
|
||||||
|
if (request.second.id != _staleRequestId) {
|
||||||
|
owner().histories().cancelRequest(request.second.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_staleRequestId) {
|
||||||
|
session().api().request(_staleRequestId).cancel();
|
||||||
|
}
|
||||||
if (_requestId) {
|
if (_requestId) {
|
||||||
session().api().request(_requestId).cancel();
|
session().api().request(_requestId).cancel();
|
||||||
}
|
}
|
||||||
for (const auto &request : _topicRequests) {
|
|
||||||
owner().histories().cancelRequest(request.second.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Session &Forum::owner() const {
|
Session &Forum::owner() const {
|
||||||
|
@ -100,6 +106,19 @@ void Forum::preloadTopics() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Forum::reloadTopics() {
|
||||||
|
_allLoaded = false;
|
||||||
|
session().api().request(base::take(_requestId)).cancel();
|
||||||
|
_offsetDate = 0;
|
||||||
|
_offsetId = _offsetTopicId = 0;
|
||||||
|
for (const auto &[rootId, topic] : _topics) {
|
||||||
|
if (!topic->creating()) {
|
||||||
|
_staleRootIds.emplace(topic->rootId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
requestTopics();
|
||||||
|
}
|
||||||
|
|
||||||
void Forum::requestTopics() {
|
void Forum::requestTopics() {
|
||||||
if (_allLoaded || _requestId) {
|
if (_allLoaded || _requestId) {
|
||||||
return;
|
return;
|
||||||
|
@ -121,6 +140,7 @@ void Forum::requestTopics() {
|
||||||
if (_allLoaded) {
|
if (_allLoaded) {
|
||||||
_chatsListLoadedEvents.fire({});
|
_chatsListLoadedEvents.fire({});
|
||||||
}
|
}
|
||||||
|
requestSomeStale();
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
_allLoaded = true;
|
_allLoaded = true;
|
||||||
_requestId = 0;
|
_requestId = 0;
|
||||||
|
@ -161,6 +181,7 @@ void Forum::applyReceivedTopics(
|
||||||
const auto rootId = topic.match([&](const auto &data) {
|
const auto rootId = topic.match([&](const auto &data) {
|
||||||
return data.vid().v;
|
return data.vid().v;
|
||||||
});
|
});
|
||||||
|
_staleRootIds.remove(rootId);
|
||||||
topic.match([&](const MTPDforumTopicDeleted &data) {
|
topic.match([&](const MTPDforumTopicDeleted &data) {
|
||||||
if (updateOffset) {
|
if (updateOffset) {
|
||||||
LOG(("API Error: Got a deleted topic in getForumTopics."));
|
LOG(("API Error: Got a deleted topic in getForumTopics."));
|
||||||
|
@ -189,9 +210,67 @@ void Forum::applyReceivedTopics(
|
||||||
&& (list.isEmpty() || list.size() == data.vcount().v)) {
|
&& (list.isEmpty() || list.size() == data.vcount().v)) {
|
||||||
_allLoaded = true;
|
_allLoaded = true;
|
||||||
}
|
}
|
||||||
|
if (!_staleRootIds.empty()) {
|
||||||
|
requestSomeStale();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Forum::requestSomeStale() {
|
||||||
|
if (_staleRequestId || (!_offsetId && _requestId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto type = Histories::RequestType::History;
|
||||||
|
auto rootIds = QVector<MTPint>();
|
||||||
|
rootIds.reserve(std::min(int(_staleRootIds.size()), kStalePerRequest));
|
||||||
|
for (auto i = begin(_staleRootIds); i != end(_staleRootIds);) {
|
||||||
|
const auto rootId = *i;
|
||||||
|
i = _staleRootIds.erase(i);
|
||||||
|
|
||||||
|
if (_topicRequests.contains(rootId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
rootIds.push_back(MTP_int(rootId));
|
||||||
|
if (rootIds.size() == kStalePerRequest) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const auto call = [=] {
|
||||||
|
for (const auto &id : rootIds) {
|
||||||
|
finishTopicRequest(id.v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
auto &histories = owner().histories();
|
||||||
|
_staleRequestId = histories.sendRequest(_history, type, [=](
|
||||||
|
Fn<void()> finish) {
|
||||||
|
return session().api().request(
|
||||||
|
MTPchannels_GetForumTopicsByID(
|
||||||
|
channel()->inputChannel,
|
||||||
|
MTP_vector<MTPint>(rootIds))
|
||||||
|
).done([=](const MTPmessages_ForumTopics &result) {
|
||||||
|
applyReceivedTopics(result);
|
||||||
|
call();
|
||||||
|
finish();
|
||||||
|
}).fail([=] {
|
||||||
|
call();
|
||||||
|
finish();
|
||||||
|
}).send();
|
||||||
|
});
|
||||||
|
for (const auto &id : rootIds) {
|
||||||
|
_topicRequests[id.v].id = _staleRequestId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Forum::finishTopicRequest(MsgId rootId) {
|
||||||
|
if (const auto request = _topicRequests.take(rootId)) {
|
||||||
|
for (const auto &callback : request->callbacks) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Forum::requestTopic(MsgId rootId, Fn<void()> done) {
|
void Forum::requestTopic(MsgId rootId, Fn<void()> done) {
|
||||||
|
_staleRootIds.remove(rootId);
|
||||||
|
|
||||||
auto &request = _topicRequests[rootId];
|
auto &request = _topicRequests[rootId];
|
||||||
if (done) {
|
if (done) {
|
||||||
request.callbacks.push_back(std::move(done));
|
request.callbacks.push_back(std::move(done));
|
||||||
|
@ -200,11 +279,7 @@ void Forum::requestTopic(MsgId rootId, Fn<void()> done) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto call = [=] {
|
const auto call = [=] {
|
||||||
if (const auto request = _topicRequests.take(rootId)) {
|
finishTopicRequest(rootId);
|
||||||
for (const auto &callback : request->callbacks) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const auto type = Histories::RequestType::History;
|
const auto type = Histories::RequestType::History;
|
||||||
auto &histories = owner().histories();
|
auto &histories = owner().histories();
|
||||||
|
@ -215,11 +290,9 @@ void Forum::requestTopic(MsgId rootId, Fn<void()> done) {
|
||||||
channel()->inputChannel,
|
channel()->inputChannel,
|
||||||
MTP_vector<MTPint>(1, MTP_int(rootId.bare)))
|
MTP_vector<MTPint>(1, MTP_int(rootId.bare)))
|
||||||
).done([=](const MTPmessages_ForumTopics &result) {
|
).done([=](const MTPmessages_ForumTopics &result) {
|
||||||
if (const auto forum = _history->peer->forum()) {
|
applyReceivedTopics(result);
|
||||||
forum->applyReceivedTopics(result);
|
call();
|
||||||
call();
|
finish();
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
call();
|
call();
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
-> rpl::producer<not_null<ForumTopic*>>;
|
-> rpl::producer<not_null<ForumTopic*>>;
|
||||||
|
|
||||||
void preloadTopics();
|
void preloadTopics();
|
||||||
|
void reloadTopics();
|
||||||
void requestTopics();
|
void requestTopics();
|
||||||
[[nodiscard]] rpl::producer<> chatsListChanges() const;
|
[[nodiscard]] rpl::producer<> chatsListChanges() const;
|
||||||
[[nodiscard]] rpl::producer<> chatsListLoadedEvents() const;
|
[[nodiscard]] rpl::producer<> chatsListLoadedEvents() const;
|
||||||
|
@ -79,6 +80,9 @@ private:
|
||||||
std::vector<Fn<void()>> callbacks;
|
std::vector<Fn<void()>> callbacks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void requestSomeStale();
|
||||||
|
void finishTopicRequest(MsgId rootId);
|
||||||
|
|
||||||
void applyReceivedTopics(
|
void applyReceivedTopics(
|
||||||
const MTPmessages_ForumTopics &topics,
|
const MTPmessages_ForumTopics &topics,
|
||||||
bool updateOffset);
|
bool updateOffset);
|
||||||
|
@ -90,6 +94,8 @@ private:
|
||||||
Dialogs::MainList _topicsList;
|
Dialogs::MainList _topicsList;
|
||||||
|
|
||||||
base::flat_map<MsgId, TopicRequest> _topicRequests;
|
base::flat_map<MsgId, TopicRequest> _topicRequests;
|
||||||
|
base::flat_set<MsgId> _staleRootIds;
|
||||||
|
mtpRequestId _staleRequestId = 0;
|
||||||
|
|
||||||
mtpRequestId _requestId = 0;
|
mtpRequestId _requestId = 0;
|
||||||
TimeId _offsetDate = 0;
|
TimeId _offsetDate = 0;
|
||||||
|
|
|
@ -1185,7 +1185,7 @@ void History::newItemAdded(not_null<HistoryItem*> item) {
|
||||||
if (item->unread(this)) {
|
if (item->unread(this)) {
|
||||||
if (unreadCountKnown()) {
|
if (unreadCountKnown()) {
|
||||||
setUnreadCount(unreadCount() + 1);
|
setUnreadCount(unreadCount() + 1);
|
||||||
} else {
|
} else if (!peer->isForum()) {
|
||||||
owner().histories().requestDialogEntry(this);
|
owner().histories().requestDialogEntry(this);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -678,9 +678,10 @@ void TopBarWidget::mousePressEvent(QMouseEvent *e) {
|
||||||
&& !showSelectedState()
|
&& !showSelectedState()
|
||||||
&& !_chooseForReportReason;
|
&& !_chooseForReportReason;
|
||||||
if (handleClick) {
|
if (handleClick) {
|
||||||
if (_animatingMode && _back->rect().contains(e->pos())) {
|
if ((_animatingMode && _back->rect().contains(e->pos()))
|
||||||
|
|| (_activeChat.section == Section::ChatsList)) {
|
||||||
backClicked();
|
backClicked();
|
||||||
} else {
|
} else {
|
||||||
infoClicked();
|
infoClicked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -690,8 +691,6 @@ void TopBarWidget::infoClicked() {
|
||||||
const auto key = _activeChat.key;
|
const auto key = _activeChat.key;
|
||||||
if (!key) {
|
if (!key) {
|
||||||
return;
|
return;
|
||||||
} else if (key.folder()) {
|
|
||||||
_controller->closeFolder();
|
|
||||||
} else if (const auto topic = key.topic()) {
|
} else if (const auto topic = key.topic()) {
|
||||||
_controller->showSection(std::make_shared<Info::Memento>(topic));
|
_controller->showSection(std::make_shared<Info::Memento>(topic));
|
||||||
} else if (key.peer()->isSelf()) {
|
} else if (key.peer()->isSelf()) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 12814dcf5067d687c47c710689902fd1219bec4f
|
Subproject commit eca70a7b2df50c775224116fd3f6eebdf5cc4907
|
Loading…
Add table
Reference in a new issue