mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 07:07:08 +02:00
Use new caption edit in ComposeControls.
This commit is contained in:
parent
42c96b4c7f
commit
7ed020ecc5
4 changed files with 71 additions and 13 deletions
Telegram/SourceFiles/history/view
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/platform/base_platform_info.h"
|
||||
#include "base/qt_signal_producer.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "boxes/edit_caption_box.h"
|
||||
#include "chat_helpers/emoji_suggestions_widget.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "menu/menu_send.h"
|
||||
|
@ -29,8 +30,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_user.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_forum_topic.h"
|
||||
#include "data/data_peer_values.h"
|
||||
#include "data/data_photo_media.h"
|
||||
#include "data/stickers/data_stickers.h"
|
||||
#include "data/stickers/data_custom_emoji.h"
|
||||
#include "data/data_web_page.h"
|
||||
|
@ -1939,6 +1942,12 @@ void ComposeControls::applyDraft(FieldHistoryAction fieldHistoryAction) {
|
|||
_header->editMessage({ _history->peer->id, draft->msgId });
|
||||
_header->replyToMessage({});
|
||||
} else {
|
||||
_canReplaceMedia = false;
|
||||
_photoEditMedia = nullptr;
|
||||
if (updateReplaceMediaButton(FullMsgId())) {
|
||||
updateControlsVisibility();
|
||||
updateControlsGeometry(_wrap->size());
|
||||
}
|
||||
_header->replyToMessage({ _history->peer->id, draft->msgId });
|
||||
if (_header->replyingToMessage()) {
|
||||
cancelForward();
|
||||
|
@ -2250,7 +2259,7 @@ void ComposeControls::finishAnimating() {
|
|||
}
|
||||
|
||||
void ComposeControls::updateControlsGeometry(QSize size) {
|
||||
// _attachToggle (_sendAs) -- _inlineResults ------ _tabbedPanel -- _fieldBarCancel
|
||||
// (_attachToggle|_replaceMedia) (_sendAs) -- _inlineResults ------ _tabbedPanel -- _fieldBarCancel
|
||||
// (_attachDocument|_attachPhoto) _field (_ttlInfo) (_silent|_botCommandStart) _tabbedSelectorToggle _send
|
||||
|
||||
const auto fieldWidth = size.width()
|
||||
|
@ -2275,6 +2284,9 @@ void ComposeControls::updateControlsGeometry(QSize size) {
|
|||
const auto buttonsTop = size.height() - _attachToggle->height();
|
||||
|
||||
auto left = st::historySendRight;
|
||||
if (_replaceMedia) {
|
||||
_replaceMedia->moveToLeft(left, buttonsTop);
|
||||
}
|
||||
_attachToggle->moveToLeft(left, buttonsTop);
|
||||
left += _attachToggle->width();
|
||||
if (_sendAs) {
|
||||
|
@ -2321,6 +2333,12 @@ void ComposeControls::updateControlsVisibility() {
|
|||
if (_sendAs) {
|
||||
_sendAs->show();
|
||||
}
|
||||
if (_replaceMedia) {
|
||||
_replaceMedia->show();
|
||||
_attachToggle->hide();
|
||||
} else {
|
||||
_attachToggle->show();
|
||||
}
|
||||
}
|
||||
|
||||
bool ComposeControls::updateBotCommandShown() {
|
||||
|
@ -2556,11 +2574,47 @@ void ComposeControls::editMessage(not_null<HistoryItem*> item) {
|
|||
previewState));
|
||||
applyDraft();
|
||||
|
||||
const auto media = item->media();
|
||||
_canReplaceMedia = media && media->allowsEditMedia();
|
||||
_photoEditMedia = (_canReplaceMedia
|
||||
&& media->photo()
|
||||
&& !media->photo()->isNull())
|
||||
? media->photo()->createMediaView()
|
||||
: nullptr;
|
||||
if (_photoEditMedia) {
|
||||
_photoEditMedia->wanted(Data::PhotoSize::Large, item->fullId());
|
||||
}
|
||||
if (updateReplaceMediaButton(item->fullId())) {
|
||||
updateControlsVisibility();
|
||||
updateControlsGeometry(_wrap->size());
|
||||
}
|
||||
|
||||
if (_autocomplete) {
|
||||
InvokeQueued(_autocomplete.get(), [=] { checkAutocomplete(); });
|
||||
}
|
||||
}
|
||||
|
||||
bool ComposeControls::updateReplaceMediaButton(FullMsgId id) {
|
||||
if (!_canReplaceMedia) {
|
||||
const auto result = (_replaceMedia != nullptr);
|
||||
_replaceMedia = nullptr;
|
||||
return result;
|
||||
} else if (_replaceMedia) {
|
||||
return false;
|
||||
}
|
||||
_replaceMedia = std::make_unique<Ui::IconButton>(
|
||||
_wrap.get(),
|
||||
st::historyReplaceMedia);
|
||||
_replaceMedia->setClickedCallback([=] {
|
||||
EditCaptionBox::StartMediaReplace(
|
||||
_window,
|
||||
id,
|
||||
_field->getTextWithTags(),
|
||||
crl::guard(_wrap.get(), [=] { cancelEditMessage(); }));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void ComposeControls::cancelEditMessage() {
|
||||
Expects(_history != nullptr);
|
||||
Expects(draftKeyCurrent() != Data::DraftKey::None());
|
||||
|
|
|
@ -36,6 +36,7 @@ struct MessagePosition;
|
|||
struct Draft;
|
||||
class DraftKey;
|
||||
enum class PreviewState : char;
|
||||
class PhotoMedia;
|
||||
} // namespace Data
|
||||
|
||||
namespace InlineBots {
|
||||
|
@ -227,6 +228,7 @@ private:
|
|||
void updateWrappingVisibility();
|
||||
void updateControlsVisibility();
|
||||
void updateControlsGeometry(QSize size);
|
||||
bool updateReplaceMediaButton(FullMsgId id);
|
||||
void updateOuterGeometry(QRect rect);
|
||||
void paintBackground(QRect clip);
|
||||
|
||||
|
@ -307,6 +309,7 @@ private:
|
|||
|
||||
const std::shared_ptr<Ui::SendButton> _send;
|
||||
const not_null<Ui::IconButton*> _attachToggle;
|
||||
std::unique_ptr<Ui::IconButton> _replaceMedia;
|
||||
const not_null<Ui::EmojiButton*> _tabbedSelectorToggle;
|
||||
const not_null<Ui::InputField*> _field;
|
||||
const not_null<Ui::IconButton*> _botCommandStart;
|
||||
|
@ -355,6 +358,9 @@ private:
|
|||
bool _isInlineBot = false;
|
||||
bool _botCommandShown = false;
|
||||
|
||||
std::shared_ptr<Data::PhotoMedia> _photoEditMedia;
|
||||
bool _canReplaceMedia = false;
|
||||
|
||||
std::unique_ptr<WebpageProcessor> _preview;
|
||||
|
||||
rpl::lifetime _uploaderSubscriptions;
|
||||
|
|
|
@ -321,11 +321,7 @@ RepliesWidget::RepliesWidget(
|
|||
}) | rpl::start_with_next([=](auto fullId) {
|
||||
if (const auto item = session().data().message(fullId)) {
|
||||
const auto media = item->media();
|
||||
if (media && !media->webpage()) {
|
||||
if (media->allowsEditCaption()) {
|
||||
controller->show(Box<EditCaptionBox>(controller, item));
|
||||
}
|
||||
} else {
|
||||
if (!media || media->webpage() || media->allowsEditCaption()) {
|
||||
_composeControls->editMessage(fullId);
|
||||
}
|
||||
}
|
||||
|
@ -1228,7 +1224,10 @@ void RepliesWidget::edit(
|
|||
TextUtilities::ConvertTextTagsToEntities(textWithTags.tags) };
|
||||
TextUtilities::PrepareForSending(left, prepareFlags);
|
||||
|
||||
if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) {
|
||||
if (!TextUtilities::CutPart(sending, left, MaxMessageSize)
|
||||
&& (!item
|
||||
|| !item->media()
|
||||
|| !item->media()->allowsEditCaption())) {
|
||||
if (item) {
|
||||
controller()->show(Box<DeleteMessagesBox>(item, false));
|
||||
} else {
|
||||
|
|
|
@ -174,11 +174,7 @@ ScheduledWidget::ScheduledWidget(
|
|||
) | rpl::start_with_next([=](auto fullId) {
|
||||
if (const auto item = session().data().message(fullId)) {
|
||||
const auto media = item->media();
|
||||
if (media && !media->webpage()) {
|
||||
if (media->allowsEditCaption()) {
|
||||
controller->show(Box<EditCaptionBox>(controller, item));
|
||||
}
|
||||
} else {
|
||||
if (!media || media->webpage() || media->allowsEditCaption()) {
|
||||
_composeControls->editMessage(fullId);
|
||||
}
|
||||
}
|
||||
|
@ -664,7 +660,10 @@ void ScheduledWidget::edit(
|
|||
TextUtilities::ConvertTextTagsToEntities(textWithTags.tags) };
|
||||
TextUtilities::PrepareForSending(left, prepareFlags);
|
||||
|
||||
if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) {
|
||||
if (!TextUtilities::CutPart(sending, left, MaxMessageSize)
|
||||
&& (!item
|
||||
|| !item->media()
|
||||
|| !item->media()->allowsEditCaption())) {
|
||||
if (item) {
|
||||
controller()->show(Box<DeleteMessagesBox>(item, false));
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue