diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 4424995a71..3273af203a 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -406,7 +406,7 @@ void Application::uploadProfilePhoto(const QImage &tosend, const PeerId &peerId) int32 filesize = 0; QByteArray data; - ReadyLocalMedia ready(ToPreparePhoto, file, filename, filesize, data, id, id, peerId, photo, photoThumbs, MTP_documentEmpty(MTP_long(0)), jpeg); + ReadyLocalMedia ready(ToPreparePhoto, file, filename, filesize, data, id, id, peerId, photo, photoThumbs, MTP_documentEmpty(MTP_long(0)), jpeg, false); connect(App::uploader(), SIGNAL(photoReady(MsgId, const MTPInputFile &)), App::app(), SLOT(photoUpdated(MsgId, const MTPInputFile &)), Qt::UniqueConnection); diff --git a/Telegram/SourceFiles/boxes/photosendbox.cpp b/Telegram/SourceFiles/boxes/photosendbox.cpp index ad45e6584f..064a717e37 100644 --- a/Telegram/SourceFiles/boxes/photosendbox.cpp +++ b/Telegram/SourceFiles/boxes/photosendbox.cpp @@ -119,7 +119,7 @@ a_opacity(0, 1) { void PhotoSendBox::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { - onSend(); + onSend((e->modifiers().testFlag(Qt::ControlModifier) || e->modifiers().testFlag(Qt::MetaModifier)) && e->modifiers().testFlag(Qt::ShiftModifier)); } else if (e->key() == Qt::Key_Escape) { onCancel(); } @@ -200,18 +200,19 @@ void PhotoSendBox::animStep(float64 ms) { update(); } -void PhotoSendBox::onSend() { +void PhotoSendBox::onSend(bool ctrlShiftEnter) { if (!_img) { - if (App::main()) App::main()->confirmShareContact(_phone, _fname, _lname); + if (App::main()) App::main()->confirmShareContact(ctrlShiftEnter, _phone, _fname, _lname); } else { if (!_compressed.isHidden()) { cSetCompressPastedImage(_compressed.checked()); App::writeUserConfig(); } if (_compressed.isHidden() || _compressed.checked()) { + _img->ctrlShiftEnter = ctrlShiftEnter; if (App::main()) App::main()->confirmSendImage(*_img); } else { - if (App::main()) App::main()->confirmSendImageUncompressed(); + if (App::main()) App::main()->confirmSendImageUncompressed(ctrlShiftEnter); } } emit closed(); diff --git a/Telegram/SourceFiles/boxes/photosendbox.h b/Telegram/SourceFiles/boxes/photosendbox.h index b350089cf2..a219e827a0 100644 --- a/Telegram/SourceFiles/boxes/photosendbox.h +++ b/Telegram/SourceFiles/boxes/photosendbox.h @@ -36,7 +36,7 @@ public: public slots: - void onSend(); + void onSend(bool ctrlShiftEnter = false); void onCancel(); private: diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index b687279581..64d30d34ca 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -2235,7 +2235,7 @@ mtpRequestId HistoryWidget::onForward(const PeerId &peer, SelectedItemSet toForw hist->loadAround(0); if (item->id > 0 && msg) { - App::main()->readServerHistory(item->history(), false); + App::main()->readServerHistory(hist, false); newId = clientMsgId(); hist->addToBackForwarded(newId, msg); @@ -2244,7 +2244,7 @@ mtpRequestId HistoryWidget::onForward(const PeerId &peer, SelectedItemSet toForw // newId = clientMsgId(); // MTP::send(MTPmessages_ForwardMessage(histPeer->input, MTP_int(item->id), MTP_long(randomId)), App::main()->rpcDone(&MainWidget::sentFullDataReceived, randomId)); } else if (msg) { - App::main()->readServerHistory(item->history(), false); + App::main()->readServerHistory(hist, false); newId = clientMsgId(); @@ -2282,25 +2282,28 @@ void HistoryWidget::onShareContact(const PeerId &peer, UserData *contact) { App::main()->showPeer(peer, 0, false, true); if (!hist) return; - shareContact(contact->phone, contact->firstName, contact->lastName, int32(contact->id & 0xFFFFFFFF)); + shareContact(peer, contact->phone, contact->firstName, contact->lastName, int32(contact->id & 0xFFFFFFFF)); } -void HistoryWidget::shareContact(const QString &phone, const QString &fname, const QString &lname, int32 userId) { - App::main()->readServerHistory(hist, false); +void HistoryWidget::shareContact(const PeerId &peer, const QString &phone, const QString &fname, const QString &lname, int32 userId) { + History *h = App::history(peer); + App::main()->readServerHistory(h, false); uint64 randomId = MTP::nonce(); MsgId newId = clientMsgId(); - hist->loadAround(0); + h->loadAround(0); - hist->addToBack(MTP_message(MTP_int(newId), MTP_int(MTP::authedId()), App::peerToMTP(histPeer->id), MTP_bool(true), MTP_bool(true), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname), MTP_int(userId)))); + h->addToBack(MTP_message(MTP_int(newId), MTP_int(MTP::authedId()), App::peerToMTP(peer), MTP_bool(true), MTP_bool(true), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname), MTP_int(userId)))); - MTP::send(MTPmessages_SendMedia(histPeer->input, MTP_inputMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname)), MTP_long(randomId)), App::main()->rpcDone(&MainWidget::sentFullDataReceived, randomId)); + MTP::send(MTPmessages_SendMedia(App::peer(peer)->input, MTP_inputMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname)), MTP_long(randomId)), App::main()->rpcDone(&MainWidget::sentFullDataReceived, randomId)); App::historyRegRandom(randomId, newId); - App::main()->historyToDown(hist); + if (hist && histPeer && peer == histPeer->id) { + App::main()->historyToDown(hist); + } App::main()->dialogsToUp(); - peerMessagesUpdated(); + peerMessagesUpdated(peer); } void HistoryWidget::onSendPaths(const PeerId &peer) { @@ -2735,11 +2738,15 @@ void HistoryWidget::shareContactConfirmation(const QString &phone, const QString App::wnd()->showLayer(new PhotoSendBox(phone, fname, lname)); } -void HistoryWidget::uploadConfirmImageUncompressed() { +void HistoryWidget::uploadConfirmImageUncompressed(bool ctrlShiftEnter) { if (!hist || !confirmImageId || confirmImage.isNull()) return; App::wnd()->activateWindow(); - imageLoader.append(confirmImage, histPeer->id, ToPrepareDocument); + PeerId peerId = histPeer->id; + if (confirmWithText) { + onSend(ctrlShiftEnter); + } + imageLoader.append(confirmImage, peerId, ToPrepareDocument, ctrlShiftEnter); confirmImageId = 0; confirmWithText = false; confirmImage = QImage(); @@ -2776,22 +2783,25 @@ void HistoryWidget::onPhotoReady() { void HistoryWidget::onPhotoFailed(quint64 id) { } -void HistoryWidget::confirmShareContact(const QString &phone, const QString &fname, const QString &lname) { +void HistoryWidget::confirmShareContact(bool ctrlShiftEnter, const QString &phone, const QString &fname, const QString &lname) { + if (!histPeer) return; + + PeerId peerId = histPeer->id; if (0xFFFFFFFFFFFFFFFFL == confirmImageId) { if (confirmWithText) { - onSend(); + onSend(ctrlShiftEnter); } confirmImageId = 0; confirmWithText = false; confirmImage = QImage(); } - shareContact(phone, fname, lname); + shareContact(peerId, phone, fname, lname); } void HistoryWidget::confirmSendImage(const ReadyLocalMedia &img) { if (img.id == confirmImageId) { if (confirmWithText) { - onSend(); + onSend(img.ctrlShiftEnter); } confirmImageId = 0; confirmWithText = false; diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index a5335354a9..a8bb845033 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -288,10 +288,10 @@ public: void uploadImage(const QImage &img, bool withText = false); void uploadFile(const QString &file, bool withText = false); // with confirmation void shareContactConfirmation(const QString &phone, const QString &fname, const QString &lname, bool withText = false); - void uploadConfirmImageUncompressed(); + void uploadConfirmImageUncompressed(bool ctrlShiftEnter); void uploadMedias(const QStringList &files, ToPrepareMediaType type); void uploadMedia(const QByteArray &fileContent, ToPrepareMediaType type); - void confirmShareContact(const QString &phone, const QString &fname, const QString &lname); + void confirmShareContact(bool ctrlShiftEnter, const QString &phone, const QString &fname, const QString &lname); void confirmSendImage(const ReadyLocalMedia &img); void cancelSendImage(); @@ -304,7 +304,7 @@ public: void onShareContact(const PeerId &peer, UserData *contact); void onSendPaths(const PeerId &peer); - void shareContact(const QString &phone, const QString &fname, const QString &lname, int32 userId = 0); + void shareContact(const PeerId &peer, const QString &phone, const QString &fname, const QString &lname, int32 userId = 0); PeerData *peer() const; PeerData *activePeer() const; diff --git a/Telegram/SourceFiles/localimageloader.cpp b/Telegram/SourceFiles/localimageloader.cpp index 07c6b73f9d..85a333db5d 100644 --- a/Telegram/SourceFiles/localimageloader.cpp +++ b/Telegram/SourceFiles/localimageloader.cpp @@ -38,6 +38,7 @@ void LocalImageLoaderPrivate::prepareImages() { PeerId peer; uint64 id, jpeg_id = 0; ToPrepareMediaType type; + bool ctrlShiftEnter = false; { QMutexLocker lock(loader->toPrepareMutex()); ToPrepareMedias &list(loader->toPrepareMedias()); @@ -49,6 +50,7 @@ void LocalImageLoaderPrivate::prepareImages() { peer = list.front().peer; id = list.front().id; type = list.front().type; + ctrlShiftEnter = list.front().ctrlShiftEnter; } if (img.isNull()) { @@ -182,7 +184,7 @@ void LocalImageLoaderPrivate::prepareImages() { { QMutexLocker lock(loader->readyMutex()); - loader->readyList().push_back(ReadyLocalMedia(type, file, filename, filesize, data, id, jpeg_id, peer, photo, photoThumbs, document, jpeg)); + loader->readyList().push_back(ReadyLocalMedia(type, file, filename, filesize, data, id, jpeg_id, peer, photo, photoThumbs, document, jpeg, ctrlShiftEnter)); } { @@ -208,7 +210,7 @@ void LocalImageLoader::append(const QStringList &files, const PeerId &peer, ToPr { QMutexLocker lock(toPrepareMutex()); for (QStringList::const_iterator i = files.cbegin(), e = files.cend(); i != e; ++i) { - toPrepare.push_back(ToPrepareMedia(*i, peer, t)); + toPrepare.push_back(ToPrepareMedia(*i, peer, t, false)); } } if (!thread) { @@ -223,7 +225,7 @@ PhotoId LocalImageLoader::append(const QByteArray &img, const PeerId &peer, ToPr PhotoId result = 0; { QMutexLocker lock(toPrepareMutex()); - toPrepare.push_back(ToPrepareMedia(img, peer, t)); + toPrepare.push_back(ToPrepareMedia(img, peer, t, false)); result = toPrepare.back().id; } if (!thread) { @@ -235,11 +237,11 @@ PhotoId LocalImageLoader::append(const QByteArray &img, const PeerId &peer, ToPr return result; } -PhotoId LocalImageLoader::append(const QImage &img, const PeerId &peer, ToPrepareMediaType t) { +PhotoId LocalImageLoader::append(const QImage &img, const PeerId &peer, ToPrepareMediaType t, bool ctrlShiftEnter) { PhotoId result = 0; { QMutexLocker lock(toPrepareMutex()); - toPrepare.push_back(ToPrepareMedia(img, peer, t)); + toPrepare.push_back(ToPrepareMedia(img, peer, t, ctrlShiftEnter)); result = toPrepare.back().id; } if (!thread) { @@ -255,7 +257,7 @@ PhotoId LocalImageLoader::append(const QString &file, const PeerId &peer, ToPrep PhotoId result = 0; { QMutexLocker lock(toPrepareMutex()); - toPrepare.push_back(ToPrepareMedia(file, peer, t)); + toPrepare.push_back(ToPrepareMedia(file, peer, t, false)); result = toPrepare.back().id; } if (!thread) { diff --git a/Telegram/SourceFiles/localimageloader.h b/Telegram/SourceFiles/localimageloader.h index ff5449ecd6..7d7957195e 100644 --- a/Telegram/SourceFiles/localimageloader.h +++ b/Telegram/SourceFiles/localimageloader.h @@ -25,11 +25,11 @@ enum ToPrepareMediaType { }; struct ToPrepareMedia { - ToPrepareMedia(const QString &file, const PeerId &peer, ToPrepareMediaType t) : id(MTP::nonce()), file(file), peer(peer), type(t) { + ToPrepareMedia(const QString &file, const PeerId &peer, ToPrepareMediaType t, bool ctrlShiftEnter) : id(MTP::nonce()), file(file), peer(peer), type(t), ctrlShiftEnter(ctrlShiftEnter) { } - ToPrepareMedia(const QImage &img, const PeerId &peer, ToPrepareMediaType t) : id(MTP::nonce()), img(img), peer(peer), type(t) { + ToPrepareMedia(const QImage &img, const PeerId &peer, ToPrepareMediaType t, bool ctrlShiftEnter) : id(MTP::nonce()), img(img), peer(peer), type(t), ctrlShiftEnter(ctrlShiftEnter) { } - ToPrepareMedia(const QByteArray &data, const PeerId &peer, ToPrepareMediaType t) : id(MTP::nonce()), data(data), peer(peer), type(t) { + ToPrepareMedia(const QByteArray &data, const PeerId &peer, ToPrepareMediaType t, bool ctrlShiftEnter) : id(MTP::nonce()), data(data), peer(peer), type(t), ctrlShiftEnter(ctrlShiftEnter) { } PhotoId id; QString file; @@ -37,13 +37,14 @@ struct ToPrepareMedia { QByteArray data; PeerId peer; ToPrepareMediaType type; + bool ctrlShiftEnter; }; typedef QList ToPrepareMedias; typedef QMap LocalFileParts; struct ReadyLocalMedia { - ReadyLocalMedia(ToPrepareMediaType type, const QString &file, const QString &filename, int32 filesize, const QByteArray &data, const uint64 &id, const uint64 &jpeg_id, const PeerId &peer, const MTPPhoto &photo, const PreparedPhotoThumbs &photoThumbs, const MTPDocument &document, const QByteArray &jpeg) : - type(type), file(file), filename(filename), filesize(filesize), data(data), id(id), jpeg_id(jpeg_id), peer(peer), photo(photo), document(document), photoThumbs(photoThumbs) { + ReadyLocalMedia(ToPrepareMediaType type, const QString &file, const QString &filename, int32 filesize, const QByteArray &data, const uint64 &id, const uint64 &jpeg_id, const PeerId &peer, const MTPPhoto &photo, const PreparedPhotoThumbs &photoThumbs, const MTPDocument &document, const QByteArray &jpeg, bool ctrlShiftEnter) : + type(type), file(file), filename(filename), filesize(filesize), data(data), id(id), jpeg_id(jpeg_id), peer(peer), photo(photo), document(document), photoThumbs(photoThumbs), ctrlShiftEnter(ctrlShiftEnter) { if (!jpeg.isEmpty()) { int32 size = jpeg.size(); for (int32 i = 0, part = 0; i < size; i += UploadPartSize, ++part) { @@ -65,6 +66,8 @@ struct ReadyLocalMedia { PreparedPhotoThumbs photoThumbs; LocalFileParts parts; QByteArray jpeg_md5; + + bool ctrlShiftEnter; }; typedef QList ReadyLocalMedias; @@ -101,7 +104,7 @@ public: LocalImageLoader(QObject *parent); void append(const QStringList &files, const PeerId &peer, ToPrepareMediaType t = ToPrepareAuto); PhotoId append(const QByteArray &img, const PeerId &peer, ToPrepareMediaType t = ToPrepareAuto); - PhotoId append(const QImage &img, const PeerId &peer, ToPrepareMediaType t = ToPreparePhoto); + PhotoId append(const QImage &img, const PeerId &peer, ToPrepareMediaType t = ToPreparePhoto, bool ctrlShiftEnter = false); PhotoId append(const QString &file, const PeerId &peer, ToPrepareMediaType t = ToPrepareAuto); QMutex *readyMutex(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 0b88d5cd48..5bab3a1dfa 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -981,16 +981,16 @@ void MainWidget::updateOnlineDisplay() { if (App::wnd()->settingsWidget()) App::wnd()->settingsWidget()->updateOnlineDisplay(); } -void MainWidget::confirmShareContact(const QString &phone, const QString &fname, const QString &lname) { - history.confirmShareContact(phone, fname, lname); +void MainWidget::confirmShareContact(bool ctrlShiftEnter, const QString &phone, const QString &fname, const QString &lname) { + history.confirmShareContact(ctrlShiftEnter, phone, fname, lname); } void MainWidget::confirmSendImage(const ReadyLocalMedia &img) { history.confirmSendImage(img); } -void MainWidget::confirmSendImageUncompressed() { - history.uploadConfirmImageUncompressed(); +void MainWidget::confirmSendImageUncompressed(bool ctrlShiftEnter) { + history.uploadConfirmImageUncompressed(ctrlShiftEnter); } void MainWidget::cancelSendImage() { diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 1a147fbf80..182534ad5b 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -213,9 +213,9 @@ public: void showBackFromStack(); QRect historyRect() const; - void confirmShareContact(const QString &phone, const QString &fname, const QString &lname); + void confirmShareContact(bool ctrlShiftEnter, const QString &phone, const QString &fname, const QString &lname); void confirmSendImage(const ReadyLocalMedia &img); - void confirmSendImageUncompressed(); + void confirmSendImageUncompressed(bool ctrlShiftEnter); void cancelSendImage(); void destroyData(); diff --git a/Telegram/SourceFiles/pspecific_mac_p.mm b/Telegram/SourceFiles/pspecific_mac_p.mm index ff16dfe171..9e310fba2e 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.mm +++ b/Telegram/SourceFiles/pspecific_mac_p.mm @@ -709,10 +709,9 @@ QString objc_currentLang() { } QString objc_convertFileUrl(const QString &url) { - NSString *nsurl = [[[NSURL URLWithString: [NSString stringWithUTF8String: (qsl("file://") + url).toUtf8().constData()]] filePathURL] absoluteString]; + NSString *nsurl = [[[NSURL URLWithString: [NSString stringWithUTF8String: (qsl("file://") + url).toUtf8().constData()]] filePathURL] path]; if (!nsurl) return QString(); - QString result = QString::fromUtf8([nsurl cStringUsingEncoding:NSUTF8StringEncoding]); - return result.startsWith(qsl("file://")) ? result.mid(7) : result; + return QString::fromUtf8([nsurl cStringUsingEncoding:NSUTF8StringEncoding]); }