mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Fix grouping of music files / just files.
This commit is contained in:
parent
0d37949e74
commit
012ebdd15e
7 changed files with 52 additions and 30 deletions
|
@ -4234,6 +4234,7 @@ void ApiWrap::sendFiles(
|
||||||
? type
|
? type
|
||||||
: SendMediaType::Photo;
|
: SendMediaType::Photo;
|
||||||
break;
|
break;
|
||||||
|
case Ui::PreparedFile::AlbumType::Music:
|
||||||
case Ui::PreparedFile::AlbumType::Video:
|
case Ui::PreparedFile::AlbumType::Video:
|
||||||
case Ui::PreparedFile::AlbumType::File:
|
case Ui::PreparedFile::AlbumType::File:
|
||||||
type = SendMediaType::File;
|
type = SendMediaType::File;
|
||||||
|
|
|
@ -603,9 +603,10 @@ void EditCaptionBox::createEditMediaButton() {
|
||||||
if (Core::IsMimeSticker(mime)) {
|
if (Core::IsMimeSticker(mime)) {
|
||||||
showError(tr::lng_edit_media_invalid_file);
|
showError(tr::lng_edit_media_invalid_file);
|
||||||
return false;
|
return false;
|
||||||
} else if (_isAlbum) { // #TODO edit in file-albums
|
} else if (_isAlbum) { // #TODO files edit in file-albums
|
||||||
if (!Core::IsMimeAcceptedForAlbum(mime)
|
if (!Core::IsMimeAcceptedForAlbum(mime)
|
||||||
|| file.type == Ui::PreparedFile::AlbumType::File
|
|| file.type == Ui::PreparedFile::AlbumType::File
|
||||||
|
|| file.type == Ui::PreparedFile::AlbumType::Music
|
||||||
|| file.type == Ui::PreparedFile::AlbumType::None) {
|
|| file.type == Ui::PreparedFile::AlbumType::None) {
|
||||||
showError(tr::lng_edit_media_album_error);
|
showError(tr::lng_edit_media_album_error);
|
||||||
return false;
|
return false;
|
||||||
|
@ -710,7 +711,9 @@ bool EditCaptionBox::fileFromClipboard(not_null<const QMimeData*> data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto file = &list.files.front();
|
const auto file = &list.files.front();
|
||||||
if (_isAlbum && (file->type == AlbumType::File || file->type == AlbumType::None)) {
|
if (_isAlbum && (file->type == AlbumType::File
|
||||||
|
|| file->type == AlbumType::None
|
||||||
|
|| file->type == AlbumType::Music)) {
|
||||||
const auto imageAsDoc = [&] {
|
const auto imageAsDoc = [&] {
|
||||||
using Info = Ui::PreparedFileInformation;
|
using Info = Ui::PreparedFileInformation;
|
||||||
const auto fileMedia = &file->information->media;
|
const auto fileMedia = &file->information->media;
|
||||||
|
|
|
@ -118,8 +118,7 @@ SendFilesBox::Block::Block(
|
||||||
const auto count = till - from;
|
const auto count = till - from;
|
||||||
const auto my = gsl::make_span(*items).subspan(from, count);
|
const auto my = gsl::make_span(*items).subspan(from, count);
|
||||||
const auto &first = my.front();
|
const auto &first = my.front();
|
||||||
_isAlbum = (my.size() > 1)
|
_isAlbum = (my.size() > 1);
|
||||||
|| (first.type == Ui::PreparedFile::AlbumType::Photo);
|
|
||||||
if (_isAlbum) {
|
if (_isAlbum) {
|
||||||
const auto preview = Ui::CreateChild<Ui::AlbumPreview>(
|
const auto preview = Ui::CreateChild<Ui::AlbumPreview>(
|
||||||
parent.get(),
|
parent.get(),
|
||||||
|
@ -492,6 +491,7 @@ void SendFilesBox::generatePreviewFrom(int fromBlock) {
|
||||||
const auto albumCount = (i - albumStart);
|
const auto albumCount = (i - albumStart);
|
||||||
if ((type == Type::File)
|
if ((type == Type::File)
|
||||||
|| (type == Type::None)
|
|| (type == Type::None)
|
||||||
|
|| (type == Type::Music)
|
||||||
|| (albumCount == Ui::MaxAlbumItems())) {
|
|| (albumCount == Ui::MaxAlbumItems())) {
|
||||||
pushBlock(std::exchange(albumStart, -1), i);
|
pushBlock(std::exchange(albumStart, -1), i);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1508,10 +1508,7 @@ bool DocumentData::isAudioFile() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DocumentData::isSharedMediaMusic() const {
|
bool DocumentData::isSharedMediaMusic() const {
|
||||||
if (const auto songData = song()) {
|
return isSong();
|
||||||
return (songData->duration > 0);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DocumentData::isVideoFile() const {
|
bool DocumentData::isVideoFile() const {
|
||||||
|
|
|
@ -257,6 +257,7 @@ std::optional<PreparedList> PreparedFileFromFilesDialog(
|
||||||
// const auto file = &list.files.front();
|
// const auto file = &list.files.front();
|
||||||
// if (!Core::IsMimeAcceptedForAlbum(mimeFile)
|
// if (!Core::IsMimeAcceptedForAlbum(mimeFile)
|
||||||
// || file->type == PreparedFile::AlbumType::File
|
// || file->type == PreparedFile::AlbumType::File
|
||||||
|
// || file->type == PreparedFile::AlbumType::Music
|
||||||
// || file->type == PreparedFile::AlbumType::None) {
|
// || file->type == PreparedFile::AlbumType::None) {
|
||||||
// errorCallback(tr::lng_edit_media_album_error);
|
// errorCallback(tr::lng_edit_media_album_error);
|
||||||
// return std::nullopt;
|
// return std::nullopt;
|
||||||
|
@ -339,6 +340,7 @@ void PrepareDetails(PreparedFile &file, int previewWidth) {
|
||||||
|
|
||||||
using Image = PreparedFileInformation::Image;
|
using Image = PreparedFileInformation::Image;
|
||||||
using Video = PreparedFileInformation::Video;
|
using Video = PreparedFileInformation::Video;
|
||||||
|
using Song = PreparedFileInformation::Song;
|
||||||
if (const auto image = std::get_if<Image>(
|
if (const auto image = std::get_if<Image>(
|
||||||
&file.information->media)) {
|
&file.information->media)) {
|
||||||
if (ValidPhotoForAlbum(*image, file.information->filemime)) {
|
if (ValidPhotoForAlbum(*image, file.information->filemime)) {
|
||||||
|
@ -365,6 +367,8 @@ void PrepareDetails(PreparedFile &file, int previewWidth) {
|
||||||
file.preview.setDevicePixelRatio(cRetinaFactor());
|
file.preview.setDevicePixelRatio(cRetinaFactor());
|
||||||
file.type = PreparedFile::AlbumType::Video;
|
file.type = PreparedFile::AlbumType::Video;
|
||||||
}
|
}
|
||||||
|
} else if (const auto song = std::get_if<Song>(&file.information->media)) {
|
||||||
|
file.type = PreparedFile::AlbumType::Music;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,21 +73,28 @@ bool PreparedList::canBeSentInSlowmodeWith(const PreparedList &other) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using Type = PreparedFile::AlbumType;
|
||||||
auto &&all = ranges::view::concat(files, other.files);
|
auto &&all = ranges::view::concat(files, other.files);
|
||||||
const auto hasNonGrouping = ranges::contains(
|
const auto has = [&](Type type) {
|
||||||
all,
|
return ranges::contains(all, type, &PreparedFile::type);
|
||||||
PreparedFile::AlbumType::None,
|
};
|
||||||
&PreparedFile::type);
|
const auto hasNonGrouping = has(Type::None);
|
||||||
const auto hasFiles = ranges::contains(
|
const auto hasPhotos = has(Type::Photo);
|
||||||
all,
|
const auto hasFiles = has(Type::File);
|
||||||
PreparedFile::AlbumType::File,
|
const auto hasVideos = has(Type::Video);
|
||||||
&PreparedFile::type);
|
const auto hasMusic = has(Type::Music);
|
||||||
const auto hasVideos = ranges::contains(
|
|
||||||
all,
|
|
||||||
PreparedFile::AlbumType::Video,
|
|
||||||
&PreparedFile::type);
|
|
||||||
|
|
||||||
// File-s and Video-s never can be grouped.
|
// File-s and Video-s never can be grouped.
|
||||||
|
// Music-s can be grouped only with themselves.
|
||||||
|
if (hasNonGrouping) {
|
||||||
|
return false;
|
||||||
|
} else if (hasFiles) {
|
||||||
|
return !hasMusic && !hasVideos;
|
||||||
|
} else if (hasVideos) {
|
||||||
|
return !hasMusic && !hasFiles;
|
||||||
|
} else if (hasMusic) {
|
||||||
|
return !hasVideos && !hasFiles && !hasPhotos;
|
||||||
|
}
|
||||||
return !hasNonGrouping && (!hasFiles || !hasVideos);
|
return !hasNonGrouping && (!hasFiles || !hasVideos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,34 +146,42 @@ std::vector<PreparedGroup> DivideByGroups(
|
||||||
|
|
||||||
auto group = Ui::PreparedList();
|
auto group = Ui::PreparedList();
|
||||||
|
|
||||||
|
enum class GroupType {
|
||||||
|
PhotoVideo,
|
||||||
|
File,
|
||||||
|
Music,
|
||||||
|
None,
|
||||||
|
};
|
||||||
// For groupType Type::Video means media album,
|
// For groupType Type::Video means media album,
|
||||||
// Type::File means file album,
|
// Type::File means file album,
|
||||||
// Type::None means no grouping.
|
// Type::None means no grouping.
|
||||||
using Type = Ui::PreparedFile::AlbumType;
|
using Type = Ui::PreparedFile::AlbumType;
|
||||||
auto groupType = Type::None;
|
auto groupType = GroupType::None;
|
||||||
|
|
||||||
auto result = std::vector<PreparedGroup>();
|
auto result = std::vector<PreparedGroup>();
|
||||||
auto pushGroup = [&] {
|
auto pushGroup = [&] {
|
||||||
result.push_back(PreparedGroup{
|
result.push_back(PreparedGroup{
|
||||||
.list = base::take(group),
|
.list = base::take(group),
|
||||||
.grouped = (groupType != Type::None)
|
.grouped = (groupType != GroupType::None)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
for (auto i = 0; i != list.files.size(); ++i) {
|
for (auto i = 0; i != list.files.size(); ++i) {
|
||||||
auto &file = list.files[i];
|
auto &file = list.files[i];
|
||||||
const auto fileGroupType = (file.type == Type::Video)
|
const auto fileGroupType = (file.type == Type::Music)
|
||||||
? (groupFiles ? Type::Video : Type::None)
|
? (groupFiles ? GroupType::Music : GroupType::None)
|
||||||
|
: (file.type == Type::Video)
|
||||||
|
? (groupFiles ? GroupType::PhotoVideo : GroupType::None)
|
||||||
: (file.type == Type::Photo)
|
: (file.type == Type::Photo)
|
||||||
? ((groupFiles && sendImagesAsPhotos)
|
? ((groupFiles && sendImagesAsPhotos)
|
||||||
? Type::Video
|
? GroupType::PhotoVideo
|
||||||
: (groupFiles && !sendImagesAsPhotos)
|
: (groupFiles && !sendImagesAsPhotos)
|
||||||
? Type::File
|
? GroupType::File
|
||||||
: Type::None)
|
: GroupType::None)
|
||||||
: (file.type == Type::File)
|
: (file.type == Type::File)
|
||||||
? (groupFiles ? Type::File : Type::None)
|
? (groupFiles ? GroupType::File : GroupType::None)
|
||||||
: Type::None;
|
: GroupType::None;
|
||||||
if ((!group.files.empty() && groupType != fileGroupType)
|
if ((!group.files.empty() && groupType != fileGroupType)
|
||||||
|| ((groupType != Type::None)
|
|| ((groupType != GroupType::None)
|
||||||
&& (group.files.size() == Ui::MaxAlbumItems()))) {
|
&& (group.files.size() == Ui::MaxAlbumItems()))) {
|
||||||
pushGroup();
|
pushGroup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,12 @@ struct PreparedFile {
|
||||||
// Photo-s can be grouped if 'groupFiles'.
|
// Photo-s can be grouped if 'groupFiles'.
|
||||||
// Photo-s + Video-s can be grouped if 'groupFiles && sendImagesAsPhotos'.
|
// Photo-s + Video-s can be grouped if 'groupFiles && sendImagesAsPhotos'.
|
||||||
// Video-s can be grouped if 'groupFiles'.
|
// Video-s can be grouped if 'groupFiles'.
|
||||||
|
// Music-s can be grouped if 'groupFiles'.
|
||||||
enum class AlbumType {
|
enum class AlbumType {
|
||||||
File,
|
File,
|
||||||
Photo,
|
Photo,
|
||||||
Video,
|
Video,
|
||||||
|
Music,
|
||||||
None,
|
None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue