Allow sending to General in "View as Messages".
This commit is contained in:
		
							parent
							
								
									96b651c29b
								
							
						
					
					
						commit
						4c6d33fd54
					
				
					 3 changed files with 71 additions and 18 deletions
				
			
		|  | @ -4166,6 +4166,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| "lng_forum_topics_no_discussion" = "Topics can't be enabled in discussion groups at the moment."; | "lng_forum_topics_no_discussion" = "Topics can't be enabled in discussion groups at the moment."; | ||||||
| "lng_forum_choose_title_and_icon" = "Choose title and icon for your topic"; | "lng_forum_choose_title_and_icon" = "Choose title and icon for your topic"; | ||||||
| "lng_forum_replies_only" = "You can reply to messages in topics."; | "lng_forum_replies_only" = "You can reply to messages in topics."; | ||||||
|  | "lng_forum_message_in" = "Message in {topic}"; | ||||||
|  | "lng_forum_reply_in" = "Reply in {topic}"; | ||||||
| "lng_forum_no_topics" = "No topics currently created in this forum."; | "lng_forum_no_topics" = "No topics currently created in this forum."; | ||||||
| "lng_forum_create_topic" = "Create topic"; | "lng_forum_create_topic" = "Create topic"; | ||||||
| "lng_forum_discard_sure" = "Are you sure you want to discard this topic?"; | "lng_forum_discard_sure" = "Are you sure you want to discard this topic?"; | ||||||
|  |  | ||||||
|  | @ -508,10 +508,7 @@ HistoryWidget::HistoryWidget( | ||||||
| 			if (!_peer || isRecording()) { | 			if (!_peer || isRecording()) { | ||||||
| 				return false; | 				return false; | ||||||
| 			} | 			} | ||||||
| 			const auto replyTo = (_replyTo && !_editMsgId) | 			const auto topic = resolveReplyToTopic(); | ||||||
| 				? _replyEditMsg |  | ||||||
| 				: 0; |  | ||||||
| 			const auto topic = replyTo ? replyTo->topic() : nullptr; |  | ||||||
| 			return topic | 			return topic | ||||||
| 				? Data::CanSendAnyOf(topic, Data::FilesSendRestrictions()) | 				? Data::CanSendAnyOf(topic, Data::FilesSendRestrictions()) | ||||||
| 				: Data::CanSendAnyOf(_peer, Data::FilesSendRestrictions()); | 				: Data::CanSendAnyOf(_peer, Data::FilesSendRestrictions()); | ||||||
|  | @ -2134,6 +2131,7 @@ void HistoryWidget::showHistory( | ||||||
| 		setHistory(nullptr); | 		setHistory(nullptr); | ||||||
| 		_list = nullptr; | 		_list = nullptr; | ||||||
| 		_peer = nullptr; | 		_peer = nullptr; | ||||||
|  | 		_topicsRequested.clear(); | ||||||
| 		_canSendMessages = false; | 		_canSendMessages = false; | ||||||
| 		_canSendTexts = false; | 		_canSendTexts = false; | ||||||
| 		_fieldDisabled = nullptr; | 		_fieldDisabled = nullptr; | ||||||
|  | @ -2721,8 +2719,6 @@ std::optional<QString> HistoryWidget::writeRestriction() const { | ||||||
| 		: std::nullopt; | 		: std::nullopt; | ||||||
| 	if (result) { | 	if (result) { | ||||||
| 		return result; | 		return result; | ||||||
| 	} else if (_peer && _peer->isForum()) { |  | ||||||
| 		return tr::lng_forum_replies_only(tr::now); |  | ||||||
| 	} | 	} | ||||||
| 	return std::nullopt; | 	return std::nullopt; | ||||||
| } | } | ||||||
|  | @ -5223,7 +5219,31 @@ void HistoryWidget::updateFieldPlaceholder() { | ||||||
| 			&& !_keyboard->placeholder().isEmpty()) { | 			&& !_keyboard->placeholder().isEmpty()) { | ||||||
| 			return rpl::single(_keyboard->placeholder()); | 			return rpl::single(_keyboard->placeholder()); | ||||||
| 		} else if (const auto channel = _history->peer->asChannel()) { | 		} else if (const auto channel = _history->peer->asChannel()) { | ||||||
| 			if (channel->isBroadcast()) { | 			const auto topic = resolveReplyToTopic(); | ||||||
|  | 			const auto topicRootId = topic | ||||||
|  | 				? topic->rootId() | ||||||
|  | 				: channel->forum() | ||||||
|  | 				? resolveReplyToTopicRootId() | ||||||
|  | 				: MsgId(); | ||||||
|  | 			if (topicRootId) { | ||||||
|  | 				auto title = rpl::single(topic | ||||||
|  | 					? topic->title() | ||||||
|  | 					: (topicRootId == Data::ForumTopic::kGeneralId) | ||||||
|  | 					? u"General"_q | ||||||
|  | 					: u"Topic"_q | ||||||
|  | 				) | rpl::then(session().changes().topicUpdates( | ||||||
|  | 					Data::TopicUpdate::Flag::Title | ||||||
|  | 				) | rpl::filter([=](const Data::TopicUpdate &update) { | ||||||
|  | 					return (update.topic->peer() == channel) | ||||||
|  | 						&& (update.topic->rootId() == topicRootId); | ||||||
|  | 				}) | rpl::map([=](const Data::TopicUpdate &update) { | ||||||
|  | 					return update.topic->title(); | ||||||
|  | 				})); | ||||||
|  | 				const auto phrase = replyTo().messageId | ||||||
|  | 					? tr::lng_forum_reply_in | ||||||
|  | 					: tr::lng_forum_message_in; | ||||||
|  | 				return phrase(lt_topic, std::move(title)); | ||||||
|  | 			} else if (channel->isBroadcast()) { | ||||||
| 				return session().data().notifySettings().silentPosts(channel) | 				return session().data().notifySettings().silentPosts(channel) | ||||||
| 					? tr::lng_broadcast_silent_ph() | 					? tr::lng_broadcast_silent_ph() | ||||||
| 					: tr::lng_broadcast_ph(); | 					: tr::lng_broadcast_ph(); | ||||||
|  | @ -5284,15 +5304,42 @@ bool HistoryWidget::showSendingFilesError( | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | MsgId HistoryWidget::resolveReplyToTopicRootId() { | ||||||
|  | 	Expects(_peer != nullptr); | ||||||
|  | 
 | ||||||
|  | 	const auto replyToInfo = replyTo(); | ||||||
|  | 	const auto replyToMessage = (replyToInfo.messageId.peer == _peer->id) | ||||||
|  | 		? session().data().message(replyToInfo.messageId) | ||||||
|  | 		: nullptr; | ||||||
|  | 	const auto result = replyToMessage | ||||||
|  | 		? replyToMessage->topicRootId() | ||||||
|  | 		: replyToInfo.topicRootId; | ||||||
|  | 	if (result | ||||||
|  | 		&& _peer->isForum() | ||||||
|  | 		&& !_peer->forumTopicFor(result) | ||||||
|  | 		&& _topicsRequested.emplace(result).second) { | ||||||
|  | 		_peer->forum()->requestTopic(result, crl::guard(_list, [=] { | ||||||
|  | 			updateCanSendMessage(); | ||||||
|  | 			updateFieldPlaceholder(); | ||||||
|  | 			_topicsRequested.remove(result); | ||||||
|  | 		})); | ||||||
|  | 	} | ||||||
|  | 	return result; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | Data::ForumTopic *HistoryWidget::resolveReplyToTopic() { | ||||||
|  | 	return _peer | ||||||
|  | 		? _peer->forumTopicFor(resolveReplyToTopicRootId()) | ||||||
|  | 		: nullptr; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool HistoryWidget::showSendMessageError( | bool HistoryWidget::showSendMessageError( | ||||||
| 		const TextWithTags &textWithTags, | 		const TextWithTags &textWithTags, | ||||||
| 		bool ignoreSlowmodeCountdown) const { | 		bool ignoreSlowmodeCountdown) { | ||||||
| 	if (!_canSendMessages) { | 	if (!_canSendMessages) { | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| 	const auto topicRootId = _replyEditMsg | 	const auto topicRootId = resolveReplyToTopicRootId(); | ||||||
| 		? _replyEditMsg->topicRootId() |  | ||||||
| 		: 0; |  | ||||||
| 	const auto error = GetErrorTextForSending( | 	const auto error = GetErrorTextForSending( | ||||||
| 		_peer, | 		_peer, | ||||||
| 		{ | 		{ | ||||||
|  | @ -5691,6 +5738,8 @@ FullReplyTo HistoryWidget::replyTo() const { | ||||||
| 		? _replyTo | 		? _replyTo | ||||||
| 		: _kbReplyTo | 		: _kbReplyTo | ||||||
| 		? FullReplyTo{ _kbReplyTo->fullId() } | 		? FullReplyTo{ _kbReplyTo->fullId() } | ||||||
|  | 		: (_peer && _peer->forum()) | ||||||
|  | 		? FullReplyTo{ .topicRootId = Data::ForumTopic::kGeneralId } | ||||||
| 		: FullReplyTo(); | 		: FullReplyTo(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -7570,11 +7619,7 @@ bool HistoryWidget::updateCanSendMessage() { | ||||||
| 	if (!_peer) { | 	if (!_peer) { | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| 	const auto checkTopicFromReplyTo = _replyTo | 	const auto topic = resolveReplyToTopic(); | ||||||
| 		&& !_editMsgId |  | ||||||
| 		&& (_replyTo.messageId.peer == _peer->id); |  | ||||||
| 	const auto replyTo = checkTopicFromReplyTo ? _replyEditMsg : 0; |  | ||||||
| 	const auto topic = replyTo ? replyTo->topic() : nullptr; |  | ||||||
| 	const auto allWithoutPolls = Data::AllSendRestrictions() | 	const auto allWithoutPolls = Data::AllSendRestrictions() | ||||||
| 		& ~ChatRestriction::SendPolls; | 		& ~ChatRestriction::SendPolls; | ||||||
| 	const auto newCanSendMessages = topic | 	const auto newCanSendMessages = topic | ||||||
|  | @ -7786,6 +7831,9 @@ void HistoryWidget::updateReplyEditTexts(bool force) { | ||||||
| 		_replyEditMsg = session().data().message( | 		_replyEditMsg = session().data().message( | ||||||
| 			_editMsgId ? _peer->id : _replyTo.messageId.peer, | 			_editMsgId ? _peer->id : _replyTo.messageId.peer, | ||||||
| 			_editMsgId ? _editMsgId : _replyTo.messageId.msg); | 			_editMsgId ? _editMsgId : _replyTo.messageId.msg); | ||||||
|  | 		if (!_editMsgId) { | ||||||
|  | 			updateFieldPlaceholder(); | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 	if (_replyEditMsg) { | 	if (_replyEditMsg) { | ||||||
| 		const auto media = _replyEditMsg->media(); | 		const auto media = _replyEditMsg->media(); | ||||||
|  |  | ||||||
|  | @ -457,7 +457,7 @@ private: | ||||||
| 		std::optional<bool> compress) const; | 		std::optional<bool> compress) const; | ||||||
| 	bool showSendMessageError( | 	bool showSendMessageError( | ||||||
| 		const TextWithTags &textWithTags, | 		const TextWithTags &textWithTags, | ||||||
| 		bool ignoreSlowmodeCountdown) const; | 		bool ignoreSlowmodeCountdown); | ||||||
| 
 | 
 | ||||||
| 	void sendingFilesConfirmed( | 	void sendingFilesConfirmed( | ||||||
| 		Ui::PreparedList &&list, | 		Ui::PreparedList &&list, | ||||||
|  | @ -474,7 +474,9 @@ private: | ||||||
| 	void moveFieldControls(); | 	void moveFieldControls(); | ||||||
| 	void updateFieldSize(); | 	void updateFieldSize(); | ||||||
| 
 | 
 | ||||||
| 	bool canWriteMessage() const; | 	[[nodiscard]] MsgId resolveReplyToTopicRootId(); | ||||||
|  | 	[[nodiscard]] Data::ForumTopic *resolveReplyToTopic(); | ||||||
|  | 	[[nodiscard]] bool canWriteMessage() const; | ||||||
| 	std::optional<QString> writeRestriction() const; | 	std::optional<QString> writeRestriction() const; | ||||||
| 	void orderWidgets(); | 	void orderWidgets(); | ||||||
| 
 | 
 | ||||||
|  | @ -695,6 +697,7 @@ private: | ||||||
| 	bool _canSendMessages = false; | 	bool _canSendMessages = false; | ||||||
| 	bool _canSendTexts = false; | 	bool _canSendTexts = false; | ||||||
| 	MsgId _showAtMsgId = ShowAtUnreadMsgId; | 	MsgId _showAtMsgId = ShowAtUnreadMsgId; | ||||||
|  | 	base::flat_set<MsgId> _topicsRequested; | ||||||
| 	TextWithEntities _showAtMsgHighlightPart; | 	TextWithEntities _showAtMsgHighlightPart; | ||||||
| 	int _showAtMsgHighlightPartOffsetHint = 0; | 	int _showAtMsgHighlightPartOffsetHint = 0; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston