Allow replace media by paste in replies/scheduled.
This commit is contained in:
		
							parent
							
								
									3a8237f03a
								
							
						
					
					
						commit
						58f735e19b
					
				
					 4 changed files with 40 additions and 25 deletions
				
			
		| 
						 | 
				
			
			@ -1157,6 +1157,22 @@ void ComposeControls::setMimeDataHook(MimeDataHook hook) {
 | 
			
		|||
	_field->setMimeDataHook(std::move(hook));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ComposeControls::confirmMediaEdit(Ui::PreparedList &list) {
 | 
			
		||||
	if (!isEditingMessage()) {
 | 
			
		||||
		return false;
 | 
			
		||||
	} else if (_canReplaceMedia) {
 | 
			
		||||
		EditCaptionBox::StartMediaReplace(
 | 
			
		||||
			_window,
 | 
			
		||||
			_editingId,
 | 
			
		||||
			std::move(list),
 | 
			
		||||
			_field->getTextWithTags(),
 | 
			
		||||
			crl::guard(_wrap.get(), [=] { cancelEditMessage(); }));
 | 
			
		||||
	} else {
 | 
			
		||||
		_window->showToast({ tr::lng_edit_caption_attach(tr::now) });
 | 
			
		||||
	}
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
rpl::producer<FileChosen> ComposeControls::fileChosen() const {
 | 
			
		||||
	return _fileChosen.events();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1431,23 +1447,17 @@ void ComposeControls::init() {
 | 
			
		|||
		_voiceRecordBar->requestToSendWithOptions(options);
 | 
			
		||||
	}, _wrap->lifetime());
 | 
			
		||||
 | 
			
		||||
	{
 | 
			
		||||
		const auto lastMsgId = _wrap->lifetime().make_state<FullMsgId>();
 | 
			
		||||
	_header->editMsgId(
 | 
			
		||||
	) | rpl::start_with_next([=](const auto &id) {
 | 
			
		||||
		_editingId = id;
 | 
			
		||||
	}, _wrap->lifetime());
 | 
			
		||||
 | 
			
		||||
		_header->editMsgId(
 | 
			
		||||
		) | rpl::filter([=](const auto &id) {
 | 
			
		||||
			return !!id;
 | 
			
		||||
		}) | rpl::start_with_next([=](const auto &id) {
 | 
			
		||||
			*lastMsgId = id;
 | 
			
		||||
		}, _wrap->lifetime());
 | 
			
		||||
 | 
			
		||||
		session().data().itemRemoved(
 | 
			
		||||
		) | rpl::filter([=](not_null<const HistoryItem*> item) {
 | 
			
		||||
			return item->id && ((*lastMsgId) == item->fullId());
 | 
			
		||||
		}) | rpl::start_with_next([=] {
 | 
			
		||||
			cancelEditMessage();
 | 
			
		||||
		}, _wrap->lifetime());
 | 
			
		||||
	}
 | 
			
		||||
	session().data().itemRemoved(
 | 
			
		||||
	) | rpl::filter([=](not_null<const HistoryItem*> item) {
 | 
			
		||||
		return (_editingId == item->fullId());
 | 
			
		||||
	}) | rpl::start_with_next([=] {
 | 
			
		||||
		cancelEditMessage();
 | 
			
		||||
	}, _wrap->lifetime());
 | 
			
		||||
 | 
			
		||||
	_window->materializeLocalDraftsRequests(
 | 
			
		||||
	) | rpl::start_with_next([=] {
 | 
			
		||||
| 
						 | 
				
			
			@ -1921,7 +1931,7 @@ void ComposeControls::applyDraft(FieldHistoryAction fieldHistoryAction) {
 | 
			
		|||
	InvokeQueued(_autocomplete.get(), [=] { updateStickersByEmoji(); });
 | 
			
		||||
	const auto guard = gsl::finally([&] {
 | 
			
		||||
		updateSendButtonType();
 | 
			
		||||
		updateReplaceMediaButton(editingId);
 | 
			
		||||
		updateReplaceMediaButton();
 | 
			
		||||
		updateControlsVisibility();
 | 
			
		||||
		updateControlsGeometry(_wrap->size());
 | 
			
		||||
	});
 | 
			
		||||
| 
						 | 
				
			
			@ -2588,7 +2598,7 @@ void ComposeControls::editMessage(not_null<HistoryItem*> item) {
 | 
			
		|||
	if (_photoEditMedia) {
 | 
			
		||||
		_photoEditMedia->wanted(Data::PhotoSize::Large, item->fullId());
 | 
			
		||||
	}
 | 
			
		||||
	if (updateReplaceMediaButton(item->fullId())) {
 | 
			
		||||
	if (updateReplaceMediaButton()) {
 | 
			
		||||
		updateControlsVisibility();
 | 
			
		||||
		updateControlsGeometry(_wrap->size());
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -2598,7 +2608,7 @@ void ComposeControls::editMessage(not_null<HistoryItem*> item) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ComposeControls::updateReplaceMediaButton(FullMsgId id) {
 | 
			
		||||
bool ComposeControls::updateReplaceMediaButton() {
 | 
			
		||||
	if (!_canReplaceMedia) {
 | 
			
		||||
		const auto result = (_replaceMedia != nullptr);
 | 
			
		||||
		_replaceMedia = nullptr;
 | 
			
		||||
| 
						 | 
				
			
			@ -2612,7 +2622,7 @@ bool ComposeControls::updateReplaceMediaButton(FullMsgId id) {
 | 
			
		|||
	_replaceMedia->setClickedCallback([=] {
 | 
			
		||||
		EditCaptionBox::StartMediaReplace(
 | 
			
		||||
			_window,
 | 
			
		||||
			id,
 | 
			
		||||
			_editingId,
 | 
			
		||||
			_field->getTextWithTags(),
 | 
			
		||||
			crl::guard(_wrap.get(), [=] { cancelEditMessage(); }));
 | 
			
		||||
	});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,6 +55,7 @@ class EmojiButton;
 | 
			
		|||
class SendAsButton;
 | 
			
		||||
class SilentToggle;
 | 
			
		||||
class DropdownMenu;
 | 
			
		||||
struct PreparedList;
 | 
			
		||||
} // namespace Ui
 | 
			
		||||
 | 
			
		||||
namespace Main {
 | 
			
		||||
| 
						 | 
				
			
			@ -143,6 +144,7 @@ public:
 | 
			
		|||
		not_null<const QMimeData*> data,
 | 
			
		||||
		Ui::InputField::MimeAction action)>;
 | 
			
		||||
	void setMimeDataHook(MimeDataHook hook);
 | 
			
		||||
	bool confirmMediaEdit(Ui::PreparedList &list);
 | 
			
		||||
 | 
			
		||||
	bool pushTabbedSelectorToThirdSection(
 | 
			
		||||
		not_null<Data::Thread*> thread,
 | 
			
		||||
| 
						 | 
				
			
			@ -228,7 +230,7 @@ private:
 | 
			
		|||
	void updateWrappingVisibility();
 | 
			
		||||
	void updateControlsVisibility();
 | 
			
		||||
	void updateControlsGeometry(QSize size);
 | 
			
		||||
	bool updateReplaceMediaButton(FullMsgId id);
 | 
			
		||||
	bool updateReplaceMediaButton();
 | 
			
		||||
	void updateOuterGeometry(QRect rect);
 | 
			
		||||
	void paintBackground(QRect clip);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -236,8 +238,6 @@ private:
 | 
			
		|||
	[[nodiscard]] SendMenu::Type sendMenuType() const;
 | 
			
		||||
	[[nodiscard]] SendMenu::Type sendButtonMenuType() const;
 | 
			
		||||
 | 
			
		||||
	void sendSilent();
 | 
			
		||||
	void sendScheduled();
 | 
			
		||||
	[[nodiscard]] auto sendContentRequests(
 | 
			
		||||
		SendRequestType requestType = SendRequestType::Text) const;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -358,6 +358,7 @@ private:
 | 
			
		|||
	bool _isInlineBot = false;
 | 
			
		||||
	bool _botCommandShown = false;
 | 
			
		||||
 | 
			
		||||
	FullMsgId _editingId;
 | 
			
		||||
	std::shared_ptr<Data::PhotoMedia> _photoEditMedia;
 | 
			
		||||
	bool _canReplaceMedia = false;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -937,7 +937,9 @@ bool RepliesWidget::confirmSendingFiles(
 | 
			
		|||
bool RepliesWidget::confirmSendingFiles(
 | 
			
		||||
		Ui::PreparedList &&list,
 | 
			
		||||
		const QString &insertTextOnCancel) {
 | 
			
		||||
	if (showSendingFilesError(list)) {
 | 
			
		||||
	if (_composeControls->confirmMediaEdit(list)) {
 | 
			
		||||
		return true;
 | 
			
		||||
	} else if (showSendingFilesError(list)) {
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -402,7 +402,9 @@ bool ScheduledWidget::confirmSendingFiles(
 | 
			
		|||
bool ScheduledWidget::confirmSendingFiles(
 | 
			
		||||
		Ui::PreparedList &&list,
 | 
			
		||||
		const QString &insertTextOnCancel) {
 | 
			
		||||
	if (showSendingFilesError(list)) {
 | 
			
		||||
	if (_composeControls->confirmMediaEdit(list)) {
 | 
			
		||||
		return true;
 | 
			
		||||
	} else if (showSendingFilesError(list)) {
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue