tdesktop/Telegram/SourceFiles/dialogs/dialogs_entry.h

229 lines
5.7 KiB
C
Raw Normal View History

/*
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"
#include "dialogs/dialogs_key.h"
2019-07-24 11:45:24 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Data {
class Session;
class Folder;
2020-05-28 14:32:10 +00:00
class CloudImageView;
} // namespace Data
namespace Dialogs {
class Row;
class IndexedList;
class MainList;
2020-02-07 09:43:12 +00:00
struct RowsByLetter {
not_null<Row*> main;
base::flat_map<QChar, not_null<Row*>> letters;
};
enum class SortMode {
2020-03-17 13:04:30 +00:00
Date = 0x00,
Name = 0x01,
Add = 0x02,
};
struct PositionChange {
int from = -1;
int to = -1;
};
2019-04-22 14:22:39 +00:00
struct UnreadState {
int messages = 0;
int messagesMuted = 0;
int chats = 0;
int chatsMuted = 0;
int marks = 0;
int marksMuted = 0;
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;
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;
return *this;
}
bool empty() const {
return !messages && !chats && !marks;
}
2019-04-22 14:22:39 +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;
}
class Entry {
public:
2020-06-12 14:09:04 +00:00
enum class Type {
History,
Folder,
};
Entry(not_null<Data::Session*> owner, Type type);
Entry(const Entry &other) = delete;
Entry &operator=(const Entry &other) = delete;
virtual ~Entry() = default;
2020-02-07 09:43:12 +00:00
[[nodiscard]] Data::Session &owner() const;
[[nodiscard]] Main::Session &session() const;
2020-06-12 14:09:04 +00:00
History *asHistory();
Data::Folder *asFolder();
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);
}
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;
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);
void addChatListEntryByLetter(
2020-02-07 09:43:12 +00:00
FilterId filterId,
QChar letter,
not_null<Row*> row);
2020-06-12 14:09:04 +00:00
void updateChatListEntry();
2020-03-17 13:04:30 +00:00
[[nodiscard]] bool isPinnedDialog(FilterId filterId) const {
return lookupPinnedIndex(filterId) != 0;
}
2020-03-17 13:04:30 +00:00
void cachePinnedIndex(FilterId filterId, int index);
[[nodiscard]] bool isTopPromoted() const;
2020-03-17 13:04:30 +00:00
[[nodiscard]] uint64 sortKeyInChatList(FilterId filterId) const {
return filterId
? computeSortPosition(filterId)
: _sortKeyInChatList;
}
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();
bool needUpdateInChatList() const;
virtual TimeId adjustedChatListTimeId() const;
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
virtual bool shouldBeInChatList() const = 0;
virtual int chatListUnreadCount() const = 0;
2018-06-26 18:03:45 +00:00
virtual bool chatListUnreadMark() const = 0;
virtual bool chatListMutedBadge() const = 0;
2019-04-22 14:22:39 +00:00
virtual UnreadState chatListUnreadState() 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;
virtual const base::flat_set<QString> &chatListNameWords() const = 0;
virtual const base::flat_set<QChar> &chatListFirstLetters() const = 0;
virtual bool folderKnown() const {
return true;
}
virtual Data::Folder *folder() const {
return nullptr;
}
virtual void loadUserpic() = 0;
virtual void paintUserpic(
Painter &p,
2020-05-28 14:32:10 +00:00
std::shared_ptr<Data::CloudImageView> &view,
int x,
int y,
int size) const = 0;
void paintUserpicLeft(
Painter &p,
2020-05-28 14:32:10 +00:00
std::shared_ptr<Data::CloudImageView> &view,
int x,
int y,
int w,
int size) const {
2020-05-28 14:32:10 +00:00
paintUserpic(p, view, rtl() ? (w - x - size) : x, y, size);
}
2019-01-15 11:57:45 +00:00
TimeId chatListTimeId() const {
return _timeId;
}
mutable const HistoryItem *textCachedFor = nullptr; // cache
2019-06-12 13:26:04 +00:00
mutable Ui::Text::String lastItemTextCache;
2019-04-22 14:22:39 +00:00
protected:
void notifyUnreadStateChange(const UnreadState &wasState);
2019-04-22 14:22:39 +00:00
auto unreadStateChangeNotifier(bool required) {
const auto notify = required && inChatList();
const auto wasState = notify ? chatListUnreadState() : UnreadState();
return gsl::finally([=] {
if (notify) {
notifyUnreadStateChange(wasState);
}
});
}
2020-03-17 13:04:30 +00:00
[[nodiscard]] int lookupPinnedIndex(FilterId filterId) const;
2020-04-29 08:46:02 +00:00
void cacheTopPromoted(bool promoted);
private:
virtual void changedChatListPinHook();
2020-03-17 13:04:30 +00:00
void pinnedIndexChanged(int was, int now);
[[nodiscard]] uint64 computeSortPosition(FilterId filterId) const;
void setChatListExistence(bool exists);
2020-02-07 09:43:12 +00:00
not_null<Row*> mainChatListLink(FilterId filterId) const;
Row *maybeMainChatListLink(FilterId filterId) const;
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;
uint64 _sortKeyInChatList = 0;
uint64 _sortKeyByDate = 0;
2020-03-17 13:04:30 +00:00
base::flat_map<FilterId, int> _pinnedIndex;
2019-01-15 11:57:45 +00:00
TimeId _timeId = 0;
2020-04-29 08:46:02 +00:00
bool _isTopPromoted = false;
2020-06-12 14:09:04 +00:00
const bool _isFolder = false;
};
} // namespace Dialogs