mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 23:27:09 +02:00
Better General topic support.
This commit is contained in:
parent
7866013ab6
commit
01748d8aba
6 changed files with 46 additions and 25 deletions
|
@ -3490,10 +3490,12 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
const auto replyTo = replyToId
|
||||
? peer->owner().message(peer, replyToId)
|
||||
: nullptr;
|
||||
const auto topicRootId = replyTo ? replyTo->topicRootId() : replyToId;
|
||||
const auto topic = topicRootId
|
||||
? peer->forumTopicFor(topicRootId)
|
||||
: nullptr;
|
||||
const auto topicRootId = replyTo
|
||||
? replyTo->topicRootId()
|
||||
: action.topicRootId
|
||||
? action.topicRootId
|
||||
: Data::ForumTopic::kGeneralId;
|
||||
const auto topic = peer->forumTopicFor(topicRootId);
|
||||
if (!(topic ? topic->canWrite() : peer->canWrite())
|
||||
|| Api::SendDice(message)) {
|
||||
return;
|
||||
|
|
|
@ -162,9 +162,12 @@ QImage ForumTopicGeneralIconFrame(int size, const style::color &color) {
|
|||
}
|
||||
|
||||
TextWithEntities ForumTopicIconWithTitle(
|
||||
MsgId rootId,
|
||||
DocumentId iconId,
|
||||
const QString &title) {
|
||||
return iconId
|
||||
return (rootId == ForumTopic::kGeneralId)
|
||||
? TextWithEntities{ u"# "_q + title }
|
||||
: iconId
|
||||
? Data::SingleCustomEmoji(iconId).append(title)
|
||||
: TextWithEntities{ title };
|
||||
}
|
||||
|
@ -185,24 +188,7 @@ ForumTopic::ForumTopic(not_null<Forum*> forum, MsgId rootId)
|
|||
Thread::setMuted(owner().notifySettings().isMuted(this));
|
||||
|
||||
_sendActionPainter->setTopic(this);
|
||||
|
||||
_replies->unreadCountValue(
|
||||
) | rpl::map([=](std::optional<int> value) {
|
||||
return value ? _replies->displayedUnreadCount() : value;
|
||||
}) | rpl::distinct_until_changed(
|
||||
) | rpl::combine_previous(
|
||||
) | rpl::filter([=] {
|
||||
return inChatList();
|
||||
}) | rpl::start_with_next([=](
|
||||
std::optional<int> previous,
|
||||
std::optional<int> now) {
|
||||
if (previous.value_or(0) != now.value_or(0)) {
|
||||
_forum->recentTopicsInvalidate(this);
|
||||
}
|
||||
notifyUnreadStateChange(unreadStateFor(
|
||||
previous.value_or(0),
|
||||
previous.has_value()));
|
||||
}, _replies->lifetime());
|
||||
subscribeToUnreadChanges();
|
||||
|
||||
if (isGeneral()) {
|
||||
style::PaletteChanged(
|
||||
|
@ -311,12 +297,37 @@ void ForumTopic::setRealRootId(MsgId realId) {
|
|||
_rootId = realId;
|
||||
_lastKnownServerMessageId = realId;
|
||||
_replies = std::make_shared<RepliesList>(history(), _rootId);
|
||||
if (_sendActionPainter) {
|
||||
_sendActionPainter->setTopic(nullptr);
|
||||
}
|
||||
_sendActionPainter = owner().sendActionManager().repliesPainter(
|
||||
history(),
|
||||
_rootId);
|
||||
_sendActionPainter->setTopic(this);
|
||||
subscribeToUnreadChanges();
|
||||
}
|
||||
}
|
||||
|
||||
void ForumTopic::subscribeToUnreadChanges() {
|
||||
_replies->unreadCountValue(
|
||||
) | rpl::map([=](std::optional<int> value) {
|
||||
return value ? _replies->displayedUnreadCount() : value;
|
||||
}) | rpl::distinct_until_changed(
|
||||
) | rpl::combine_previous(
|
||||
) | rpl::filter([=] {
|
||||
return inChatList();
|
||||
}) | rpl::start_with_next([=](
|
||||
std::optional<int> previous,
|
||||
std::optional<int> now) {
|
||||
if (previous.value_or(0) != now.value_or(0)) {
|
||||
_forum->recentTopicsInvalidate(this);
|
||||
}
|
||||
notifyUnreadStateChange(unreadStateFor(
|
||||
previous.value_or(0),
|
||||
previous.has_value()));
|
||||
}, _lifetime);
|
||||
}
|
||||
|
||||
void ForumTopic::readTillEnd() {
|
||||
_replies->readTill(_lastKnownServerMessageId);
|
||||
}
|
||||
|
@ -672,7 +683,7 @@ QString ForumTopic::title() const {
|
|||
}
|
||||
|
||||
TextWithEntities ForumTopic::titleWithIcon() const {
|
||||
return ForumTopicIconWithTitle(_iconId, _title);
|
||||
return ForumTopicIconWithTitle(_rootId, _iconId, _title);
|
||||
}
|
||||
|
||||
int ForumTopic::titleVersion() const {
|
||||
|
|
|
@ -49,6 +49,7 @@ class Forum;
|
|||
int size,
|
||||
const style::color &color);
|
||||
[[nodiscard]] TextWithEntities ForumTopicIconWithTitle(
|
||||
MsgId rootId,
|
||||
DocumentId iconId,
|
||||
const QString &title);
|
||||
|
||||
|
@ -181,6 +182,7 @@ private:
|
|||
|
||||
int chatListNameVersion() const override;
|
||||
|
||||
void subscribeToUnreadChanges();
|
||||
[[nodiscard]] Dialogs::UnreadState unreadStateFor(
|
||||
int count,
|
||||
bool known) const;
|
||||
|
|
|
@ -627,6 +627,7 @@ TextWithEntities GenerateDefaultBannedRightsChangeText(
|
|||
return topic.match([&](const MTPDforumTopic &data) {
|
||||
return Ui::Text::Link(
|
||||
Data::ForumTopicIconWithTitle(
|
||||
data.vid().v,
|
||||
data.vicon_emoji_id().value_or_empty(),
|
||||
qs(data.vtitle())),
|
||||
u"internal:url:https://t.me/c/%1/%2"_q.arg(
|
||||
|
|
|
@ -646,6 +646,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
|
|||
lt_topic,
|
||||
Ui::Text::Link(
|
||||
Data::ForumTopicIconWithTitle(
|
||||
id,
|
||||
action.vicon_emoji_id().value_or_empty(),
|
||||
qs(action.vtitle())),
|
||||
topicUrl),
|
||||
|
@ -693,6 +694,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
|
|||
{ tr::lng_action_topic_placeholder(tr::now) },
|
||||
lt_title,
|
||||
Data::ForumTopicIconWithTitle(
|
||||
topicRootId(),
|
||||
action.vicon_emoji_id().value_or_empty(),
|
||||
qs(*action.vtitle())),
|
||||
Ui::Text::WithEntities);
|
||||
|
|
|
@ -705,7 +705,10 @@ auto Element::contextDependentServiceText() -> TextWithLinks {
|
|||
const QString &title,
|
||||
std::optional<DocumentId> iconId) {
|
||||
return Ui::Text::Link(
|
||||
Data::ForumTopicIconWithTitle(iconId.value_or(0), title),
|
||||
Data::ForumTopicIconWithTitle(
|
||||
topicRootId,
|
||||
iconId.value_or(0),
|
||||
title),
|
||||
topicUrl);
|
||||
};
|
||||
const auto wrapParentTopic = [&] {
|
||||
|
|
Loading…
Add table
Reference in a new issue