mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-09 21:23:43 +00:00
Clear the source field when content moves to rich editor
This commit is contained in:
@@ -2243,6 +2243,27 @@ void HistoryWidget::saveThreadFieldDraft(std::unique_ptr<Data::Draft> draft) {
|
||||
applyDraft(Ui::InputField::HistoryAction::NewEntry);
|
||||
}
|
||||
|
||||
void HistoryWidget::migrateFieldToRichEditor() {
|
||||
if (!_history) {
|
||||
return;
|
||||
}
|
||||
if (editingMessage()) {
|
||||
cancelEdit();
|
||||
} else {
|
||||
clearFieldText();
|
||||
saveThreadFieldDraft(nullptr);
|
||||
_history->clearCloudDraft(MsgId(), PeerId());
|
||||
if (const auto cloudDraft = _history->createCloudDraft(
|
||||
MsgId(),
|
||||
PeerId(),
|
||||
nullptr)) {
|
||||
session().api().saveDraftToCloud(
|
||||
not_null{ _history },
|
||||
*cloudDraft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::fileChosen(ChatHelpers::FileChosen &&data) {
|
||||
controller()->hideLayer(anim::type::normal);
|
||||
if (const auto info = data.document->sticker()
|
||||
@@ -3463,6 +3484,11 @@ void HistoryWidget::registerThreadFieldBridge() {
|
||||
if (const auto widget = weak.get()) {
|
||||
widget->saveThreadFieldDraft(std::move(draft));
|
||||
}
|
||||
},
|
||||
[weak] {
|
||||
if (const auto widget = weak.get()) {
|
||||
widget->migrateFieldToRichEditor();
|
||||
}
|
||||
});
|
||||
Iv::Editor::FieldVisibleValue(
|
||||
&session(),
|
||||
|
||||
@@ -702,6 +702,7 @@ private:
|
||||
[[nodiscard]] bool shouldShowRichDraftPreview() const;
|
||||
[[nodiscard]] std::unique_ptr<Data::Draft> readThreadFieldDraft() const;
|
||||
void saveThreadFieldDraft(std::unique_ptr<Data::Draft> draft);
|
||||
void migrateFieldToRichEditor();
|
||||
void setHistory(History *history);
|
||||
void setEditMsgId(MsgId msgId);
|
||||
|
||||
|
||||
@@ -2163,6 +2163,31 @@ void ComposeControls::saveThreadFieldDraft(std::unique_ptr<Data::Draft> draft) {
|
||||
applyDraft(Ui::InputField::HistoryAction::NewEntry);
|
||||
}
|
||||
|
||||
void ComposeControls::migrateFieldToRichEditor() {
|
||||
if (!_history) {
|
||||
return;
|
||||
}
|
||||
if (isEditingMessage()) {
|
||||
cancelEditMessage();
|
||||
} else {
|
||||
clearFieldText();
|
||||
saveThreadFieldDraft(nullptr);
|
||||
_history->clearCloudDraft(_topicRootId, _monoforumPeerId);
|
||||
if (const auto thread = _history->threadFor(
|
||||
_topicRootId,
|
||||
_monoforumPeerId)) {
|
||||
if (const auto cloudDraft = _history->createCloudDraft(
|
||||
_topicRootId,
|
||||
_monoforumPeerId,
|
||||
nullptr)) {
|
||||
session().api().saveDraftToCloud(
|
||||
not_null{ thread },
|
||||
*cloudDraft);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ComposeControls::clearFieldText(
|
||||
TextUpdateEvents events,
|
||||
FieldHistoryAction fieldHistoryAction) {
|
||||
@@ -2881,6 +2906,9 @@ void ComposeControls::registerThreadFieldBridge() {
|
||||
},
|
||||
[this](std::unique_ptr<Data::Draft> draft) {
|
||||
saveThreadFieldDraft(std::move(draft));
|
||||
},
|
||||
[this] {
|
||||
migrateFieldToRichEditor();
|
||||
});
|
||||
Iv::Editor::FieldVisibleValue(
|
||||
_session,
|
||||
|
||||
@@ -448,6 +448,7 @@ private:
|
||||
[[nodiscard]] bool shouldShowRichDraftPreview() const;
|
||||
[[nodiscard]] std::unique_ptr<Data::Draft> readThreadFieldDraft() const;
|
||||
void saveThreadFieldDraft(std::unique_ptr<Data::Draft> draft);
|
||||
void migrateFieldToRichEditor();
|
||||
|
||||
const style::ComposeControls &_st;
|
||||
ChatHelpers::ComposeFeatures _features;
|
||||
|
||||
@@ -96,6 +96,7 @@ struct ComposeThreadEntry {
|
||||
rpl::variable<bool> fieldVisible = false;
|
||||
ThreadFieldDraftReader readDraft;
|
||||
ThreadFieldDraftSaver saveDraft;
|
||||
ThreadFieldMigratedAway migratedAway;
|
||||
};
|
||||
|
||||
[[nodiscard]] ComposeThreadKey ComposeKey(
|
||||
@@ -566,6 +567,9 @@ public:
|
||||
});
|
||||
if (!migrated.blocks.empty()) {
|
||||
*page = std::move(migrated);
|
||||
if (entry->migratedAway) {
|
||||
entry->migratedAway();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3969,11 +3973,13 @@ void RegisterThreadFieldBridge(
|
||||
MsgId topicRootId,
|
||||
PeerId monoforumPeerId,
|
||||
ThreadFieldDraftReader readDraft,
|
||||
ThreadFieldDraftSaver saveDraft) {
|
||||
ThreadFieldDraftSaver saveDraft,
|
||||
ThreadFieldMigratedAway migratedAway) {
|
||||
auto &entry = ComposeThreadEntryFor(
|
||||
ComposeKey(session, peerId, topicRootId, monoforumPeerId));
|
||||
entry.readDraft = std::move(readDraft);
|
||||
entry.saveDraft = std::move(saveDraft);
|
||||
entry.migratedAway = std::move(migratedAway);
|
||||
}
|
||||
|
||||
void UnregisterThreadFieldBridge(
|
||||
@@ -3985,6 +3991,7 @@ void UnregisterThreadFieldBridge(
|
||||
ComposeKey(session, peerId, topicRootId, monoforumPeerId));
|
||||
entry.readDraft = nullptr;
|
||||
entry.saveDraft = nullptr;
|
||||
entry.migratedAway = nullptr;
|
||||
}
|
||||
|
||||
void CloseAllWindows() {
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Iv::Editor {
|
||||
|
||||
using ThreadFieldDraftReader = Fn<std::unique_ptr<::Data::Draft>()>;
|
||||
using ThreadFieldDraftSaver = Fn<void(std::unique_ptr<::Data::Draft>)>;
|
||||
using ThreadFieldMigratedAway = Fn<void()>;
|
||||
|
||||
[[nodiscard]] bool CheckRichMessagesPremium(
|
||||
not_null<Window::SessionController*> controller);
|
||||
@@ -70,7 +71,8 @@ void RegisterThreadFieldBridge(
|
||||
MsgId topicRootId,
|
||||
PeerId monoforumPeerId,
|
||||
ThreadFieldDraftReader readDraft,
|
||||
ThreadFieldDraftSaver saveDraft);
|
||||
ThreadFieldDraftSaver saveDraft,
|
||||
ThreadFieldMigratedAway migratedAway);
|
||||
void UnregisterThreadFieldBridge(
|
||||
not_null<Main::Session*> session,
|
||||
PeerId peerId,
|
||||
|
||||
Reference in New Issue
Block a user