Show error when forwarding to slowmode group.
This commit is contained in:
		
							parent
							
								
									f4754f210c
								
							
						
					
					
						commit
						4a10a88ecf
					
				
					 2 changed files with 75 additions and 36 deletions
				
			
		|  | @ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| #include "boxes/share_box.h" | #include "boxes/share_box.h" | ||||||
| #include "boxes/confirm_box.h" | #include "boxes/confirm_box.h" | ||||||
| #include "ui/toast/toast.h" | #include "ui/toast/toast.h" | ||||||
|  | #include "ui/text/text_utilities.h" | ||||||
| #include "ui/text_options.h" | #include "ui/text_options.h" | ||||||
| #include "core/application.h" | #include "core/application.h" | ||||||
| #include "layout.h" | #include "layout.h" | ||||||
|  | @ -107,6 +108,58 @@ bool HasInlineItems(const HistoryItemsList &items) { | ||||||
| 
 | 
 | ||||||
| } // namespace
 | } // namespace
 | ||||||
| 
 | 
 | ||||||
|  | QString GetErrorTextForForward( | ||||||
|  | 		not_null<PeerData*> peer, | ||||||
|  | 		const HistoryItemsList &items, | ||||||
|  | 		const TextWithTags &comment) { | ||||||
|  | 	if (!peer->canWrite()) { | ||||||
|  | 		return tr::lng_forward_cant(tr::now); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	for (const auto item : items) { | ||||||
|  | 		if (const auto media = item->media()) { | ||||||
|  | 			const auto error = media->errorTextForForward(peer); | ||||||
|  | 			if (!error.isEmpty() && error != qstr("skip")) { | ||||||
|  | 				return error; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	const auto error = Data::RestrictionError( | ||||||
|  | 		peer, | ||||||
|  | 		ChatRestriction::f_send_inline); | ||||||
|  | 	if (error && HasInlineItems(items)) { | ||||||
|  | 		return *error; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if (peer->slowmodeApplied() && !comment.text.isEmpty()) { | ||||||
|  | 		return tr::lng_slowmode_no_many(tr::now); | ||||||
|  | 	} else if (peer->slowmodeApplied() && items.size() > 1) { | ||||||
|  | 		const auto albumForward = [&] { | ||||||
|  | 			if (const auto groupId = items.front()->groupId()) { | ||||||
|  | 				for (const auto item : items) { | ||||||
|  | 					if (item->groupId() != groupId) { | ||||||
|  | 						return false; | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 			return false; | ||||||
|  | 		}(); | ||||||
|  | 		if (!albumForward) { | ||||||
|  | 			return tr::lng_slowmode_no_many(tr::now); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if (const auto left = peer->slowmodeSecondsLeft()) { | ||||||
|  | 		return tr::lng_slowmode_enabled( | ||||||
|  | 			tr::now, | ||||||
|  | 			lt_left, | ||||||
|  | 			formatDurationWords(left)); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return QString(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void FastShareMessage(not_null<HistoryItem*> item) { | void FastShareMessage(not_null<HistoryItem*> item) { | ||||||
| 	struct ShareData { | 	struct ShareData { | ||||||
| 		ShareData(not_null<PeerData*> peer, MessageIdsList &&ids) | 		ShareData(not_null<PeerData*> peer, MessageIdsList &&ids) | ||||||
|  | @ -158,23 +211,28 @@ void FastShareMessage(not_null<HistoryItem*> item) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		auto restrictedSomewhere = false; | 		const auto error = [&] { | ||||||
| 		auto restrictedEverywhere = true; |  | ||||||
| 		auto firstError = QString(); |  | ||||||
| 			for (const auto peer : result) { | 			for (const auto peer : result) { | ||||||
| 			const auto error = GetErrorTextForForward(peer, items); | 				const auto error = GetErrorTextForForward( | ||||||
|  | 					peer, | ||||||
|  | 					items, | ||||||
|  | 					comment); | ||||||
| 				if (!error.isEmpty()) { | 				if (!error.isEmpty()) { | ||||||
| 				if (firstError.isEmpty()) { | 					return std::make_pair(error, peer); | ||||||
| 					firstError = error; |  | ||||||
| 				} | 				} | ||||||
| 				restrictedSomewhere = true; |  | ||||||
| 				continue; |  | ||||||
| 			} | 			} | ||||||
| 			restrictedEverywhere = false; | 			return std::make_pair(QString(), result.front()); | ||||||
|  | 		}(); | ||||||
|  | 		if (!error.first.isEmpty()) { | ||||||
|  | 			auto text = TextWithEntities(); | ||||||
|  | 			if (result.size() > 1) { | ||||||
|  | 				text.append( | ||||||
|  | 					Ui::Text::Bold(App::peerName(error.second)) | ||||||
|  | 				).append("\n\n"); | ||||||
| 			} | 			} | ||||||
| 		if (restrictedEverywhere) { | 			text.append(error.first); | ||||||
| 			Ui::show( | 			Ui::show( | ||||||
| 				Box<InformBox>(firstError), | 				Box<InformBox>(text), | ||||||
| 				LayerOption::KeepOther); | 				LayerOption::KeepOther); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  | @ -206,10 +264,6 @@ void FastShareMessage(not_null<HistoryItem*> item) { | ||||||
| 			return result; | 			return result; | ||||||
| 		}; | 		}; | ||||||
| 		for (const auto peer : result) { | 		for (const auto peer : result) { | ||||||
| 			if (!GetErrorTextForForward(peer, items).isEmpty()) { |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			const auto history = peer->owner().history(peer); | 			const auto history = peer->owner().history(peer); | ||||||
| 			if (!comment.text.isEmpty()) { | 			if (!comment.text.isEmpty()) { | ||||||
| 				auto message = ApiWrap::MessageToSend(history); | 				auto message = ApiWrap::MessageToSend(history); | ||||||
|  | @ -274,22 +328,7 @@ MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer) { | ||||||
| QString GetErrorTextForForward( | QString GetErrorTextForForward( | ||||||
| 		not_null<PeerData*> peer, | 		not_null<PeerData*> peer, | ||||||
| 		const HistoryItemsList &items) { | 		const HistoryItemsList &items) { | ||||||
| 	if (!peer->canWrite()) { | 	return GetErrorTextForForward(peer, items, TextWithTags()); | ||||||
| 		return tr::lng_forward_cant(tr::now); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	for (const auto item : items) { |  | ||||||
| 		if (const auto media = item->media()) { |  | ||||||
| 			const auto error = media->errorTextForForward(peer); |  | ||||||
| 			if (!error.isEmpty() && error != qstr("skip")) { |  | ||||||
| 				return error; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	const auto error = Data::RestrictionError( |  | ||||||
| 		peer, |  | ||||||
| 		ChatRestriction::f_send_inline); |  | ||||||
| 	return (error && HasInlineItems(items)) ? *error : QString(); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct HistoryMessage::CreateConfig { | struct HistoryMessage::CreateConfig { | ||||||
|  |  | ||||||
|  | @ -810,8 +810,8 @@ QPointer<Ui::RpWidget> ShowForwardMessagesBox( | ||||||
| 					Ui::Toast::Show(tr::lng_share_done(tr::now)); | 					Ui::Toast::Show(tr::lng_share_done(tr::now)); | ||||||
| 				}); | 				}); | ||||||
| 			} | 			} | ||||||
| 		} else { | 		} else if (!App::main()->setForwardDraft(peer->id, std::move(ids))) { | ||||||
| 			App::main()->setForwardDraft(peer->id, std::move(ids)); | 			return; | ||||||
| 		} | 		} | ||||||
| 		if (const auto strong = *weak) { | 		if (const auto strong = *weak) { | ||||||
| 			strong->closeBox(); | 			strong->closeBox(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston