| 359 | } |
| 360 | |
| 361 | [[nodiscard]] rpl::producer<PeersWithReactions> WhoReactedIds( |
| 362 | not_null<HistoryItem*> item, |
| 363 | const ReactionId &reaction, |
| 364 | not_null<QWidget*> context) { |
| 365 | auto weak = base::make_weak(context); |
| 366 | const auto session = &item->history()->session(); |
| 367 | return [=](auto consumer) { |
| 368 | if (!weak) { |
| 369 | return rpl::lifetime(); |
| 370 | } |
| 371 | const auto context = PreparedContextAt(weak.get(), session); |
| 372 | auto &entry = context->cacheReacted(item, reaction); |
| 373 | if (!entry.requestId) { |
| 374 | using Flag = MTPmessages_GetMessageReactionsList::Flag; |
| 375 | entry.requestId = session->api().request( |
| 376 | MTPmessages_GetMessageReactionsList( |
| 377 | MTP_flags(reaction.empty() |
| 378 | ? Flag(0) |
| 379 | : Flag::f_reaction), |
| 380 | item->history()->peer->input(), |
| 381 | MTP_int(item->id), |
| 382 | ReactionToMTP(reaction), |
| 383 | MTPstring(), // offset |
| 384 | MTP_int(kContextReactionsLimit) |
| 385 | ) |
| 386 | ).done([=](const MTPmessages_MessageReactionsList &result) { |
| 387 | auto &entry = context->cacheReacted(item, reaction); |
| 388 | entry.requestId = 0; |
| 389 | |
| 390 | result.match([&]( |
| 391 | const MTPDmessages_messageReactionsList &data) { |
| 392 | session->data().processUsers(data.vusers()); |
| 393 | session->data().processChats(data.vchats()); |
| 394 | |
| 395 | auto parsed = PeersWithReactions{ |
| 396 | .fullReactionsCount = data.vcount().v, |
| 397 | }; |
| 398 | parsed.list.reserve(data.vreactions().v.size()); |
| 399 | for (const auto &vote : data.vreactions().v) { |
| 400 | const auto &data = vote.data(); |
| 401 | parsed.list.push_back(PeerWithReaction{ |
| 402 | .peerWithDate = { |
| 403 | .peer = peerFromMTP(data.vpeer_id()), |
| 404 | .date = data.vdate().v, |
| 405 | .dateReacted = true, |
| 406 | }, |
| 407 | .reaction = Data::ReactionFromMTP( |
| 408 | data.vreaction()), |
| 409 | }); |
| 410 | } |
| 411 | entry.data = std::move(parsed); |
| 412 | }); |
| 413 | }).fail([=] { |
| 414 | auto &entry = context->cacheReacted(item, reaction); |
| 415 | entry.requestId = 0; |
| 416 | if (entry.data.current().state == WhoReadState::Unknown) { |
| 417 | entry.data = PeersWithReactions{ |
| 418 | .state = WhoReadState::Empty, |
no test coverage detected