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

Support pinned topics in forums.

This commit is contained in:
John Preston
2022-10-19 12:19:11 +04:00
parent 306179ca7c
commit adaa1d0c55
7 changed files with 86 additions and 41 deletions

View File

@@ -70,6 +70,13 @@ not_null<Dialogs::MainList*> Forum::topicsList() {
return &_topicsList;
}
void Forum::unpinTopic() {
const auto list = _topicsList.pinned();
while (!list->order().empty()) {
list->setPinned(list->order().front(), false);
}
}
rpl::producer<> Forum::destroyed() const {
return channel()->flagsValue(
) | rpl::filter([=](const ChannelData::Flags::Change &update) {

View File

@@ -41,6 +41,7 @@ public:
void requestTopics();
[[nodiscard]] rpl::producer<> chatsListChanges() const;
[[nodiscard]] rpl::producer<> chatsListLoadedEvents() const;
void unpinTopic();
void requestTopic(MsgId rootId, Fn<void()> done = nullptr);
ForumTopic *applyTopicAdded(

View File

@@ -206,6 +206,10 @@ bool ForumTopic::canToggleClosed() const {
return !creating() && canEdit();
}
bool ForumTopic::canTogglePinned() const {
return !creating() && channel()->canEditTopics();
}
bool ForumTopic::creating() const {
return _forum->creating(_rootId);
}
@@ -238,11 +242,10 @@ void ForumTopic::applyTopic(const MTPDforumTopic &data) {
}
applyColorId(data.vicon_color().v);
const auto pinned = _list->pinned();
if (data.is_pinned()) {
pinned->addPinned(Dialogs::Key(this));
owner().setChatPinned(this, 0, true);
} else {
pinned->setPinned(Dialogs::Key(this), false);
_list->pinned()->setPinned(this, false);
}
owner().notifySettings().apply(this, data.vnotify_settings());

View File

@@ -63,6 +63,7 @@ public:
[[nodiscard]] bool canEdit() const;
[[nodiscard]] bool canToggleClosed() const;
[[nodiscard]] bool canTogglePinned() const;
[[nodiscard]] bool closed() const;
void setClosed(bool closed);

View File

@@ -1823,10 +1823,13 @@ void Session::setChatPinned(
bool pinned) {
Expects(key.entry()->folderKnown());
const auto list = filterId
const auto list = (filterId
? chatsFilters().chatsList(filterId)
: chatsList(key.entry()->folder());
list->pinned()->setPinned(key, pinned);
: chatsListFor(key.entry()))->pinned();
if (const auto topic = key.topic()) {
topic->forum()->unpinTopic();
}
list->setPinned(key, pinned);
notifyPinnedDialogsOrderUpdated();
}