diff --git a/Telegram/SourceFiles/api/api_sending.cpp b/Telegram/SourceFiles/api/api_sending.cpp index fdcd0314c..ebd0be1c7 100644 --- a/Telegram/SourceFiles/api/api_sending.cpp +++ b/Telegram/SourceFiles/api/api_sending.cpp @@ -122,20 +122,18 @@ void SendExistingMedia( session->data().registerMessageRandomId(randomId, newId); - if (!forwarding) { - history->addNewLocalMessage( - newId.msg, - flags, - clientFlags, - 0, - replyTo, - HistoryItem::NewMessageDate(message.action.options.scheduled), - messageFromId, - messagePostAuthor, - media, - caption, - MTPReplyMarkup()); - } + history->addNewLocalMessage( + newId.msg, + flags, + clientFlags, + 0, + replyTo, + HistoryItem::NewMessageDate(message.action.options.scheduled), + messageFromId, + messagePostAuthor, + media, + caption, + MTPReplyMarkup()); auto performRequest = [=](const auto &repeatRequest) -> void { auto &histories = history->owner().histories(); @@ -301,36 +299,34 @@ bool SendDice( session->data().registerMessageRandomId(randomId, newId); - if (!forwarding) { - const auto views = 1; - const auto forwards = 0; - history->addNewMessage( - MTP_message( - MTP_flags(flags), - MTP_int(newId.msg), - peerToMTP(messageFromId), - peerToMTP(history->peer->id), - MTPMessageFwdHeader(), - MTPint(), // via_bot_id - replyHeader, - MTP_int(HistoryItem::NewMessageDate( - message.action.options.scheduled)), - MTP_string(), - MTP_messageMediaDice(MTP_int(0), MTP_string(emoji)), - MTPReplyMarkup(), - MTP_vector(), - MTP_int(views), - MTP_int(forwards), - MTPMessageReplies(), - MTPint(), // edit_date - MTP_string(messagePostAuthor), - MTPlong(), - //MTPMessageReactions(), - MTPVector(), - MTPint()), // ttl_period - clientFlags, - NewMessageType::Unread); - } + const auto views = 1; + const auto forwards = 0; + history->addNewMessage( + MTP_message( + MTP_flags(flags), + MTP_int(newId.msg), + peerToMTP(messageFromId), + peerToMTP(history->peer->id), + MTPMessageFwdHeader(), + MTPint(), // via_bot_id + replyHeader, + MTP_int(HistoryItem::NewMessageDate( + message.action.options.scheduled)), + MTP_string(), + MTP_messageMediaDice(MTP_int(0), MTP_string(emoji)), + MTPReplyMarkup(), + MTP_vector(), + MTP_int(views), + MTP_int(forwards), + MTPMessageReplies(), + MTPint(), // edit_date + MTP_string(messagePostAuthor), + MTPlong(), + //MTPMessageReactions(), + MTPVector(), + MTPint()), // ttl_period + clientFlags, + NewMessageType::Unread); const auto requestType = Data::Histories::RequestType::Send; histories.sendRequest(history, requestType, [=](Fn finish) { diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 0df03776c..285ecca62 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3795,10 +3795,12 @@ void ApiWrap::forwardMessagesUnquoted( auto currentGroupId = items.front()->groupId(); auto lastGroup = LastGroupType::None; auto ids = QVector(); - auto randomIds = QVector(); + auto randomIds = QVector(); auto fromIter = items.begin(); auto toIter = items.begin(); auto messageGroupCount = 0; + auto messageFromId = anonymousPost ? 0 : _session->userPeerId(); + auto messagePostAuthor = peer->isBroadcast() ? _session->user()->name : QString(); const auto needNextGroup = [&] (not_null item) { auto lastGroupCheck = false; @@ -3845,7 +3847,7 @@ void ApiWrap::forwardMessagesUnquoted( auto currentIds = QVector(); currentIds.push_back(MTP_int(item->id)); - auto currentRandomId = randomIds.takeFirst(); + auto currentRandomId = MTP_long(randomIds.takeFirst()); auto currentRandomIds = QVector(); currentRandomIds.push_back(currentRandomId); @@ -3885,12 +3887,27 @@ void ApiWrap::forwardMessagesUnquoted( mediaInputs->reserve(ids.size()); mediaRefs->reserve(ids.size()); + const auto views = 1; + const auto forwards = 0; + const auto newGroupId = openssl::RandomValue(); + + auto msgFlags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media; + auto clientFlags = NewMessageClientFlags(); + + FillMessagePostFlags(action, peer, msgFlags); + + if (action.options.scheduled) { + msgFlags |= MTPDmessage::Flag::f_from_scheduled; + } else { + clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry; + } + for (auto i = fromIter, e = toIter; i != e; i++) { const auto item = *i; const auto media = item->media(); medias->push_back(media); - auto inputMedia = media->photo() + const auto inputMedia = media->photo() ? MTP_inputMediaPhoto(MTP_flags(0), media->photo()->mtpInput(), MTPint()) : MTP_inputMediaDocument(MTP_flags(0), media->document()->mtpInput(), MTPint(), MTPstring()); auto caption = cForwardCaptioned() @@ -3905,14 +3922,49 @@ void ApiWrap::forwardMessagesUnquoted( ? MTPDinputSingleMedia::Flag::f_entities : MTPDinputSingleMedia::Flag(0); + const auto newId = FullMsgId( + peerToChannel(peer->id), + _session->data().nextLocalMessageId()); auto randomId = randomIds.takeFirst(); mediaInputs->push_back(MTP_inputSingleMedia( MTP_flags(flags), inputMedia, - randomId, + MTP_long(randomId), MTP_string(caption.text), sentEntities)); + + _session->data().registerMessageRandomId(randomId, newId); + + if (const auto photo = media->photo()) { + history->addNewLocalMessage( + newId.msg, + msgFlags, + clientFlags, + 0, // viaBotId + 0, // replyTo + HistoryItem::NewMessageDate(action.options.scheduled), + messageFromId, + messagePostAuthor, + photo, + caption, + MTPReplyMarkup(), + newGroupId); + } else if (const auto document = media->document()) { + history->addNewLocalMessage( + newId.msg, + msgFlags, + clientFlags, + 0, // viaBotId + 0, // replyTo + HistoryItem::NewMessageDate(action.options.scheduled), + messageFromId, + messagePostAuthor, + document, + caption, + MTPReplyMarkup(), + newGroupId); + } } const auto finalFlags = MTPmessages_SendMultiMedia::Flags(0) @@ -4149,7 +4201,7 @@ void ApiWrap::forwardMessagesUnquoted( fromIter = i; } ids.push_back(MTP_int(item->id)); - randomIds.push_back(MTP_long(randomId)); + randomIds.push_back(randomId); if (item->media() && item->media()->canBeGrouped()) { lastGroup = ((item->media()->photo() || (item->media()->document() @@ -4515,37 +4567,35 @@ void ApiWrap::sendMessage( sendFlags |= MTPmessages_SendMessage::Flag::f_schedule_date; } else { clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry; - } - if (!forwarding) { - const auto views = 1; - const auto forwards = 0; - lastMessage = history->addNewMessage( - MTP_message( - MTP_flags(flags), - MTP_int(newId.msg), - peerToMTP(messageFromId), - peerToMTP(peer->id), - MTPMessageFwdHeader(), - MTPint(), // via_bot_id - replyHeader, - MTP_int( - HistoryItem::NewMessageDate(action.options.scheduled)), - msgText, - media, - MTPReplyMarkup(), - localEntities, - MTP_int(views), - MTP_int(forwards), - MTPMessageReplies(), - MTPint(), // edit_date - MTP_string(messagePostAuthor), - MTPlong(), - //MTPMessageReactions(), - MTPVector(), - MTPint()), // ttl_period - clientFlags, - NewMessageType::Unread); - } + } + const auto views = 1; + const auto forwards = 0; + lastMessage = history->addNewMessage( + MTP_message( + MTP_flags(flags), + MTP_int(newId.msg), + peerToMTP(messageFromId), + peerToMTP(peer->id), + MTPMessageFwdHeader(), + MTPint(), // via_bot_id + replyHeader, + MTP_int( + HistoryItem::NewMessageDate(action.options.scheduled)), + msgText, + media, + MTPReplyMarkup(), + localEntities, + MTP_int(views), + MTP_int(forwards), + MTPMessageReplies(), + MTPint(), // edit_date + MTP_string(messagePostAuthor), + MTPlong(), + //MTPMessageReactions(), + MTPVector(), + MTPint()), // ttl_period + clientFlags, + NewMessageType::Unread); histories.sendRequest(history, requestType, [=](Fn finish) { history->sendRequestId = request(MTPmessages_SendMessage( MTP_flags(sendFlags), diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index c678d24d8..e92ec9d87 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -542,7 +542,8 @@ not_null History::addNewLocalMessage( const QString &postAuthor, not_null document, const TextWithEntities &caption, - const MTPReplyMarkup &markup) { + const MTPReplyMarkup &markup, + uint64 newGroupId) { return addNewItem( makeMessage( id, @@ -555,7 +556,8 @@ not_null History::addNewLocalMessage( postAuthor, document, caption, - markup), + markup, + newGroupId), true); } @@ -570,7 +572,8 @@ not_null History::addNewLocalMessage( const QString &postAuthor, not_null photo, const TextWithEntities &caption, - const MTPReplyMarkup &markup) { + const MTPReplyMarkup &markup, + uint64 newGroupId) { return addNewItem( makeMessage( id, @@ -583,7 +586,8 @@ not_null History::addNewLocalMessage( postAuthor, photo, caption, - markup), + markup, + newGroupId), true); } diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index de84e3dcf..b068377fb 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -142,7 +142,8 @@ public: const QString &postAuthor, not_null document, const TextWithEntities &caption, - const MTPReplyMarkup &markup); + const MTPReplyMarkup &markup, + uint64 newGroupId = 0); not_null addNewLocalMessage( MsgId id, MTPDmessage::Flags flags, @@ -154,7 +155,8 @@ public: const QString &postAuthor, not_null photo, const TextWithEntities &caption, - const MTPReplyMarkup &markup); + const MTPReplyMarkup &markup, + uint64 newGroupId = 0); not_null addNewLocalMessage( MsgId id, MTPDmessage::Flags flags, diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 8c6bf3b2f..6d09fe388 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -697,7 +697,8 @@ HistoryMessage::HistoryMessage( const QString &postAuthor, not_null document, const TextWithEntities &caption, - const MTPReplyMarkup &markup) + const MTPReplyMarkup &markup, + uint64 newGroupId) : HistoryItem( history, id, @@ -709,6 +710,11 @@ HistoryMessage::HistoryMessage( _media = std::make_unique(this, document); setText(caption); + + if (newGroupId) { + setGroupId( + MessageGroupId::FromRaw(history->peer->id, newGroupId)); + } } HistoryMessage::HistoryMessage( @@ -723,7 +729,8 @@ HistoryMessage::HistoryMessage( const QString &postAuthor, not_null photo, const TextWithEntities &caption, - const MTPReplyMarkup &markup) + const MTPReplyMarkup &markup, + uint64 newGroupId) : HistoryItem( history, id, @@ -735,6 +742,11 @@ HistoryMessage::HistoryMessage( _media = std::make_unique(this, photo); setText(caption); + + if (newGroupId) { + setGroupId( + MessageGroupId::FromRaw(history->peer->id, newGroupId)); + } } HistoryMessage::HistoryMessage( diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 36e3ac653..4a2e9fa79 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -87,7 +87,8 @@ public: const QString &postAuthor, not_null document, const TextWithEntities &caption, - const MTPReplyMarkup &markup); // local document + const MTPReplyMarkup &markup, + uint64 newGroupId = 0); // local document HistoryMessage( not_null history, MsgId id, @@ -100,7 +101,8 @@ public: const QString &postAuthor, not_null photo, const TextWithEntities &caption, - const MTPReplyMarkup &markup); // local photo + const MTPReplyMarkup &markup, + uint64 newGroupId = 0); // local photo HistoryMessage( not_null history, MsgId id,