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

Method toggleHidden

Telegram/SourceFiles/data/data_stories.cpp:1322–1404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1320}
1321
1322void Stories::toggleHidden(
1323 PeerId peerId,
1324 bool hidden,
1325 std::shared_ptr<Ui::Show> show) {
1326 const auto peer = _owner->peer(peerId);
1327 const auto byHints = peer->isUser()
1328 && !peer->asUser()->isBot()
1329 && !peer->asUser()->isContact()
1330 && !peer->asUser()->isServiceUser();
1331 const auto justRemove = (byHints || peer->isServiceUser()) && hidden;
1332 if (peer->hasStoriesHidden() != hidden) {
1333 if (byHints && hidden) {
1334 peer->asUser()->setStoriesCorrespondent(false);
1335 } else if (!justRemove) {
1336 peer->setStoriesHidden(hidden);
1337 }
1338 session().api().request(MTPstories_TogglePeerStoriesHidden(
1339 peer->input(),
1340 MTP_bool(hidden)
1341 )).send();
1342 if (byHints) {
1343 peer->session().topPeers().remove(peer);
1344 }
1345 }
1346
1347 const auto name = peer->shortName();
1348 const auto guard = gsl::finally([&] {
1349 if (show && !justRemove) {
1350 const auto phrase = hidden
1351 ? tr::lng_stories_hidden_to_contacts
1352 : tr::lng_stories_shown_in_chats;
1353 show->showToast(phrase(
1354 tr::now,
1355 lt_user,
1356 tr::bold(name),
1357 tr::rich));
1358 }
1359 });
1360
1361 if (justRemove) {
1362 apply(peer, nullptr);
1363 return;
1364 }
1365
1366 const auto i = _all.find(peerId);
1367 if (i == end(_all)) {
1368 return;
1369 }
1370 i->second.hidden = hidden;
1371 const auto info = i->second.info();
1372 const auto main = static_cast<int>(StorySourcesList::NotHidden);
1373 const auto other = static_cast<int>(StorySourcesList::Hidden);
1374 const auto proj = &StoriesSourceInfo::id;
1375 if (hidden) {
1376 const auto i = ranges::find(_sources[main], peerId, proj);
1377 if (i != end(_sources[main])) {
1378 _sources[main].erase(i);
1379 notifySourcesChanged(StorySourcesList::NotHidden);

Callers 1

FillSourceMenuFunction · 0.80

Calls 15

MTP_boolFunction · 0.85
asUserMethod · 0.80
isContactMethod · 0.80
isServiceUserMethod · 0.80
setStoriesHiddenMethod · 0.80
apiMethod · 0.80
shortNameMethod · 0.80
infoMethod · 0.80
phraseClass · 0.50
peerMethod · 0.45
isUserMethod · 0.45

Tested by

no test coverage detected