mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Append server-side topic search results.
This commit is contained in:
@@ -34,7 +34,7 @@ constexpr auto kTopicsFirstLoad = 20;
|
||||
constexpr auto kLoadedTopicsMinCount = 20;
|
||||
constexpr auto kTopicsPerPage = 500;
|
||||
constexpr auto kStalePerRequest = 100;
|
||||
constexpr auto kGeneralColorId = 0xA9A9A9;
|
||||
// constexpr auto kGeneralColorId = 0xA9A9A9;
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -113,8 +113,7 @@ void Forum::preloadTopics() {
|
||||
void Forum::reloadTopics() {
|
||||
_topicsList.setLoaded(false);
|
||||
session().api().request(base::take(_requestId)).cancel();
|
||||
_offsetDate = 0;
|
||||
_offsetId = _offsetTopicId = 0;
|
||||
_offset = {};
|
||||
for (const auto &[rootId, topic] : _topics) {
|
||||
if (!topic->creating()) {
|
||||
_staleRootIds.emplace(topic->rootId());
|
||||
@@ -127,18 +126,22 @@ void Forum::requestTopics() {
|
||||
if (_topicsList.loaded() || _requestId) {
|
||||
return;
|
||||
}
|
||||
const auto firstLoad = !_offsetDate;
|
||||
const auto firstLoad = !_offset.date;
|
||||
const auto loadCount = firstLoad ? kTopicsFirstLoad : kTopicsPerPage;
|
||||
_requestId = session().api().request(MTPchannels_GetForumTopics(
|
||||
MTP_flags(0),
|
||||
channel()->inputChannel,
|
||||
MTPstring(), // q
|
||||
MTP_int(_offsetDate),
|
||||
MTP_int(_offsetId),
|
||||
MTP_int(_offsetTopicId),
|
||||
MTP_int(_offset.date),
|
||||
MTP_int(_offset.id),
|
||||
MTP_int(_offset.topicId),
|
||||
MTP_int(loadCount)
|
||||
)).done([=](const MTPmessages_ForumTopics &result) {
|
||||
applyReceivedTopics(result, true);
|
||||
applyReceivedTopics(result, _offset);
|
||||
const auto &list = result.data().vtopics().v;
|
||||
if (list.isEmpty() || list.size() == result.data().vcount().v) {
|
||||
_topicsList.setLoaded();
|
||||
}
|
||||
_requestId = 0;
|
||||
_chatsListChanges.fire({});
|
||||
if (_topicsList.loaded()) {
|
||||
@@ -155,10 +158,6 @@ void Forum::requestTopics() {
|
||||
}).send();
|
||||
}
|
||||
|
||||
void Forum::applyReceivedTopics(const MTPmessages_ForumTopics &result) {
|
||||
applyReceivedTopics(result, false);
|
||||
}
|
||||
|
||||
void Forum::applyTopicDeleted(MsgId rootId) {
|
||||
_topicsDeleted.emplace(rootId);
|
||||
|
||||
@@ -176,7 +175,19 @@ void Forum::applyTopicDeleted(MsgId rootId) {
|
||||
|
||||
void Forum::applyReceivedTopics(
|
||||
const MTPmessages_ForumTopics &topics,
|
||||
bool updateOffset) {
|
||||
ForumOffsets &updateOffsets) {
|
||||
applyReceivedTopics(topics, [&](not_null<ForumTopic*> topic) {
|
||||
if (const auto last = topic->lastServerMessage()) {
|
||||
updateOffsets.date = last->date();
|
||||
updateOffsets.id = last->id;
|
||||
}
|
||||
updateOffsets.topicId = topic->rootId();
|
||||
});
|
||||
}
|
||||
|
||||
void Forum::applyReceivedTopics(
|
||||
const MTPmessages_ForumTopics &topics,
|
||||
Fn<void(not_null<ForumTopic*>)> callback) {
|
||||
const auto &data = topics.data();
|
||||
owner().processUsers(data.vusers());
|
||||
owner().processChats(data.vchats());
|
||||
@@ -189,9 +200,6 @@ void Forum::applyReceivedTopics(
|
||||
});
|
||||
_staleRootIds.remove(rootId);
|
||||
topic.match([&](const MTPDforumTopicDeleted &data) {
|
||||
if (updateOffset) {
|
||||
LOG(("API Error: Got a deleted topic in getForumTopics."));
|
||||
}
|
||||
applyTopicDeleted(rootId);
|
||||
}, [&](const MTPDforumTopic &data) {
|
||||
_topicsDeleted.remove(rootId);
|
||||
@@ -204,26 +212,18 @@ void Forum::applyReceivedTopics(
|
||||
).first->second.get()
|
||||
: i->second.get();
|
||||
raw->applyTopic(data);
|
||||
if (updateOffset) {
|
||||
if (const auto last = raw->lastServerMessage()) {
|
||||
_offsetDate = last->date();
|
||||
_offsetId = last->id;
|
||||
}
|
||||
_offsetTopicId = rootId;
|
||||
if (callback) {
|
||||
callback(raw);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (updateOffset
|
||||
&& (list.isEmpty() || list.size() == data.vcount().v)) {
|
||||
_topicsList.setLoaded();
|
||||
}
|
||||
if (!_staleRootIds.empty()) {
|
||||
requestSomeStale();
|
||||
}
|
||||
}
|
||||
|
||||
void Forum::requestSomeStale() {
|
||||
if (_staleRequestId || (!_offsetId && _requestId)) {
|
||||
if (_staleRequestId || (!_offset.id && _requestId)) {
|
||||
return;
|
||||
}
|
||||
const auto type = Histories::RequestType::History;
|
||||
|
@@ -24,6 +24,16 @@ namespace Data {
|
||||
|
||||
class Session;
|
||||
|
||||
struct ForumOffsets {
|
||||
TimeId date = 0;
|
||||
MsgId id = 0;
|
||||
MsgId topicId = 0;
|
||||
|
||||
friend inline constexpr auto operator<=>(
|
||||
ForumOffsets,
|
||||
ForumOffsets) = default;
|
||||
};
|
||||
|
||||
class Forum final {
|
||||
public:
|
||||
explicit Forum(not_null<History*> history);
|
||||
@@ -57,7 +67,12 @@ public:
|
||||
[[nodiscard]] ForumTopic *enforceTopicFor(MsgId rootId);
|
||||
[[nodiscard]] bool topicDeleted(MsgId rootId) const;
|
||||
|
||||
void applyReceivedTopics(const MTPmessages_ForumTopics &topics);
|
||||
void applyReceivedTopics(
|
||||
const MTPmessages_ForumTopics &topics,
|
||||
ForumOffsets &updateOffsets);
|
||||
void applyReceivedTopics(
|
||||
const MTPmessages_ForumTopics &topics,
|
||||
Fn<void(not_null<ForumTopic*>)> callback = nullptr);
|
||||
|
||||
[[nodiscard]] MsgId reserveCreatingId(
|
||||
const QString &title,
|
||||
@@ -84,10 +99,6 @@ private:
|
||||
void requestSomeStale();
|
||||
void finishTopicRequest(MsgId rootId);
|
||||
|
||||
void applyReceivedTopics(
|
||||
const MTPmessages_ForumTopics &topics,
|
||||
bool updateOffset);
|
||||
|
||||
const not_null<History*> _history;
|
||||
|
||||
base::flat_map<MsgId, std::unique_ptr<ForumTopic>> _topics;
|
||||
@@ -100,9 +111,7 @@ private:
|
||||
mtpRequestId _staleRequestId = 0;
|
||||
|
||||
mtpRequestId _requestId = 0;
|
||||
TimeId _offsetDate = 0;
|
||||
MsgId _offsetId = 0;
|
||||
MsgId _offsetTopicId = 0;
|
||||
ForumOffsets _offset;
|
||||
|
||||
base::flat_set<MsgId> _creatingRootIds;
|
||||
|
||||
|
@@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "history/history_unread_things.h"
|
||||
#include "history/view/history_view_item_preview.h"
|
||||
#include "main/main_session.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/color_int_conversion.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
@@ -148,6 +149,7 @@ ForumTopic::ForumTopic(not_null<Forum*> forum, MsgId rootId)
|
||||
rootId))
|
||||
, _rootId(rootId)
|
||||
, _lastKnownServerMessageId(rootId)
|
||||
, _creationDate(creating() ? base::unixtime::now() : 0)
|
||||
, _flags(creating() ? Flag::My : Flag()) {
|
||||
Thread::setMuted(owner().notifySettings().isMuted(this));
|
||||
|
||||
@@ -201,6 +203,10 @@ MsgId ForumTopic::rootId() const {
|
||||
return _rootId;
|
||||
}
|
||||
|
||||
TimeId ForumTopic::creationDate() const {
|
||||
return _creationDate;
|
||||
}
|
||||
|
||||
bool ForumTopic::my() const {
|
||||
return (_flags & Flag::My);
|
||||
}
|
||||
@@ -261,6 +267,8 @@ void ForumTopic::readTillEnd() {
|
||||
void ForumTopic::applyTopic(const MTPDforumTopic &data) {
|
||||
Expects(_rootId == data.vid().v);
|
||||
|
||||
_creationDate = data.vdate().v;
|
||||
|
||||
applyTitle(qs(data.vtitle()));
|
||||
if (const auto iconId = data.vicon_emoji_id()) {
|
||||
applyIconId(iconId->v);
|
||||
|
@@ -60,6 +60,7 @@ public:
|
||||
[[nodiscard]] not_null<Forum*> forum() const;
|
||||
[[nodiscard]] rpl::producer<> destroyed() const;
|
||||
[[nodiscard]] MsgId rootId() const;
|
||||
[[nodiscard]] TimeId creationDate() const;
|
||||
|
||||
[[nodiscard]] bool my() const;
|
||||
[[nodiscard]] bool canWrite() const;
|
||||
@@ -171,6 +172,7 @@ private:
|
||||
base::flat_set<QString> _titleWords;
|
||||
base::flat_set<QChar> _titleFirstLetters;
|
||||
int _titleVersion = 0;
|
||||
TimeId _creationDate = 0;
|
||||
int32 _colorId = 0;
|
||||
Flags _flags;
|
||||
|
||||
|
Reference in New Issue
Block a user