summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Preston <johnprestonmail@gmail.com>2018-07-16 20:31:07 +0300
committerJohn Preston <johnprestonmail@gmail.com>2018-08-20 17:26:28 +0300
commitc913c77fef4326790d816a797436458fcb1809aa (patch)
treedd2d17f7afecf2bec6c8bdb9f767946bcd85ba1e
parent557d363d029a6760b17db2e3bfdc4bbc4d12420e (diff)
Refresh file references when sending stickers.
-rw-r--r--Telegram/SourceFiles/apiwrap.cpp163
-rw-r--r--Telegram/SourceFiles/apiwrap.h16
-rw-r--r--Telegram/SourceFiles/boxes/sticker_set_box.cpp2
-rw-r--r--Telegram/SourceFiles/chat_helpers/gifs_list_widget.h8
-rw-r--r--Telegram/SourceFiles/chat_helpers/stickers_list_widget.h2
-rw-r--r--Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp8
-rw-r--r--Telegram/SourceFiles/chat_helpers/tabbed_selector.h8
-rw-r--r--Telegram/SourceFiles/data/data_document.cpp8
-rw-r--r--Telegram/SourceFiles/data/data_document.h2
-rw-r--r--Telegram/SourceFiles/export/data/export_data_types.h2
-rw-r--r--Telegram/SourceFiles/history/history_widget.cpp108
-rw-r--r--Telegram/SourceFiles/history/history_widget.h17
-rw-r--r--Telegram/SourceFiles/mainwidget.cpp2
-rw-r--r--Telegram/SourceFiles/storage/file_download.cpp3
14 files changed, 218 insertions, 131 deletions
diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp
index 90365476ad..688035e8eb 100644
--- a/Telegram/SourceFiles/apiwrap.cpp
+++ b/Telegram/SourceFiles/apiwrap.cpp
@@ -2377,14 +2377,8 @@ void ApiWrap::channelRangeDifferenceDone(
template <typename Request>
void ApiWrap::requestFileReference(
Data::FileOrigin origin,
- not_null<mtpFileLoader*> loader,
- int requestId,
- const QByteArray &current,
+ FileReferencesHandler &&handler,
Request &&data) {
- auto handler = crl::guard(loader, [=](
- const Data::UpdatedFileReferences &data) {
- loader->refreshFileReferenceFrom(data, requestId, current);
- });
const auto i = _fileReferenceHandlers.find(origin);
if (i != end(_fileReferenceHandlers)) {
i->second.push_back(std::move(handler));
@@ -2396,6 +2390,15 @@ void ApiWrap::requestFileReference(
request(std::move(data)).done([=](const auto &result) {
const auto parsed = Data::GetFileReferences(result);
+ for (const auto &[origin, reference] : parsed) {
+ const auto documentId = base::get_if<DocumentFileLocationId>(
+ &origin);
+ if (documentId) {
+ _session->data().document(
+ *documentId
+ )->refreshFileReference(reference);
+ }
+ }
const auto i = _fileReferenceHandlers.find(origin);
Assert(i != end(_fileReferenceHandlers));
auto handlers = std::move(i->second);
@@ -2419,16 +2422,32 @@ void ApiWrap::refreshFileReference(
not_null<mtpFileLoader*> loader,
int requestId,
const QByteArray &current) {
- const auto request = [&](auto &&data) {
+ return refreshFileReference(origin, crl::guard(loader, [=](
+ const Data::UpdatedFileReferences &data) {
+ loader->refreshFileReferenceFrom(data, requestId, current);
+ }));
+}
+
+void ApiWrap::refreshFileReference(
+ Data::FileOrigin origin,
+ FileReferencesHandler &&handler) {
+ const auto request = [&](
+ auto &&data,
+ Fn<void()> &&additional = nullptr) {
requestFileReference(
origin,
- loader,
- requestId,
- current,
+ std::move(handler),
std::move(data));
+ if (additional) {
+ const auto i = _fileReferenceHandlers.find(origin);
+ Assert(i != end(_fileReferenceHandlers));
+ i->second.push_back([=](auto&&) {
+ additional();
+ });
+ }
};
const auto fail = [&] {
- loader->refreshFileReferenceFrom({}, requestId, current);
+ handler(Data::UpdatedFileReferences());
};
origin.match([&](Data::FileOriginMessage data) {
if (const auto item = App::histItemById(data)) {
@@ -2479,14 +2498,21 @@ void ApiWrap::refreshFileReference(
|| data.setId == Stickers::RecentSetId) {
request(MTPmessages_GetRecentStickers(
MTP_flags(0),
- MTP_int(0)));
+ MTP_int(0)),
+ [] { crl::on_main([] { Local::writeRecentStickers(); }); });
} else if (data.setId == Stickers::FavedSetId) {
- request(MTPmessages_GetFavedStickers(MTP_int(0)));
+ request(MTPmessages_GetFavedStickers(MTP_int(0)),
+ [] { crl::on_main([] { Local::writeFavedStickers(); }); });
} else {
request(MTPmessages_GetStickerSet(
MTP_inputStickerSetID(
MTP_long(data.setId),
- MTP_long(data.accessHash))));
+ MTP_long(data.accessHash))),
+ [] { crl::on_main([] {
+ Local::writeInstalledStickers();
+ Local::writeRecentStickers();
+ Local::writeFavedStickers();
+ }); });
}
}, [&](Data::FileOriginSavedGifs data) {
request(MTPmessages_GetSavedGifs(MTP_int(0)));
@@ -4314,6 +4340,113 @@ void ApiWrap::sendInlineResult(
}
}
+void ApiWrap::sendExistingDocument(
+ not_null<DocumentData*> document,
+ Data::FileOrigin origin,
+ TextWithEntities caption,
+ const SendOptions &options) {
+ Auth().api().sendAction(options);
+
+ const auto history = options.history;
+ const auto peer = history->peer;
+ const auto newId = FullMsgId(peerToChannel(peer->id), clientMsgId());
+ const auto randomId = rand_value<uint64>();
+
+ auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media;
+ auto sendFlags = MTPmessages_SendMedia::Flags(0);
+ if (options.replyTo) {
+ flags |= MTPDmessage::Flag::f_reply_to_msg_id;
+ sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
+ }
+ bool channelPost = peer->isChannel() && !peer->isMegagroup();
+ bool silentPost = channelPost && Auth().data().notifySilentPosts(peer);
+ if (channelPost) {
+ flags |= MTPDmessage::Flag::f_views;
+ flags |= MTPDmessage::Flag::f_post;
+ }
+ if (!channelPost) {
+ flags |= MTPDmessage::Flag::f_from_id;
+ } else if (peer->asChannel()->addsSignature()) {
+ flags |= MTPDmessage::Flag::f_post_author;
+ }
+ if (silentPost) {
+ sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
+ }
+ auto messageFromId = channelPost ? 0 : Auth().userId();
+ auto messagePostAuthor = channelPost
+ ? App::peerName(Auth().user()) : QString();
+
+ TextUtilities::Trim(caption);
+ auto sentEntities = TextUtilities::EntitiesToMTP(
+ caption.entities,
+ TextUtilities::ConvertOption::SkipLocal);
+ if (!sentEntities.v.isEmpty()) {
+ sendFlags |= MTPmessages_SendMedia::Flag::f_entities;
+ }
+
+ App::historyRegRandom(randomId, newId);
+
+ history->addNewDocument(
+ newId.msg,
+ flags,
+ 0,
+ options.replyTo,
+ unixtime(),
+ messageFromId,
+ messagePostAuthor,
+ document,
+ caption,
+ MTPnullMarkup);
+ auto failHandler = std::make_shared<Fn<void(const RPCError&)>>();
+
+ const auto replyTo = options.replyTo;
+ const auto captionText = caption.text;
+ auto performRequest = [=] {
+ history->sendRequestId = request(MTPmessages_SendMedia(
+ MTP_flags(sendFlags),
+ peer->input,
+ MTP_int(replyTo),
+ MTP_inputMediaDocument(
+ MTP_flags(0),
+ document->mtpInput(),
+ MTPint()),
+ MTP_string(captionText),
+ MTP_long(randomId),
+ MTPnullMarkup,
+ sentEntities
+ )).done([=](const MTPUpdates &result) {
+ applyUpdates(result, randomId);
+ }).fail(
+ base::duplicate(*failHandler)
+ ).afterRequest(history->sendRequestId
+ ).send();
+ };
+ *failHandler = [=](const RPCError &error) {
+ if (error.code() == 400
+ && error.type().startsWith(qstr("FILE_REFERENCE_"))) {
+ const auto current = document->fileReference();
+ auto refreshed = [=](const Data::UpdatedFileReferences &data) {
+ if (document->fileReference() != current) {
+ performRequest();
+ } else {
+ sendMessageFail(error);
+ }
+ };
+ refreshFileReference(origin, std::move(refreshed));
+ } else {
+ sendMessageFail(error);
+ }
+ };
+ performRequest();
+
+ if (const auto main = App::main()) {
+ main->finishForwarding(history);
+ if (document->sticker()) {
+ main->incrementSticker(document);
+ }
+ }
+}
+
void ApiWrap::uploadAlbumMedia(
not_null<HistoryItem*> item,
const MessageGroupId &groupId,
diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h
index 973d81475f..861356ebdd 100644
--- a/Telegram/SourceFiles/apiwrap.h
+++ b/Telegram/SourceFiles/apiwrap.h
@@ -97,6 +97,11 @@ public:
void requestParticipantsCountDelayed(not_null<ChannelData*> channel);
void requestChannelRangeDifference(not_null<History*> history);
+ using UpdatedFileReferences = Data::UpdatedFileReferences;
+ using FileReferencesHandler = FnMut<void(const UpdatedFileReferences&)>;
+ void refreshFileReference(
+ Data::FileOrigin origin,
+ FileReferencesHandler &&handler);
void refreshFileReference(
Data::FileOrigin origin,
not_null<mtpFileLoader*> loader,
@@ -303,6 +308,11 @@ public:
not_null<UserData*> bot,
not_null<InlineBots::Result*> data,
const SendOptions &options);
+ void sendExistingDocument(
+ not_null<DocumentData*> document,
+ Data::FileOrigin origin,
+ TextWithEntities caption,
+ const SendOptions &options);
~ApiWrap();
@@ -324,8 +334,6 @@ private:
using SimpleFileLocationId = Data::SimpleFileLocationId;
using DocumentFileLocationId = Data::DocumentFileLocationId;
using FileLocationId = Data::FileLocationId;
- using UpdatedFileReferences = Data::UpdatedFileReferences;
- using FileReferencesHandler = FnMut<void(const UpdatedFileReferences&)>;
void updatesReceived(const MTPUpdates &updates);
void checkQuitPreventFinished();
@@ -484,9 +492,7 @@ private:
template <typename Request>
void requestFileReference(
Data::FileOrigin origin,
- not_null<mtpFileLoader*> loader,
- int requestId,
- const QByteArray &current,
+ FileReferencesHandler &&handler,
Request &&data);
not_null<AuthSession*> _session;
diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp
index 7477c8ab64..37aacc2ae9 100644
--- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp
+++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp
@@ -302,7 +302,7 @@ void StickerSetBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
int index = stickerFromGlobalPos(e->globalPos());
if (index >= 0 && index < _pack.size() && !isMasksSet()) {
if (auto main = App::main()) {
- if (main->onSendSticker(_pack.at(index))) {
+ if (main->onSendSticker(_pack[index])) {
Ui::hideSettingsAndLayer();
}
}
diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h
index 7169cbaf46..715e8aec85 100644
--- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h
+++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h
@@ -81,9 +81,11 @@ private slots:
void onUpdateInlineItems();
signals:
- void selected(DocumentData *sticker);
- void selected(PhotoData *photo);
- void selected(InlineBots::Result *result, UserData *bot);
+ void selected(not_null<DocumentData*> sticker);
+ void selected(not_null<PhotoData*> photo);
+ void selected(
+ not_null<InlineBots::Result*> result,
+ not_null<UserData*> bot);
void cancelled();
void emptyInlineRows();
diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h
index 928606794b..c1a343441d 100644
--- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h
+++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h
@@ -87,7 +87,7 @@ private slots:
void onPreview();
signals:
- void selected(DocumentData *sticker);
+ void selected(not_null<DocumentData*> sticker);
void scrollUpdated();
void checkForHide();
diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp
index efb1b14f96..efad2d079e 100644
--- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp
+++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp
@@ -309,11 +309,11 @@ TabbedSelector::TabbedSelector(QWidget *parent, not_null<Window::Controller*> co
connect(stickers(), SIGNAL(scrollUpdated()), this, SLOT(onScroll()));
connect(_scroll, SIGNAL(scrolled()), this, SLOT(onScroll()));
connect(emoji(), SIGNAL(selected(EmojiPtr)), this, SIGNAL(emojiSelected(EmojiPtr)));
- connect(stickers(), SIGNAL(selected(DocumentData*)), this, SIGNAL(stickerSelected(DocumentData*)));
+ connect(stickers(), SIGNAL(selected(not_null<DocumentData*>)), this, SIGNAL(stickerOrGifSelected(not_null<DocumentData*>)));
connect(stickers(), SIGNAL(checkForHide()), this, SIGNAL(checkForHide()));
- connect(gifs(), SIGNAL(selected(DocumentData*)), this, SIGNAL(stickerSelected(DocumentData*)));
- connect(gifs(), SIGNAL(selected(PhotoData*)), this, SIGNAL(photoSelected(PhotoData*)));
- connect(gifs(), SIGNAL(selected(InlineBots::Result*, UserData*)), this, SIGNAL(inlineResultSelected(InlineBots::Result*, UserData*)));
+ connect(gifs(), SIGNAL(selected(not_null<DocumentData*>)), this, SIGNAL(stickerOrGifSelected(not_null<DocumentData*>)));
+ connect(gifs(), SIGNAL(selected(not_null<PhotoData*>)), this, SIGNAL(photoSelected(not_null<PhotoData*>)));
+ connect(gifs(), SIGNAL(selected(not_null<InlineBots::Result*>,not_null<UserData*>)), this, SIGNAL(inlineResultSelected(not_null<InlineBots::Result*>,not_null<UserData*>)));
connect(gifs(), SIGNAL(cancelled()), this, SIGNAL(cancelled()));
_topShadow->raise();
diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h
index 2ab9d84571..8c942b62b9 100644
--- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h
+++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h
@@ -92,9 +92,11 @@ private slots:
signals:
void emojiSelected(EmojiPtr emoji);
- void stickerSelected(DocumentData *sticker);
- void photoSelected(PhotoData *photo);
- void inlineResultSelected(InlineBots::Result *result, UserData *bot);
+ void stickerOrGifSelected(not_null<DocumentData*> sticker);
+ void photoSelected(not_null<PhotoData*> photo);
+ void inlineResultSelected(
+ not_null<InlineBots::Result*> result,
+ not_null<UserData*> bot);
void cancelled();
void slideFinished();
diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp
index 133ffe7082..669f70c6fa 100644
--- a/Telegram/SourceFiles/data/data_document.cpp
+++ b/Telegram/SourceFiles/data/data_document.cpp
@@ -1055,6 +1055,14 @@ MTPInputDocument DocumentData::mtpInput() const {
return MTP_inputDocumentEmpty();
}
+QByteArray DocumentData::fileReference() const {
+ return _fileReference;
+}
+
+void DocumentData::refreshFileReference(const QByteArray &value) {
+ _fileReference = value;
+}
+
QString DocumentData::filename() const {
return _filename;
}
diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h
index 4b34db75a3..3495078592 100644
--- a/Telegram/SourceFiles/data/data_document.h
+++ b/Telegram/SourceFiles/data/data_document.h
@@ -158,6 +158,8 @@ public:
bool hasWebLocation() const;
bool isValid() const;
MTPInputDocument mtpInput() const;
+ QByteArray fileReference() const;
+ void refreshFileReference(const QByteArray &value);
// When we have some client-side generated document
// (for example for displaying an external inline bot result)
diff --git a/Telegram/SourceFiles/export/data/export_data_types.h b/Telegram/SourceFiles/export/data/export_data_types.h
index c9de8f3d69..997199cb97 100644
--- a/Telegram/SourceFiles/export/data/export_data_types.h
+++ b/Telegram/SourceFiles/export/data/export_data_types.h
@@ -44,7 +44,7 @@ inline auto NumberToString(Type value, int length = 0, char filler = '0')
return FillLeft(
Utf8String(result.data(), int(result.size())),
length,
- filler);
+ filler).replace(',', '.');
}
struct UserpicsInfo {
diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp
index cd3ace0309..2c3415cf5e 100644
--- a/Telegram/SourceFiles/history/history_widget.cpp
+++ b/Telegram/SourceFiles/history/history_widget.cpp
@@ -470,9 +470,9 @@ HistoryWidget::HistoryWidget(
&TabbedSelector::emojiSelected,
_field,
[=](EmojiPtr emoji) { InsertEmojiToField(_field, emoji); });
- connect(_tabbedSelector, SIGNAL(stickerSelected(DocumentData*)), this, SLOT(onStickerSend(DocumentData*)));
- connect(_tabbedSelector, SIGNAL(photoSelected(PhotoData*)), this, SLOT(onPhotoSend(PhotoData*)));
- connect(_tabbedSelector, SIGNAL(inlineResultSelected(InlineBots::Result*,UserData*)), this, SLOT(onInlineResultSend(InlineBots::Result*,UserData*)));
+ connect(_tabbedSelector, SIGNAL(stickerOrGifSelected(not_null<DocumentData*>)), this, SLOT(onStickerOrGifSend(not_null<DocumentData*>)));
+ connect(_tabbedSelector, SIGNAL(photoSelected(not_null<PhotoData*>)), this, SLOT(onPhotoSend(not_null<PhotoData*>)));
+ connect(_tabbedSelector, SIGNAL(inlineResultSelected(not_null<InlineBots::Result*>,not_null<UserData*>)), this, SLOT(onInlineResultSend(not_null<InlineBots::Result*>,not_null<UserData*>)));
connect(Media::Capture::instance(), SIGNAL(error()), this, SLOT(onRecordError()));
connect(Media::Capture::instance(), SIGNAL(updated(quint16,qint32)), this, SLOT(onRecordUpdate(quint16,qint32)));
connect(Media::Capture::instance(), SIGNAL(done(QByteArray,VoiceWaveform,qint32)), this, SLOT(onRecordDone(QByteArray,VoiceWaveform,qint32)));
@@ -5416,7 +5416,7 @@ void HistoryWidget::onFieldTabbed() {
}
}
-bool HistoryWidget::onStickerSend(DocumentData *sticker) {
+bool HistoryWidget::onStickerOrGifSend(not_null<DocumentData*> document) {
if (auto megagroup = _peer ? _peer->asMegagroup() : nullptr) {
if (megagroup->restricted(ChannelRestriction::f_send_stickers)) {
Ui::show(
@@ -5425,10 +5425,13 @@ bool HistoryWidget::onStickerSend(DocumentData *sticker) {
return false;
}
}
- return sendExistingDocument(sticker, TextWithEntities());
+ return sendExistingDocument(
+ document,
+ document->stickerOrGifOrigin(),
+ TextWithEntities());
}
-void HistoryWidget::onPhotoSend(PhotoData *photo) {
+void HistoryWidget::onPhotoSend(not_null<PhotoData*> photo) {
if (auto megagroup = _peer ? _peer->asMegagroup() : nullptr) {
if (megagroup->restricted(ChannelRestriction::f_send_media)) {
Ui::show(
@@ -5441,11 +5444,8 @@ void HistoryWidget::onPhotoSend(PhotoData *photo) {
}
void HistoryWidget::onInlineResultSend(
- InlineBots::Result *result,
- UserData *bot) {
- Expects(result != nullptr);
- Expects(bot != nullptr);
-
+ not_null<InlineBots::Result*> result,
+ not_null<UserData*> bot) {
if (!_peer || !_peer->canWrite()) {
return;
}
@@ -5594,14 +5594,10 @@ void HistoryWidget::destroyPinnedBar() {
}
bool HistoryWidget::sendExistingDocument(
- DocumentData *doc,
+ not_null<DocumentData*> document,
+ Data::FileOrigin origin,
TextWithEntities caption) {
- if (!_peer || !_peer->canWrite() || !doc) {
- return false;
- }
-
- MTPInputDocument mtpInput = doc->mtpInput();
- if (mtpInput.type() == mtpc_inputDocumentEmpty) {
+ if (!_peer || !_peer->canWrite()) {
return false;
}
@@ -5609,77 +5605,7 @@ bool HistoryWidget::sendExistingDocument(
options.clearDraft = false;
options.replyTo = replyToId();
options.generateLocal = true;
- Auth().api().sendAction(options);
-
- uint64 randomId = rand_value<uint64>();
- FullMsgId newId(_channel, clientMsgId());
-
- auto flags = NewMessageFlags(_peer) | MTPDmessage::Flag::f_media;
- auto sendFlags = MTPmessages_SendMedia::Flags(0);
- if (options.replyTo) {
- flags |= MTPDmessage::Flag::f_reply_to_msg_id;
- sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
- }
- bool channelPost = _peer->isChannel() && !_peer->isMegagroup();
- bool silentPost = channelPost && Auth().data().notifySilentPosts(_peer);
- if (channelPost) {
- flags |= MTPDmessage::Flag::f_views;
- flags |= MTPDmessage::Flag::f_post;
- }
- if (!channelPost) {
- flags |= MTPDmessage::Flag::f_from_id;
- } else if (_peer->asChannel()->addsSignature()) {
- flags |= MTPDmessage::Flag::f_post_author;
- }
- if (silentPost) {
- sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
- }
- auto messageFromId = channelPost ? 0 : Auth().userId();
- auto messagePostAuthor = channelPost
- ? App::peerName(Auth().user()) : QString();
-
- TextUtilities::Trim(caption);
- auto sentEntities = TextUtilities::EntitiesToMTP(
- caption.entities,
- TextUtilities::ConvertOption::SkipLocal);
- if (!sentEntities.v.isEmpty()) {
- sendFlags |= MTPmessages_SendMedia::Flag::f_entities;
- }
-
- _history->addNewDocument(
- newId.msg,
- flags,
- 0,
- options.replyTo,
- unixtime(),
- messageFromId,
- messagePostAuthor,
- doc,
- caption,
- MTPnullMarkup);
- _history->sendRequestId = MTP::send(
- MTPmessages_SendMedia(
- MTP_flags(sendFlags),
- _peer->input,
- MTP_int(options.replyTo),
- MTP_inputMediaDocument(
- MTP_flags(0),
- mtpInput,
- MTPint()),
- MTP_string(caption.text),
- MTP_long(randomId),
- MTPnullMarkup,
- sentEntities),
- App::main()->rpcDone(&MainWidget::sentUpdatesReceived),
- App::main()->rpcFail(&MainWidget::sendMessageFail),
- 0,
- 0,
- _history->sendRequestId);
- App::main()->finishForwarding(_history);
-
- if (doc->sticker()) App::main()->incrementSticker(doc);
-
- App::historyRegRandom(randomId, newId);
+ Auth().api().sendExistingDocument(document, origin, caption, options);
if (_fieldAutocomplete->stickersShown()) {
clearFieldText();
@@ -5696,9 +5622,9 @@ bool HistoryWidget::sendExistingDocument(
}
void HistoryWidget::sendExistingPhoto(
- PhotoData *photo,
+ not_null<PhotoData*> photo,
TextWithEntities caption) {
- if (!_peer || !_peer->canWrite() || !photo) {
+ if (!_peer || !_peer->canWrite()) {
return;
}
diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h
index 2ebbfffae8..30244973f3 100644
--- a/Telegram/SourceFiles/history/history_widget.h
+++ b/Telegram/SourceFiles/history/history_widget.h
@@ -394,9 +394,11 @@ public slots:
void onTextChange();
void onFieldTabbed();
- bool onStickerSend(DocumentData *sticker);
- void onPhotoSend(PhotoData *photo);
- void onInlineResultSend(InlineBots::Result *result, UserData *bot);
+ bool onStickerOrGifSend(not_null<DocumentData*> document);
+ void onPhotoSend(not_null<PhotoData*> photo);
+ void onInlineResultSend(
+ not_null<InlineBots::Result*> result,
+ not_null<UserData*> bot);
void onWindowVisibleChanged();
@@ -596,8 +598,13 @@ private:
void destroyPinnedBar();
void unpinDone(const MTPUpdates &updates);
- bool sendExistingDocument(DocumentData *doc, TextWithEntities caption);
- void sendExistingPhoto(PhotoData *photo, TextWithEntities caption);
+ bool sendExistingDocument(
+ not_null<DocumentData*> document,
+ Data::FileOrigin origin,
+ TextWithEntities caption);
+ void sendExistingPhoto(
+ not_null<PhotoData*> photo,
+ TextWithEntities caption);
void drawField(Painter &p, const QRect &rect);
void paintEditHeader(Painter &p, const QRect &rect, int left, int top) const;
diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp
index e2aed7768c..916668274e 100644
--- a/Telegram/SourceFiles/mainwidget.cpp
+++ b/Telegram/SourceFiles/mainwidget.cpp
@@ -1688,7 +1688,7 @@ void MainWidget::onSendFileConfirm(
}
bool MainWidget::onSendSticker(DocumentData *document) {
- return _history->onStickerSend(document);
+ return _history->onStickerOrGifSend(document);
}
void MainWidget::dialogsCancelled() {
diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp
index 099f51640b..8378aa7a55 100644
--- a/Telegram/SourceFiles/storage/file_download.cpp
+++ b/Telegram/SourceFiles/storage/file_download.cpp
@@ -917,7 +917,8 @@ bool mtpFileLoader::partFailed(
if (MTP::isDefaultHandledError(error)) {
return false;
}
- if (error.type().startsWith(qstr("FILE_REFERENCE_"))) {
+ if (error.code() == 400
+ && error.type().startsWith(qstr("FILE_REFERENCE_"))) {
Auth().api().refreshFileReference(
_origin,
this,