2018-01-05 15:57:18 +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
|
|
|
|
|
|
|
|
#include "base/flat_map.h"
|
2022-10-08 11:14:38 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2022-10-19 13:55:33 +00:00
|
|
|
#include "base/flags.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2022-08-09 15:53:40 +00:00
|
|
|
#include "ui/unread_badge.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2022-10-13 10:32:03 +00:00
|
|
|
class HistoryItem;
|
|
|
|
class UserData;
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
2019-04-16 14:05:56 +00:00
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
class Session;
|
2019-04-17 13:22:37 +00:00
|
|
|
class Folder;
|
2022-09-20 18:12:30 +00:00
|
|
|
class ForumTopic;
|
2020-05-28 14:32:10 +00:00
|
|
|
class CloudImageView;
|
2019-04-16 14:05:56 +00:00
|
|
|
} // namespace Data
|
|
|
|
|
2022-09-29 10:33:17 +00:00
|
|
|
namespace Ui {
|
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Dialogs::Ui {
|
|
|
|
using namespace ::Ui;
|
|
|
|
struct PaintContext;
|
|
|
|
} // namespace Dialogs::Ui
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
namespace Dialogs {
|
|
|
|
|
|
|
|
class Row;
|
|
|
|
class IndexedList;
|
2020-03-16 10:20:18 +00:00
|
|
|
class MainList;
|
2020-02-07 09:43:12 +00:00
|
|
|
|
|
|
|
struct RowsByLetter {
|
|
|
|
not_null<Row*> main;
|
|
|
|
base::flat_map<QChar, not_null<Row*>> letters;
|
|
|
|
};
|
2018-01-05 15:57:18 +00:00
|
|
|
|
|
|
|
enum class SortMode {
|
2020-03-17 13:04:30 +00:00
|
|
|
Date = 0x00,
|
|
|
|
Name = 0x01,
|
|
|
|
Add = 0x02,
|
2018-01-05 15:57:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PositionChange {
|
2019-04-16 14:05:56 +00:00
|
|
|
int from = -1;
|
|
|
|
int to = -1;
|
2018-01-05 15:57:18 +00:00
|
|
|
};
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
struct UnreadState {
|
2019-04-24 15:28:01 +00:00
|
|
|
int messages = 0;
|
|
|
|
int messagesMuted = 0;
|
|
|
|
int chats = 0;
|
|
|
|
int chatsMuted = 0;
|
|
|
|
int marks = 0;
|
|
|
|
int marksMuted = 0;
|
2022-10-20 08:57:12 +00:00
|
|
|
int reactions = 0;
|
|
|
|
int reactionsMuted = 0;
|
|
|
|
int mentions = 0;
|
2019-04-24 15:28:01 +00:00
|
|
|
bool known = false;
|
|
|
|
|
|
|
|
UnreadState &operator+=(const UnreadState &other) {
|
|
|
|
messages += other.messages;
|
|
|
|
messagesMuted += other.messagesMuted;
|
|
|
|
chats += other.chats;
|
|
|
|
chatsMuted += other.chatsMuted;
|
|
|
|
marks += other.marks;
|
|
|
|
marksMuted += other.marksMuted;
|
2022-10-20 08:57:12 +00:00
|
|
|
reactions += other.reactions;
|
|
|
|
reactionsMuted += other.reactionsMuted;
|
|
|
|
mentions += other.mentions;
|
2019-04-24 15:28:01 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
UnreadState &operator-=(const UnreadState &other) {
|
|
|
|
messages -= other.messages;
|
|
|
|
messagesMuted -= other.messagesMuted;
|
|
|
|
chats -= other.chats;
|
|
|
|
chatsMuted -= other.chatsMuted;
|
|
|
|
marks -= other.marks;
|
|
|
|
marksMuted -= other.marksMuted;
|
2022-10-20 08:57:12 +00:00
|
|
|
reactions -= other.reactions;
|
|
|
|
reactionsMuted -= other.reactionsMuted;
|
|
|
|
mentions -= other.mentions;
|
2019-04-24 15:28:01 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2019-04-22 14:22:39 +00:00
|
|
|
};
|
|
|
|
|
2019-04-24 15:28:01 +00:00
|
|
|
inline UnreadState operator+(const UnreadState &a, const UnreadState &b) {
|
|
|
|
auto result = a;
|
|
|
|
result += b;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline UnreadState operator-(const UnreadState &a, const UnreadState &b) {
|
|
|
|
auto result = a;
|
|
|
|
result -= b;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
struct BadgesState {
|
|
|
|
int unreadCounter = 0;
|
|
|
|
bool unread : 1 = false;
|
|
|
|
bool unreadMuted : 1 = false;
|
|
|
|
bool mention : 1 = false;
|
|
|
|
bool mentionMuted : 1 = false;
|
|
|
|
bool reaction : 1 = false;
|
|
|
|
bool reactionMuted : 1 = false;
|
|
|
|
|
|
|
|
friend inline constexpr auto operator<=>(
|
|
|
|
BadgesState,
|
|
|
|
BadgesState) = default;
|
|
|
|
|
|
|
|
[[nodiscard]] bool empty() const {
|
|
|
|
return !unread && !mention && !reaction;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class CountInBadge : uchar {
|
|
|
|
Default,
|
|
|
|
Chats,
|
|
|
|
Messages,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class IncludeInBadge : uchar {
|
|
|
|
Default,
|
|
|
|
Unmuted,
|
|
|
|
All,
|
|
|
|
UnmutedOrAll,
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] BadgesState BadgesForUnread(
|
|
|
|
const UnreadState &state,
|
|
|
|
CountInBadge count = CountInBadge::Default,
|
|
|
|
IncludeInBadge include = IncludeInBadge::Default);
|
|
|
|
|
2022-10-08 11:14:38 +00:00
|
|
|
class Entry : public base::has_weak_ptr {
|
2018-01-05 15:57:18 +00:00
|
|
|
public:
|
2022-09-20 18:12:30 +00:00
|
|
|
enum class Type : uchar {
|
2020-06-12 14:09:04 +00:00
|
|
|
History,
|
|
|
|
Folder,
|
2022-09-20 18:12:30 +00:00
|
|
|
ForumTopic,
|
2020-06-12 14:09:04 +00:00
|
|
|
};
|
|
|
|
Entry(not_null<Data::Session*> owner, Type type);
|
2022-10-07 13:56:07 +00:00
|
|
|
virtual ~Entry();
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2020-02-07 09:43:12 +00:00
|
|
|
[[nodiscard]] Data::Session &owner() const;
|
|
|
|
[[nodiscard]] Main::Session &session() const;
|
2019-04-16 14:05:56 +00:00
|
|
|
|
2020-06-12 14:09:04 +00:00
|
|
|
History *asHistory();
|
|
|
|
Data::Folder *asFolder();
|
2022-10-13 10:32:03 +00:00
|
|
|
Data::Thread *asThread();
|
2022-09-23 19:21:31 +00:00
|
|
|
Data::ForumTopic *asTopic();
|
2020-06-12 14:09:04 +00:00
|
|
|
|
2022-10-13 17:34:04 +00:00
|
|
|
const History *asHistory() const;
|
|
|
|
const Data::Folder *asFolder() const;
|
|
|
|
const Data::Thread *asThread() const;
|
|
|
|
const Data::ForumTopic *asTopic() const;
|
|
|
|
|
2020-03-16 10:20:18 +00:00
|
|
|
PositionChange adjustByPosInChatList(
|
|
|
|
FilterId filterId,
|
|
|
|
not_null<MainList*> list);
|
2020-02-07 09:43:12 +00:00
|
|
|
[[nodiscard]] bool inChatList(FilterId filterId = 0) const {
|
|
|
|
return _chatListLinks.contains(filterId);
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
2020-06-12 14:09:04 +00:00
|
|
|
RowsByLetter *chatListLinks(FilterId filterId);
|
|
|
|
const RowsByLetter *chatListLinks(FilterId filterId) const;
|
2020-02-07 09:43:12 +00:00
|
|
|
[[nodiscard]] int posInChatList(FilterId filterId) const;
|
2020-03-16 10:20:18 +00:00
|
|
|
not_null<Row*> addToChatList(
|
|
|
|
FilterId filterId,
|
|
|
|
not_null<MainList*> list);
|
|
|
|
void removeFromChatList(
|
|
|
|
FilterId filterId,
|
|
|
|
not_null<MainList*> list);
|
2020-02-07 09:43:12 +00:00
|
|
|
void removeChatListEntryByLetter(FilterId filterId, QChar letter);
|
2018-01-05 15:57:18 +00:00
|
|
|
void addChatListEntryByLetter(
|
2020-02-07 09:43:12 +00:00
|
|
|
FilterId filterId,
|
2018-01-05 15:57:18 +00:00
|
|
|
QChar letter,
|
|
|
|
not_null<Row*> row);
|
2020-06-12 14:09:04 +00:00
|
|
|
void updateChatListEntry();
|
2022-10-19 13:55:33 +00:00
|
|
|
void updateChatListEntryPostponed();
|
2020-03-17 13:04:30 +00:00
|
|
|
[[nodiscard]] bool isPinnedDialog(FilterId filterId) const {
|
|
|
|
return lookupPinnedIndex(filterId) != 0;
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
2020-03-17 13:04:30 +00:00
|
|
|
void cachePinnedIndex(FilterId filterId, int index);
|
|
|
|
[[nodiscard]] uint64 sortKeyInChatList(FilterId filterId) const {
|
|
|
|
return filterId
|
|
|
|
? computeSortPosition(filterId)
|
|
|
|
: _sortKeyInChatList;
|
2020-03-09 11:17:56 +00:00
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
void updateChatListSortPosition();
|
2019-01-15 11:57:45 +00:00
|
|
|
void setChatListTimeId(TimeId date);
|
2018-01-29 17:13:24 +00:00
|
|
|
virtual void updateChatListExistence();
|
2018-01-23 16:51:12 +00:00
|
|
|
bool needUpdateInChatList() const;
|
2019-04-18 09:00:38 +00:00
|
|
|
virtual TimeId adjustedChatListTimeId() const;
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2019-04-18 11:31:30 +00:00
|
|
|
virtual int fixedOnTopIndex() const = 0;
|
|
|
|
static constexpr auto kArchiveFixOnTopIndex = 1;
|
2020-04-24 10:31:28 +00:00
|
|
|
static constexpr auto kTopPromotionFixOnTopIndex = 2;
|
2019-04-18 11:31:30 +00:00
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
virtual bool shouldBeInChatList() const = 0;
|
2019-04-22 14:22:39 +00:00
|
|
|
virtual UnreadState chatListUnreadState() const = 0;
|
2022-10-20 08:57:12 +00:00
|
|
|
virtual BadgesState chatListBadgesState() const = 0;
|
2019-01-15 11:57:45 +00:00
|
|
|
virtual HistoryItem *chatListMessage() const = 0;
|
|
|
|
virtual bool chatListMessageKnown() const = 0;
|
|
|
|
virtual void requestChatListMessage() = 0;
|
|
|
|
virtual const QString &chatListName() const = 0;
|
2021-02-19 11:54:27 +00:00
|
|
|
virtual const QString &chatListNameSortKey() const = 0;
|
2019-01-15 11:57:45 +00:00
|
|
|
virtual const base::flat_set<QString> &chatListNameWords() const = 0;
|
|
|
|
virtual const base::flat_set<QChar> &chatListFirstLetters() const = 0;
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2019-04-18 09:00:38 +00:00
|
|
|
virtual bool folderKnown() const {
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 13:22:37 +00:00
|
|
|
virtual Data::Folder *folder() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
virtual void loadUserpic() = 0;
|
|
|
|
virtual void paintUserpic(
|
|
|
|
Painter &p,
|
2020-05-28 14:32:10 +00:00
|
|
|
std::shared_ptr<Data::CloudImageView> &view,
|
2022-09-29 10:33:17 +00:00
|
|
|
const Ui::PaintContext &context) const = 0;
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2021-10-01 12:42:44 +00:00
|
|
|
[[nodiscard]] TimeId chatListTimeId() const {
|
2019-01-15 11:57:45 +00:00
|
|
|
return _timeId;
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2022-08-09 11:12:19 +00:00
|
|
|
[[nodiscard]] const Ui::Text::String &chatListNameText() const;
|
2022-10-20 08:57:12 +00:00
|
|
|
[[nodiscard]] Ui::PeerBadge &chatListPeerBadge() const {
|
|
|
|
return _chatListPeerBadge;
|
2022-08-09 15:53:40 +00:00
|
|
|
}
|
2022-08-09 11:12:19 +00:00
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
protected:
|
2020-03-16 10:20:18 +00:00
|
|
|
void notifyUnreadStateChange(const UnreadState &wasState);
|
2022-10-20 15:57:15 +00:00
|
|
|
inline auto unreadStateChangeNotifier(bool required);
|
2019-04-22 14:22:39 +00:00
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
[[nodiscard]] int lookupPinnedIndex(FilterId filterId) const;
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
private:
|
2022-10-19 13:55:33 +00:00
|
|
|
enum class Flag : uchar {
|
|
|
|
IsThread = (1 << 0),
|
|
|
|
IsHistory = (1 << 1),
|
|
|
|
UpdatePostponed = (1 << 2),
|
2022-10-20 08:57:12 +00:00
|
|
|
InUnreadChangeBlock = (1 << 3),
|
2022-10-19 13:55:33 +00:00
|
|
|
};
|
|
|
|
friend inline constexpr bool is_flag_type(Flag) { return true; }
|
|
|
|
using Flags = base::flags<Flag>;
|
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
virtual void changedChatListPinHook();
|
2021-12-02 07:51:54 +00:00
|
|
|
void pinnedIndexChanged(FilterId filterId, int was, int now);
|
2020-03-17 13:04:30 +00:00
|
|
|
[[nodiscard]] uint64 computeSortPosition(FilterId filterId) const;
|
2018-01-23 16:51:12 +00:00
|
|
|
|
2022-08-09 11:12:19 +00:00
|
|
|
[[nodiscard]] virtual int chatListNameVersion() const = 0;
|
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
void setChatListExistence(bool exists);
|
2020-02-07 09:43:12 +00:00
|
|
|
not_null<Row*> mainChatListLink(FilterId filterId) const;
|
|
|
|
Row *maybeMainChatListLink(FilterId filterId) const;
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2020-06-12 14:09:04 +00:00
|
|
|
const not_null<Data::Session*> _owner;
|
2020-02-07 09:43:12 +00:00
|
|
|
base::flat_map<FilterId, RowsByLetter> _chatListLinks;
|
2018-01-05 15:57:18 +00:00
|
|
|
uint64 _sortKeyInChatList = 0;
|
2020-03-09 11:17:56 +00:00
|
|
|
uint64 _sortKeyByDate = 0;
|
2020-03-17 13:04:30 +00:00
|
|
|
base::flat_map<FilterId, int> _pinnedIndex;
|
2022-10-20 08:57:12 +00:00
|
|
|
mutable Ui::PeerBadge _chatListPeerBadge;
|
2022-08-09 11:12:19 +00:00
|
|
|
mutable Ui::Text::String _chatListNameText;
|
|
|
|
mutable int _chatListNameVersion = 0;
|
2019-01-15 11:57:45 +00:00
|
|
|
TimeId _timeId = 0;
|
2022-10-19 13:55:33 +00:00
|
|
|
Flags _flags;
|
2018-01-05 15:57:18 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
auto Entry::unreadStateChangeNotifier(bool required) {
|
|
|
|
Expects(!(_flags & Flag::InUnreadChangeBlock));
|
|
|
|
|
|
|
|
_flags |= Flag::InUnreadChangeBlock;
|
|
|
|
const auto notify = required && inChatList();
|
|
|
|
const auto wasState = notify ? chatListUnreadState() : UnreadState();
|
|
|
|
return gsl::finally([=] {
|
|
|
|
_flags &= ~Flag::InUnreadChangeBlock;
|
|
|
|
if (notify) {
|
|
|
|
Assert(inChatList());
|
|
|
|
notifyUnreadStateChange(wasState);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
} // namespace Dialogs
|