2022-01-26 16:01:40 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class History;
|
|
|
|
|
2022-10-13 10:32:03 +00:00
|
|
|
namespace Data {
|
|
|
|
class Thread;
|
2022-10-07 13:56:07 +00:00
|
|
|
} // namespace Data
|
|
|
|
|
2022-01-26 16:01:40 +00:00
|
|
|
namespace HistoryUnreadThings {
|
|
|
|
|
|
|
|
enum class AddType {
|
|
|
|
New,
|
|
|
|
Existing,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Type {
|
|
|
|
Mentions,
|
|
|
|
Reactions,
|
|
|
|
};
|
|
|
|
|
|
|
|
class List final {
|
|
|
|
public:
|
|
|
|
[[nodiscard]] int loadedCount() const {
|
|
|
|
return _messages.size();
|
|
|
|
}
|
|
|
|
[[nodiscard]] MsgId minLoaded() const {
|
|
|
|
return _messages.empty() ? 0 : _messages.front();
|
|
|
|
}
|
|
|
|
[[nodiscard]] MsgId maxLoaded() const {
|
|
|
|
return _messages.empty() ? 0 : _messages.back();
|
|
|
|
}
|
|
|
|
[[nodiscard]] int count(int notKnownValue = -1) const {
|
|
|
|
return _count.value_or(notKnownValue);
|
|
|
|
}
|
|
|
|
[[nodiscard]] bool has() const {
|
|
|
|
return (count() > 0);
|
|
|
|
}
|
2022-01-31 15:29:46 +00:00
|
|
|
[[nodiscard]] bool contains(MsgId msgId) const {
|
|
|
|
return _messages.contains(msgId);
|
|
|
|
}
|
2022-10-07 13:56:07 +00:00
|
|
|
[[nodiscard]] const base::flat_set<MsgId> &ids() const {
|
|
|
|
return _messages;
|
|
|
|
}
|
2022-01-26 16:01:40 +00:00
|
|
|
void setCount(int count) {
|
|
|
|
_count = count;
|
|
|
|
}
|
|
|
|
void insert(MsgId msgId) {
|
|
|
|
_messages.insert(msgId);
|
|
|
|
}
|
|
|
|
void erase(MsgId msgId) {
|
|
|
|
_messages.remove(msgId);
|
|
|
|
}
|
2022-01-28 09:08:22 +00:00
|
|
|
void clear() {
|
|
|
|
_messages.clear();
|
|
|
|
}
|
2022-01-26 16:01:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::optional<int> _count;
|
|
|
|
base::flat_set<MsgId> _messages;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct All {
|
|
|
|
List mentions;
|
|
|
|
List reactions;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConstProxy {
|
|
|
|
public:
|
|
|
|
ConstProxy(const List *list, bool known) : _list(list), _known(known) {
|
|
|
|
}
|
|
|
|
ConstProxy(const ConstProxy &) = delete;
|
|
|
|
ConstProxy &operator=(const ConstProxy &) = delete;
|
|
|
|
|
|
|
|
[[nodiscard]] int loadedCount() const {
|
|
|
|
return _list ? _list->loadedCount() : 0;
|
|
|
|
}
|
|
|
|
[[nodiscard]] MsgId minLoaded() const {
|
|
|
|
return _list ? _list->minLoaded() : 0;
|
|
|
|
}
|
|
|
|
[[nodiscard]] MsgId maxLoaded() const {
|
|
|
|
return _list ? _list->maxLoaded() : 0;
|
|
|
|
}
|
|
|
|
[[nodiscard]] int count(int notKnownValue = -1) const {
|
|
|
|
return _list
|
|
|
|
? _list->count(notKnownValue)
|
|
|
|
: _known
|
|
|
|
? 0
|
|
|
|
: notKnownValue;
|
|
|
|
}
|
|
|
|
[[nodiscard]] bool has() const {
|
|
|
|
return _list && _list->has();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const List *_list = nullptr;
|
|
|
|
const bool _known = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Proxy final : public ConstProxy {
|
|
|
|
public:
|
|
|
|
Proxy(
|
2022-10-13 10:32:03 +00:00
|
|
|
not_null<Data::Thread*> thread,
|
2022-01-26 16:01:40 +00:00
|
|
|
std::unique_ptr<All> &data,
|
|
|
|
Type type,
|
|
|
|
bool known)
|
|
|
|
: ConstProxy(
|
|
|
|
(!data
|
|
|
|
? nullptr
|
|
|
|
: (type == Type::Mentions)
|
|
|
|
? &data->mentions
|
|
|
|
: &data->reactions),
|
|
|
|
known)
|
2022-10-13 10:32:03 +00:00
|
|
|
, _thread(thread)
|
2022-01-26 16:01:40 +00:00
|
|
|
, _data(data)
|
2022-01-27 12:55:34 +00:00
|
|
|
, _type(type)
|
|
|
|
, _known(known) {
|
2022-01-26 16:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setCount(int count);
|
|
|
|
bool add(MsgId msgId, AddType type);
|
|
|
|
void erase(MsgId msgId);
|
2022-01-28 09:08:22 +00:00
|
|
|
void clear();
|
2022-01-26 16:01:40 +00:00
|
|
|
|
2022-01-31 15:29:46 +00:00
|
|
|
void addSlice(const MTPmessages_Messages &slice, int alreadyLoaded);
|
|
|
|
|
|
|
|
void checkAdd(MsgId msgId, bool resolved = false);
|
2022-01-26 16:01:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void createData();
|
2022-10-07 13:56:07 +00:00
|
|
|
void notifyUpdated();
|
2022-01-26 16:01:40 +00:00
|
|
|
[[nodiscard]] List &resolveList();
|
|
|
|
|
2022-10-13 10:32:03 +00:00
|
|
|
const not_null<Data::Thread*> _thread;
|
2022-01-26 16:01:40 +00:00
|
|
|
std::unique_ptr<All> &_data;
|
|
|
|
Type _type = Type::Mentions;
|
|
|
|
bool _known = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace HistoryUnreadThings
|