Skip to content

Commit 6619ccc

Browse files
committed
Allow sending videos as files.
1 parent b28cc7c commit 6619ccc

8 files changed

Lines changed: 84 additions & 42 deletions

File tree

Telegram/Resources/langs/lang.strings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5116,6 +5116,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
51165116
"lng_send_grouped" = "Group items";
51175117
"lng_send_compressed_one" = "Compress the image";
51185118
"lng_send_compressed" = "Compress images";
5119+
"lng_send_as_documents_one" = "Send as a document";
5120+
"lng_send_as_documents" = "Send as documents";
51195121
"lng_send_media_invalid_files" = "Sorry, no valid files found.";
51205122
"lng_send_image" = "Send an image";
51215123
"lng_send_file" = "Send as a file";
@@ -5349,10 +5351,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
53495351
"lng_drag_images_here" = "Drop images here";
53505352
"lng_drag_photos_here" = "Drop photos here";
53515353
"lng_drag_files_here" = "Drop files here";
5354+
"lng_drag_media_here" = "Drop photos and videos";
53525355

53535356
"lng_drag_to_send_quick" = "to send them in a quick way";
53545357
"lng_drag_to_send_no_compression" = "to send them without compression";
53555358
"lng_drag_to_send_files" = "to send them as documents";
5359+
"lng_drag_to_send_media" = "to send them as media files";
53565360

53575361
"lng_selected_clear" = "Cancel";
53585362
"lng_selected_delete" = "Delete";

Telegram/SourceFiles/boxes/edit_caption_box.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,9 @@ void EditCaptionBox::setupDragArea() {
841841
auto computeState = [=](const QMimeData *data) {
842842
using DragState = Storage::MimeDataState;
843843
const auto state = Storage::ComputeMimeDataState(data);
844-
return (state == DragState::PhotoFiles || state == DragState::Image)
844+
return (state == DragState::PhotoFiles
845+
|| state == DragState::Image
846+
|| state == DragState::MediaFiles)
845847
? (_asFile ? DragState::Files : DragState::Image)
846848
: state;
847849
};

Telegram/SourceFiles/boxes/send_files_box.cpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,16 @@ SendFilesBox::Block::Block(
264264
});
265265
_preview.reset(preview);
266266
} else {
267-
const auto media = Ui::SingleMediaPreview::Create(
268-
parent,
269-
st,
270-
gifPaused,
271-
first,
272-
[=](Ui::AttachActionType type) {
273-
return actionAllowed((*_items)[from], type);
274-
});
267+
const auto media = way.sendImagesAsPhotos()
268+
? Ui::SingleMediaPreview::Create(
269+
parent,
270+
st,
271+
gifPaused,
272+
first,
273+
[=](Ui::AttachActionType type) {
274+
return actionAllowed((*_items)[from], type);
275+
})
276+
: nullptr;
275277
if (media) {
276278
_isSingleMedia = true;
277279
_preview.reset(media);
@@ -633,7 +635,9 @@ void SendFilesBox::setupDragArea() {
633635
auto computeState = [=](const QMimeData *data) {
634636
using DragState = Storage::MimeDataState;
635637
const auto state = Storage::ComputeMimeDataState(data);
636-
return (state == DragState::PhotoFiles || state == DragState::Image)
638+
return (state == DragState::PhotoFiles
639+
|| state == DragState::Image
640+
|| state == DragState::MediaFiles)
637641
? (_sendWay.current().sendImagesAsPhotos()
638642
? DragState::Image
639643
: DragState::Files)
@@ -973,11 +977,11 @@ void SendFilesBox::initSendWay() {
973977
const auto was = hidden();
974978
updateCaptionPlaceholder();
975979
updateEmojiPanelGeometry();
976-
for (auto &block : _blocks) {
977-
block.setSendWay(value);
978-
}
979-
refreshButtons();
980-
refreshPriceTag();
980+
applyBlockChanges();
981+
generatePreviewFrom(0);
982+
_inner->resizeToWidth(st::boxWideWidth);
983+
refreshControls();
984+
captionResized();
981985
if (was != hidden()) {
982986
updateBoxSize();
983987
updateControlsGeometry();
@@ -1296,15 +1300,15 @@ void SendFilesBox::setupSendWayControls() {
12961300
_st.files.check);
12971301
_sendImagesAsPhotos.create(
12981302
this,
1299-
tr::lng_send_compressed(tr::now),
1300-
_sendWay.current().sendImagesAsPhotos(),
1303+
tr::lng_send_as_documents(tr::now),
1304+
!_sendWay.current().sendImagesAsPhotos(),
13011305
_st.files.checkbox,
13021306
_st.files.check);
13031307

13041308
_sendWay.changes(
13051309
) | rpl::on_next([=](SendFilesWay value) {
13061310
_groupFiles->setChecked(value.groupFiles());
1307-
_sendImagesAsPhotos->setChecked(value.sendImagesAsPhotos());
1311+
_sendImagesAsPhotos->setChecked(!value.sendImagesAsPhotos());
13081312
}, lifetime());
13091313

13101314
_groupFiles->checkedChanges(
@@ -1326,10 +1330,10 @@ void SendFilesBox::setupSendWayControls() {
13261330
_sendImagesAsPhotos->checkedChanges(
13271331
) | rpl::on_next([=](bool checked) {
13281332
auto sendWay = _sendWay.current();
1329-
if (sendWay.sendImagesAsPhotos() == checked) {
1333+
if (sendWay.sendImagesAsPhotos() == !checked) {
13301334
return;
13311335
}
1332-
sendWay.setSendImagesAsPhotos(checked);
1336+
sendWay.setSendImagesAsPhotos(!checked);
13331337
if (checkWithWay(sendWay)) {
13341338
_sendWay = sendWay;
13351339
} else {
@@ -1349,9 +1353,10 @@ void SendFilesBox::setupSendWayControls() {
13491353
rpl::combine(
13501354
_groupFiles->checkedValue(),
13511355
_sendImagesAsPhotos->checkedValue()
1352-
) | rpl::on_next([=](bool groupFiles, bool asPhoto) {
1356+
) | rpl::on_next([=](bool groupFiles, bool asDocuments) {
13531357
_wayRemember->setVisible(
1354-
(groupFiles != groupFilesFirst) || (asPhoto != asPhotosFirst));
1358+
(groupFiles != groupFilesFirst)
1359+
|| ((!asDocuments) != asPhotosFirst));
13551360
captionResized();
13561361
}, lifetime());
13571362

@@ -1388,8 +1393,8 @@ void SendFilesBox::updateSendWayControls() {
13881393
_sendImagesAsPhotos->setVisible(
13891394
_list.hasSendImagesAsPhotosOption(onlyOne));
13901395
_sendImagesAsPhotos->setText((_list.files.size() > 1)
1391-
? tr::lng_send_compressed(tr::now)
1392-
: tr::lng_send_compressed_one(tr::now));
1396+
? tr::lng_send_as_documents(tr::now)
1397+
: tr::lng_send_as_documents_one(tr::now));
13931398

13941399
_hintLabel->setVisible(
13951400
_show->session().settings().photoEditorHintShown()

Telegram/SourceFiles/history/history_drag_area.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ DragArea::Areas DragArea::SetupDragAreaToContainer(
9393
moveToTop(attachDragDocument);
9494
break;
9595
case DragState::PhotoFiles:
96+
case DragState::MediaFiles:
9697
attachDragDocument->resize(
9798
width() - horizontalMargins,
9899
(height() - verticalMargins) / 2);
@@ -147,6 +148,20 @@ DragArea::Areas DragArea::SetupDragAreaToContainer(
147148
attachDragDocument->otherEnter();
148149
attachDragPhoto->otherEnter();
149150
break;
151+
case DragState::MediaFiles:
152+
attachDragDocument->setText(
153+
tr::lng_drag_files_here(tr::now),
154+
hideSubtext
155+
? QString()
156+
: tr::lng_drag_to_send_files(tr::now));
157+
attachDragPhoto->setText(
158+
tr::lng_drag_media_here(tr::now),
159+
hideSubtext
160+
? QString()
161+
: tr::lng_drag_to_send_media(tr::now));
162+
attachDragDocument->otherEnter();
163+
attachDragPhoto->otherEnter();
164+
break;
150165
case DragState::Image:
151166
attachDragPhoto->setText(
152167
tr::lng_drag_images_here(tr::now),

Telegram/SourceFiles/storage/localimageloader.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -887,22 +887,24 @@ void FileLoadTask::process(Args &&args) {
887887
isVideo = true;
888888
auto coverWidth = video->thumbnail.width();
889889
auto coverHeight = video->thumbnail.height();
890-
if (video->isGifv && !_album) {
891-
attributes.push_back(MTP_documentAttributeAnimated());
892-
}
893-
auto flags = MTPDdocumentAttributeVideo::Flags(0);
894-
if (video->supportsStreaming) {
895-
flags |= MTPDdocumentAttributeVideo::Flag::f_supports_streaming;
890+
if (!_forceFile) {
891+
if (video->isGifv && !_album) {
892+
attributes.push_back(MTP_documentAttributeAnimated());
893+
}
894+
auto flags = MTPDdocumentAttributeVideo::Flags(0);
895+
if (video->supportsStreaming) {
896+
flags |= MTPDdocumentAttributeVideo::Flag::f_supports_streaming;
897+
}
898+
const auto realSeconds = video->duration / 1000.;
899+
attributes.push_back(MTP_documentAttributeVideo(
900+
MTP_flags(flags),
901+
MTP_double(realSeconds),
902+
MTP_int(coverWidth),
903+
MTP_int(coverHeight),
904+
MTPint(),
905+
MTPdouble(),
906+
MTPstring()));
896907
}
897-
const auto realSeconds = video->duration / 1000.;
898-
attributes.push_back(MTP_documentAttributeVideo(
899-
MTP_flags(flags),
900-
MTP_double(realSeconds),
901-
MTP_int(coverWidth),
902-
MTP_int(coverHeight),
903-
MTPint(), // preload_prefix_size
904-
MTPdouble(), // video_start_ts
905-
MTPstring())); // video_codec
906908

907909
if (args.generateGoodThumbnail) {
908910
goodThumbnail = video->thumbnail;

Telegram/SourceFiles/storage/storage_media_prepare.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ MimeDataState ComputeMimeDataState(const QMimeData *data) {
133133
}
134134

135135
auto allAreSmallImages = true;
136+
auto allAreMedia = true;
136137
for (const auto &url : urls) {
137138
if (!url.isLocalFile()) {
138139
return MimeDataState::None;
@@ -162,9 +163,17 @@ MimeDataState ComputeMimeDataState(const QMimeData *data) {
162163
}
163164
}
164165
}
166+
if (allAreMedia) {
167+
const auto type = DetectNameType(file);
168+
if (type != NameType::Image && type != NameType::Video) {
169+
allAreMedia = false;
170+
}
171+
}
165172
}
166173
return allAreSmallImages
167174
? MimeDataState::PhotoFiles
175+
: allAreMedia
176+
? MimeDataState::MediaFiles
168177
: MimeDataState::Files;
169178
}
170179

Telegram/SourceFiles/storage/storage_media_prepare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum class MimeDataState {
2727
None,
2828
Files,
2929
PhotoFiles,
30+
MediaFiles,
3031
//PremiumFile,
3132
Image,
3233
};

Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,13 @@ bool PreparedList::hasGroupOption(bool slowmode) const {
235235

236236
bool PreparedList::hasSendImagesAsPhotosOption(bool slowmode) const {
237237
using Type = PreparedFile::Type;
238-
return slowmode
239-
? ((files.size() == 1) && (files.front().type == Type::Photo))
240-
: ranges::contains(files, Type::Photo, &PreparedFile::type);
238+
if (slowmode) {
239+
const auto t = files.front().type;
240+
return (files.size() == 1)
241+
&& (t == Type::Photo || t == Type::Video);
242+
}
243+
return ranges::contains(files, Type::Photo, &PreparedFile::type)
244+
|| ranges::contains(files, Type::Video, &PreparedFile::type);
241245
}
242246

243247
bool PreparedList::canHaveEditorHintLabel() const {

0 commit comments

Comments
 (0)