Pass list of members in speculative_*channel_participant.

GitOrigin-RevId: 765ef5abbb2a2c139810dda32aa1e2c1fe5e4009
This commit is contained in:
levlam 2019-03-12 16:20:53 +03:00
parent e406d6ea41
commit a893653ba6
5 changed files with 54 additions and 20 deletions

View File

@ -7544,6 +7544,31 @@ bool ContactsManager::speculative_add_count(int32 &count, int32 new_count) {
return true;
}
void ContactsManager::speculative_add_channel_participants(ChannelId channel_id, const vector<UserId> &added_user_ids,
bool by_me) {
int32 new_participant_count = 0;
for (auto &user_id : added_user_ids) {
if (!user_id.is_valid()) {
continue;
}
new_participant_count++;
}
if (new_participant_count == 0) {
return;
}
speculative_add_channel_participants(channel_id, new_participant_count, by_me);
}
void ContactsManager::speculative_delete_channel_participant(ChannelId channel_id, UserId deleted_user_id, bool by_me) {
if (!deleted_user_id.is_valid()) {
return;
}
speculative_add_channel_participants(channel_id, -1, by_me);
}
void ContactsManager::speculative_add_channel_participants(ChannelId channel_id, int32 new_participant_count,
bool by_me) {
if (by_me) {

View File

@ -172,7 +172,9 @@ class ContactsManager : public Actor {
void on_update_dialog_administrators(DialogId dialog_id, vector<UserId> administrator_user_ids, bool have_access);
void speculative_add_channel_participants(ChannelId channel_id, int32 new_participant_count, bool by_me);
void speculative_add_channel_participants(ChannelId channel_id, const vector<UserId> &added_user_ids, bool by_me);
void speculative_delete_channel_participant(ChannelId channel_id, UserId deleted_user_id, bool by_me);
void invalidate_channel_full(ChannelId channel_id, bool drop_invite_link);
@ -891,6 +893,8 @@ class ContactsManager : public Actor {
static bool speculative_add_count(int32 &count, int32 new_count);
void speculative_add_channel_participants(ChannelId channel_id, int32 new_participant_count, bool by_me);
void speculative_add_channel_user(ChannelId channel_id, UserId user_id, DialogParticipantStatus status,
DialogParticipantStatus old_status);

View File

@ -2618,19 +2618,6 @@ int32 get_message_content_index_mask(const MessageContent *content, const Td *td
return 0;
}
int32 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;
}
}
MessageId get_message_content_pinned_message_id(const MessageContent *content) {
switch (content->get_type()) {
case MessageContentType::PinMessage:
@ -2653,6 +2640,11 @@ MessageId get_message_content_replied_message_id(const MessageContent *content)
}
}
vector<UserId> get_message_content_added_user_ids(const MessageContent *content) {
CHECK(content->get_type() == MessageContentType::ChatAddUsers);
return static_cast<const MessageChatAddUsers *>(content)->user_ids;
}
UserId get_message_content_deleted_user_id(const MessageContent *content) {
switch (content->get_type()) {
case MessageContentType::ChatDeleteUser:

View File

@ -167,12 +167,12 @@ bool update_opened_message_content(MessageContent *content);
int32 get_message_content_index_mask(const MessageContent *content, const Td *td, bool is_secret, bool is_outgoing);
int32 get_message_content_new_participant_count(const MessageContent *content);
MessageId get_message_content_pinned_message_id(const MessageContent *content);
MessageId get_message_content_replied_message_id(const MessageContent *content);
vector<UserId> get_message_content_added_user_ids(const MessageContent *content);
UserId get_message_content_deleted_user_id(const MessageContent *content);
int32 get_message_content_live_location_period(const MessageContent *content);

View File

@ -22105,10 +22105,23 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
register_message_content(td_, m->content.get(), {dialog_id, message_id});
if (from_update && message_id.is_server() && dialog_id.get_type() == DialogType::Channel) {
int32 new_participant_count = get_message_content_new_participant_count(m->content.get());
if (new_participant_count != 0) {
td_->contacts_manager_->speculative_add_channel_participants(dialog_id.get_channel_id(), new_participant_count,
m->sender_user_id == my_user_id);
switch (message_content_type) {
case MessageContentType::ChatAddUsers:
td_->contacts_manager_->speculative_add_channel_participants(
dialog_id.get_channel_id(), get_message_content_added_user_ids(m->content.get()),
m->sender_user_id == my_user_id);
break;
case MessageContentType::ChatJoinedByLink:
td_->contacts_manager_->speculative_add_channel_participants(dialog_id.get_channel_id(), {m->sender_user_id},
m->sender_user_id == my_user_id);
break;
case MessageContentType::ChatDeleteUser:
td_->contacts_manager_->speculative_delete_channel_participant(
dialog_id.get_channel_id(), get_message_content_deleted_user_id(m->content.get()),
m->sender_user_id == my_user_id);
break;
default:
break;
}
}
if (from_update && message_id.is_server() && message_content_type == MessageContentType::PinMessage) {