diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index 78972e02b..1aee203d1 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -125,13 +125,15 @@ enum HistoryMediaType { }; enum MediaOverviewType { - OverviewPhotos = 0, - OverviewVideos = 1, - OverviewMusicFiles = 2, - OverviewFiles = 3, - OverviewVoiceFiles = 4, - OverviewLinks = 5, - OverviewChatPhotos = 6, + OverviewPhotos = 0, + OverviewVideos = 1, + OverviewMusicFiles = 2, + OverviewFiles = 3, + OverviewVoiceFiles = 4, + OverviewLinks = 5, + OverviewChatPhotos = 6, + OverviewRoundVoiceFiles = 7, + OverviewGIFs = 8, OverviewCount }; @@ -143,6 +145,7 @@ inline MTPMessagesFilter typeToMediaFilter(MediaOverviewType &type) { 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; diff --git a/Telegram/SourceFiles/history/history_media.h b/Telegram/SourceFiles/history/history_media.h index 05689edad..0875371d8 100644 --- a/Telegram/SourceFiles/history/history_media.h +++ b/Telegram/SourceFiles/history/history_media.h @@ -29,7 +29,7 @@ enum class MediaInBubbleState { class HistoryMedia : public HistoryElement { public: - HistoryMedia(HistoryItem *parent) : _parent(parent) { + HistoryMedia(gsl::not_null parent) : _parent(parent) { } virtual HistoryMediaType type() const = 0; @@ -69,6 +69,12 @@ public: virtual void updatePressed(int x, int y) { } + virtual int32 addToOverview(AddToOverviewMethod method) { + return 0; + } + virtual void eraseFromOverview() { + } + // if we are in selecting items mode perhaps we want to // toggle selection instead of activating the pressed link virtual bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const = 0; @@ -195,8 +201,19 @@ public: } protected: - HistoryItem *_parent; + int32 addToOneOverview(MediaOverviewType type, AddToOverviewMethod method) { + if (_parent->history()->addToOverview(type, _parent->id, method)) { + return (1 << type); + } + return 0; + } + void eraseFromOneOverview(MediaOverviewType type) { + _parent->history()->eraseFromOverview(type, _parent->id); + } + + gsl::not_null _parent; int _width = 0; MediaInBubbleState _inBubbleState = MediaInBubbleState::None; + }; diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index c886c04c4..d051d08e3 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -589,6 +589,24 @@ TextWithEntities HistoryPhoto::selectedText(TextSelection selection) const { return captionedSelectedText(lang(lng_in_dlg_photo), _caption, selection); } +int32 HistoryPhoto::addToOverview(AddToOverviewMethod method) { + auto result = int32(0); + if (_parent->toHistoryMessage()) { + result |= addToOneOverview(OverviewPhotos, method); + } else { + result |= addToOneOverview(OverviewChatPhotos, method); + } + return result; +} + +void HistoryPhoto::eraseFromOverview() { + if (_parent->toHistoryMessage()) { + eraseFromOneOverview(OverviewPhotos); + } else { + eraseFromOneOverview(OverviewChatPhotos); + } +} + ImagePtr HistoryPhoto::replyPreview() { return _data->makeReplyPreview(); } @@ -865,6 +883,14 @@ TextWithEntities HistoryVideo::selectedText(TextSelection selection) const { return captionedSelectedText(lang(lng_in_dlg_video), _caption, selection); } +int32 HistoryVideo::addToOverview(AddToOverviewMethod method) { + return addToOneOverview(OverviewVideos, method); +} + +void HistoryVideo::eraseFromOverview() { + eraseFromOneOverview(OverviewVideos); +} + void HistoryVideo::updateStatusText() const { bool showPause = false; int32 statusSize = 0, realDuration = 0; @@ -1474,6 +1500,34 @@ TextWithEntities HistoryDocument::selectedText(TextSelection selection) const { return result; } +int32 HistoryDocument::addToOverview(AddToOverviewMethod method) { + auto result = int32(0); + if (_data->voice()) { + result |= addToOneOverview(OverviewVoiceFiles, method); + result |= addToOneOverview(OverviewRoundVoiceFiles, method); + } else if (_data->song()) { + if (_data->isMusic()) { + result |= addToOneOverview(OverviewMusicFiles, method); + } + } else { + result |= addToOneOverview(OverviewFiles, method); + } + return result; +} + +void HistoryDocument::eraseFromOverview() { + if (_data->voice()) { + eraseFromOneOverview(OverviewVoiceFiles); + eraseFromOneOverview(OverviewRoundVoiceFiles); + } else if (_data->song()) { + if (_data->isMusic()) { + eraseFromOneOverview(OverviewMusicFiles); + } + } else { + eraseFromOneOverview(OverviewFiles); + } +} + template void HistoryDocument::buildStringRepresentation(Callback callback) const { const Text emptyCaption; @@ -2188,6 +2242,28 @@ TextWithEntities HistoryGif::selectedText(TextSelection selection) const { return captionedSelectedText(mediaTypeString(), _caption, selection); } +int32 HistoryGif::addToOverview(AddToOverviewMethod method) { + auto result = int32(0); + if (_data->isRoundVideo()) { + result |= addToOneOverview(OverviewRoundVoiceFiles, method); + } else if (_data->isGifv()) { + result |= addToOneOverview(OverviewGIFs, method); + } else { + result |= addToOneOverview(OverviewFiles, method); + } + return result; +} + +void HistoryGif::eraseFromOverview() { + if (_data->isRoundVideo()) { + eraseFromOneOverview(OverviewRoundVoiceFiles); + } else if (_data->isGifv()) { + eraseFromOneOverview(OverviewGIFs); + } else { + eraseFromOneOverview(OverviewFiles); + } +} + QString HistoryGif::mediaTypeString() const { return _data->isRoundVideo() ? lang(lng_in_dlg_video_message) : qsl("GIF"); } diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h index fbee130af..f06cfc067 100644 --- a/Telegram/SourceFiles/history/history_media_types.h +++ b/Telegram/SourceFiles/history/history_media_types.h @@ -139,6 +139,9 @@ public: QString inDialogsText() const override; TextWithEntities selectedText(TextSelection selection) const override; + int32 addToOverview(AddToOverviewMethod method) override; + void eraseFromOverview() override; + PhotoData *photo() const { return _data; } @@ -229,6 +232,9 @@ public: QString inDialogsText() const override; TextWithEntities selectedText(TextSelection selection) const override; + int32 addToOverview(AddToOverviewMethod method) override; + void eraseFromOverview() override; + DocumentData *getDocument() override { return _data; } @@ -388,6 +394,9 @@ public: QString inDialogsText() const override; TextWithEntities selectedText(TextSelection selection) const override; + int32 addToOverview(AddToOverviewMethod method) override; + void eraseFromOverview() override; + bool uploading() const override { return _data->uploading(); } @@ -486,6 +495,9 @@ public: QString inDialogsText() const override; TextWithEntities selectedText(TextSelection selection) const override; + int32 addToOverview(AddToOverviewMethod method) override; + void eraseFromOverview() override; + bool uploading() const override { return _data->uploading(); } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index e7c2a65e8..dc3288b1c 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -47,30 +47,6 @@ inline void initTextOptions() { _textDlgOptions.maxw = st::dialogsWidthMax * 2; } -MediaOverviewType messageMediaToOverviewType(HistoryMedia *media) { - switch (media->type()) { - case MediaTypePhoto: return OverviewPhotos; - case MediaTypeVideo: return OverviewVideos; - case MediaTypeFile: return OverviewFiles; - case MediaTypeMusicFile: return media->getDocument()->isMusic() ? OverviewMusicFiles : OverviewCount; - case MediaTypeVoiceFile: return OverviewVoiceFiles; - case MediaTypeGif: { - auto document = media->getDocument(); - return (document->isGifv() || document->isRoundVideo()) ? OverviewCount : OverviewFiles; - } break; - default: break; - } - return OverviewCount; -} - -MediaOverviewType serviceMediaToOverviewType(HistoryMedia *media) { - switch (media->type()) { - case MediaTypePhoto: return OverviewChatPhotos; - default: break; - } - return OverviewCount; -} - ApiWrap::RequestMessageDataCallback historyDependentItemCallback(const FullMsgId &msgId) { return [dependent = msgId](ChannelData *channel, MsgId msgId) { if (auto item = App::histItemById(dependent)) { @@ -987,13 +963,8 @@ int32 HistoryMessage::addToOverview(AddToOverviewMethod method) { if (!indexInOverview()) return 0; int32 result = 0; - if (HistoryMedia *media = getMedia()) { - MediaOverviewType type = messageMediaToOverviewType(media); - if (type != OverviewCount) { - if (history()->addToOverview(type, id, method)) { - result |= (1 << type); - } - } + if (auto media = getMedia()) { + result |= media->addToOverview(method); } if (hasTextLinks()) { if (history()->addToOverview(OverviewLinks, id, method)) { @@ -1004,11 +975,8 @@ int32 HistoryMessage::addToOverview(AddToOverviewMethod method) { } void HistoryMessage::eraseFromOverview() { - if (HistoryMedia *media = getMedia()) { - MediaOverviewType type = messageMediaToOverviewType(media); - if (type != OverviewCount) { - history()->eraseFromOverview(type, id); - } + if (auto media = getMedia()) { + media->eraseFromOverview(); } if (hasTextLinks()) { history()->eraseFromOverview(OverviewLinks, id); @@ -2464,22 +2432,14 @@ int32 HistoryService::addToOverview(AddToOverviewMethod method) { int32 result = 0; if (auto media = getMedia()) { - MediaOverviewType type = serviceMediaToOverviewType(media); - if (type != OverviewCount) { - if (history()->addToOverview(type, id, method)) { - result |= (1 << type); - } - } + result |= media->addToOverview(method); } return result; } void HistoryService::eraseFromOverview() { if (auto media = getMedia()) { - MediaOverviewType type = serviceMediaToOverviewType(media); - if (type != OverviewCount) { - history()->eraseFromOverview(type, id); - } + media->eraseFromOverview(); } } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 8dee7ed14..0c0d8dbfe 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1347,20 +1347,6 @@ bool MainWidget::preloadOverview(PeerData *peer, MediaOverviewType type) { return true; } -void MainWidget::preloadOverviews(PeerData *peer) { - History *h = App::history(peer->id); - bool sending = false; - for (int32 i = 0; i < OverviewCount; ++i) { - auto type = MediaOverviewType(i); - if (type != OverviewChatPhotos && preloadOverview(peer, type)) { - sending = true; - } - } - if (sending) { - MTP::sendAnything(); - } -} - void MainWidget::overviewPreloaded(PeerData *peer, const MTPmessages_Messages &result, mtpRequestId req) { MediaOverviewType type = OverviewCount; for (int32 i = 0; i < OverviewCount; ++i) { diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index e48735045..7e5128791 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -318,7 +318,6 @@ public: void jumpToDate(PeerData *peer, const QDate &date); void searchMessages(const QString &query, PeerData *inPeer); bool preloadOverview(PeerData *peer, MediaOverviewType type); - void preloadOverviews(PeerData *peer); void changingMsgId(HistoryItem *row, MsgId newId); void itemEdited(HistoryItem *item); diff --git a/Telegram/SourceFiles/profile/profile_block_shared_media.cpp b/Telegram/SourceFiles/profile/profile_block_shared_media.cpp index 9b40cd726..45476c051 100644 --- a/Telegram/SourceFiles/profile/profile_block_shared_media.cpp +++ b/Telegram/SourceFiles/profile/profile_block_shared_media.cpp @@ -58,9 +58,14 @@ SharedMediaWidget::SharedMediaWidget(QWidget *parent, PeerData *peer) : BlockWid notifyPeerUpdated(update); })); - App::main()->preloadOverviews(peer); - if (_migrated) { - App::main()->preloadOverviews(_migrated->peer); + for (auto i = 0; i != OverviewCount; ++i) { + auto type = static_cast(i); + if (!getButtonText(type, 1).isEmpty()) { + App::main()->preloadOverview(peer, type); + if (_migrated) { + App::main()->preloadOverview(_migrated->peer, type); + } + } } refreshButtons();