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