mirror of https://github.com/procxx/kepka.git
Refactored code.
- Refactored passing message id to edit media. - Removed get/setEditMedia from mainwidget. - Combined onEditMedia and onSendFileConfirm in single method. - Added argument in FileLoadTask to pass message id to edit media. - Renamed flags in apiwrap. - Added check for allowing edit media when use clipboard. - Removed unused fileIsValidForAlbum. - Removed LOGs. - Replaced _isNotAlbum with _isAlbum. - Removed _viaRemoteContent. - Removed _newMediaPath. - Added empty() to MessageGroupId.
This commit is contained in:
parent
4988d21819
commit
5d8888bb8b
|
@ -4471,7 +4471,8 @@ void ApiWrap::editMedia(
|
||||||
Storage::PreparedList &&list,
|
Storage::PreparedList &&list,
|
||||||
SendMediaType type,
|
SendMediaType type,
|
||||||
TextWithTags &&caption,
|
TextWithTags &&caption,
|
||||||
const SendOptions &options) {
|
const SendOptions &options,
|
||||||
|
MsgId msgIdToEdit) {
|
||||||
if (list.files.empty()) return;
|
if (list.files.empty()) return;
|
||||||
|
|
||||||
auto &file = list.files.front();
|
auto &file = list.files.front();
|
||||||
|
@ -4484,7 +4485,7 @@ void ApiWrap::editMedia(
|
||||||
to,
|
to,
|
||||||
caption,
|
caption,
|
||||||
nullptr,
|
nullptr,
|
||||||
true));
|
msgIdToEdit));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::sendFiles(
|
void ApiWrap::sendFiles(
|
||||||
|
@ -4620,17 +4621,17 @@ void ApiWrap::editUploadedPhoto(
|
||||||
MTPVector<MTPInputDocument>(),
|
MTPVector<MTPInputDocument>(),
|
||||||
MTP_int(0));
|
MTP_int(0));
|
||||||
|
|
||||||
auto flags2 = MTPmessages_EditMessage::Flag::f_message | 0;
|
auto flagsEditMsg = MTPmessages_EditMessage::Flag::f_message | 0;
|
||||||
flags2 |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
||||||
flags2 |= MTPmessages_EditMessage::Flag::f_entities;
|
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_entities;
|
||||||
flags2 |= MTPmessages_EditMessage::Flag::f_media;
|
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_media;
|
||||||
|
|
||||||
auto sentEntities = TextUtilities::EntitiesToMTP(
|
auto sentEntities = TextUtilities::EntitiesToMTP(
|
||||||
item->originalText().entities,
|
item->originalText().entities,
|
||||||
TextUtilities::ConvertOption::SkipLocal);
|
TextUtilities::ConvertOption::SkipLocal);
|
||||||
|
|
||||||
request(MTPmessages_EditMessage(
|
request(MTPmessages_EditMessage(
|
||||||
MTP_flags(flags2),
|
MTP_flags(flagsEditMsg),
|
||||||
item->history()->peer->input,
|
item->history()->peer->input,
|
||||||
MTP_int(item->id),
|
MTP_int(item->id),
|
||||||
MTP_string(item->originalText().text),
|
MTP_string(item->originalText().text),
|
||||||
|
@ -4683,18 +4684,17 @@ void ApiWrap::editUploadedDocument(
|
||||||
MTPVector<MTPInputDocument>(),
|
MTPVector<MTPInputDocument>(),
|
||||||
MTP_int(0));
|
MTP_int(0));
|
||||||
|
|
||||||
auto flags2 = MTPmessages_EditMessage::Flag::f_message | 0;
|
auto flagsEditMsg = MTPmessages_EditMessage::Flag::f_message | 0;
|
||||||
flags2 |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
||||||
flags2 |= MTPmessages_EditMessage::Flag::f_entities;
|
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_entities;
|
||||||
flags2 |= MTPmessages_EditMessage::Flag::f_media;
|
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_media;
|
||||||
|
|
||||||
auto sentEntities = TextUtilities::EntitiesToMTP(
|
auto sentEntities = TextUtilities::EntitiesToMTP(
|
||||||
item->originalText().entities,
|
item->originalText().entities,
|
||||||
TextUtilities::ConvertOption::SkipLocal);
|
TextUtilities::ConvertOption::SkipLocal);
|
||||||
|
|
||||||
|
|
||||||
request(MTPmessages_EditMessage(
|
request(MTPmessages_EditMessage(
|
||||||
MTP_flags(flags2),
|
MTP_flags(flagsEditMsg),
|
||||||
item->history()->peer->input,
|
item->history()->peer->input,
|
||||||
MTP_int(item->id),
|
MTP_int(item->id),
|
||||||
MTP_string(item->originalText().text),
|
MTP_string(item->originalText().text),
|
||||||
|
|
|
@ -332,7 +332,8 @@ public:
|
||||||
Storage::PreparedList &&list,
|
Storage::PreparedList &&list,
|
||||||
SendMediaType type,
|
SendMediaType type,
|
||||||
TextWithTags &&caption,
|
TextWithTags &&caption,
|
||||||
const SendOptions &options);
|
const SendOptions &options,
|
||||||
|
MsgId msgIdToEdit);
|
||||||
|
|
||||||
void sendUploadedPhoto(
|
void sendUploadedPhoto(
|
||||||
FullMsgId localId,
|
FullMsgId localId,
|
||||||
|
|
|
@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "mainwidget.h"
|
|
||||||
#include "media/clip/media_clip_reader.h"
|
#include "media/clip/media_clip_reader.h"
|
||||||
#include "storage/storage_media_prepare.h"
|
#include "storage/storage_media_prepare.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
@ -45,8 +44,9 @@ EditCaptionBox::EditCaptionBox(
|
||||||
, _msgId(item->fullId()) {
|
, _msgId(item->fullId()) {
|
||||||
Expects(item->media() != nullptr);
|
Expects(item->media() != nullptr);
|
||||||
Expects(item->media()->allowsEditCaption());
|
Expects(item->media()->allowsEditCaption());
|
||||||
|
|
||||||
_isAllowedEditMedia = item->media()->allowsEditMedia();
|
_isAllowedEditMedia = item->media()->allowsEditMedia();
|
||||||
_isNotAlbum = !item->groupId();
|
_isAlbum = !item->groupId().empty();
|
||||||
|
|
||||||
QSize dimensions;
|
QSize dimensions;
|
||||||
auto image = (Image*)nullptr;
|
auto image = (Image*)nullptr;
|
||||||
|
@ -288,9 +288,10 @@ void EditCaptionBox::updateEmojiPanelGeometry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditCaptionBox::prepareGifPreview(DocumentData* document) {
|
void EditCaptionBox::prepareGifPreview(DocumentData* document) {
|
||||||
|
const auto newPath = getNewMediaPath();
|
||||||
if (_gifPreview) {
|
if (_gifPreview) {
|
||||||
return;
|
return;
|
||||||
} else if (!document && _newMediaPath.isEmpty()) {
|
} else if (!document && newPath.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto callback = [=](Media::Clip::Notification notification) {
|
const auto callback = [=](Media::Clip::Notification notification) {
|
||||||
|
@ -301,9 +302,9 @@ void EditCaptionBox::prepareGifPreview(DocumentData* document) {
|
||||||
document,
|
document,
|
||||||
_msgId,
|
_msgId,
|
||||||
callback);
|
callback);
|
||||||
} else if (!_newMediaPath.isEmpty()) {
|
} else if (!newPath.isEmpty()) {
|
||||||
_gifPreview = Media::Clip::MakeReader(
|
_gifPreview = Media::Clip::MakeReader(
|
||||||
_newMediaPath,
|
newPath,
|
||||||
callback);
|
callback);
|
||||||
}
|
}
|
||||||
if (_gifPreview) _gifPreview->setAutoplay();
|
if (_gifPreview) _gifPreview->setAutoplay();
|
||||||
|
@ -339,23 +340,11 @@ void EditCaptionBox::updateEditPreview() {
|
||||||
const auto file = &_preparedList.files.front();
|
const auto file = &_preparedList.files.front();
|
||||||
const auto fileMedia = &file->information->media;
|
const auto fileMedia = &file->information->media;
|
||||||
|
|
||||||
const auto fileinfo = QFileInfo(_newMediaPath);
|
const auto fileinfo = QFileInfo(file->path);
|
||||||
const auto filename = fileinfo.fileName();
|
const auto filename = fileinfo.fileName();
|
||||||
const auto mimeType = Core::MimeTypeForFile(fileinfo).name();
|
const auto mimeType = Core::MimeTypeForFile(fileinfo).name();
|
||||||
|
|
||||||
if (!_isNotAlbum) {
|
if (!file->path.isEmpty()) {
|
||||||
// This check only for users, who chose not valid file with absolute path.
|
|
||||||
if ((!_newMediaPath.isEmpty()
|
|
||||||
&& !fileIsValidForAlbum(filename, mimeType))
|
|
||||||
// And for users, who send file via remoteContent.
|
|
||||||
|| _viaRemoteContent) {
|
|
||||||
_newMediaPath = QString();
|
|
||||||
_preparedList.files.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_newMediaPath.isEmpty()) {
|
|
||||||
_isImage = fileIsImage(filename, mimeType);
|
_isImage = fileIsImage(filename, mimeType);
|
||||||
}
|
}
|
||||||
_isAudio = false;
|
_isAudio = false;
|
||||||
|
@ -392,7 +381,7 @@ void EditCaptionBox::updateEditPreview() {
|
||||||
_doc = true;
|
_doc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_wayWrap->toggle(_isImage && _isNotAlbum, anim::type::instant);
|
_wayWrap->toggle(_isImage && !_isAlbum, anim::type::instant);
|
||||||
|
|
||||||
if (!_doc) {
|
if (!_doc) {
|
||||||
_thumb = App::pixmapFromImageInPlace(
|
_thumb = App::pixmapFromImageInPlace(
|
||||||
|
@ -411,18 +400,35 @@ void EditCaptionBox::createEditMediaButton() {
|
||||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_viaRemoteContent = !result.remoteContent.isEmpty();
|
|
||||||
if (!result.remoteContent.isEmpty()) {
|
if (!result.remoteContent.isEmpty()) {
|
||||||
_newMediaPath = QString();
|
// Don't use remoteContent to edit album item.
|
||||||
|
if (_isAlbum) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto image = Media::Clip::PrepareForSending(
|
||||||
|
QString(),
|
||||||
|
result.remoteContent
|
||||||
|
).thumbnail;
|
||||||
_preparedList = Storage::PrepareMediaFromImage(
|
_preparedList = Storage::PrepareMediaFromImage(
|
||||||
Media::Clip::PrepareForSending(QString(), result.remoteContent).thumbnail,
|
std::move(image),
|
||||||
std::move(result.remoteContent),
|
std::move(result.remoteContent),
|
||||||
st::sendMediaPreviewSize);
|
st::sendMediaPreviewSize);
|
||||||
} else if (!result.paths.isEmpty()) {
|
} else if (!result.paths.isEmpty()) {
|
||||||
_newMediaPath = result.paths.front();
|
auto list = Storage::PrepareMediaList(
|
||||||
_preparedList = Storage::PrepareMediaList(
|
QStringList(result.paths.front()),
|
||||||
QStringList(_newMediaPath),
|
|
||||||
st::sendMediaPreviewSize);
|
st::sendMediaPreviewSize);
|
||||||
|
|
||||||
|
// Don't rewrite _preparedList if new list is not valid for album.
|
||||||
|
if (_isAlbum) {
|
||||||
|
const auto fileMedia = &list.files.front().information->media;
|
||||||
|
if (!base::get_if<FileMediaInformation::Image>(fileMedia)
|
||||||
|
&& !base::get_if<FileMediaInformation::Video>(fileMedia)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_preparedList = std::move(list);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -431,9 +437,9 @@ void EditCaptionBox::createEditMediaButton() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto buttonCallback = [=] {
|
const auto buttonCallback = [=] {
|
||||||
const auto filters = _isNotAlbum
|
const auto filters = _isAlbum
|
||||||
? QStringList(FileDialog::AllFilesFilter())
|
? QStringList(qsl("Image and Video Files (*.png *.jpg *.mp4)"))
|
||||||
: QStringList(qsl("Image and Video Files (*.png *.jpg *.mp4)"));
|
: QStringList(FileDialog::AllFilesFilter());
|
||||||
FileDialog::GetOpenPath(
|
FileDialog::GetOpenPath(
|
||||||
this,
|
this,
|
||||||
lang(lng_choose_file),
|
lang(lng_choose_file),
|
||||||
|
@ -453,7 +459,7 @@ void EditCaptionBox::prepare() {
|
||||||
if (_isAllowedEditMedia) {
|
if (_isAllowedEditMedia) {
|
||||||
createEditMediaButton();
|
createEditMediaButton();
|
||||||
} else {
|
} else {
|
||||||
_newMediaPath = QString();
|
_preparedList.files.clear();
|
||||||
}
|
}
|
||||||
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||||
|
|
||||||
|
@ -465,6 +471,9 @@ void EditCaptionBox::prepare() {
|
||||||
not_null<const QMimeData*> data,
|
not_null<const QMimeData*> data,
|
||||||
Ui::InputField::MimeAction action) {
|
Ui::InputField::MimeAction action) {
|
||||||
if (action == Ui::InputField::MimeAction::Check) {
|
if (action == Ui::InputField::MimeAction::Check) {
|
||||||
|
if (!data->hasText() && !_isAllowedEditMedia) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (data->hasImage()) {
|
if (data->hasImage()) {
|
||||||
const auto image = qvariant_cast<QImage>(data->imageData());
|
const auto image = qvariant_cast<QImage>(data->imageData());
|
||||||
if (!image.isNull()) {
|
if (!image.isNull()) {
|
||||||
|
@ -497,6 +506,10 @@ void EditCaptionBox::prepare() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditCaptionBox::fileFromClipboard(not_null<const QMimeData*> data) {
|
bool EditCaptionBox::fileFromClipboard(not_null<const QMimeData*> data) {
|
||||||
|
if (!_isAllowedEditMedia) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto list = [&] {
|
auto list = [&] {
|
||||||
auto url = QList<QUrl>();
|
auto url = QList<QUrl>();
|
||||||
auto canAddUrl = false;
|
auto canAddUrl = false;
|
||||||
|
@ -527,13 +540,9 @@ bool EditCaptionBox::fileFromClipboard(not_null<const QMimeData*> data) {
|
||||||
return result;
|
return result;
|
||||||
}();
|
}();
|
||||||
_preparedList = std::move(list);
|
_preparedList = std::move(list);
|
||||||
_newMediaPath = _preparedList.files.empty()
|
|
||||||
? QString()
|
|
||||||
: _preparedList.files.front().path;
|
|
||||||
if (_preparedList.files.empty()) {
|
if (_preparedList.files.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_viaRemoteContent = false;
|
|
||||||
updateEditPreview();
|
updateEditPreview();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -748,7 +757,6 @@ void EditCaptionBox::save() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_preparedList.files.empty()) {
|
if (!_preparedList.files.empty()) {
|
||||||
App::main()->setEditMedia(item->fullId());
|
|
||||||
const auto textWithTags = _field->getTextWithAppliedMarkdown();
|
const auto textWithTags = _field->getTextWithAppliedMarkdown();
|
||||||
auto sending = TextWithEntities{
|
auto sending = TextWithEntities{
|
||||||
textWithTags.text,
|
textWithTags.text,
|
||||||
|
@ -760,7 +768,8 @@ void EditCaptionBox::save() {
|
||||||
std::move(_preparedList),
|
std::move(_preparedList),
|
||||||
(!_asFile && _isImage) ? SendMediaType::Photo : SendMediaType::File,
|
(!_asFile && _isImage) ? SendMediaType::Photo : SendMediaType::File,
|
||||||
_field->getTextWithAppliedMarkdown(),
|
_field->getTextWithAppliedMarkdown(),
|
||||||
ApiWrap::SendOptions(item->history()));
|
ApiWrap::SendOptions(item->history()),
|
||||||
|
item->fullId().msg);
|
||||||
closeBox();
|
closeBox();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,12 @@ private:
|
||||||
|
|
||||||
void createEditMediaButton();
|
void createEditMediaButton();
|
||||||
|
|
||||||
|
inline QString getNewMediaPath() {
|
||||||
|
return _preparedList.files.empty()
|
||||||
|
? QString()
|
||||||
|
: _preparedList.files.front().path;
|
||||||
|
}
|
||||||
|
|
||||||
not_null<Window::Controller*> _controller;
|
not_null<Window::Controller*> _controller;
|
||||||
FullMsgId _msgId;
|
FullMsgId _msgId;
|
||||||
Image *_thumbnailImage = nullptr;
|
Image *_thumbnailImage = nullptr;
|
||||||
|
@ -111,8 +117,7 @@ private:
|
||||||
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
|
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
|
||||||
QString _newMediaPath;
|
QString _newMediaPath;
|
||||||
bool _isAllowedEditMedia = false;
|
bool _isAllowedEditMedia = false;
|
||||||
bool _isNotAlbum = true;
|
bool _isAlbum = false;
|
||||||
bool _viaRemoteContent = false;
|
|
||||||
rpl::event_stream<> _editMediaClicks;
|
rpl::event_stream<> _editMediaClicks;
|
||||||
|
|
||||||
QString _error;
|
QString _error;
|
||||||
|
|
|
@ -122,22 +122,6 @@ bool fileIsImage(const QString &name, const QString &mime) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fileIsValidForAlbum(const QString &name, const QString &mime) {
|
|
||||||
QString lowermime = mime.toLower(), namelower = name.toLower();
|
|
||||||
if (lowermime.startsWith(qstr("video/mp4"))
|
|
||||||
|| lowermime.startsWith(qstr("image/jpeg"))
|
|
||||||
|| lowermime.startsWith(qstr("image/jpg"))
|
|
||||||
|| lowermime.startsWith(qstr("image/png"))) {
|
|
||||||
return true;
|
|
||||||
} else if (namelower.endsWith(qstr(".mp4"))
|
|
||||||
|| namelower.endsWith(qstr(".jpg"))
|
|
||||||
|| namelower.endsWith(qstr(".jpeg"))
|
|
||||||
|| namelower.endsWith(qstr(".png"))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString FileNameUnsafe(
|
QString FileNameUnsafe(
|
||||||
const QString &title,
|
const QString &title,
|
||||||
const QString &filter,
|
const QString &filter,
|
||||||
|
|
|
@ -72,7 +72,6 @@ struct VoiceData : public DocumentAdditionalData {
|
||||||
};
|
};
|
||||||
|
|
||||||
bool fileIsImage(const QString &name, const QString &mime);
|
bool fileIsImage(const QString &name, const QString &mime);
|
||||||
bool fileIsValidForAlbum(const QString &name, const QString &mime);
|
|
||||||
|
|
||||||
namespace Serialize {
|
namespace Serialize {
|
||||||
class Document;
|
class Document;
|
||||||
|
|
|
@ -64,7 +64,9 @@ void Groups::unregisterMessage(not_null<const HistoryItem*> item) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Groups::refreshMessage(not_null<HistoryItem*> item, bool forceRefresh) {
|
void Groups::refreshMessage(
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
|
bool justRefreshViews) {
|
||||||
if (!isGrouped(item)) {
|
if (!isGrouped(item)) {
|
||||||
unregisterMessage(item);
|
unregisterMessage(item);
|
||||||
return;
|
return;
|
||||||
|
@ -80,7 +82,7 @@ void Groups::refreshMessage(not_null<HistoryItem*> item, bool forceRefresh) {
|
||||||
}
|
}
|
||||||
auto &items = i->second.items;
|
auto &items = i->second.items;
|
||||||
|
|
||||||
if (forceRefresh) {
|
if (justRefreshViews) {
|
||||||
refreshViews(items);
|
refreshViews(items);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
void unregisterMessage(not_null<const HistoryItem*> item);
|
void unregisterMessage(not_null<const HistoryItem*> item);
|
||||||
void refreshMessage(
|
void refreshMessage(
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
bool forceRefresh = false);
|
bool justRefreshViews = false);
|
||||||
|
|
||||||
const Group *find(not_null<HistoryItem*> item) const;
|
const Group *find(not_null<HistoryItem*> item) const;
|
||||||
|
|
||||||
|
|
|
@ -98,8 +98,11 @@ struct MessageGroupId {
|
||||||
return static_cast<Type>(value);
|
return static_cast<Type>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool empty() const {
|
||||||
|
return value == None;
|
||||||
|
}
|
||||||
explicit operator bool() const {
|
explicit operator bool() const {
|
||||||
return value != None;
|
return !empty();
|
||||||
}
|
}
|
||||||
Underlying raw() const {
|
Underlying raw() const {
|
||||||
return static_cast<Underlying>(value);
|
return static_cast<Underlying>(value);
|
||||||
|
|
|
@ -3054,7 +3054,6 @@ void HistoryWidget::chooseAttach() {
|
||||||
uploadFile(result.remoteContent, SendMediaType::File);
|
uploadFile(result.remoteContent, SendMediaType::File);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG((result.paths[0]));
|
|
||||||
auto list = Storage::PrepareMediaList(
|
auto list = Storage::PrepareMediaList(
|
||||||
result.paths,
|
result.paths,
|
||||||
st::sendMediaPreviewSize);
|
st::sendMediaPreviewSize);
|
||||||
|
@ -4422,7 +4421,6 @@ void HistoryWidget::documentEdited(
|
||||||
const FullMsgId &newId,
|
const FullMsgId &newId,
|
||||||
bool silent,
|
bool silent,
|
||||||
const MTPInputFile &file) {
|
const MTPInputFile &file) {
|
||||||
LOG(("DOCUMENT EDITED %1").arg(newId.msg));
|
|
||||||
Auth().api().editUploadedDocument(newId, file, std::nullopt, silent);
|
Auth().api().editUploadedDocument(newId, file, std::nullopt, silent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4430,7 +4428,6 @@ void HistoryWidget::photoEdited(
|
||||||
const FullMsgId &newId,
|
const FullMsgId &newId,
|
||||||
bool silent,
|
bool silent,
|
||||||
const MTPInputFile &file) {
|
const MTPInputFile &file) {
|
||||||
LOG(("PHOTO EDITED %1").arg(newId.msg));
|
|
||||||
Auth().api().editUploadedPhoto(newId, file, silent);
|
Auth().api().editUploadedPhoto(newId, file, silent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4466,7 +4463,6 @@ void HistoryWidget::documentProgress(const FullMsgId &newId) {
|
||||||
? document->uploadingData->offset
|
? document->uploadingData->offset
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
LOG(("ITEM EXISTS %1 TYPE: %2 PROGRESS: %3").arg(newId.msg).arg(sendAction == SendAction::Type::UploadFile).arg(progress));
|
|
||||||
updateSendAction(
|
updateSendAction(
|
||||||
item->history(),
|
item->history(),
|
||||||
sendAction,
|
sendAction,
|
||||||
|
|
|
@ -842,11 +842,9 @@ void MainWidget::cancelUploadLayer(not_null<HistoryItem*> item) {
|
||||||
Ui::hideLayer();
|
Ui::hideLayer();
|
||||||
if (const auto item = App::histItemById(itemId)) {
|
if (const auto item = App::histItemById(itemId)) {
|
||||||
const auto history = item->history();
|
const auto history = item->history();
|
||||||
if (!item->isEditingMedia()) {
|
if (!IsServerMsgId(itemId.msg)) {
|
||||||
if (!IsServerMsgId(itemId.msg)) {
|
item->destroy();
|
||||||
item->destroy();
|
history->requestChatListMessage();
|
||||||
history->requestChatListMessage();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
item->returnSavedMedia();
|
item->returnSavedMedia();
|
||||||
session().uploader().cancel(item->fullId());
|
session().uploader().cancel(item->fullId());
|
||||||
|
@ -1318,15 +1316,8 @@ void MainWidget::inlineResultLoadFailed(FileLoader *loader, bool started) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::onSendFileConfirm(
|
void MainWidget::onSendFileConfirm(
|
||||||
const std::shared_ptr<FileLoadResult> &file) {
|
|
||||||
_history->sendFileConfirmed(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWidget::onEditMedia(
|
|
||||||
const std::shared_ptr<FileLoadResult> &file,
|
const std::shared_ptr<FileLoadResult> &file,
|
||||||
const FullMsgId &oldId) {
|
const std::optional<FullMsgId> &oldId) {
|
||||||
LOG(("ON EDIT MEDIA"));
|
|
||||||
App::main()->setEditMedia(FullMsgId());
|
|
||||||
_history->sendFileConfirmed(file, oldId);
|
_history->sendFileConfirmed(file, oldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3721,7 +3712,6 @@ void MainWidget::updateReceived(const mtpPrime *from, const mtpPrime *end) {
|
||||||
void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||||
switch (updates.type()) {
|
switch (updates.type()) {
|
||||||
case mtpc_updates: {
|
case mtpc_updates: {
|
||||||
LOG(("TYPE 1"));
|
|
||||||
auto &d = updates.c_updates();
|
auto &d = updates.c_updates();
|
||||||
if (d.vseq.v) {
|
if (d.vseq.v) {
|
||||||
if (d.vseq.v <= updSeq) {
|
if (d.vseq.v <= updSeq) {
|
||||||
|
@ -3742,7 +3732,6 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case mtpc_updatesCombined: {
|
case mtpc_updatesCombined: {
|
||||||
LOG(("TYPE 2"));
|
|
||||||
auto &d = updates.c_updatesCombined();
|
auto &d = updates.c_updatesCombined();
|
||||||
if (d.vseq_start.v) {
|
if (d.vseq_start.v) {
|
||||||
if (d.vseq_start.v <= updSeq) {
|
if (d.vseq_start.v <= updSeq) {
|
||||||
|
@ -3763,7 +3752,6 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case mtpc_updateShort: {
|
case mtpc_updateShort: {
|
||||||
LOG(("TYPE 3"));
|
|
||||||
auto &d = updates.c_updateShort();
|
auto &d = updates.c_updateShort();
|
||||||
feedUpdate(d.vupdate);
|
feedUpdate(d.vupdate);
|
||||||
|
|
||||||
|
@ -3771,7 +3759,6 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case mtpc_updateShortMessage: {
|
case mtpc_updateShortMessage: {
|
||||||
LOG(("TYPE 4"));
|
|
||||||
auto &d = updates.c_updateShortMessage();
|
auto &d = updates.c_updateShortMessage();
|
||||||
if (!session().data().userLoaded(d.vuser_id.v)
|
if (!session().data().userLoaded(d.vuser_id.v)
|
||||||
|| (d.has_via_bot_id() && !session().data().userLoaded(d.vvia_bot_id.v))
|
|| (d.has_via_bot_id() && !session().data().userLoaded(d.vvia_bot_id.v))
|
||||||
|
@ -3787,7 +3774,6 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case mtpc_updateShortChatMessage: {
|
case mtpc_updateShortChatMessage: {
|
||||||
LOG(("TYPE 5"));
|
|
||||||
auto &d = updates.c_updateShortChatMessage();
|
auto &d = updates.c_updateShortChatMessage();
|
||||||
const auto noFrom = !session().data().userLoaded(d.vfrom_id.v);
|
const auto noFrom = !session().data().userLoaded(d.vfrom_id.v);
|
||||||
const auto chat = session().data().chatLoaded(d.vchat_id.v);
|
const auto chat = session().data().chatLoaded(d.vchat_id.v);
|
||||||
|
@ -3809,7 +3795,6 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case mtpc_updateShortSentMessage: {
|
case mtpc_updateShortSentMessage: {
|
||||||
LOG(("TYPE 6"));
|
|
||||||
auto &d = updates.c_updateShortSentMessage();
|
auto &d = updates.c_updateShortSentMessage();
|
||||||
if (!IsServerMsgId(d.vid.v)) {
|
if (!IsServerMsgId(d.vid.v)) {
|
||||||
LOG(("API Error: Bad msgId got from server: %1").arg(d.vid.v));
|
LOG(("API Error: Bad msgId got from server: %1").arg(d.vid.v));
|
||||||
|
@ -3849,7 +3834,6 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case mtpc_updatesTooLong: {
|
case mtpc_updatesTooLong: {
|
||||||
LOG(("TYPE 7"));
|
|
||||||
MTP_LOG(0, ("getDifference { good - updatesTooLong received }%1").arg(cTestMode() ? " TESTMODE" : ""));
|
MTP_LOG(0, ("getDifference { good - updatesTooLong received }%1").arg(cTestMode() ? " TESTMODE" : ""));
|
||||||
return getDifference();
|
return getDifference();
|
||||||
} break;
|
} break;
|
||||||
|
|
|
@ -111,13 +111,6 @@ public:
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
void setEditMedia(FullMsgId flag) {
|
|
||||||
_editMedia = flag;
|
|
||||||
}
|
|
||||||
FullMsgId getEditMedia() const {
|
|
||||||
return _editMedia;
|
|
||||||
}
|
|
||||||
|
|
||||||
void openPeerByName(
|
void openPeerByName(
|
||||||
const QString &name,
|
const QString &name,
|
||||||
MsgId msgId = ShowAtUnreadMsgId,
|
MsgId msgId = ShowAtUnreadMsgId,
|
||||||
|
@ -165,9 +158,9 @@ public:
|
||||||
QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms);
|
QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms);
|
||||||
void checkMainSectionToLayer();
|
void checkMainSectionToLayer();
|
||||||
|
|
||||||
void onSendFileConfirm(const std::shared_ptr<FileLoadResult> &file);
|
void onSendFileConfirm(
|
||||||
void onEditMedia(const std::shared_ptr<FileLoadResult> &file,
|
const std::shared_ptr<FileLoadResult> &file,
|
||||||
const FullMsgId &oldId);
|
const std::optional<FullMsgId> &oldId);
|
||||||
bool onSendSticker(DocumentData *sticker);
|
bool onSendSticker(DocumentData *sticker);
|
||||||
|
|
||||||
void destroyData();
|
void destroyData();
|
||||||
|
@ -553,6 +546,4 @@ private:
|
||||||
bool _firstColumnResizing = false;
|
bool _firstColumnResizing = false;
|
||||||
int _firstColumnResizingShift = 0;
|
int _firstColumnResizingShift = 0;
|
||||||
|
|
||||||
FullMsgId _editMedia;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -529,7 +529,7 @@ FileLoadTask::FileLoadTask(
|
||||||
const FileLoadTo &to,
|
const FileLoadTo &to,
|
||||||
const TextWithTags &caption,
|
const TextWithTags &caption,
|
||||||
std::shared_ptr<SendingAlbum> album,
|
std::shared_ptr<SendingAlbum> album,
|
||||||
std::optional<bool> edit)
|
MsgId msgIdToEdit)
|
||||||
: _id(rand_value<uint64>())
|
: _id(rand_value<uint64>())
|
||||||
, _to(to)
|
, _to(to)
|
||||||
, _album(std::move(album))
|
, _album(std::move(album))
|
||||||
|
@ -538,7 +538,7 @@ FileLoadTask::FileLoadTask(
|
||||||
, _information(std::move(information))
|
, _information(std::move(information))
|
||||||
, _type(type)
|
, _type(type)
|
||||||
, _caption(caption)
|
, _caption(caption)
|
||||||
, _edit(edit) {
|
, _msgIdToEdit(msgIdToEdit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileLoadTask::FileLoadTask(
|
FileLoadTask::FileLoadTask(
|
||||||
|
@ -704,7 +704,7 @@ void FileLoadTask::process() {
|
||||||
_caption,
|
_caption,
|
||||||
_album);
|
_album);
|
||||||
|
|
||||||
_result->edit = _edit.value_or(false);
|
_result->edit = (_msgIdToEdit > 0);
|
||||||
|
|
||||||
QString filename, filemime;
|
QString filename, filemime;
|
||||||
qint64 filesize = 0;
|
qint64 filesize = 0;
|
||||||
|
@ -984,11 +984,13 @@ void FileLoadTask::finish() {
|
||||||
lng_send_image_too_large(lt_name, _filepath)),
|
lng_send_image_too_large(lt_name, _filepath)),
|
||||||
LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
removeFromAlbum();
|
removeFromAlbum();
|
||||||
} else if (App::main()->getEditMedia()) {
|
|
||||||
LOG(("FINISH UPLOAD EDIT"));
|
|
||||||
App::main()->onEditMedia(_result, App::main()->getEditMedia());
|
|
||||||
} else if (App::main()) {
|
} else if (App::main()) {
|
||||||
App::main()->onSendFileConfirm(_result);
|
const auto fullId = _msgIdToEdit
|
||||||
|
? std::make_optional(FullMsgId(
|
||||||
|
peerToChannel(_to.peer),
|
||||||
|
_msgIdToEdit))
|
||||||
|
: std::nullopt;
|
||||||
|
App::main()->onSendFileConfirm(_result, fullId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,7 @@ public:
|
||||||
const FileLoadTo &to,
|
const FileLoadTo &to,
|
||||||
const TextWithTags &caption,
|
const TextWithTags &caption,
|
||||||
std::shared_ptr<SendingAlbum> album = nullptr,
|
std::shared_ptr<SendingAlbum> album = nullptr,
|
||||||
std::optional<bool> edit = false);
|
MsgId msgIdToEdit = 0);
|
||||||
FileLoadTask(
|
FileLoadTask(
|
||||||
const QByteArray &voice,
|
const QByteArray &voice,
|
||||||
int32 duration,
|
int32 duration,
|
||||||
|
@ -323,7 +323,7 @@ private:
|
||||||
VoiceWaveform _waveform;
|
VoiceWaveform _waveform;
|
||||||
SendMediaType _type;
|
SendMediaType _type;
|
||||||
TextWithTags _caption;
|
TextWithTags _caption;
|
||||||
std::optional<bool> _edit;
|
MsgId _msgIdToEdit;
|
||||||
|
|
||||||
std::shared_ptr<FileLoadResult> _result;
|
std::shared_ptr<FileLoadResult> _result;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue