Add support for location-based supergroups in getCreatedPublicChats.

GitOrigin-RevId: b328d62a998dc2e2b83d9721e001f9feee129d4e
This commit is contained in:
levlam 2019-10-22 13:40:24 +03:00
parent 918f6a0cfd
commit 892a091998
8 changed files with 59 additions and 26 deletions

View File

@ -611,6 +611,7 @@ set(TDLIB_SOURCE
td/telegram/PollManager.h
td/telegram/PrivacyManager.h
td/telegram/PtsManager.h
td/telegram/PublicDialogType.h
td/telegram/QueryCombiner.h
td/telegram/ReplyMarkup.h
td/telegram/RequestActor.h

View File

@ -274,6 +274,7 @@ function split_file($file, $chunks, $undo) {
'get_erase_logevent_promise|parse_time|store_time' => 'logevent/LogEventHelper',
'messages_manager[_(-][^.]|MessagesManager' => 'MessagesManager',
'notification_manager[_(-][^.]|NotificationManager|notifications[)]' => 'NotificationManager',
'PublicDialogType|get_public_dialog_type' => 'PublicDialogType',
'SecretChatActor' => 'SecretChatActor',
'secret_chats_manager[_(-][^.]|SecretChatsManager' => 'SecretChatsManager',
'stickers_manager[_(-][^.]|StickersManager' => 'StickersManager',

View File

@ -667,6 +667,15 @@ chatInviteLink invite_link:string = ChatInviteLink;
chatInviteLinkInfo chat_id:int53 type:ChatType title:string photo:chatPhoto member_count:int32 member_user_ids:vector<int32> is_public:Bool = ChatInviteLinkInfo;
//@class PublicChatType @description Describes a type of public chats
//@description The chat is public, because it has username
publicChatTypeHasUsername = PublicChatType;
//@description The chat is public, because it is a location-based supergroup
publicChatTypeIsLocationBased = PublicChatType;
//@class ChatActionBar @description Describes actions which should be possible to do through a chat action bar
//@description The chat can be reported as spam using the method reportChat with the reason chatReportReasonSpam
@ -3115,8 +3124,8 @@ clearRecentlyFoundChats = Ok;
//@description Checks whether a username can be set for a chat @chat_id Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if chat is being created @username Username to be checked
checkChatUsername chat_id:int53 username:string = CheckChatUsernameResult;
//@description Returns a list of public chats with username created by the user
getCreatedPublicChats = Chats;
//@description Returns a list of public chats of the specified type, owned by the user @type Type of the public chats to return
getCreatedPublicChats type:PublicChatType = Chats;
//@description Returns a list of basic group and supergroup chats, which can be used as a discussion group for a channel. Basic group chats need to be first upgraded to supergroups before they can be set as a discussion group
getSuitableDiscussionChats = Chats;

Binary file not shown.

View File

@ -1969,13 +1969,20 @@ class MigrateChatQuery : public Td::ResultHandler {
class GetCreatedPublicChannelsQuery : public Td::ResultHandler {
Promise<Unit> promise_;
PublicDialogType type_;
public:
explicit GetCreatedPublicChannelsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send() {
send_query(G()->net_query_creator().create(create_storer(telegram_api::channels_getAdminedPublicChannels())));
void send(PublicDialogType type) {
type_ = type;
int32 flags = 0;
if (type_ == PublicDialogType::IsLocationBased) {
flags |= telegram_api::channels_getAdminedPublicChannels::BY_LOCATION_MASK;
}
send_query(G()->net_query_creator().create(
create_storer(telegram_api::channels_getAdminedPublicChannels(flags, false /*ignored*/, false /*ignored*/))));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -1990,13 +1997,13 @@ class GetCreatedPublicChannelsQuery : public Td::ResultHandler {
switch (constructor_id) {
case telegram_api::messages_chats::ID: {
auto chats = move_tl_object_as<telegram_api::messages_chats>(chats_ptr);
td->contacts_manager_->on_get_created_public_channels(std::move(chats->chats_));
td->contacts_manager_->on_get_created_public_channels(type_, std::move(chats->chats_));
break;
}
case telegram_api::messages_chatsSlice::ID: {
auto chats = move_tl_object_as<telegram_api::messages_chatsSlice>(chats_ptr);
LOG(ERROR) << "Receive chatsSlice in result of GetCreatedPublicChannelsQuery";
td->contacts_manager_->on_get_created_public_channels(std::move(chats->chats_));
td->contacts_manager_->on_get_created_public_channels(type_, std::move(chats->chats_));
break;
}
default:
@ -5780,23 +5787,26 @@ vector<DialogId> ContactsManager::get_dialog_ids(vector<tl_object_ptr<telegram_a
return dialog_ids;
}
vector<DialogId> ContactsManager::get_created_public_dialogs(Promise<Unit> &&promise) {
if (created_public_channels_inited_) {
vector<DialogId> ContactsManager::get_created_public_dialogs(PublicDialogType type, Promise<Unit> &&promise) {
int32 index = static_cast<int32>(type);
if (created_public_channels_inited_[index]) {
promise.set_value(Unit());
return transform(created_public_channels_, [&](ChannelId channel_id) {
return transform(created_public_channels_[index], [&](ChannelId channel_id) {
DialogId dialog_id(channel_id);
td_->messages_manager_->force_create_dialog(dialog_id, "get_created_public_dialogs");
return dialog_id;
});
}
td_->create_handler<GetCreatedPublicChannelsQuery>(std::move(promise))->send();
td_->create_handler<GetCreatedPublicChannelsQuery>(std::move(promise))->send(type);
return {};
}
void ContactsManager::on_get_created_public_channels(vector<tl_object_ptr<telegram_api::Chat>> &&chats) {
created_public_channels_inited_ = true;
created_public_channels_ = get_channel_ids(std::move(chats), "on_get_created_public_channels");
void ContactsManager::on_get_created_public_channels(PublicDialogType type,
vector<tl_object_ptr<telegram_api::Chat>> &&chats) {
int32 index = static_cast<int32>(type);
created_public_channels_[index] = get_channel_ids(std::move(chats), "on_get_created_public_channels");
created_public_channels_inited_[index] = true;
}
vector<DialogId> ContactsManager::get_dialogs_for_discussion(Promise<Unit> &&promise) {
@ -7736,12 +7746,12 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
}
}
if (c->is_username_changed) {
if (c->status.is_creator() && created_public_channels_inited_) {
if (c->status.is_creator() && created_public_channels_inited_[0]) {
if (c->username.empty()) {
td::remove(created_public_channels_, channel_id);
td::remove(created_public_channels_[0], channel_id);
} else {
if (!td::contains(created_public_channels_, channel_id)) {
created_public_channels_.push_back(channel_id);
if (!td::contains(created_public_channels_[0], channel_id)) {
created_public_channels_[0].push_back(channel_id);
}
}
}
@ -10183,14 +10193,19 @@ void ContactsManager::on_update_channel_title(Channel *c, ChannelId channel_id,
void ContactsManager::on_update_channel_status(Channel *c, ChannelId channel_id, DialogParticipantStatus &&status) {
if (c->status != status) {
LOG(INFO) << "Update " << channel_id << " status from " << c->status << " to " << status;
bool reget_channel_full = c->status.is_creator() != status.is_creator();
bool is_ownership_transferred = c->status.is_creator() != status.is_creator();
bool drop_invite_link =
c->status.is_administrator() != status.is_administrator() || c->status.is_member() != status.is_member();
c->status = status;
c->is_status_changed = true;
c->is_changed = true;
invalidate_channel_full(channel_id, drop_invite_link);
if (reget_channel_full) {
if (is_ownership_transferred) {
for (size_t i = 0; i < 2; i++) {
created_public_channels_inited_[i] = false;
created_public_channels_[i].clear();
}
auto input_channel = get_input_channel(channel_id);
if (input_channel != nullptr) {
send_get_channel_full_query(channel_id, std::move(input_channel), Auto(), "update channel creator");

View File

@ -21,6 +21,7 @@
#include "td/telegram/Location.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/Photo.h"
#include "td/telegram/PublicDialogType.h"
#include "td/telegram/QueryCombiner.h"
#include "td/telegram/SecretChatId.h"
#include "td/telegram/StickerSetId.h"
@ -218,7 +219,7 @@ class ContactsManager : public Actor {
void invalidate_invite_link_info(const string &invite_link);
void on_get_created_public_channels(vector<tl_object_ptr<telegram_api::Chat>> &&chats);
void on_get_created_public_channels(PublicDialogType type, vector<tl_object_ptr<telegram_api::Chat>> &&chats);
void on_get_dialogs_for_discussion(vector<tl_object_ptr<telegram_api::Chat>> &&chats);
@ -363,7 +364,7 @@ class ContactsManager : public Actor {
ChannelId migrate_chat_to_megagroup(ChatId chat_id, Promise<Unit> &promise);
vector<DialogId> get_created_public_dialogs(Promise<Unit> &&promise);
vector<DialogId> get_created_public_dialogs(PublicDialogType type, Promise<Unit> &&promise);
vector<DialogId> get_dialogs_for_discussion(Promise<Unit> &&promise);
@ -1306,8 +1307,8 @@ class ContactsManager : public Actor {
std::unordered_map<ChannelId, string, ChannelIdHash> channel_invite_links_; // in-memory cache for invite links
std::unordered_map<string, unique_ptr<InviteLinkInfo>> invite_link_infos_;
bool created_public_channels_inited_ = false;
vector<ChannelId> created_public_channels_;
bool created_public_channels_inited_[2] = {false, false};
vector<ChannelId> created_public_channels_[2];
bool dialogs_for_discussion_inited_ = false;
vector<DialogId> dialogs_for_discussion_;

View File

@ -67,6 +67,7 @@
#include "td/telegram/PhotoSizeSource.h"
#include "td/telegram/PollManager.h"
#include "td/telegram/PrivacyManager.h"
#include "td/telegram/PublicDialogType.h"
#include "td/telegram/RequestActor.h"
#include "td/telegram/SecretChatId.h"
#include "td/telegram/SecretChatsManager.h"
@ -1031,9 +1032,10 @@ class GetGroupsInCommonRequest : public RequestActor<> {
class GetCreatedPublicChatsRequest : public RequestActor<> {
vector<DialogId> dialog_ids_;
PublicDialogType type_;
void do_run(Promise<Unit> &&promise) override {
dialog_ids_ = td->contacts_manager_->get_created_public_dialogs(std::move(promise));
dialog_ids_ = td->contacts_manager_->get_created_public_dialogs(type_, std::move(promise));
}
void do_send_result() override {
@ -1041,7 +1043,8 @@ class GetCreatedPublicChatsRequest : public RequestActor<> {
}
public:
GetCreatedPublicChatsRequest(ActorShared<Td> td, uint64 request_id) : RequestActor(std::move(td), request_id) {
GetCreatedPublicChatsRequest(ActorShared<Td> td, uint64 request_id, PublicDialogType type)
: RequestActor(std::move(td), request_id), type_(type) {
}
};
@ -5498,7 +5501,7 @@ void Td::on_request(uint64 id, td_api::checkChatUsername &request) {
void Td::on_request(uint64 id, const td_api::getCreatedPublicChats &request) {
CHECK_IS_USER();
CREATE_NO_ARGS_REQUEST(GetCreatedPublicChatsRequest);
CREATE_REQUEST(GetCreatedPublicChatsRequest, get_public_dialog_type(request.type_));
}
void Td::on_request(uint64 id, const td_api::getSuitableDiscussionChats &request) {

View File

@ -3275,6 +3275,9 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::deleteSupergroup>(as_supergroup_id(args)));
} else if (op == "gcpc") {
send_request(td_api::make_object<td_api::getCreatedPublicChats>());
} else if (op == "gcpcl") {
send_request(td_api::make_object<td_api::getCreatedPublicChats>(
td_api::make_object<td_api::publicChatTypeIsLocationBased>()));
} else if (op == "gsdc") {
send_request(td_api::make_object<td_api::getSuitableDiscussionChats>());
} else if (op == "cpc") {