Added ability to send existing media with pre-generated local msgId.

This commit is contained in:
23rd 2022-02-08 22:16:22 +03:00 committed by John Preston
parent 298c5026be
commit cb7da60ec7
2 changed files with 17 additions and 8 deletions

View file

@ -63,7 +63,8 @@ void SendExistingMedia(
MessageToSend &&message, MessageToSend &&message,
not_null<MediaData*> media, not_null<MediaData*> media,
Fn<MTPInputMedia()> inputMedia, Fn<MTPInputMedia()> inputMedia,
Data::FileOrigin origin) { Data::FileOrigin origin,
std::optional<MsgId> localMessageId) {
const auto history = message.action.history; const auto history = message.action.history;
const auto peer = history->peer; const auto peer = history->peer;
const auto session = &history->session(); const auto session = &history->session();
@ -75,7 +76,9 @@ void SendExistingMedia(
const auto newId = FullMsgId( const auto newId = FullMsgId(
peer->id, peer->id,
session->data().nextLocalMessageId()); localMessageId
? (*localMessageId)
: session->data().nextLocalMessageId());
const auto randomId = base::RandomValue<uint64>(); const auto randomId = base::RandomValue<uint64>();
auto flags = NewMessageFlags(peer); auto flags = NewMessageFlags(peer);
@ -185,7 +188,8 @@ void SendExistingMedia(
void SendExistingDocument( void SendExistingDocument(
MessageToSend &&message, MessageToSend &&message,
not_null<DocumentData*> document) { not_null<DocumentData*> document,
std::optional<MsgId> localMessageId) {
const auto inputMedia = [=] { const auto inputMedia = [=] {
return MTP_inputMediaDocument( return MTP_inputMediaDocument(
MTP_flags(0), MTP_flags(0),
@ -197,7 +201,8 @@ void SendExistingDocument(
std::move(message), std::move(message),
document, document,
inputMedia, inputMedia,
document->stickerOrGifOrigin()); document->stickerOrGifOrigin(),
std::move(localMessageId));
if (document->sticker()) { if (document->sticker()) {
document->owner().stickers().incrementSticker(document); document->owner().stickers().incrementSticker(document);
@ -206,7 +211,8 @@ void SendExistingDocument(
void SendExistingPhoto( void SendExistingPhoto(
MessageToSend &&message, MessageToSend &&message,
not_null<PhotoData*> photo) { not_null<PhotoData*> photo,
std::optional<MsgId> localMessageId) {
const auto inputMedia = [=] { const auto inputMedia = [=] {
return MTP_inputMediaPhoto( return MTP_inputMediaPhoto(
MTP_flags(0), MTP_flags(0),
@ -217,7 +223,8 @@ void SendExistingPhoto(
std::move(message), std::move(message),
photo, photo,
inputMedia, inputMedia,
Data::FileOrigin()); Data::FileOrigin(),
std::move(localMessageId));
} }
bool SendDice(MessageToSend &message) { bool SendDice(MessageToSend &message) {

View file

@ -23,11 +23,13 @@ struct SendAction;
void SendExistingDocument( void SendExistingDocument(
MessageToSend &&message, MessageToSend &&message,
not_null<DocumentData*> document); not_null<DocumentData*> document,
std::optional<MsgId> localMessageId = std::nullopt);
void SendExistingPhoto( void SendExistingPhoto(
MessageToSend &&message, MessageToSend &&message,
not_null<PhotoData*> photo); not_null<PhotoData*> photo,
std::optional<MsgId> localMessageId = std::nullopt);
bool SendDice(MessageToSend &message); bool SendDice(MessageToSend &message);