Skip to content

Commit f18e7df

Browse files
committed
Support messageRichText in update_used_hashtags.
1 parent e3e6309 commit f18e7df

5 files changed

Lines changed: 41 additions & 0 deletions

File tree

td/telegram/MessageContent.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13289,6 +13289,11 @@ void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date)
1328913289
void update_used_hashtags(Td *td, const MessageContent *content) {
1329013290
const FormattedText *text = get_message_content_text(content);
1329113291
if (text == nullptr || text->text.empty()) {
13292+
if (content->get_type() == MessageContentType::RichText) {
13293+
for (const auto &hashtag : static_cast<const MessageRichText *>(content)->text.get_hashtags()) {
13294+
send_closure(td->hashtag_hints_, &HashtagHints::hashtag_used, hashtag);
13295+
}
13296+
}
1329213297
return;
1329313298
}
1329413299

td/telegram/RichMessage.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "td/telegram/Td.h"
1616
#include "td/telegram/telegram_api.h"
1717

18+
#include "td/utils/algorithm.h"
1819
#include "td/utils/common.h"
1920
#include "td/utils/FlatHashMap.h"
2021
#include "td/utils/logging.h"
@@ -116,6 +117,14 @@ bool RichMessage::has_bot_commands() const {
116117
return false;
117118
}
118119

120+
vector<string> RichMessage::get_hashtags() const {
121+
vector<string> hashtags;
122+
for (const auto &block : blocks_) {
123+
td::append(hashtags, block->get_hashtags());
124+
}
125+
return hashtags;
126+
}
127+
119128
td_api::object_ptr<td_api::richMessage> RichMessage::get_rich_message_object(Td *td, bool skip_bot_commands) const {
120129
return td_api::make_object<td_api::richMessage>(
121130
get_page_blocks_object(blocks_, td, string(), string(), skip_bot_commands), is_rtl_, is_full_);

td/telegram/RichMessage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class RichMessage {
5252

5353
bool has_bot_commands() const;
5454

55+
vector<string> get_hashtags() const;
56+
5557
td_api::object_ptr<td_api::richMessage> get_rich_message_object(Td *td, bool skip_bot_commands) const;
5658

5759
RichMessage clone() const;

td/telegram/WebPageBlock.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,6 +3526,29 @@ bool WebPageBlock::has_bot_commands() const {
35263526
return result;
35273527
}
35283528

3529+
vector<string> WebPageBlock::get_hashtags() const {
3530+
vector<string> result;
3531+
for_each_rich_text([&](const RichText *text) {
3532+
if (text->type == RichText::Type::Hashtag) {
3533+
string hashtag;
3534+
text->for_each_rich_text([&](const RichText *text) {
3535+
if (text->type == RichText::Type::Plain) {
3536+
hashtag += text->content;
3537+
}
3538+
});
3539+
if (!hashtag.empty()) {
3540+
if (hashtag[0] == '#') {
3541+
hashtag = hashtag.substr(1);
3542+
}
3543+
if (!hashtag.empty()) {
3544+
result.push_back(hashtag);
3545+
}
3546+
}
3547+
}
3548+
});
3549+
return result;
3550+
}
3551+
35293552
template <class F>
35303553
void WebPageBlock::call_impl(Type type, const WebPageBlock *ptr, F &&f) {
35313554
switch (type) {

td/telegram/WebPageBlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class WebPageBlock {
108108

109109
bool has_bot_commands() const;
110110

111+
vector<string> get_hashtags() const;
112+
111113
virtual unique_ptr<WebPageBlock> clone() const = 0;
112114

113115
virtual td_api::object_ptr<td_api::PageBlock> get_page_block_object(Context *context) const = 0;

0 commit comments

Comments
 (0)