tdesktop/Telegram/SourceFiles/data/data_forum_topic.h

187 lines
5.2 KiB
C
Raw Normal View History

2022-09-20 18:12:30 +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 "data/data_thread.h"
#include "data/notify/data_peer_notify_settings.h"
#include "base/flags.h"
2022-09-20 18:12:30 +00:00
class ChannelData;
namespace style {
struct ForumTopicIcon;
} // namespace style
2022-09-20 18:12:30 +00:00
namespace Dialogs {
class MainList;
} // namespace Dialogs
namespace Main {
class Session;
} // namespace Main
namespace HistoryView {
class SendActionPainter;
} // namespace HistoryView
2022-09-20 18:12:30 +00:00
namespace Data {
class RepliesList;
2022-09-20 18:12:30 +00:00
class Session;
class Forum;
2022-09-20 18:12:30 +00:00
[[nodiscard]] const base::flat_map<int32, QString> &ForumTopicIcons();
[[nodiscard]] const std::vector<int32> &ForumTopicColorIds();
[[nodiscard]] const QString &ForumTopicIcon(int32 colorId);
[[nodiscard]] QString ForumTopicIconPath(const QString &name);
[[nodiscard]] QImage ForumTopicIconBackground(int32 colorId, int size);
[[nodiscard]] QImage ForumTopicIconFrame(
int32 colorId,
const QString &title,
const style::ForumTopicIcon &st);
class ForumTopic final : public Thread {
2022-09-20 18:12:30 +00:00
public:
ForumTopic(not_null<Forum*> forum, MsgId rootId);
2022-10-04 15:34:45 +00:00
~ForumTopic();
2022-09-20 18:12:30 +00:00
not_null<History*> owningHistory() override {
return history();
}
2022-09-20 18:12:30 +00:00
[[nodiscard]] std::shared_ptr<RepliesList> replies() const;
2022-09-27 12:05:47 +00:00
[[nodiscard]] not_null<ChannelData*> channel() const;
[[nodiscard]] not_null<History*> history() const;
[[nodiscard]] not_null<Forum*> forum() const;
[[nodiscard]] rpl::producer<> destroyed() const;
2022-09-20 18:12:30 +00:00
[[nodiscard]] MsgId rootId() const;
2022-10-18 15:39:41 +00:00
[[nodiscard]] bool canEdit() const;
[[nodiscard]] bool canToggleClosed() const;
2022-10-19 08:19:11 +00:00
[[nodiscard]] bool canTogglePinned() const;
2022-10-19 10:59:37 +00:00
[[nodiscard]] bool canDelete() const;
2022-10-18 15:39:41 +00:00
[[nodiscard]] bool closed() const;
void setClosed(bool closed);
void setClosedAndSave(bool closed);
[[nodiscard]] bool creating() const;
void discard();
2022-10-04 15:34:45 +00:00
void setRealRootId(MsgId realId);
void applyTopic(const MTPDforumTopic &data);
2022-09-20 18:12:30 +00:00
TimeId adjustedChatListTimeId() const override;
int fixedOnTopIndex() const override;
bool shouldBeInChatList() const override;
Dialogs::UnreadState chatListUnreadState() const override;
Dialogs::BadgesState chatListBadgesState() const override;
2022-09-20 18:12:30 +00:00
HistoryItem *chatListMessage() const override;
bool chatListMessageKnown() const override;
void requestChatListMessage() override;
const QString &chatListName() const override;
const QString &chatListNameSortKey() const override;
const base::flat_set<QString> &chatListNameWords() const override;
const base::flat_set<QChar> &chatListFirstLetters() const override;
void hasUnreadMentionChanged(bool has) override;
void hasUnreadReactionChanged(bool has) override;
2022-09-20 18:12:30 +00:00
[[nodiscard]] HistoryItem *lastMessage() const;
[[nodiscard]] HistoryItem *lastServerMessage() const;
[[nodiscard]] bool lastMessageKnown() const;
[[nodiscard]] bool lastServerMessageKnown() const;
2022-10-14 13:25:05 +00:00
[[nodiscard]] MsgId lastKnownServerMessageId() const;
2022-09-20 18:12:30 +00:00
2022-09-27 12:05:47 +00:00
[[nodiscard]] QString title() const;
void applyTitle(const QString &title);
2022-09-27 12:05:47 +00:00
[[nodiscard]] DocumentId iconId() const;
void applyIconId(DocumentId iconId);
[[nodiscard]] int32 colorId() const;
void applyColorId(int32 colorId);
void applyItemAdded(not_null<HistoryItem*> item);
void applyItemRemoved(MsgId id);
void maybeSetLastMessage(not_null<HistoryItem*> item);
[[nodiscard]] PeerNotifySettings &notify() {
return _notify;
}
[[nodiscard]] const PeerNotifySettings &notify() const {
return _notify;
}
2022-09-20 18:12:30 +00:00
void loadUserpic() override;
void paintUserpic(
Painter &p,
std::shared_ptr<CloudImageView> &view,
const Dialogs::Ui::PaintContext &context) const override;
2022-09-20 18:12:30 +00:00
[[nodiscard]] bool isServerSideUnread(
not_null<const HistoryItem*> item) const override;
void setMuted(bool muted) override;
[[nodiscard]] auto sendActionPainter()
->not_null<HistoryView::SendActionPainter*> override;
2022-09-20 18:12:30 +00:00
private:
2022-10-18 15:39:41 +00:00
enum class Flag : uchar {
Closed = (1 << 0),
My = (1 << 1),
};
friend inline constexpr bool is_flag_type(Flag) { return true; }
using Flags = base::flags<Flag>;
2022-09-20 18:12:30 +00:00
void indexTitleParts();
void validateDefaultIcon() const;
2022-09-20 18:12:30 +00:00
void applyTopicTopMessage(MsgId topMessageId);
2022-10-14 13:25:05 +00:00
void growLastKnownServerMessageId(MsgId id);
2022-09-20 18:12:30 +00:00
void setLastMessage(HistoryItem *item);
void setLastServerMessage(HistoryItem *item);
void setChatListMessage(HistoryItem *item);
int chatListNameVersion() const override;
[[nodiscard]] Dialogs::UnreadState unreadStateFor(
int count,
bool known) const;
const not_null<Forum*> _forum;
2022-09-20 18:12:30 +00:00
const not_null<Dialogs::MainList*> _list;
std::shared_ptr<RepliesList> _replies;
std::shared_ptr<HistoryView::SendActionPainter> _sendActionPainter;
2022-10-04 15:34:45 +00:00
MsgId _rootId = 0;
2022-10-14 13:25:05 +00:00
MsgId _lastKnownServerMessageId = 0;
2022-09-20 18:12:30 +00:00
PeerNotifySettings _notify;
2022-09-20 18:12:30 +00:00
QString _title;
2022-09-27 12:05:47 +00:00
DocumentId _iconId = 0;
2022-09-20 18:12:30 +00:00
base::flat_set<QString> _titleWords;
base::flat_set<QChar> _titleFirstLetters;
int _titleVersion = 0;
int32 _colorId = 0;
2022-10-18 15:39:41 +00:00
Flags _flags;
2022-09-20 18:12:30 +00:00
std::unique_ptr<Ui::Text::CustomEmoji> _icon;
mutable QImage _defaultIcon; // on-demand
2022-09-20 18:12:30 +00:00
std::optional<HistoryItem*> _lastMessage;
std::optional<HistoryItem*> _lastServerMessage;
std::optional<HistoryItem*> _chatListMessage;
base::flat_set<FullMsgId> _requestedGroups;
2022-09-20 18:12:30 +00:00
rpl::lifetime _lifetime;
};
} // namespace Data