2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Create / move forum topics on new messages.

This commit is contained in:
John Preston
2022-09-23 23:21:31 +04:00
parent 388fe6adfb
commit eaf679916a
19 changed files with 155 additions and 58 deletions

View File

@@ -67,7 +67,7 @@ Data::Folder *Entry::asFolder() {
: nullptr;
}
Data::ForumTopic *Entry::asForumTopic() {
Data::ForumTopic *Entry::asTopic() {
return (_type == Type::ForumTopic)
? static_cast<Data::ForumTopic*>(this)
: nullptr;
@@ -186,9 +186,6 @@ const Ui::Text::String &Entry::chatListNameText() const {
}
void Entry::setChatListExistence(bool exists) {
if (asForumTopic()) {
return;
}
if (exists && _sortKeyInChatList) {
owner().refreshChatListEntry(this);
updateChatListEntry();
@@ -263,7 +260,7 @@ not_null<Row*> Entry::addToChatList(
void Entry::removeFromChatList(
FilterId filterId,
not_null<MainList*> list) {
if (!asForumTopic() && isPinnedDialog(filterId)) {
if (!asTopic() && isPinnedDialog(filterId)) {
owner().setChatPinned(this, filterId, false);
}

View File

@@ -107,7 +107,7 @@ public:
History *asHistory();
Data::Folder *asFolder();
Data::ForumTopic *asForumTopic();
Data::ForumTopic *asTopic();
PositionChange adjustByPosInChatList(
FilterId filterId,

View File

@@ -25,7 +25,7 @@ Key::Key(History *history) : _value(history) {
Key::Key(Data::Folder *folder) : _value(folder) {
}
Key::Key(Data::ForumTopic *forumTopic) : _value(forumTopic) {
Key::Key(Data::ForumTopic *topic) : _value(topic) {
}
Key::Key(not_null<History*> history) : _value(history) {
@@ -34,7 +34,7 @@ Key::Key(not_null<History*> history) : _value(history) {
Key::Key(not_null<Data::Folder*> folder) : _value(folder) {
}
Key::Key(not_null<Data::ForumTopic*> forumTopic) : _value(forumTopic) {
Key::Key(not_null<Data::ForumTopic*> topic) : _value(topic) {
}
not_null<Entry*> Key::entry() const {
@@ -51,8 +51,8 @@ Folder *Key::folder() const {
return _value ? _value->asFolder() : nullptr;
}
ForumTopic *Key::forumTopic() const {
return _value ? _value->asForumTopic() : nullptr;
ForumTopic *Key::topic() const {
return _value ? _value->asTopic() : nullptr;
}
PeerData *Key::peer() const {

View File

@@ -28,12 +28,12 @@ public:
}
Key(History *history);
Key(Data::Folder *folder);
Key(Data::ForumTopic *forumTopic);
Key(Data::ForumTopic *topic);
Key(not_null<Entry*> entry) : _value(entry) {
}
Key(not_null<History*> history);
Key(not_null<Data::Folder*> folder);
Key(not_null<Data::ForumTopic*> forumTopic);
Key(not_null<Data::ForumTopic*> topic);
explicit operator bool() const {
return (_value != nullptr);
@@ -41,7 +41,7 @@ public:
not_null<Entry*> entry() const;
History *history() const;
Data::Folder *folder() const;
Data::ForumTopic *forumTopic() const;
Data::ForumTopic *topic() const;
PeerData *peer() const;
inline bool operator<(const Key &other) const {

View File

@@ -98,6 +98,9 @@ public:
[[nodiscard]] Data::Folder *folder() const {
return _id.folder();
}
[[nodiscard]] Data::ForumTopic *topic() const {
return _id.topic();
}
[[nodiscard]] not_null<Entry*> entry() const {
return _id.entry();
}

View File

@@ -263,10 +263,10 @@ Widget::Widget(
const auto openSearchResult = !controller->selectingPeer()
&& row.filteredRow;
const auto history = row.key.history();
if (const auto forumTopic = row.key.forumTopic()) {
if (const auto topic = row.key.topic()) {
controller->showRepliesForMessage(
forumTopic->forum(),
forumTopic->rootId());
topic->forum(),
topic->rootId());
} else if (history && history->peer->isForum()) {
controller->openForum(history->peer->asChannel());
} else if (history) {

View File

@@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_channel.h"
#include "data/data_user.h"
#include "data/data_folder.h"
#include "data/data_forum_topic.h"
#include "data/data_peer_values.h"
namespace Dialogs::Ui {
@@ -852,6 +853,7 @@ void RowPainter::paint(
bool paused) {
const auto entry = row->entry();
const auto history = row->history();
const auto topic = row->topic();
const auto peer = history ? history->peer.get() : nullptr;
const auto unreadCount = entry->chatListUnreadCount();
const auto unreadMark = entry->chatListUnreadMark();
@@ -960,22 +962,23 @@ void RowPainter::paint(
color,
ms)
: false;
const auto view = actionWasPainted
? nullptr
: history
? &history->lastItemDialogsView
: topic
? &topic->lastItemDialogsView
: nullptr;
if (const auto folder = row->folder()) {
PaintListEntryText(p, rect, active, selected, row, ms, paused);
} else if (history && !actionWasPainted) {
if (!history->lastItemDialogsView.prepared(item)) {
history->lastItemDialogsView.prepare(
} else if (view) {
if (!view->prepared(item)) {
view->prepare(
item,
[=] { history->updateChatListEntry(); },
[=] { entry->updateChatListEntry(); },
{});
}
history->lastItemDialogsView.paint(
p,
rect,
active,
selected,
ms,
paused);
view->paint(p, rect, active, selected, ms, paused);
}
};
const auto paintCounterCallback = [&] {