Skip to content

Commit afbfb4d

Browse files
committed
Apply community change from MessageChangeCommunity.
1 parent 36fccee commit afbfb4d

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

‎td/telegram/ChatManager.cpp‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8152,10 +8152,17 @@ void ChatManager::on_update_channel_linked_channel_id(ChannelId channel_id, Chan
81528152
}
81538153

81548154
void ChatManager::on_update_channel_linked_community_id(ChannelId channel_id, CommunityId linked_community_id) {
8155-
auto channel_full = get_channel_full_force(channel_id, true, "on_update_channel_linked_community_id");
8156-
if (channel_full != nullptr) {
8157-
on_update_channel_full_linked_community_id(channel_full, channel_id, linked_community_id);
8158-
update_channel_full(channel_full, channel_id, "on_update_channel_linked_community_id");
8155+
auto c = get_channel(channel_id);
8156+
if (c != nullptr && c->linked_community_id != linked_community_id) {
8157+
c->linked_community_id = linked_community_id;
8158+
c->need_save_to_database = true;
8159+
update_channel(c, channel_id);
8160+
8161+
auto channel_full = get_channel_full_force(channel_id, true, "on_update_channel_linked_community_id");
8162+
if (channel_full != nullptr) {
8163+
on_update_channel_full_linked_community_id(channel_full, channel_id, linked_community_id);
8164+
update_channel_full(channel_full, channel_id, "on_update_channel_linked_community_id");
8165+
}
81598166
}
81608167
}
81618168

‎td/telegram/MessageContent.cpp‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13697,9 +13697,22 @@ void apply_updates_from_service_message_content(Td *td, const MessageContent *co
1369713697
return td->messages_manager_->get_message_from_server(
1369813698
get_message_content_replied_message_full_id(dialog_id, content), Promise<Unit>(),
1369913699
"apply_updates_from_service_message_content");
13700-
case MessageContentType::ChangeCommunity:
13701-
// TODO apply community change
13702-
return;
13700+
case MessageContentType::ChangeCommunity: {
13701+
auto community_id = static_cast<const MessageChangeCommunity *>(content)->community_id;
13702+
switch (dialog_id.get_type()) {
13703+
case DialogType::User:
13704+
if (td->user_manager_->is_user_bot(dialog_id.get_user_id())) {
13705+
td->user_manager_->on_update_user_linked_community_id(dialog_id.get_user_id(), community_id);
13706+
}
13707+
return;
13708+
case DialogType::Channel:
13709+
td->chat_manager_->on_update_channel_linked_community_id(dialog_id.get_channel_id(), community_id);
13710+
return;
13711+
default:
13712+
LOG(ERROR) << "Receive ChangeCommunity in " << dialog_id;
13713+
return;
13714+
}
13715+
}
1370313716
default:
1370413717
// nothing to do
1370513718
return;

‎td/telegram/UserManager.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,6 +3771,12 @@ void UserManager::on_update_user_linked_community_id(UserId user_id, CommunityId
37713771
if (u != nullptr) {
37723772
on_update_user_linked_community_id(u, user_id, linked_community_id);
37733773
update_user(u, user_id);
3774+
3775+
auto user_full = get_user_full_force(user_id, "on_update_user_linked_community_id");
3776+
if (user_full != nullptr) {
3777+
on_update_user_full_linked_community_id(user_full, linked_community_id);
3778+
update_user_full(user_full, user_id, "on_update_user_linked_community_id");
3779+
}
37743780
}
37753781
}
37763782

0 commit comments

Comments
 (0)