Store public message links separately for each dialog.

GitOrigin-RevId: 2b227d07c8ec7c42cabd7af78ffde3ff07799f92
This commit is contained in:
levlam 2020-09-14 01:39:34 +03:00
parent 1cd9f5d8c9
commit e082b2ac49
2 changed files with 12 additions and 6 deletions

View File

@ -15652,8 +15652,9 @@ std::pair<string, string> MessagesManager::get_public_message_link(FullMessageId
return {};
}
auto it = public_message_links_[for_group].find({linked_dialog_id, linked_message_id});
if (it == public_message_links_[for_group].end()) {
auto &links = public_message_links_[for_group][linked_dialog_id].links_;
auto it = links.find(linked_message_id);
if (it == links.end()) {
td_->create_handler<ExportChannelMessageLinkQuery>(std::move(promise))
->send(linked_dialog_id.get_channel_id(), linked_message_id, for_group, false);
return {};
@ -15665,8 +15666,9 @@ std::pair<string, string> MessagesManager::get_public_message_link(FullMessageId
}
}
auto it = public_message_links_[for_group].find(full_message_id);
if (it == public_message_links_[for_group].end()) {
auto &links = public_message_links_[for_group][dialog_id].links_;
auto it = links.find(m->message_id);
if (it == links.end()) {
td_->create_handler<ExportChannelMessageLinkQuery>(std::move(promise))
->send(dialog_id.get_channel_id(), m->message_id, for_group, false);
return {};
@ -15683,7 +15685,8 @@ std::pair<string, string> MessagesManager::get_public_message_link(FullMessageId
void MessagesManager::on_get_public_message_link(FullMessageId full_message_id, bool for_group, string url,
string html) {
LOG_IF(ERROR, url.empty() && html.empty()) << "Receive empty public link for " << full_message_id;
public_message_links_[for_group][full_message_id] = {std::move(url), std::move(html)};
public_message_links_[for_group][full_message_id.get_dialog_id()].links_[full_message_id.get_message_id()] = {
std::move(url), std::move(html)};
}
string MessagesManager::get_message_link(FullMessageId full_message_id, Promise<Unit> &&promise) {

View File

@ -2978,7 +2978,10 @@ class MessagesManager : public Actor {
std::unordered_map<int64, FoundMessages> found_fts_messages_; // random_id -> FoundMessages
std::unordered_map<int64, FoundMessages> found_message_public_forwards_; // random_id -> FoundMessages
std::unordered_map<FullMessageId, std::pair<string, string>, FullMessageIdHash> public_message_links_[2];
struct PublicMessageLinks {
std::unordered_map<MessageId, std::pair<string, string>, MessageIdHash> links_;
};
std::unordered_map<DialogId, PublicMessageLinks, DialogIdHash> public_message_links_[2];
std::unordered_map<int64, tl_object_ptr<td_api::chatEvents>> chat_events_; // random_id -> chat events