Separate inline query results cache for different chat types.
This commit is contained in:
parent
6a38d219f0
commit
9e0dba0db4
@ -66,8 +66,10 @@ class GetInlineBotResultsQuery : public Td::ResultHandler {
|
|||||||
explicit GetInlineBotResultsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
explicit GetInlineBotResultsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
NetQueryRef send(UserId bot_user_id, tl_object_ptr<telegram_api::InputUser> bot_input_user, DialogId dialog_id,
|
NetQueryRef send(UserId bot_user_id, tl_object_ptr<telegram_api::InputUser> bot_input_user,
|
||||||
Location user_location, const string &query, const string &offset, uint64 query_hash) {
|
tl_object_ptr<telegram_api::InputPeer> input_peer, Location user_location, const string &query,
|
||||||
|
const string &offset, uint64 query_hash) {
|
||||||
|
CHECK(input_peer != nullptr);
|
||||||
bot_user_id_ = bot_user_id;
|
bot_user_id_ = bot_user_id;
|
||||||
query_hash_ = query_hash;
|
query_hash_ = query_hash;
|
||||||
int32 flags = 0;
|
int32 flags = 0;
|
||||||
@ -75,11 +77,6 @@ class GetInlineBotResultsQuery : public Td::ResultHandler {
|
|||||||
flags |= GET_INLINE_BOT_RESULTS_FLAG_HAS_LOCATION;
|
flags |= GET_INLINE_BOT_RESULTS_FLAG_HAS_LOCATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
|
||||||
if (input_peer == nullptr) {
|
|
||||||
input_peer = make_tl_object<telegram_api::inputPeerEmpty>();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto net_query = G()->net_query_creator().create(telegram_api::messages_getInlineBotResults(
|
auto net_query = G()->net_query_creator().create(telegram_api::messages_getInlineBotResults(
|
||||||
flags, std::move(bot_input_user), std::move(input_peer),
|
flags, std::move(bot_input_user), std::move(input_peer),
|
||||||
user_location.empty() ? nullptr : user_location.get_input_geo_point(), query, offset));
|
user_location.empty() ? nullptr : user_location.get_input_geo_point(), query, offset));
|
||||||
@ -760,13 +757,34 @@ uint64 InlineQueriesManager::send_inline_query(UserId bot_user_id, DialogId dial
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_broadcast_channel =
|
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
||||||
dialog_id.get_type() == DialogType::Channel &&
|
if (input_peer == nullptr) {
|
||||||
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast;
|
input_peer = make_tl_object<telegram_api::inputPeerEmpty>();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto peer_type = [&] {
|
||||||
|
switch (input_peer->get_id()) {
|
||||||
|
case telegram_api::inputPeerEmpty::ID:
|
||||||
|
return 0;
|
||||||
|
case telegram_api::inputPeerSelf::ID:
|
||||||
|
return 1;
|
||||||
|
case telegram_api::inputPeerChat::ID:
|
||||||
|
return 2;
|
||||||
|
case telegram_api::inputPeerUser::ID:
|
||||||
|
case telegram_api::inputPeerUserFromMessage::ID:
|
||||||
|
return dialog_id == DialogId(bot_user_id) ? 3 : 4;
|
||||||
|
case telegram_api::inputPeerChannel::ID:
|
||||||
|
case telegram_api::inputPeerChannelFromMessage::ID:
|
||||||
|
return 5 + static_cast<int>(td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()));
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
uint64 query_hash = std::hash<std::string>()(trim(query));
|
uint64 query_hash = std::hash<std::string>()(trim(query));
|
||||||
query_hash = query_hash * 2023654985u + bot_user_id.get();
|
query_hash = query_hash * 2023654985u + bot_user_id.get();
|
||||||
query_hash = query_hash * 2023654985u + static_cast<uint64>(is_broadcast_channel);
|
query_hash = query_hash * 2023654985u + static_cast<uint64>(peer_type);
|
||||||
query_hash = query_hash * 2023654985u + std::hash<std::string>()(offset);
|
query_hash = query_hash * 2023654985u + std::hash<std::string>()(offset);
|
||||||
if (r_bot_data.ok().need_location) {
|
if (r_bot_data.ok().need_location) {
|
||||||
query_hash = query_hash * 2023654985u + static_cast<uint64>(user_location.get_latitude() * 1e4);
|
query_hash = query_hash * 2023654985u + static_cast<uint64>(user_location.get_latitude() * 1e4);
|
||||||
@ -791,8 +809,8 @@ uint64 InlineQueriesManager::send_inline_query(UserId bot_user_id, DialogId dial
|
|||||||
pending_inline_query_->promise.set_error(Status::Error(406, "Request cancelled"));
|
pending_inline_query_->promise.set_error(Status::Error(406, "Request cancelled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
pending_inline_query_ = make_unique<PendingInlineQuery>(
|
pending_inline_query_ = make_unique<PendingInlineQuery>(PendingInlineQuery{
|
||||||
PendingInlineQuery{query_hash, bot_user_id, dialog_id, user_location, query, offset, std::move(promise)});
|
query_hash, bot_user_id, std::move(input_peer), user_location, query, offset, std::move(promise)});
|
||||||
|
|
||||||
loop();
|
loop();
|
||||||
|
|
||||||
@ -816,9 +834,9 @@ void InlineQueriesManager::loop() {
|
|||||||
}
|
}
|
||||||
sent_query_ =
|
sent_query_ =
|
||||||
td_->create_handler<GetInlineBotResultsQuery>(std::move(pending_inline_query_->promise))
|
td_->create_handler<GetInlineBotResultsQuery>(std::move(pending_inline_query_->promise))
|
||||||
->send(pending_inline_query_->bot_user_id, std::move(bot_input_user), pending_inline_query_->dialog_id,
|
->send(pending_inline_query_->bot_user_id, std::move(bot_input_user),
|
||||||
pending_inline_query_->user_location, pending_inline_query_->query, pending_inline_query_->offset,
|
std::move(pending_inline_query_->input_peer), pending_inline_query_->user_location,
|
||||||
pending_inline_query_->query_hash);
|
pending_inline_query_->query, pending_inline_query_->offset, pending_inline_query_->query_hash);
|
||||||
|
|
||||||
next_inline_query_time_ = now + INLINE_QUERY_DELAY_MS * 1e-3;
|
next_inline_query_time_ = now + INLINE_QUERY_DELAY_MS * 1e-3;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ class InlineQueriesManager : public Actor {
|
|||||||
struct PendingInlineQuery {
|
struct PendingInlineQuery {
|
||||||
uint64 query_hash;
|
uint64 query_hash;
|
||||||
UserId bot_user_id;
|
UserId bot_user_id;
|
||||||
DialogId dialog_id;
|
tl_object_ptr<telegram_api::InputPeer> input_peer;
|
||||||
Location user_location;
|
Location user_location;
|
||||||
string query;
|
string query;
|
||||||
string offset;
|
string offset;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user