| 2166 | } |
| 2167 | |
| 2168 | void Stories::toggleInProfileList( |
| 2169 | const std::vector<FullStoryId> &ids, |
| 2170 | bool inProfile) { |
| 2171 | if (ids.empty()) { |
| 2172 | return; |
| 2173 | } |
| 2174 | const auto peer = session().data().peer(ids.front().peer); |
| 2175 | auto list = QVector<MTPint>(); |
| 2176 | list.reserve(ids.size()); |
| 2177 | for (const auto &id : ids) { |
| 2178 | if (id.peer == peer->id) { |
| 2179 | list.push_back(MTP_int(id.story)); |
| 2180 | } |
| 2181 | } |
| 2182 | if (list.empty()) { |
| 2183 | return; |
| 2184 | } |
| 2185 | const auto api = &_owner->session().api(); |
| 2186 | api->request(MTPstories_TogglePinned( |
| 2187 | peer->input(), |
| 2188 | MTP_vector<MTPint>(list), |
| 2189 | MTP_bool(inProfile) |
| 2190 | )).done([=](const MTPVector<MTPint> &result) { |
| 2191 | const auto peerId = peer->id; |
| 2192 | auto &saved = _saved[peerId]; |
| 2193 | const auto loaded = saved.loaded; |
| 2194 | const auto lastId = !saved.ids.list.empty() |
| 2195 | ? saved.ids.list.back() |
| 2196 | : saved.lastId |
| 2197 | ? saved.lastId |
| 2198 | : std::numeric_limits<StoryId>::max(); |
| 2199 | auto dirty = false; |
| 2200 | for (const auto &id : result.v) { |
| 2201 | if (const auto maybeStory = lookup({ peerId, id.v })) { |
| 2202 | const auto story = *maybeStory; |
| 2203 | story->setInProfile(inProfile); |
| 2204 | if (inProfile) { |
| 2205 | const auto add = loaded || (id.v >= lastId); |
| 2206 | if (!add) { |
| 2207 | dirty = true; |
| 2208 | } else if (InsertSorted(saved.ids.list, id.v)) { |
| 2209 | if (saved.total >= 0) { |
| 2210 | ++saved.total; |
| 2211 | } |
| 2212 | } |
| 2213 | } else if (RemoveSorted(saved.ids.list, id.v)) { |
| 2214 | if (saved.total > 0) { |
| 2215 | --saved.total; |
| 2216 | } |
| 2217 | } else if (!loaded) { |
| 2218 | dirty = true; |
| 2219 | } |
| 2220 | } else if (!loaded) { |
| 2221 | dirty = true; |
| 2222 | } |
| 2223 | } |
| 2224 | if (dirty) { |
| 2225 | albumIdsLoadMore(peerId, kStoriesAlbumIdSaved); |
no test coverage detected