Add get_message_content_new_participant_count.

GitOrigin-RevId: b4c884cdd8d947af3a5a8a3263da2b3bc547be4d
This commit is contained in:
levlam 2018-09-28 19:07:14 +03:00
parent d5683ee224
commit 6539fbcff6
2 changed files with 20 additions and 20 deletions

View File

@ -23363,6 +23363,19 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(DialogId dialog
return add_message_to_dialog(d, std::move(message), from_update, need_update, need_update_dialog_pos, source);
}
int32 MessagesManager::get_message_content_new_participant_count(const MessageContent *content) {
switch (content->get_type()) {
case MessageContentType::ChatAddUsers:
return narrow_cast<int32>(static_cast<const MessageChatAddUsers *>(content)->user_ids.size());
case MessageContentType::ChatJoinedByLink:
return 1;
case MessageContentType::ChatDeleteUser:
return -1;
default:
return 0;
}
}
MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, unique_ptr<Message> message,
bool from_update, bool *need_update,
bool *need_update_dialog_pos, const char *source) {
@ -23823,30 +23836,15 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
if (from_update && message_id.is_server() && dialog_id.get_type() == DialogType::Channel) {
int32 new_participant_count = 0;
switch (message_content_type) {
case MessageContentType::ChatAddUsers:
new_participant_count =
narrow_cast<int32>(static_cast<const MessageChatAddUsers *>(message->content.get())->user_ids.size());
break;
case MessageContentType::ChatJoinedByLink:
new_participant_count = 1;
break;
case MessageContentType::ChatDeleteUser:
new_participant_count = -1;
break;
case MessageContentType::PinMessage:
td_->contacts_manager_->on_update_channel_pinned_message(
dialog_id.get_channel_id(), static_cast<const MessagePinMessage *>(message->content.get())->message_id);
break;
default:
// nothing to do
break;
}
int32 new_participant_count = get_message_content_new_participant_count(message->content.get());
if (new_participant_count != 0) {
td_->contacts_manager_->speculative_add_channel_participants(dialog_id.get_channel_id(), new_participant_count,
message->sender_user_id == my_user_id);
}
if (message_content_type == MessageContentType::PinMessage) {
td_->contacts_manager_->on_update_channel_pinned_message(
dialog_id.get_channel_id(), static_cast<const MessagePinMessage *>(message->content.get())->message_id);
}
}
if (!td_->auth_manager_->is_bot() && from_update && message->forward_info == nullptr &&
(message->is_outgoing || dialog_id == my_dialog_id)) {

View File

@ -2249,6 +2249,8 @@ class MessagesManager : public Actor {
static int32 get_message_content_index_mask(const MessageContent *content, const Td *td, bool is_secret,
bool is_outgoing);
static int32 get_message_content_new_participant_count(const MessageContent *content);
Message *add_message_to_dialog(DialogId dialog_id, unique_ptr<Message> message, bool from_update, bool *need_update,
bool *need_update_dialog_pos, const char *source);