2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Cloud draft handling improved. Fixed Edit while already editing a msg.

This commit is contained in:
John Preston
2016-06-09 17:31:10 +03:00
parent 19cacd0efb
commit a428534345
14 changed files with 197 additions and 145 deletions

View File

@@ -174,7 +174,7 @@ bool MainWidget::onShareUrl(const PeerId &peer, const QString &url, const QStrin
History *h = App::history(peer);
TextWithTags textWithTags = { url + '\n' + text, TextWithTags::Tags() };
MessageCursor cursor = { url.size() + 1, url.size() + 1 + text.size(), QFIXED_MAX };
h->setLocalDraft(std_::make_unique<HistoryDraft>(textWithTags, 0, cursor, false));
h->setLocalDraft(std_::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
h->clearEditDraft();
bool opened = _history->peer() && (_history->peer()->id == peer);
if (opened) {
@@ -194,7 +194,7 @@ bool MainWidget::onInlineSwitchChosen(const PeerId &peer, const QString &botAndQ
History *h = App::history(peer);
TextWithTags textWithTags = { botAndQuery, TextWithTags::Tags() };
MessageCursor cursor = { botAndQuery.size(), botAndQuery.size(), QFIXED_MAX };
h->setLocalDraft(std_::make_unique<HistoryDraft>(textWithTags, 0, cursor, false));
h->setLocalDraft(std_::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
h->clearEditDraft();
bool opened = _history->peer() && (_history->peer()->id == peer);
if (opened) {
@@ -3772,9 +3772,11 @@ void MainWidget::saveDraftToCloud() {
auto peer = _history->peer();
if (auto history = App::historyLoaded(peer)) {
writeDrafts(history);
auto localDraft = history->localDraft();
auto cloudDraft = history->cloudDraft();
if (!historyDraftsAreEqual(localDraft, cloudDraft)) {
if (!Data::draftsAreEqual(localDraft, cloudDraft)) {
App::api()->saveDraftToCloudDelayed(history);
}
}
@@ -3784,6 +3786,23 @@ void MainWidget::applyCloudDraft(History *history) {
_history->applyCloudDraft(history);
}
void MainWidget::writeDrafts(History *history) {
Local::MessageDraft storedLocalDraft, storedEditDraft;
MessageCursor localCursor, editCursor;
if (auto localDraft = history->localDraft()) {
if (!Data::draftsAreEqual(localDraft, history->cloudDraft())) {
storedLocalDraft = Local::MessageDraft(localDraft->msgId, localDraft->textWithTags, localDraft->previewCancelled);
localCursor = localDraft->cursor;
}
}
if (auto editDraft = history->editDraft()) {
storedEditDraft = Local::MessageDraft(editDraft->msgId, editDraft->textWithTags, editDraft->previewCancelled);
editCursor = editDraft->cursor;
}
Local::writeDrafts(history->peer->id, storedLocalDraft, storedEditDraft);
Local::writeDraftCursors(history->peer->id, localCursor, editCursor);
}
void MainWidget::checkIdleFinish() {
if (this != App::main()) return;
if (psIdleTime() < uint64(Global::OfflineIdleTimeout())) {
@@ -4668,6 +4687,8 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
if (draftMessage.type() == mtpc_draftMessage) {
auto &draft = draftMessage.c_draftMessage();
Data::applyPeerCloudDraft(peerId, draft);
} else {
Data::clearPeerCloudDraft(peerId);
}
} break;