| 1127 | } |
| 1128 | |
| 1129 | void ApiWrap::requestProfileMusic( |
| 1130 | FnMut<bool(Data::ProfileMusicInfo&&)> start, |
| 1131 | Fn<bool(DownloadProgress)> progress, |
| 1132 | Fn<bool(Data::ProfileMusicSlice&&)> slice, |
| 1133 | FnMut<void()> finish) { |
| 1134 | Expects(_profileMusicProcess == nullptr); |
| 1135 | |
| 1136 | _profileMusicProcess = std::make_unique<ProfileMusicProcess>(); |
| 1137 | _profileMusicProcess->start = std::move(start); |
| 1138 | _profileMusicProcess->fileProgress = std::move(progress); |
| 1139 | _profileMusicProcess->handleSlice = std::move(slice); |
| 1140 | _profileMusicProcess->finish = std::move(finish); |
| 1141 | |
| 1142 | mainRequest(MTPusers_GetSavedMusic( |
| 1143 | _user, |
| 1144 | MTP_int(0), // offset |
| 1145 | MTP_int(kProfileMusicSliceLimit), // limit |
| 1146 | MTP_long(0) // hash |
| 1147 | )).done([=](const MTPusers_SavedMusic &result) mutable { |
| 1148 | Expects(_profileMusicProcess != nullptr); |
| 1149 | |
| 1150 | auto startInfo = result.match( |
| 1151 | [](const MTPDusers_savedMusic &data) { |
| 1152 | return Data::ProfileMusicInfo{ data.vcount().v }; |
| 1153 | }, [](const MTPDusers_savedMusicNotModified &data) { |
| 1154 | return Data::ProfileMusicInfo{ 0 }; |
| 1155 | }); |
| 1156 | if (!_profileMusicProcess->start(std::move(startInfo))) { |
| 1157 | return; |
| 1158 | } |
| 1159 | |
| 1160 | handleProfileMusicSlice(result); |
| 1161 | }).send(); |
| 1162 | } |
| 1163 | |
| 1164 | void ApiWrap::handleProfileMusicSlice(const MTPusers_SavedMusic &result) { |
| 1165 | Expects(_profileMusicProcess != nullptr); |