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

Function PreparedContextAt

Telegram/SourceFiles/api/api_who_reacted.cpp:189–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187}
188
189[[nodiscard]] not_null<Context*> PreparedContextAt(
190 not_null<QWidget*> key,
191 not_null<Main::Session*> session) {
192 const auto context = ContextAt(key);
193 if (context->subscriptions.contains(session)) {
194 return context;
195 }
196 session->changes().messageUpdates(
197 Data::MessageUpdate::Flag::Destroyed
198 ) | rpl::on_next([=](const Data::MessageUpdate &update) {
199 const auto i = context->cachedRead.find(update.item);
200 if (i != end(context->cachedRead)) {
201 session->api().request(i->second.requestId).cancel();
202 context->cachedRead.erase(i);
203 }
204 const auto j = context->cachedReacted.find(update.item);
205 if (j != end(context->cachedReacted)) {
206 for (auto &[reaction, entry] : j->second) {
207 session->api().request(entry.requestId).cancel();
208 }
209 context->cachedReacted.erase(j);
210 }
211 }, context->subscriptions[session]);
212 session->data().reactionsRemoved(
213 ) | rpl::on_next([=](const Data::ReactionsRemoved &update) {
214 for (auto &[item, map] : context->cachedReacted) {
215 if (item->history()->peer->id != update.peer->id) {
216 continue;
217 } else if (update.msgId && item->id != update.msgId) {
218 continue;
219 }
220 for (auto &entry : map) {
221 auto data = entry.second.data.current();
222 if (ApplyReactionsRemovedToCachedData(data, update)) {
223 entry.second.data = std::move(data);
224 }
225 }
226 }
227 }, context->subscriptions[session]);
228 Data::AmPremiumValue(
229 session
230 ) | rpl::skip(1) | rpl::filter(
231 rpl::mappers::_1
232 ) | rpl::on_next([=] {
233 for (auto &[item, cache] : context->cachedRead) {
234 if (cache.data.current().state == Ui::WhoReadState::MyHidden) {
235 cache.data = Peers{ .state = Ui::WhoReadState::Unknown };
236 }
237 }
238 }, context->subscriptions[session]);
239 session->api().globalPrivacy().hideReadTime(
240 ) | rpl::skip(1) | rpl::filter(
241 !rpl::mappers::_1
242 ) | rpl::on_next([=] {
243 for (auto &[item, cache] : context->cachedRead) {
244 if (cache.data.current().state == Ui::WhoReadState::MyHidden) {
245 cache.data = Peers{ .state = Ui::WhoReadState::Unknown };
246 }

Callers 2

WhoReadIdsFunction · 0.85
WhoReactedIdsFunction · 0.85

Calls 15

ContextAtFunction · 0.85
AmPremiumValueFunction · 0.85
messageUpdatesMethod · 0.80
apiMethod · 0.80
reactionsRemovedMethod · 0.80
hideReadTimeMethod · 0.80
containsMethod · 0.45
changesMethod · 0.45
findMethod · 0.45
cancelMethod · 0.45
requestMethod · 0.45

Tested by

no test coverage detected