mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-11 08:48:14 +00:00
Fix "Topic Author" badge for the new topics.
This commit is contained in:
parent
da941e4837
commit
1953cc2f8a
@ -152,8 +152,9 @@ struct TopicUpdate {
|
||||
ColorId = (1U << 7),
|
||||
CloudDraft = (1U << 8),
|
||||
Closed = (1U << 9),
|
||||
Creator = (1U << 10),
|
||||
|
||||
LastUsedBit = (1U << 9),
|
||||
LastUsedBit = (1U << 10),
|
||||
};
|
||||
using Flags = base::flags<Flag>;
|
||||
friend inline constexpr auto is_flag_type(Flag) { return true; }
|
||||
|
@ -333,6 +333,7 @@ ForumTopic *Forum::applyTopicAdded(
|
||||
raw->applyColorId(colorId);
|
||||
raw->applyIconId(iconId);
|
||||
if (!creating(rootId)) {
|
||||
requestTopic(rootId);
|
||||
raw->addToChatList(FilterId(), topicsList());
|
||||
_chatsListChanges.fire({});
|
||||
}
|
||||
@ -345,7 +346,9 @@ MsgId Forum::reserveCreatingId(
|
||||
DocumentId iconId) {
|
||||
const auto result = owner().nextLocalMessageId();
|
||||
_creatingRootIds.emplace(result);
|
||||
applyTopicAdded(result, title, colorId, iconId);
|
||||
const auto topic = applyTopicAdded(result, title, colorId, iconId);
|
||||
// Perhaps it will be created from some public channel name.
|
||||
//topic->applyCreator(session().userPeerId());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -416,9 +419,7 @@ ForumTopic *Forum::enforceTopicFor(MsgId rootId) {
|
||||
if (i != end(_topics)) {
|
||||
return i->second.get();
|
||||
}
|
||||
const auto result = applyTopicAdded(rootId, {}, {}, {});
|
||||
requestTopic(rootId);
|
||||
return result;
|
||||
return applyTopicAdded(rootId, {}, {}, {});
|
||||
}
|
||||
|
||||
bool Forum::topicDeleted(MsgId rootId) const {
|
||||
|
@ -285,7 +285,7 @@ void ForumTopic::readTillEnd() {
|
||||
void ForumTopic::applyTopic(const MTPDforumTopic &data) {
|
||||
Expects(_rootId == data.vid().v);
|
||||
|
||||
_creatorId = peerFromMTP(data.vfrom_id());
|
||||
applyCreator(peerFromMTP(data.vfrom_id()));
|
||||
_creationDate = data.vdate().v;
|
||||
|
||||
applyTitle(qs(data.vtitle()));
|
||||
@ -328,6 +328,13 @@ void ForumTopic::applyTopic(const MTPDforumTopic &data) {
|
||||
unreadReactions().setCount(data.vunread_reactions_count().v);
|
||||
}
|
||||
|
||||
void ForumTopic::applyCreator(PeerId creatorId) {
|
||||
if (_creatorId != creatorId) {
|
||||
_creatorId = creatorId;
|
||||
session().changes().topicUpdated(this, UpdateFlag::Creator);
|
||||
}
|
||||
}
|
||||
|
||||
bool ForumTopic::closed() const {
|
||||
return _flags & Flag::Closed;
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ public:
|
||||
void applyIconId(DocumentId iconId);
|
||||
[[nodiscard]] int32 colorId() const;
|
||||
void applyColorId(int32 colorId);
|
||||
void applyCreator(PeerId creatorId);
|
||||
void applyItemAdded(not_null<HistoryItem*> item);
|
||||
void applyItemRemoved(MsgId id);
|
||||
void maybeSetLastMessage(not_null<HistoryItem*> item);
|
||||
|
@ -109,6 +109,12 @@ void RepliesList::subscribeToUpdates() {
|
||||
apply(update);
|
||||
}, _lifetime);
|
||||
|
||||
_history->session().changes().topicUpdates(
|
||||
TopicUpdate::Flag::Creator
|
||||
) | rpl::start_with_next([=](const TopicUpdate &update) {
|
||||
apply(update);
|
||||
}, _lifetime);
|
||||
|
||||
_history->owner().channelDifferenceTooLong(
|
||||
) | rpl::start_with_next([=](not_null<ChannelData*> channel) {
|
||||
if (channel == _history->peer) {
|
||||
@ -133,6 +139,27 @@ void RepliesList::apply(const MessageUpdate &update) {
|
||||
}
|
||||
}
|
||||
|
||||
void RepliesList::apply(const TopicUpdate &update) {
|
||||
if (update.topic->history() == _history
|
||||
&& update.topic->rootId() == _rootId) {
|
||||
if (update.flags & TopicUpdate::Flag::Creator) {
|
||||
applyTopicCreator(update.topic->creatorId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RepliesList::applyTopicCreator(PeerId creatorId) {
|
||||
const auto owner = &_history->owner();
|
||||
const auto peerId = _history->peer->id;
|
||||
for (const auto &id : _list) {
|
||||
if (const auto item = owner->message(peerId, id)) {
|
||||
if (item->from()->id == creatorId) {
|
||||
owner->requestItemResize(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<MessagesSlice> RepliesList::source(
|
||||
MessagePosition aroundId,
|
||||
int limitBefore,
|
||||
|
@ -20,6 +20,7 @@ class Histories;
|
||||
struct MessagePosition;
|
||||
struct MessagesSlice;
|
||||
struct MessageUpdate;
|
||||
struct TopicUpdate;
|
||||
struct RepliesReadTillUpdate;
|
||||
|
||||
class RepliesList final : public base::has_weak_ptr {
|
||||
@ -32,6 +33,7 @@ public:
|
||||
|
||||
void apply(const RepliesReadTillUpdate &update);
|
||||
void apply(const MessageUpdate &update);
|
||||
void apply(const TopicUpdate &update);
|
||||
void applyDifferenceTooLong();
|
||||
|
||||
[[nodiscard]] rpl::producer<MessagesSlice> source(
|
||||
@ -87,6 +89,7 @@ private:
|
||||
not_null<Viewer*> viewer,
|
||||
not_null<HistoryItem*> item);
|
||||
[[nodiscard]] bool applyUpdate(const MessageUpdate &update);
|
||||
void applyTopicCreator(PeerId creatorId);
|
||||
void injectRootMessageAndReverse(not_null<Viewer*> viewer);
|
||||
void injectRootMessage(not_null<Viewer*> viewer);
|
||||
void injectRootDivider(
|
||||
|
@ -331,6 +331,12 @@ void Session::subscribeForTopicRepliesLists() {
|
||||
}
|
||||
}, _lifetime);
|
||||
|
||||
session().changes().topicUpdates(
|
||||
TopicUpdate::Flag::Creator
|
||||
) | rpl::start_with_next([=](const TopicUpdate &update) {
|
||||
update.topic->replies()->apply(update);
|
||||
}, _lifetime);
|
||||
|
||||
channelDifferenceTooLong(
|
||||
) | rpl::start_with_next([=](not_null<ChannelData*> channel) {
|
||||
if (const auto forum = channel->forum()) {
|
||||
|
@ -537,6 +537,10 @@ void RepliesWidget::subscribeToTopic() {
|
||||
|
||||
if (!_topic->creating()) {
|
||||
subscribeToPinnedMessages();
|
||||
|
||||
if (!_topic->creatorId()) {
|
||||
_topic->forum()->requestTopic(_topic->rootId());
|
||||
}
|
||||
}
|
||||
|
||||
_cornerButtons.updateUnreadThingsVisibility();
|
||||
|
Loading…
Reference in New Issue
Block a user