mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-01 03:50:43 +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:
parent
db064381d9
commit
7b5e5c2587
@ -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());
|
||||
}
|
||||
|
||||
|
@ -564,7 +564,6 @@ int Options::findField(not_null<Ui::InputField*> field) const {
|
||||
&Option::field) - begin(_list);
|
||||
|
||||
Ensures(result >= 0 && result < _list.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,6 @@ const Set &Full::setOrDefault(Source source, Type type) const {
|
||||
const auto &result = my.hasValue(type) ? my : Defaults().set(source);
|
||||
|
||||
Ensures(result.hasValue(type));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/file_utilities.h"
|
||||
#include "core/mime_type.h"
|
||||
#include "media/media_audio.h"
|
||||
#include "history/history_item.h"
|
||||
#include "boxes/send_files_box.h"
|
||||
#include "media/media_clip_reader.h"
|
||||
#include "mainwidget.h"
|
||||
@ -24,6 +25,40 @@ namespace {
|
||||
|
||||
constexpr auto kThumbnailQuality = 87;
|
||||
|
||||
auto FindAlbumItem(
|
||||
std::vector<SendingAlbum::Item> &items,
|
||||
not_null<HistoryItem*> item) {
|
||||
const auto result = ranges::find(
|
||||
items,
|
||||
item->fullId(),
|
||||
&SendingAlbum::Item::msgId);
|
||||
|
||||
Ensures(result != end(items));
|
||||
return result;
|
||||
}
|
||||
|
||||
MTPInputSingleMedia PrepareAlbumItemMedia(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPInputMedia &media,
|
||||
uint64 randomId) {
|
||||
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);
|
||||
|
||||
return MTP_inputSingleMedia(
|
||||
MTP_flags(flags),
|
||||
media,
|
||||
MTP_long(randomId),
|
||||
MTP_string(caption.text),
|
||||
sentEntities);
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
using Storage::ValidateThumbDimensions;
|
||||
@ -241,6 +276,44 @@ void TaskQueueWorker::onTaskAdded() {
|
||||
SendingAlbum::SendingAlbum() : groupId(rand_value<uint64>()) {
|
||||
}
|
||||
|
||||
void SendingAlbum::fillMedia(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPInputMedia &media,
|
||||
uint64 randomId) {
|
||||
const auto i = FindAlbumItem(items, item);
|
||||
Assert(!i->media);
|
||||
|
||||
i->media = PrepareAlbumItemMedia(item, media, randomId);
|
||||
}
|
||||
|
||||
void SendingAlbum::refreshMediaCaption(not_null<HistoryItem*> item) {
|
||||
const auto i = FindAlbumItem(items, item);
|
||||
if (!i->media) {
|
||||
return;
|
||||
}
|
||||
i->media = i->media->match([&](const MTPDinputSingleMedia &data) {
|
||||
return PrepareAlbumItemMedia(item, data.vmedia, data.vrandom_id.v);
|
||||
});
|
||||
}
|
||||
|
||||
void SendingAlbum::removeItem(not_null<HistoryItem*> item) {
|
||||
const auto localId = item->fullId();
|
||||
const auto i = ranges::find(items, localId, &Item::msgId);
|
||||
const auto moveCaption = (items.size() > 1) && (i == begin(items));
|
||||
Assert(i != end(items));
|
||||
items.erase(i);
|
||||
if (moveCaption) {
|
||||
const auto caption = item->originalText();
|
||||
const auto firstId = items.front().msgId;
|
||||
if (const auto first = App::histItemById(firstId)) {
|
||||
// We don't need to finishEdition() here, because the whole
|
||||
// album will be rebuilt after one item was removed from it.
|
||||
first->setText(caption);
|
||||
refreshMediaCaption(first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileLoadResult::FileLoadResult(
|
||||
TaskId taskId,
|
||||
uint64 id,
|
||||
|
@ -163,6 +163,7 @@ struct SendingAlbum {
|
||||
struct Item {
|
||||
explicit Item(TaskId taskId) : taskId(taskId) {
|
||||
}
|
||||
|
||||
TaskId taskId;
|
||||
FullMsgId msgId;
|
||||
std::optional<MTPInputSingleMedia> media;
|
||||
@ -170,6 +171,13 @@ struct SendingAlbum {
|
||||
|
||||
SendingAlbum();
|
||||
|
||||
void fillMedia(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPInputMedia &media,
|
||||
uint64 randomId);
|
||||
void refreshMediaCaption(not_null<HistoryItem*> item);
|
||||
void removeItem(not_null<HistoryItem*> item);
|
||||
|
||||
uint64 groupId = 0;
|
||||
std::vector<Item> items;
|
||||
bool silent = false;
|
||||
|
Loading…
Reference in New Issue
Block a user