diff --git a/.gitignore b/.gitignore index c667fdda1b..fb98a0183a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ /Telegram/Resources/art/grid_200x.png /Telegram/Resources/art/sprite_125x.png /Telegram/Resources/art/sprite_150x.png +/Telegram/Debug/ /Telegram/*.user *.vcxproj* *.sln diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 0edbb09cfa..aca50c4c49 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -958,6 +958,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_context_delete_file" = "Delete File"; "lng_context_close_file" = "Close File"; "lng_context_copy_text" = "Copy Text"; +"lng_context_open_gif" = "Open GIF"; "lng_context_save_gif" = "Save GIF"; "lng_context_to_msg" = "Go To Message"; "lng_context_reply_msg" = "Reply"; diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index 1aee203d19..78be71feb3 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -138,22 +138,6 @@ enum MediaOverviewType { OverviewCount }; -inline MTPMessagesFilter typeToMediaFilter(MediaOverviewType &type) { - switch (type) { - case OverviewPhotos: return MTP_inputMessagesFilterPhotos(); - case OverviewVideos: return MTP_inputMessagesFilterVideo(); - case OverviewMusicFiles: return MTP_inputMessagesFilterMusic(); - case OverviewFiles: return MTP_inputMessagesFilterDocument(); - case OverviewVoiceFiles: return MTP_inputMessagesFilterVoice(); - case OverviewRoundVoiceFiles: return MTP_inputMessagesFilterRoundVoice(); - case OverviewLinks: return MTP_inputMessagesFilterUrl(); - case OverviewChatPhotos: return MTP_inputMessagesFilterChatPhotos(); - case OverviewCount: break; - default: type = OverviewCount; break; - } - return MTPMessagesFilter(); -} - struct TextWithTags { struct Tag { int offset, length; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 53a8c35eb2..fc0823c98f 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1291,6 +1291,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true); } else { if (document->loaded() && document->isGifv()) { + if (!cAutoPlayGif()) { + _menu->addAction(lang(lng_context_open_gif), this, SLOT(openContextGif()))->setEnabled(true); + } _menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true); } if (!document->filepath(DocumentData::FilePathResolveChecked).isEmpty()) { @@ -1384,6 +1387,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true); } else { if (document->isGifv()) { + if (!cAutoPlayGif()) { + _menu->addAction(lang(lng_context_open_gif), this, SLOT(openContextGif()))->setEnabled(true); + } _menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true); } if (!document->filepath(DocumentData::FilePathResolveChecked).isEmpty()) { @@ -1522,6 +1528,16 @@ void HistoryInner::saveDocumentToFile(DocumentData *document) { DocumentSaveClickHandler::doSave(document, true); } +void HistoryInner::openContextGif() { + if (auto item = App::contextItem()) { + if (auto media = item->getMedia()) { + if (auto document = media->getDocument()) { + App::wnd()->showDocument(document, item); + } + } + } +} + void HistoryInner::saveContextGif() { if (auto item = App::contextItem()) { if (auto media = item->getMedia()) { diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index c1f554054d..f3caf6cc83 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -118,6 +118,7 @@ public slots: void cancelContextDownload(); void showContextInFolder(); void saveContextGif(); + void openContextGif(); void copyContextText(); void copySelectedText(); diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index d051d08e3a..73636e598c 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -1707,6 +1707,7 @@ HistoryGif::HistoryGif(HistoryItem *parent, DocumentData *document, const QStrin , _data(document) , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { setDocumentLinks(_data, true); + _openInMediaviewLink = MakeShared(_data); setStatusSize(FileStatusSizeReady); @@ -2217,6 +2218,8 @@ HistoryTextState HistoryGif::getState(int x, int y, HistoryStateRequest request) result.link = _cancell; } else if (!_gif || !cAutoPlayGif() || _data->isRoundVideo()) { result.link = _data->loaded() ? _openl : (_data->loading() ? _cancell : _savel); + } else { + result.link = _openInMediaviewLink; } if (!isChildMedia) { int32 fullRight = usex + skipx + usew, fullBottom = skipy + height; diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h index f06cfc067c..fd87eac2bc 100644 --- a/Telegram/SourceFiles/history/history_media_types.h +++ b/Telegram/SourceFiles/history/history_media_types.h @@ -580,6 +580,7 @@ private: } gsl::not_null _data; + ClickHandlerPtr _openInMediaviewLink; int32 _thumbw = 1; int32 _thumbh = 1; Text _caption; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 0c0d8dbfe4..736f073afa 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -71,6 +71,25 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "calls/calls_instance.h" #include "calls/calls_top_bar.h" +namespace { + +MTPMessagesFilter typeToMediaFilter(MediaOverviewType &type) { + switch (type) { + case OverviewPhotos: return MTP_inputMessagesFilterPhotos(); + case OverviewVideos: return MTP_inputMessagesFilterVideo(); + case OverviewMusicFiles: return MTP_inputMessagesFilterMusic(); + case OverviewFiles: return MTP_inputMessagesFilterDocument(); + case OverviewVoiceFiles: return MTP_inputMessagesFilterVoice(); + case OverviewRoundVoiceFiles: return MTP_inputMessagesFilterRoundVoice(); + case OverviewGIFs: return MTP_inputMessagesFilterGif(); + case OverviewLinks: return MTP_inputMessagesFilterUrl(); + case OverviewChatPhotos: return MTP_inputMessagesFilterChatPhotos(); + default: return MTP_inputMessagesFilterEmpty(); + } +} + +} // namespace + StackItemSection::StackItemSection(std::unique_ptr &&memento) : StackItem(nullptr) , _memento(std::move(memento)) { } @@ -1335,11 +1354,13 @@ void MainWidget::searchMessages(const QString &query, PeerData *inPeer) { } bool MainWidget::preloadOverview(PeerData *peer, MediaOverviewType type) { - MTPMessagesFilter filter = typeToMediaFilter(type); - if (type == OverviewCount) return false; + auto filter = typeToMediaFilter(type); + if (filter.type() == mtpc_inputMessagesFilterEmpty) { + return false; + } - History *h = App::history(peer->id); - if (h->overviewCountLoaded(type) || _overviewPreload[type].contains(peer)) { + auto history = App::history(peer->id); + if (history->overviewCountLoaded(type) || _overviewPreload[type].contains(peer)) { return false; } @@ -1399,13 +1420,17 @@ bool MainWidget::overviewFailed(PeerData *peer, const RPCError &error, mtpReques void MainWidget::loadMediaBack(PeerData *peer, MediaOverviewType type, bool many) { if (_overviewLoad[type].constFind(peer) != _overviewLoad[type].cend()) return; - History *history = App::history(peer->id); - if (history->overviewLoaded(type)) return; + auto history = App::history(peer->id); + if (history->overviewLoaded(type)) { + return; + } - MsgId minId = history->overviewMinId(type); - int32 limit = (many || history->overview[type].size() > MediaOverviewStartPerPage) ? SearchPerPage : MediaOverviewStartPerPage; - MTPMessagesFilter filter = typeToMediaFilter(type); - if (type == OverviewCount) return; + auto minId = history->overviewMinId(type); + auto limit = (many || history->overview[type].size() > MediaOverviewStartPerPage) ? SearchPerPage : MediaOverviewStartPerPage; + auto filter = typeToMediaFilter(type); + if (filter.type() == mtpc_inputMessagesFilterEmpty) { + return; + } _overviewLoad[type].insert(peer, MTP::send(MTPmessages_Search(MTP_flags(0), peer->input, MTPstring(), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(minId), MTP_int(limit)), rpcDone(&MainWidget::overviewLoaded, history))); } diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index b15042be8b..689e9e1756 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -368,7 +368,7 @@ void MediaView::updateControls() { _dateNav = myrtlrect(st::mediaviewTextLeft, height() - st::mediaviewTextTop, st::mediaviewFont->width(_dateText), st::mediaviewFont->height); } updateHeader(); - if (_photo || (_history && (_overview == OverviewPhotos || _overview == OverviewChatPhotos || _overview == OverviewFiles || _overview == OverviewVideos))) { + if (_photo || (_history && _overview != OverviewCount)) { _leftNavVisible = (_index > 0) || (_index == 0 && ( (!_msgmigrated && _history && _history->overview[_overview].size() < _history->overviewCount(_overview)) || (_msgmigrated && _migrated && _migrated->overview[_overview].size() < _migrated->overviewCount(_overview)) || @@ -1152,7 +1152,7 @@ void MediaView::showDocument(DocumentData *doc, HistoryItem *context) { _canForward = _msgid > 0; _canDelete = context ? context->canDelete() : false; if (_history) { - _overview = doc->isVideo() ? OverviewVideos : OverviewFiles; + _overview = doc->isGifv() ? OverviewGIFs : doc->isVideo() ? OverviewVideos : OverviewFiles; findCurrent(); } if (doc->isVideo() || doc->isRoundVideo()) { @@ -2153,7 +2153,7 @@ bool MediaView::moveToNext(int32 delta) { } return false; } - if ((_history && _overview != OverviewPhotos && _overview != OverviewChatPhotos && _overview != OverviewFiles && _overview != OverviewVideos) || (_overview == OverviewCount && !_user)) { + if (_overview == OverviewCount && (_history || !_user)) { return false; } if (_msgmigrated && !_history->overviewLoaded(_overview)) {