Fixed refreshing of file reference in api toggling media module.
This commit is contained in:
parent
cf6b995c50
commit
4ad31ce4e0
|
@ -169,7 +169,7 @@ void SendExistingMedia(
|
|||
} else {
|
||||
api->sendMessageFail(error, peer, randomId, newId);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
api->sendMessageFail(error, peer, randomId, newId);
|
||||
}
|
||||
|
|
|
@ -17,19 +17,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace Api {
|
||||
namespace {
|
||||
|
||||
template <typename ToggleRequest, typename DoneCallback>
|
||||
template <typename ToggleRequestCallback, typename DoneCallback>
|
||||
void ToggleExistingMedia(
|
||||
not_null<DocumentData*> document,
|
||||
Data::FileOrigin origin,
|
||||
ToggleRequest toggleRequest,
|
||||
ToggleRequestCallback toggleRequest,
|
||||
DoneCallback &&done) {
|
||||
const auto api = &document->owner().session().api();
|
||||
|
||||
auto performRequest = [=](const auto &repeatRequest) -> void {
|
||||
const auto usedFileReference = document->fileReference();
|
||||
api->request(std::move(
|
||||
toggleRequest
|
||||
)).done(done).fail([=](const MTP::Error &error) {
|
||||
api->request(
|
||||
toggleRequest()
|
||||
).done(done).fail([=](const MTP::Error &error) {
|
||||
if (error.code() == 400
|
||||
&& error.type().startsWith(u"FILE_REFERENCE_"_q)) {
|
||||
auto refreshed = [=](const Data::UpdatedFileReferences &d) {
|
||||
|
@ -65,7 +65,9 @@ void ToggleFavedSticker(
|
|||
ToggleExistingMedia(
|
||||
document,
|
||||
std::move(origin),
|
||||
MTPmessages_FaveSticker(document->mtpInput(), MTP_bool(!faved)),
|
||||
[=, d = document] {
|
||||
return MTPmessages_FaveSticker(d->mtpInput(), MTP_bool(!faved));
|
||||
},
|
||||
[=] { document->owner().stickers().setFaved(document, faved); });
|
||||
}
|
||||
|
||||
|
@ -84,10 +86,12 @@ void ToggleRecentSticker(
|
|||
ToggleExistingMedia(
|
||||
document,
|
||||
std::move(origin),
|
||||
MTPmessages_SaveRecentSticker(
|
||||
MTP_flags(MTPmessages_SaveRecentSticker::Flag(0)),
|
||||
document->mtpInput(),
|
||||
MTP_bool(!saved)),
|
||||
[=] {
|
||||
return MTPmessages_SaveRecentSticker(
|
||||
MTP_flags(MTPmessages_SaveRecentSticker::Flag(0)),
|
||||
document->mtpInput(),
|
||||
MTP_bool(!saved));
|
||||
},
|
||||
std::move(done));
|
||||
}
|
||||
|
||||
|
@ -106,7 +110,9 @@ void ToggleSavedGif(
|
|||
ToggleExistingMedia(
|
||||
document,
|
||||
std::move(origin),
|
||||
MTPmessages_SaveGif(document->mtpInput(), MTP_bool(!saved)),
|
||||
[=, d = document] {
|
||||
return MTPmessages_SaveGif(d->mtpInput(), MTP_bool(!saved));
|
||||
},
|
||||
std::move(done));
|
||||
}
|
||||
|
||||
|
@ -118,7 +124,9 @@ void ToggleSavedRingtone(
|
|||
ToggleExistingMedia(
|
||||
document,
|
||||
std::move(origin),
|
||||
MTPaccount_SaveRingtone(document->mtpInput(), MTP_bool(!saved)),
|
||||
[=, d = document] {
|
||||
return MTPaccount_SaveRingtone(d->mtpInput(), MTP_bool(!saved));
|
||||
},
|
||||
std::move(done));
|
||||
}
|
||||
|
||||
|
|
|
@ -2332,6 +2332,9 @@ void ApiWrap::refreshFileReference(
|
|||
void ApiWrap::refreshFileReference(
|
||||
Data::FileOrigin origin,
|
||||
FileReferencesHandler &&handler) {
|
||||
const auto fail = [&] {
|
||||
handler(UpdatedFileReferences());
|
||||
};
|
||||
const auto request = [&](
|
||||
auto &&data,
|
||||
Fn<void()> &&additional = nullptr) {
|
||||
|
@ -2349,9 +2352,6 @@ void ApiWrap::refreshFileReference(
|
|||
}
|
||||
}
|
||||
};
|
||||
const auto fail = [&] {
|
||||
handler(UpdatedFileReferences());
|
||||
};
|
||||
v::match(origin.data, [&](Data::FileOriginMessage data) {
|
||||
if (const auto item = _session->data().message(data)) {
|
||||
if (item->isScheduled()) {
|
||||
|
|
Loading…
Reference in New Issue