Move update_used_hashtags to MessageContent.cpp.

GitOrigin-RevId: 67b8a3defbc9f2249dff0d57a40bd42ec743cd39
This commit is contained in:
levlam 2020-01-27 03:34:23 +03:00
parent e666d10c8d
commit 4a1125887a
3 changed files with 35 additions and 27 deletions

View File

@ -27,6 +27,7 @@
#include "td/telegram/Game.h"
#include "td/telegram/Game.hpp"
#include "td/telegram/Global.h"
#include "td/telegram/HashtagHints.h"
#include "td/telegram/InputMessageText.h"
#include "td/telegram/Location.h"
#include "td/telegram/MessageEntity.h"
@ -5189,4 +5190,35 @@ void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date)
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, date);
}
void update_used_hashtags(Td *td, const MessageContent *content) {
const FormattedText *text = get_message_content_text(content);
if (text == nullptr || text->text.empty()) {
return;
}
const unsigned char *ptr = Slice(text->text).ubegin();
const unsigned char *end = Slice(text->text).uend();
int32 utf16_pos = 0;
for (auto &entity : text->entities) {
if (entity.type != MessageEntity::Type::Hashtag) {
continue;
}
while (utf16_pos < entity.offset && ptr < end) {
utf16_pos += 1 + (ptr[0] >= 0xf0);
ptr = next_utf8_unsafe(ptr, nullptr, "update_used_hashtags");
}
CHECK(utf16_pos == entity.offset);
auto from = ptr;
while (utf16_pos < entity.offset + entity.length && ptr < end) {
utf16_pos += 1 + (ptr[0] >= 0xf0);
ptr = next_utf8_unsafe(ptr, nullptr, "update_used_hashtags 2");
}
CHECK(utf16_pos == entity.offset + entity.length);
auto to = ptr;
send_closure(td->hashtag_hints_, &HashtagHints::hashtag_used, Slice(from + 1, to).str());
}
}
} // namespace td

View File

@ -268,4 +268,6 @@ StickerSetId add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet
void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date);
void update_used_hashtags(Td *td, const MessageContent *content);
} // namespace td

View File

@ -20,7 +20,6 @@
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/HashtagHints.h"
#include "td/telegram/InlineQueriesManager.h"
#include "td/telegram/InputMessageText.h"
#include "td/telegram/Location.h"
@ -29014,33 +29013,8 @@ void MessagesManager::update_used_hashtags(DialogId dialog_id, const Message *m)
m->via_bot_user_id.is_valid() || m->hide_via_bot || m->forward_info != nullptr || m->had_forward_info) {
return;
}
const FormattedText *text = get_message_content_text(m->content.get());
if (text == nullptr || text->text.empty()) {
return;
}
const unsigned char *ptr = Slice(text->text).ubegin();
const unsigned char *end = Slice(text->text).uend();
int32 utf16_pos = 0;
for (auto &entity : text->entities) {
if (entity.type != MessageEntity::Type::Hashtag) {
continue;
}
while (utf16_pos < entity.offset && ptr < end) {
utf16_pos += 1 + (ptr[0] >= 0xf0);
ptr = next_utf8_unsafe(ptr, nullptr, "update_used_hashtags");
}
CHECK(utf16_pos == entity.offset);
auto from = ptr;
while (utf16_pos < entity.offset + entity.length && ptr < end) {
utf16_pos += 1 + (ptr[0] >= 0xf0);
ptr = next_utf8_unsafe(ptr, nullptr, "update_used_hashtags 2");
}
CHECK(utf16_pos == entity.offset + entity.length);
auto to = ptr;
send_closure(td_->hashtag_hints_, &HashtagHints::hashtag_used, Slice(from + 1, to).str());
}
::td::update_used_hashtags(td_, m->content.get());
}
void MessagesManager::update_top_dialogs(DialogId dialog_id, const Message *m) {