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

View file

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