Add update_top_dialogs function.

GitOrigin-RevId: c5ea2e50e47693d37cb9e2d7dfea6176a2afed43
This commit is contained in:
levlam 2019-11-30 19:29:52 +03:00
parent a75e53cdf3
commit 0c2c587f8c
2 changed files with 72 additions and 57 deletions

View File

@ -25212,64 +25212,14 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
auto pinned_message_id = get_message_content_pinned_message_id(m->content.get()); auto pinned_message_id = get_message_content_pinned_message_id(m->content.get());
on_update_dialog_pinned_message_id(dialog_id, pinned_message_id); on_update_dialog_pinned_message_id(dialog_id, pinned_message_id);
} }
if (!td_->auth_manager_->is_bot() && from_update && m->forward_info == nullptr && !m->had_forward_info && if (!td_->auth_manager_->is_bot() && from_update && (m->is_outgoing || dialog_id == my_dialog_id) &&
(m->is_outgoing || dialog_id == my_dialog_id) && dialog_id.get_type() != DialogType::SecretChat && dialog_id.get_type() != DialogType::SecretChat && !message_id.is_local() && m->forward_info == nullptr &&
!message_id.is_local()) { !m->had_forward_info) {
on_sent_message_content(td_, m->content.get()); on_sent_message_content(td_, m->content.get());
} }
if (from_update) { if (from_update) {
update_used_hashtags(dialog_id, m); update_used_hashtags(dialog_id, m);
} update_top_dialogs(dialog_id, m);
if (!td_->auth_manager_->is_bot() && from_update && message_id.is_server() &&
(m->is_outgoing || dialog_id == my_dialog_id) && dialog_id.get_type() != DialogType::SecretChat) {
if (m->via_bot_user_id.is_valid() && m->forward_info == nullptr && !m->had_forward_info) {
// forwarded game messages can't be distinguished from sent via bot game messages, so increase rating anyway
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, TopDialogCategory::BotInline,
DialogId(m->via_bot_user_id), m->date);
}
if (m->forward_info != nullptr && d->last_outgoing_forwarded_message_date < m->date) {
TopDialogCategory category =
dialog_id.get_type() == DialogType::User ? TopDialogCategory::ForwardUsers : TopDialogCategory::ForwardChats;
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, m->date);
d->last_outgoing_forwarded_message_date = m->date;
}
TopDialogCategory category = TopDialogCategory::Size;
switch (dialog_id.get_type()) {
case DialogType::User: {
if (td_->contacts_manager_->is_user_bot(dialog_id.get_user_id())) {
category = TopDialogCategory::BotPM;
} else {
category = TopDialogCategory::Correspondent;
}
break;
}
case DialogType::Chat:
category = TopDialogCategory::Group;
break;
case DialogType::Channel:
switch (td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id())) {
case ChannelType::Broadcast:
category = TopDialogCategory::Channel;
break;
case ChannelType::Megagroup:
category = TopDialogCategory::Group;
break;
case ChannelType::Unknown:
break;
default:
UNREACHABLE();
break;
}
break;
case DialogType::SecretChat:
case DialogType::None:
default:
UNREACHABLE();
}
if (category != TopDialogCategory::Size) {
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, m->date);
}
} }
Message *result_message = treap_insert_message(&d->messages, std::move(message)); Message *result_message = treap_insert_message(&d->messages, std::move(message));
@ -27833,8 +27783,8 @@ void MessagesManager::after_get_channel_difference(DialogId dialog_id, bool succ
void MessagesManager::update_used_hashtags(DialogId dialog_id, const Message *m) { void MessagesManager::update_used_hashtags(DialogId dialog_id, const Message *m) {
CHECK(m != nullptr); CHECK(m != nullptr);
if (td_->auth_manager_->is_bot() || m->via_bot_user_id.is_valid() || m->hide_via_bot || m->forward_info != nullptr || if (td_->auth_manager_->is_bot() || (!m->is_outgoing && dialog_id != get_my_dialog_id()) ||
m->had_forward_info || (!m->is_outgoing && dialog_id != get_my_dialog_id())) { m->via_bot_user_id.is_valid() || m->hide_via_bot || m->forward_info != nullptr || m->had_forward_info) {
return; return;
} }
const FormattedText *text = get_message_content_text(m->content.get()); const FormattedText *text = get_message_content_text(m->content.get());
@ -27866,6 +27816,68 @@ void MessagesManager::update_used_hashtags(DialogId dialog_id, const Message *m)
} }
} }
void MessagesManager::update_top_dialogs(DialogId dialog_id, const Message *m) {
auto dialog_type = dialog_id.get_type();
if (td_->auth_manager_->is_bot() || (!m->is_outgoing && dialog_id != get_my_dialog_id()) ||
dialog_type == DialogType::SecretChat || !m->message_id.is_any_server()) {
return;
}
bool is_forward = m->forward_info != nullptr || m->had_forward_info;
if (m->via_bot_user_id.is_valid() && !is_forward) {
// forwarded game messages can't be distinguished from sent via bot game messages, so increase rating anyway
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, TopDialogCategory::BotInline,
DialogId(m->via_bot_user_id), m->date);
}
if (is_forward) {
auto &last_forward_date = last_outgoing_forwarded_message_date_[dialog_id];
if (last_forward_date < m->date) {
TopDialogCategory category =
dialog_type == DialogType::User ? TopDialogCategory::ForwardUsers : TopDialogCategory::ForwardChats;
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, m->date);
last_forward_date = m->date;
}
}
TopDialogCategory category = TopDialogCategory::Size;
switch (dialog_type) {
case DialogType::User: {
if (td_->contacts_manager_->is_user_bot(dialog_id.get_user_id())) {
category = TopDialogCategory::BotPM;
} else {
category = TopDialogCategory::Correspondent;
}
break;
}
case DialogType::Chat:
category = TopDialogCategory::Group;
break;
case DialogType::Channel:
switch (td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id())) {
case ChannelType::Broadcast:
category = TopDialogCategory::Channel;
break;
case ChannelType::Megagroup:
category = TopDialogCategory::Group;
break;
case ChannelType::Unknown:
break;
default:
UNREACHABLE();
break;
}
break;
case DialogType::SecretChat:
case DialogType::None:
default:
UNREACHABLE();
}
if (category != TopDialogCategory::Size) {
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, m->date);
}
}
MessagesManager::Message *MessagesManager::continue_send_message(DialogId dialog_id, unique_ptr<Message> &&m, MessagesManager::Message *MessagesManager::continue_send_message(DialogId dialog_id, unique_ptr<Message> &&m,
uint64 logevent_id) { uint64 logevent_id) {
CHECK(logevent_id != 0); CHECK(logevent_id != 0);

View File

@ -1041,7 +1041,6 @@ class MessagesManager : public Actor {
int32 pending_last_message_date = 0; int32 pending_last_message_date = 0;
MessageId pending_last_message_id; MessageId pending_last_message_id;
MessageId max_notification_message_id; MessageId max_notification_message_id;
int32 last_outgoing_forwarded_message_date = 0;
MessageId max_added_message_id; MessageId max_added_message_id;
MessageId being_added_message_id; MessageId being_added_message_id;
@ -2271,6 +2270,8 @@ class MessagesManager : public Actor {
void update_used_hashtags(DialogId dialog_id, const Message *m); void update_used_hashtags(DialogId dialog_id, const Message *m);
void update_top_dialogs(DialogId dialog_id, const Message *m);
string get_search_text(const Message *m) const; string get_search_text(const Message *m) const;
unique_ptr<Message> parse_message(DialogId dialog_id, const BufferSlice &value, bool is_scheduled); unique_ptr<Message> parse_message(DialogId dialog_id, const BufferSlice &value, bool is_scheduled);
@ -2592,6 +2593,8 @@ class MessagesManager : public Actor {
std::unordered_map<FullMessageId, FileSourceId, FullMessageIdHash> full_message_id_to_file_source_id_; std::unordered_map<FullMessageId, FileSourceId, FullMessageIdHash> full_message_id_to_file_source_id_;
std::unordered_map<DialogId, int32, DialogIdHash> last_outgoing_forwarded_message_date_;
struct OnlineMemberCountInfo { struct OnlineMemberCountInfo {
int32 online_member_count = 0; int32 online_member_count = 0;
double updated_time = 0; double updated_time = 0;