tdesktop/Telegram/SourceFiles/data/data_forum_topic.h

228 lines
6.5 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;
class ListMemento;
} // 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);
2022-11-29 13:25:18 +00:00
[[nodiscard]] QImage ForumTopicGeneralIconFrame(
int size,
const style::color &color);
2022-11-02 12:39:13 +00:00
[[nodiscard]] TextWithEntities ForumTopicIconWithTitle(
2022-11-29 13:48:51 +00:00
MsgId rootId,
2022-11-02 12:39:13 +00:00
DocumentId iconId,
const QString &title);
class ForumTopic final : public Thread {
2022-09-20 18:12:30 +00:00
public:
2022-11-29 11:54:47 +00:00
static constexpr auto kGeneralId = 1;
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
2022-11-29 11:54:47 +00:00
[[nodiscard]] bool isGeneral() const {
return (_rootId == kGeneralId);
}
[[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-28 08:54:06 +00:00
[[nodiscard]] PeerId creatorId() const;
[[nodiscard]] TimeId creationDate() const;
2022-09-20 18:12:30 +00:00
[[nodiscard]] not_null<HistoryView::ListMemento*> listMemento();
[[nodiscard]] bool my() const;
[[nodiscard]] bool canWrite() const;
2022-11-01 14:22:15 +00:00
[[nodiscard]] bool canSendPolls() 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 hidden() const;
void setHidden(bool hidden);
[[nodiscard]] bool creating() const;
void discard();
2022-10-04 15:34:45 +00:00
void setRealRootId(MsgId realId);
void readTillEnd();
2022-10-04 15:34:45 +00:00
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;
2022-11-02 12:39:13 +00:00
[[nodiscard]] TextWithEntities titleWithIcon() const;
[[nodiscard]] int titleVersion() 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 applyCreator(PeerId creatorId);
void applyCreationDate(TimeId date);
void applyIsMy(bool my);
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;
void clearUserpicLoops();
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),
Hidden = (1 << 1),
My = (1 << 2),
HasPinnedMessages = (1 << 3),
GeneralIconActive = (1 << 4),
GeneralIconSelected = (1 << 5),
2022-10-18 15:39:41 +00:00
};
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-11-29 13:25:18 +00:00
void validateGeneralIcon(const Dialogs::Ui::PaintContext &context) 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);
void invalidateTitleWithIcon();
2022-09-20 18:12:30 +00:00
void setLastMessage(HistoryItem *item);
void setLastServerMessage(HistoryItem *item);
void setChatListMessage(HistoryItem *item);
int chatListNameVersion() const override;
2022-11-29 13:48:51 +00:00
void subscribeToUnreadChanges();
[[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::unique_ptr<HistoryView::ListMemento> _listMemento;
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;
2022-10-28 08:54:06 +00:00
PeerId _creatorId = 0;
TimeId _creationDate = 0;
2022-10-28 08:54:06 +00:00
int _titleVersion = 0;
int32 _colorId = 0;
2022-11-29 13:25:18 +00:00
mutable 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