Fix crash when forwarding text message and photo

This commit is contained in:
Eric Kotato 2021-03-29 19:56:00 +03:00
parent cec3ced431
commit 6018a52828

View file

@ -3799,16 +3799,12 @@ void ApiWrap::forwardMessagesUnquoted(
auto localIds = std::shared_ptr<base::flat_map<uint64, FullMsgId>>(); auto localIds = std::shared_ptr<base::flat_map<uint64, FullMsgId>>();
auto fromIter = items.begin(); auto fromIter = items.begin();
auto toIter = items.begin(); auto toIter = items.begin();
auto messageGroupCount = 0;
const auto needNextGroup = [&] (not_null<HistoryItem *> item) { const auto needNextGroup = [&] (not_null<HistoryItem *> item) {
if (cForwardAlbumsAsIs()) { auto lastGroupCheck = false;
const auto newFrom = item->history()->peer;
const auto newGroupId = item->groupId();
return forwardFrom != newFrom
|| currentGroupId != newGroupId;
} else if (cForwardGrouped()) {
if (item->media() && item->media()->canBeGrouped()) { if (item->media() && item->media()->canBeGrouped()) {
return lastGroup != ((item->media()->photo() lastGroupCheck = lastGroup != ((item->media()->photo()
|| (item->media()->document() || (item->media()->document()
&& item->media()->document()->isVideoFile())) && item->media()->document()->isVideoFile()))
? LastGroupType::Medias ? LastGroupType::Medias
@ -3817,15 +3813,24 @@ void ApiWrap::forwardMessagesUnquoted(
? LastGroupType::Music ? LastGroupType::Music
: LastGroupType::Documents); : LastGroupType::Documents);
} else { } else {
return lastGroup != LastGroupType::None; lastGroupCheck = lastGroup != LastGroupType::None;
} }
if (cForwardAlbumsAsIs()) {
const auto newFrom = item->history()->peer;
const auto newGroupId = item->groupId();
return forwardFrom != newFrom
|| currentGroupId != newGroupId
|| lastGroupCheck;
} else if (cForwardGrouped()) {
return lastGroupCheck;
} else { } else {
return true; return true;
} }
}; };
const auto isGrouped = [&] { const auto isGrouped = [&] {
return lastGroup != LastGroupType::None && fromIter != toIter; return lastGroup != LastGroupType::None && messageGroupCount > 1;
}; };
const auto forwardQuotedSingle = [&] (not_null<HistoryItem *> item) { const auto forwardQuotedSingle = [&] (not_null<HistoryItem *> item) {
@ -4142,6 +4147,7 @@ void ApiWrap::forwardMessagesUnquoted(
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = openssl::RandomValue<uint64>();
if (needNextGroup(item)) { if (needNextGroup(item)) {
sendAccumulated(); sendAccumulated();
messageGroupCount = 0;
forwardFrom = item->history()->peer; forwardFrom = item->history()->peer;
currentGroupId = item->groupId(); currentGroupId = item->groupId();
fromIter = i; fromIter = i;
@ -4161,6 +4167,7 @@ void ApiWrap::forwardMessagesUnquoted(
lastGroup = LastGroupType::None; lastGroup = LastGroupType::None;
} }
toIter = ++i; toIter = ++i;
messageGroupCount++;
} }
sendAccumulated(); sendAccumulated();
_session->data().sendHistoryChangeNotifications(); _session->data().sendHistoryChangeNotifications();