2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 22:25:12 +00:00

Move caption to the next album item on cancel.

After #4869 albums are sent with captions in the first media.
In case we cancel the first media leaving the rest of the album
the caption will be lost unless we move it to the new "first" media.
This commit is contained in:
John Preston
2018-12-26 11:22:36 +04:00
parent db064381d9
commit 7b5e5c2587
5 changed files with 83 additions and 35 deletions

View File

@@ -4898,37 +4898,13 @@ void ApiWrap::sendAlbumWithUploaded(
const auto albumIt = _sendingAlbums.find(groupId.raw());
Assert(albumIt != _sendingAlbums.end());
const auto &album = albumIt->second;
const auto proj = [](const SendingAlbum::Item &item) {
return item.msgId;
};
const auto itemIt = ranges::find(album->items, localId, proj);
Assert(itemIt != album->items.end());
Assert(!itemIt->media);
auto caption = item->originalText();
TextUtilities::Trim(caption);
auto sentEntities = TextUtilities::EntitiesToMTP(
caption.entities,
TextUtilities::ConvertOption::SkipLocal);
const auto flags = !sentEntities.v.isEmpty()
? MTPDinputSingleMedia::Flag::f_entities
: MTPDinputSingleMedia::Flag(0);
itemIt->media = MTP_inputSingleMedia(
MTP_flags(flags),
media,
MTP_long(randomId),
MTP_string(caption.text),
sentEntities);
album->fillMedia(item, media, randomId);
sendAlbumIfReady(album.get());
}
void ApiWrap::sendAlbumWithCancelled(
not_null<HistoryItem*> item,
const MessageGroupId &groupId) {
const auto localId = item->fullId();
const auto albumIt = _sendingAlbums.find(groupId.raw());
if (albumIt == _sendingAlbums.end()) {
// Sometimes we destroy item being sent already after the album
@@ -4940,14 +4916,7 @@ void ApiWrap::sendAlbumWithCancelled(
return;
}
const auto &album = albumIt->second;
const auto proj = [](const SendingAlbum::Item &item) {
return item.msgId;
};
const auto itemIt = ranges::find(album->items, localId, proj);
Assert(itemIt != album->items.end());
album->items.erase(itemIt);
album->removeItem(item);
sendAlbumIfReady(album.get());
}