MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / toggleInProfileList

Method toggleInProfileList

Telegram/SourceFiles/data/data_stories.cpp:2168–2230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2166}
2167
2168void 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);

Callers 2

toggleStoryInProfileMethod · 0.80

Calls 15

MTP_boolFunction · 0.85
InsertSortedFunction · 0.85
RemoveSortedFunction · 0.85
frontMethod · 0.80
apiMethod · 0.80
setInProfileMethod · 0.80
MTP_intFunction · 0.70
emptyMethod · 0.45
peerMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
sessionMethod · 0.45

Tested by

no test coverage detected