void MediaView::loadPhotosBack() { if (_loadRequest || _index < 0) return; if (_history && _history->_photosOverviewCount != 0) { MsgId minId = 0; for (History::MediaOverviewIds::const_iterator i = _history->_photosOverviewIds.cbegin(), e = _history->_photosOverviewIds.cend(); i != e; ++i) { if (*i > 0) { minId = *i; break; } } int32 limit = (_index < MediaOverviewStartPerPage && _history->_photosOverview.size() > MediaOverviewStartPerPage) ? SearchPerPage : MediaOverviewStartPerPage; _loadRequest = MTP::send(MTPmessages_Search(_history->peer->input, MTPstring(), MTP_inputMessagesFilterPhotos(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(minId), MTP_int(limit)), rpcDone(&MediaView::photosLoaded, _history)); } else if (_user && _user->photosCount != 0) { int32 limit = (_index < MediaOverviewStartPerPage && _user->photos.size() > MediaOverviewStartPerPage) ? SearchPerPage : MediaOverviewStartPerPage; _loadRequest = MTP::send(MTPphotos_GetUserPhotos(_user->inputUser, MTP_int(_user->photos.size()), MTP_int(0), MTP_int(limit)), rpcDone(&MediaView::userPhotosLoaded, _user)); } }
MTPmessages_Search PrepareSearchRequest( not_null<PeerData*> peer, Storage::SharedMediaType type, const QString &query, MsgId messageId, SparseIdsLoadDirection direction) { const auto filter = [&] { using Type = Storage::SharedMediaType; switch (type) { case Type::Photo: return MTP_inputMessagesFilterPhotos(); case Type::Video: return MTP_inputMessagesFilterVideo(); case Type::PhotoVideo: return MTP_inputMessagesFilterPhotoVideo(); case Type::MusicFile: return MTP_inputMessagesFilterMusic(); case Type::File: return MTP_inputMessagesFilterDocument(); case Type::VoiceFile: return MTP_inputMessagesFilterVoice(); case Type::RoundVoiceFile: return MTP_inputMessagesFilterRoundVoice(); case Type::RoundFile: return MTP_inputMessagesFilterRoundVideo(); case Type::GIF: return MTP_inputMessagesFilterGif(); case Type::Link: return MTP_inputMessagesFilterUrl(); case Type::ChatPhoto: return MTP_inputMessagesFilterChatPhotos(); } return MTP_inputMessagesFilterEmpty(); }(); const auto minId = 0; const auto maxId = 0; const auto limit = messageId ? kSharedMediaLimit : 0; const auto offsetId = [&] { switch (direction) { case SparseIdsLoadDirection::Before: case SparseIdsLoadDirection::Around: return messageId; case SparseIdsLoadDirection::After: return messageId + 1; } Unexpected("Direction in PrepareSearchRequest"); }(); const auto addOffset = [&] { switch (direction) { case SparseIdsLoadDirection::Before: return 0; case SparseIdsLoadDirection::Around: return -limit / 2; case SparseIdsLoadDirection::After: return -limit; } Unexpected("Direction in PrepareSearchRequest"); }(); return MTPmessages_Search( MTP_flags(0), peer->input, MTP_string(query), MTP_inputUserEmpty(), filter, MTP_int(0), MTP_int(0), MTP_int(offsetId), MTP_int(addOffset), MTP_int(limit), MTP_int(maxId), MTP_int(minId)); }