Fix "Topic Author" badge for the new topics.
This commit is contained in:
		
							parent
							
								
									da941e4837
								
							
						
					
					
						commit
						1953cc2f8a
					
				
					 8 changed files with 56 additions and 6 deletions
				
			
		| 
						 | 
					@ -152,8 +152,9 @@ struct TopicUpdate {
 | 
				
			||||||
		ColorId = (1U << 7),
 | 
							ColorId = (1U << 7),
 | 
				
			||||||
		CloudDraft = (1U << 8),
 | 
							CloudDraft = (1U << 8),
 | 
				
			||||||
		Closed = (1U << 9),
 | 
							Closed = (1U << 9),
 | 
				
			||||||
 | 
							Creator = (1U << 10),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		LastUsedBit = (1U << 9),
 | 
							LastUsedBit = (1U << 10),
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	using Flags = base::flags<Flag>;
 | 
						using Flags = base::flags<Flag>;
 | 
				
			||||||
	friend inline constexpr auto is_flag_type(Flag) { return true; }
 | 
						friend inline constexpr auto is_flag_type(Flag) { return true; }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -333,6 +333,7 @@ ForumTopic *Forum::applyTopicAdded(
 | 
				
			||||||
	raw->applyColorId(colorId);
 | 
						raw->applyColorId(colorId);
 | 
				
			||||||
	raw->applyIconId(iconId);
 | 
						raw->applyIconId(iconId);
 | 
				
			||||||
	if (!creating(rootId)) {
 | 
						if (!creating(rootId)) {
 | 
				
			||||||
 | 
							requestTopic(rootId);
 | 
				
			||||||
		raw->addToChatList(FilterId(), topicsList());
 | 
							raw->addToChatList(FilterId(), topicsList());
 | 
				
			||||||
		_chatsListChanges.fire({});
 | 
							_chatsListChanges.fire({});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -345,7 +346,9 @@ MsgId Forum::reserveCreatingId(
 | 
				
			||||||
		DocumentId iconId) {
 | 
							DocumentId iconId) {
 | 
				
			||||||
	const auto result = owner().nextLocalMessageId();
 | 
						const auto result = owner().nextLocalMessageId();
 | 
				
			||||||
	_creatingRootIds.emplace(result);
 | 
						_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;
 | 
						return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -416,9 +419,7 @@ ForumTopic *Forum::enforceTopicFor(MsgId rootId) {
 | 
				
			||||||
	if (i != end(_topics)) {
 | 
						if (i != end(_topics)) {
 | 
				
			||||||
		return i->second.get();
 | 
							return i->second.get();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	const auto result = applyTopicAdded(rootId, {}, {}, {});
 | 
						return applyTopicAdded(rootId, {}, {}, {});
 | 
				
			||||||
	requestTopic(rootId);
 | 
					 | 
				
			||||||
	return result;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Forum::topicDeleted(MsgId rootId) const {
 | 
					bool Forum::topicDeleted(MsgId rootId) const {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -285,7 +285,7 @@ void ForumTopic::readTillEnd() {
 | 
				
			||||||
void ForumTopic::applyTopic(const MTPDforumTopic &data) {
 | 
					void ForumTopic::applyTopic(const MTPDforumTopic &data) {
 | 
				
			||||||
	Expects(_rootId == data.vid().v);
 | 
						Expects(_rootId == data.vid().v);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_creatorId = peerFromMTP(data.vfrom_id());
 | 
						applyCreator(peerFromMTP(data.vfrom_id()));
 | 
				
			||||||
	_creationDate = data.vdate().v;
 | 
						_creationDate = data.vdate().v;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	applyTitle(qs(data.vtitle()));
 | 
						applyTitle(qs(data.vtitle()));
 | 
				
			||||||
| 
						 | 
					@ -328,6 +328,13 @@ void ForumTopic::applyTopic(const MTPDforumTopic &data) {
 | 
				
			||||||
	unreadReactions().setCount(data.vunread_reactions_count().v);
 | 
						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 {
 | 
					bool ForumTopic::closed() const {
 | 
				
			||||||
	return _flags & Flag::Closed;
 | 
						return _flags & Flag::Closed;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -116,6 +116,7 @@ public:
 | 
				
			||||||
	void applyIconId(DocumentId iconId);
 | 
						void applyIconId(DocumentId iconId);
 | 
				
			||||||
	[[nodiscard]] int32 colorId() const;
 | 
						[[nodiscard]] int32 colorId() const;
 | 
				
			||||||
	void applyColorId(int32 colorId);
 | 
						void applyColorId(int32 colorId);
 | 
				
			||||||
 | 
						void applyCreator(PeerId creatorId);
 | 
				
			||||||
	void applyItemAdded(not_null<HistoryItem*> item);
 | 
						void applyItemAdded(not_null<HistoryItem*> item);
 | 
				
			||||||
	void applyItemRemoved(MsgId id);
 | 
						void applyItemRemoved(MsgId id);
 | 
				
			||||||
	void maybeSetLastMessage(not_null<HistoryItem*> item);
 | 
						void maybeSetLastMessage(not_null<HistoryItem*> item);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -109,6 +109,12 @@ void RepliesList::subscribeToUpdates() {
 | 
				
			||||||
		apply(update);
 | 
							apply(update);
 | 
				
			||||||
	}, _lifetime);
 | 
						}, _lifetime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_history->session().changes().topicUpdates(
 | 
				
			||||||
 | 
							TopicUpdate::Flag::Creator
 | 
				
			||||||
 | 
						) | rpl::start_with_next([=](const TopicUpdate &update) {
 | 
				
			||||||
 | 
							apply(update);
 | 
				
			||||||
 | 
						}, _lifetime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_history->owner().channelDifferenceTooLong(
 | 
						_history->owner().channelDifferenceTooLong(
 | 
				
			||||||
	) | rpl::start_with_next([=](not_null<ChannelData*> channel) {
 | 
						) | rpl::start_with_next([=](not_null<ChannelData*> channel) {
 | 
				
			||||||
		if (channel == _history->peer) {
 | 
							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(
 | 
					rpl::producer<MessagesSlice> RepliesList::source(
 | 
				
			||||||
		MessagePosition aroundId,
 | 
							MessagePosition aroundId,
 | 
				
			||||||
		int limitBefore,
 | 
							int limitBefore,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,6 +20,7 @@ class Histories;
 | 
				
			||||||
struct MessagePosition;
 | 
					struct MessagePosition;
 | 
				
			||||||
struct MessagesSlice;
 | 
					struct MessagesSlice;
 | 
				
			||||||
struct MessageUpdate;
 | 
					struct MessageUpdate;
 | 
				
			||||||
 | 
					struct TopicUpdate;
 | 
				
			||||||
struct RepliesReadTillUpdate;
 | 
					struct RepliesReadTillUpdate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class RepliesList final : public base::has_weak_ptr {
 | 
					class RepliesList final : public base::has_weak_ptr {
 | 
				
			||||||
| 
						 | 
					@ -32,6 +33,7 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void apply(const RepliesReadTillUpdate &update);
 | 
						void apply(const RepliesReadTillUpdate &update);
 | 
				
			||||||
	void apply(const MessageUpdate &update);
 | 
						void apply(const MessageUpdate &update);
 | 
				
			||||||
 | 
						void apply(const TopicUpdate &update);
 | 
				
			||||||
	void applyDifferenceTooLong();
 | 
						void applyDifferenceTooLong();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[[nodiscard]] rpl::producer<MessagesSlice> source(
 | 
						[[nodiscard]] rpl::producer<MessagesSlice> source(
 | 
				
			||||||
| 
						 | 
					@ -87,6 +89,7 @@ private:
 | 
				
			||||||
		not_null<Viewer*> viewer,
 | 
							not_null<Viewer*> viewer,
 | 
				
			||||||
		not_null<HistoryItem*> item);
 | 
							not_null<HistoryItem*> item);
 | 
				
			||||||
	[[nodiscard]] bool applyUpdate(const MessageUpdate &update);
 | 
						[[nodiscard]] bool applyUpdate(const MessageUpdate &update);
 | 
				
			||||||
 | 
						void applyTopicCreator(PeerId creatorId);
 | 
				
			||||||
	void injectRootMessageAndReverse(not_null<Viewer*> viewer);
 | 
						void injectRootMessageAndReverse(not_null<Viewer*> viewer);
 | 
				
			||||||
	void injectRootMessage(not_null<Viewer*> viewer);
 | 
						void injectRootMessage(not_null<Viewer*> viewer);
 | 
				
			||||||
	void injectRootDivider(
 | 
						void injectRootDivider(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -331,6 +331,12 @@ void Session::subscribeForTopicRepliesLists() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}, _lifetime);
 | 
						}, _lifetime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						session().changes().topicUpdates(
 | 
				
			||||||
 | 
							TopicUpdate::Flag::Creator
 | 
				
			||||||
 | 
						) | rpl::start_with_next([=](const TopicUpdate &update) {
 | 
				
			||||||
 | 
							update.topic->replies()->apply(update);
 | 
				
			||||||
 | 
						}, _lifetime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	channelDifferenceTooLong(
 | 
						channelDifferenceTooLong(
 | 
				
			||||||
	) | rpl::start_with_next([=](not_null<ChannelData*> channel) {
 | 
						) | rpl::start_with_next([=](not_null<ChannelData*> channel) {
 | 
				
			||||||
		if (const auto forum = channel->forum()) {
 | 
							if (const auto forum = channel->forum()) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -537,6 +537,10 @@ void RepliesWidget::subscribeToTopic() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!_topic->creating()) {
 | 
						if (!_topic->creating()) {
 | 
				
			||||||
		subscribeToPinnedMessages();
 | 
							subscribeToPinnedMessages();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!_topic->creatorId()) {
 | 
				
			||||||
 | 
								_topic->forum()->requestTopic(_topic->rootId());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_cornerButtons.updateUnreadThingsVisibility();
 | 
						_cornerButtons.updateUnreadThingsVisibility();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue