2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-01 23:25:15 +00:00

voice messages moved to documents with waveforms

This commit is contained in:
John Preston
2016-02-12 19:35:06 +03:00
parent ffa588bf5d
commit 189d0e8de3
36 changed files with 1615 additions and 2495 deletions

View File

@@ -198,10 +198,11 @@ FileLoadTask::FileLoadTask(const QImage &image, PrepareMediaType type, const Fil
, _result(0) {
}
FileLoadTask::FileLoadTask(const QByteArray &audio, int32 duration, const FileLoadTo &to) : _id(MTP::nonce<uint64>())
FileLoadTask::FileLoadTask(const QByteArray &voice, int32 duration, const VoiceWaveform &waveform, const FileLoadTo &to) : _id(MTP::nonce<uint64>())
, _to(to)
, _content(audio)
, _content(voice)
, _duration(duration)
, _waveform(waveform)
, _type(PrepareAudio)
, _confirm(FileLoadNoForceConfirm)
, _result(0) {
@@ -220,7 +221,7 @@ void FileLoadTask::process() {
QString thumbname = "thumb.jpg";
QByteArray thumbdata;
bool animated = false;
bool animated = false, song = false, gif = false, voice = (_type == PrepareAudio);
QImage fullimage = _image;
if (!_filepath.isEmpty()) {
@@ -232,30 +233,32 @@ void FileLoadTask::process() {
filesize = info.size();
filemime = mimeTypeForFile(info).name();
filename = info.fileName();
if (filesize <= MaxUploadPhotoSize && _type != PrepareAudio) {
if (filesize <= MaxUploadPhotoSize && !voice) {
bool opaque = (filemime != stickerMime);
fullimage = App::readImage(_filepath, 0, opaque, &animated);
}
} else if (!_content.isEmpty()) {
filesize = _content.size();
MimeType mimeType = mimeTypeForData(_content);
filemime = mimeType.name();
if (filesize <= MaxUploadPhotoSize && _type != PrepareAudio) {
bool opaque = (filemime != stickerMime);
fullimage = App::readImage(_content, 0, opaque, &animated);
}
if (filemime == "image/jpeg") {
filename = filedialogDefaultName(qsl("image"), qsl(".jpg"), QString(), true);
} else if (_type == PrepareAudio) {
if (voice) {
filename = filedialogDefaultName(qsl("audio"), qsl(".ogg"), QString(), true);
filemime = "audio/ogg";
} else {
QString ext;
QStringList patterns = mimeType.globPatterns();
if (!patterns.isEmpty()) {
ext = patterns.front().replace('*', QString());
MimeType mimeType = mimeTypeForData(_content);
filemime = mimeType.name();
if (filesize <= MaxUploadPhotoSize && !voice) {
bool opaque = (filemime != stickerMime);
fullimage = App::readImage(_content, 0, opaque, &animated);
}
if (filemime == "image/jpeg") {
filename = filedialogDefaultName(qsl("image"), qsl(".jpg"), QString(), true);
} else {
QString ext;
QStringList patterns = mimeType.globPatterns();
if (!patterns.isEmpty()) {
ext = patterns.front().replace('*', QString());
}
filename = filedialogDefaultName(qsl("file"), ext, QString(), true);
}
filename = filedialogDefaultName(qsl("file"), ext, QString(), true);
}
} else if (!_image.isNull()) {
_image = QImage();
@@ -292,10 +295,8 @@ void FileLoadTask::process() {
MTPPhotoSize thumbSize(MTP_photoSizeEmpty(MTP_string("")));
MTPPhoto photo(MTP_photoEmpty(MTP_long(0)));
MTPDocument document(MTP_documentEmpty(MTP_long(0)));
MTPAudio audio(MTP_audioEmpty(MTP_long(0)));
bool song = false, gif = false;
if (_type != PrepareAudio) {
if (!voice) {
if (filemime == qstr("audio/mp3") || filemime == qstr("audio/m4a") || filemime == qstr("audio/aac") || filemime == qstr("audio/ogg") || filemime == qstr("audio/flac") ||
filename.endsWith(qstr(".mp3"), Qt::CaseInsensitive) || filename.endsWith(qstr(".m4a"), Qt::CaseInsensitive) ||
filename.endsWith(qstr(".aac"), Qt::CaseInsensitive) || filename.endsWith(qstr(".ogg"), Qt::CaseInsensitive) ||
@@ -358,7 +359,7 @@ void FileLoadTask::process() {
}
}
if (!fullimage.isNull() && fullimage.width() > 0 && !song && !gif) {
if (!fullimage.isNull() && fullimage.width() > 0 && !song && !gif && !voice) {
int32 w = fullimage.width(), h = fullimage.height();
attributes.push_back(MTP_documentAttributeImageSize(MTP_int(w), MTP_int(h)));
@@ -408,8 +409,10 @@ void FileLoadTask::process() {
}
}
if (_type == PrepareAudio) {
audio = MTP_audio(MTP_long(_id), MTP_long(0), MTP_int(unixtime()), MTP_int(_duration), MTP_string(filemime), MTP_int(filesize), MTP_int(MTP::maindc()));
if (voice) {
attributes[0] = MTP_documentAttributeAudio(MTP_int(MTPDdocumentAttributeAudio::flag_voice | MTPDdocumentAttributeAudio::flag_waveform), MTP_int(_duration), MTPstring(), MTPstring(), MTP_string(documentWaveformEncode5bit(_waveform)));
attributes.resize(1);
document = MTP_document(MTP_long(_id), MTP_long(0), MTP_int(unixtime()), MTP_string(filemime), MTP_int(filesize), thumbSize, MTP_int(MTP::maindc()), MTP_vector<MTPDocumentAttribute>(attributes));
} else {
document = MTP_document(MTP_long(_id), MTP_long(0), MTP_int(unixtime()), MTP_string(filemime), MTP_int(filesize), thumbSize, MTP_int(MTP::maindc()), MTP_vector<MTPDocumentAttribute>(attributes));
if (photo.type() == mtpc_photoEmpty) {
@@ -431,7 +434,6 @@ void FileLoadTask::process() {
_result->thumb = thumb;
_result->photo = photo;
_result->audio = audio;
_result->document = document;
_result->photoThumbs = photoThumbs;
}