tg_cli: as_{basic_group,supergroup,secret_chat}_id.

GitOrigin-RevId: 747434e8cc75ec25dcdd461a574d55af6d0cf7c4
This commit is contained in:
levlam 2019-01-07 18:37:53 +03:00
parent 3c6008aa9c
commit b4c0d1b876
3 changed files with 76 additions and 45 deletions

View File

@ -61,16 +61,16 @@ ChatId DialogId::get_chat_id() const {
return ChatId(static_cast<int32>(-id)); return ChatId(static_cast<int32>(-id));
} }
SecretChatId DialogId::get_secret_chat_id() const {
CHECK(get_type() == DialogType::SecretChat);
return SecretChatId(static_cast<int32>(id - ZERO_SECRET_ID));
}
ChannelId DialogId::get_channel_id() const { ChannelId DialogId::get_channel_id() const {
CHECK(get_type() == DialogType::Channel); CHECK(get_type() == DialogType::Channel);
return ChannelId(static_cast<int32>(MAX_CHANNEL_ID - id)); return ChannelId(static_cast<int32>(MAX_CHANNEL_ID - id));
} }
SecretChatId DialogId::get_secret_chat_id() const {
CHECK(get_type() == DialogType::SecretChat);
return SecretChatId(static_cast<int32>(id - ZERO_SECRET_ID));
}
DialogId::DialogId(UserId user_id) { DialogId::DialogId(UserId user_id) {
if (user_id.is_valid()) { if (user_id.is_valid()) {
id = static_cast<int64>(user_id.get()); id = static_cast<int64>(user_id.get());

View File

@ -70,8 +70,8 @@ class DialogId {
UserId get_user_id() const; UserId get_user_id() const;
ChatId get_chat_id() const; ChatId get_chat_id() const;
SecretChatId get_secret_chat_id() const;
ChannelId get_channel_id() const; ChannelId get_channel_id() const;
SecretChatId get_secret_chat_id() const;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const { void store(StorerT &storer) const {

View File

@ -485,6 +485,35 @@ class CliClient final : public Actor {
return transform(full_split(user_ids, delimiter), [this](Slice str) { return as_user_id(str); }); return transform(full_split(user_ids, delimiter), [this](Slice str) { return as_user_id(str); });
} }
int32 as_basic_group_id(Slice str) const {
str = trim(str);
auto result = to_integer<int32>(str);
if (result < 0) {
return -result;
}
return result;
}
int32 as_supergroup_id(Slice str) const {
str = trim(str);
auto result = to_integer<int64>(str);
int64 shift = static_cast<int64>(-1000000000000ll);
if (result <= shift) {
return static_cast<int32>(shift - result);
}
return static_cast<int32>(result);
}
int32 as_secret_chat_id(Slice str) const {
str = trim(str);
auto result = to_integer<int64>(str);
int64 shift = static_cast<int64>(-2000000000000ll);
if (result <= shift + std::numeric_limits<int32>::max()) {
return static_cast<int32>(result - shift);
}
return static_cast<int32>(result);
}
static int32 as_file_id(string str) { static int32 as_file_id(string str) {
return to_integer<int32>(trim(std::move(str))); return to_integer<int32>(trim(std::move(str)));
} }
@ -1262,7 +1291,7 @@ class CliClient final : public Actor {
string payload = query.get_arg("payload").str(); string payload = query.get_arg("payload").str();
LOG(INFO) << "Callback URL:" << query.get_arg("callback_url"); LOG(INFO) << "Callback URL:" << query.get_arg("callback_url");
send_request( send_request(
make_tl_object<td_api::getPassportAuthorizationForm>(to_integer<int32>(bot_id), scope, public_key, payload)); make_tl_object<td_api::getPassportAuthorizationForm>(as_user_id(bot_id), scope, public_key, payload));
} else if (op == "gpaf") { } else if (op == "gpaf") {
string bot_id; string bot_id;
string scope; string scope;
@ -1286,18 +1315,18 @@ class CliClient final : public Actor {
std::tie(bot_id, args) = split(args); std::tie(bot_id, args) = split(args);
std::tie(scope, payload) = split(args); std::tie(scope, payload) = split(args);
send_request( send_request(
make_tl_object<td_api::getPassportAuthorizationForm>(to_integer<int32>(bot_id), scope, public_key, payload)); make_tl_object<td_api::getPassportAuthorizationForm>(as_user_id(bot_id), scope, public_key, payload));
} else if (op == "gpafae") { } else if (op == "gpafae") {
string id; string form_id;
string password; string password;
std::tie(id, password) = split(args); std::tie(form_id, password) = split(args);
send_request( send_request(
make_tl_object<td_api::getPassportAuthorizationFormAvailableElements>(to_integer<int32>(id), password)); make_tl_object<td_api::getPassportAuthorizationFormAvailableElements>(to_integer<int32>(form_id), password));
} else if (op == "spaf") { } else if (op == "spaf") {
string id; string form_id;
string types; string types;
std::tie(id, types) = split(args); std::tie(form_id, types) = split(args);
send_request(make_tl_object<td_api::sendPassportAuthorizationForm>(to_integer<int32>(id), send_request(make_tl_object<td_api::sendPassportAuthorizationForm>(to_integer<int32>(form_id),
as_passport_element_types(types))); as_passport_element_types(types)));
} else if (op == "gpcl") { } else if (op == "gpcl") {
send_request(make_tl_object<td_api::getPreferredCountryLanguage>(args)); send_request(make_tl_object<td_api::getPreferredCountryLanguage>(args));
@ -1477,7 +1506,8 @@ class CliClient final : public Actor {
if (args.empty()) { if (args.empty()) {
send_request(make_tl_object<td_api::getContacts>()); send_request(make_tl_object<td_api::getContacts>());
} else { } else {
send_request(make_tl_object<td_api::searchContacts>("", to_integer<int32>(args))); auto limit = to_integer<int32>(args);
send_request(make_tl_object<td_api::searchContacts>("", limit));
} }
} else if (op == "ImportContacts" || op == "cic") { } else if (op == "ImportContacts" || op == "cic") {
vector<string> contacts_str = full_split(args, ';'); vector<string> contacts_str = full_split(args, ';');
@ -1944,9 +1974,10 @@ class CliClient final : public Actor {
} else if (op == "gtss") { } else if (op == "gtss") {
send_request(make_tl_object<td_api::getTrendingStickerSets>()); send_request(make_tl_object<td_api::getTrendingStickerSets>());
} else if (op == "gatss") { } else if (op == "gatss") {
send_request(make_tl_object<td_api::getAttachedStickerSets>(to_integer<int32>(args))); send_request(make_tl_object<td_api::getAttachedStickerSets>(as_file_id(args)));
} else if (op == "storage") { } else if (op == "storage") {
send_request(make_tl_object<td_api::getStorageStatistics>(to_integer<int32>(args))); auto chat_limit = to_integer<int32>(args);
send_request(make_tl_object<td_api::getStorageStatistics>(chat_limit));
} else if (op == "storage_fast") { } else if (op == "storage_fast") {
send_request(make_tl_object<td_api::getStorageStatisticsFast>()); send_request(make_tl_object<td_api::getStorageStatisticsFast>());
} else if (op == "optimize_storage") { } else if (op == "optimize_storage") {
@ -2083,15 +2114,15 @@ class CliClient final : public Actor {
} else if (op == "guf") { } else if (op == "guf") {
send_request(make_tl_object<td_api::getUserFullInfo>(as_user_id(args))); send_request(make_tl_object<td_api::getUserFullInfo>(as_user_id(args)));
} else if (op == "gbg") { } else if (op == "gbg") {
send_request(make_tl_object<td_api::getBasicGroup>(to_integer<int32>(args))); send_request(make_tl_object<td_api::getBasicGroup>(as_basic_group_id(args)));
} else if (op == "gbgf") { } else if (op == "gbgf") {
send_request(make_tl_object<td_api::getBasicGroupFullInfo>(to_integer<int32>(args))); send_request(make_tl_object<td_api::getBasicGroupFullInfo>(as_basic_group_id(args)));
} else if (op == "gsg" || op == "gch") { } else if (op == "gsg" || op == "gch") {
send_request(make_tl_object<td_api::getSupergroup>(to_integer<int32>(args))); send_request(make_tl_object<td_api::getSupergroup>(as_supergroup_id(args)));
} else if (op == "gsgf" || op == "gchf") { } else if (op == "gsgf" || op == "gchf") {
send_request(make_tl_object<td_api::getSupergroupFullInfo>(to_integer<int32>(args))); send_request(make_tl_object<td_api::getSupergroupFullInfo>(as_supergroup_id(args)));
} else if (op == "gsc") { } else if (op == "gsc") {
send_request(make_tl_object<td_api::getSecretChat>(to_integer<int32>(args))); send_request(make_tl_object<td_api::getSecretChat>(as_secret_chat_id(args)));
} else if (op == "scm") { } else if (op == "scm") {
string chat_id; string chat_id;
string limit; string limit;
@ -2123,7 +2154,7 @@ class CliClient final : public Actor {
limit = "10"; limit = "10";
} }
send_request(make_tl_object<td_api::getSupergroupMembers>( send_request(make_tl_object<td_api::getSupergroupMembers>(
to_integer<int32>(supergroup_id), make_tl_object<td_api::supergroupMembersFilterAdministrators>(), as_supergroup_id(supergroup_id), make_tl_object<td_api::supergroupMembersFilterAdministrators>(),
to_integer<int32>(offset), to_integer<int32>(limit))); to_integer<int32>(offset), to_integer<int32>(limit)));
} else if (op == "GetChatAdministrators") { } else if (op == "GetChatAdministrators") {
string chat_id = args; string chat_id = args;
@ -2144,7 +2175,7 @@ class CliClient final : public Actor {
limit = "10"; limit = "10";
} }
send_request(make_tl_object<td_api::getSupergroupMembers>( send_request(make_tl_object<td_api::getSupergroupMembers>(
to_integer<int32>(supergroup_id), make_tl_object<td_api::supergroupMembersFilterBanned>(query), as_supergroup_id(supergroup_id), make_tl_object<td_api::supergroupMembersFilterBanned>(query),
to_integer<int32>(offset), to_integer<int32>(limit))); to_integer<int32>(offset), to_integer<int32>(limit)));
} else if (op == "GetSupergroupBots") { } else if (op == "GetSupergroupBots") {
string supergroup_id; string supergroup_id;
@ -2159,7 +2190,7 @@ class CliClient final : public Actor {
if (limit.empty()) { if (limit.empty()) {
limit = "10"; limit = "10";
} }
send_request(make_tl_object<td_api::getSupergroupMembers>(to_integer<int32>(supergroup_id), send_request(make_tl_object<td_api::getSupergroupMembers>(as_supergroup_id(supergroup_id),
make_tl_object<td_api::supergroupMembersFilterBots>(), make_tl_object<td_api::supergroupMembersFilterBots>(),
to_integer<int32>(offset), to_integer<int32>(limit))); to_integer<int32>(offset), to_integer<int32>(limit)));
} else if (op == "GetSupergroupMembers") { } else if (op == "GetSupergroupMembers") {
@ -2175,7 +2206,7 @@ class CliClient final : public Actor {
if (limit.empty()) { if (limit.empty()) {
limit = "10"; limit = "10";
} }
send_request(make_tl_object<td_api::getSupergroupMembers>(to_integer<int32>(supergroup_id), send_request(make_tl_object<td_api::getSupergroupMembers>(as_supergroup_id(supergroup_id),
make_tl_object<td_api::supergroupMembersFilterRecent>(), make_tl_object<td_api::supergroupMembersFilterRecent>(),
to_integer<int32>(offset), to_integer<int32>(limit))); to_integer<int32>(offset), to_integer<int32>(limit)));
} else if (op == "SearchSupergroupMembers") { } else if (op == "SearchSupergroupMembers") {
@ -2194,7 +2225,7 @@ class CliClient final : public Actor {
limit = "10"; limit = "10";
} }
send_request(make_tl_object<td_api::getSupergroupMembers>( send_request(make_tl_object<td_api::getSupergroupMembers>(
to_integer<int32>(supergroup_id), make_tl_object<td_api::supergroupMembersFilterSearch>(query), as_supergroup_id(supergroup_id), make_tl_object<td_api::supergroupMembersFilterSearch>(query),
to_integer<int32>(offset), to_integer<int32>(limit))); to_integer<int32>(offset), to_integer<int32>(limit)));
} else if (op == "GetSupergroupRestricted") { } else if (op == "GetSupergroupRestricted") {
string supergroup_id; string supergroup_id;
@ -2212,7 +2243,7 @@ class CliClient final : public Actor {
limit = "10"; limit = "10";
} }
send_request(make_tl_object<td_api::getSupergroupMembers>( send_request(make_tl_object<td_api::getSupergroupMembers>(
to_integer<int32>(supergroup_id), make_tl_object<td_api::supergroupMembersFilterRestricted>(query), as_supergroup_id(supergroup_id), make_tl_object<td_api::supergroupMembersFilterRestricted>(query),
to_integer<int32>(offset), to_integer<int32>(limit))); to_integer<int32>(offset), to_integer<int32>(limit)));
} else if (op == "gdialog" || op == "gd") { } else if (op == "gdialog" || op == "gd") {
send_request(make_tl_object<td_api::getChat>(as_chat_id(args))); send_request(make_tl_object<td_api::getChat>(as_chat_id(args)));
@ -2354,7 +2385,7 @@ class CliClient final : public Actor {
send_request(make_tl_object<td_api::forwardMessages>(chat, as_chat_id(from_chat_id), as_message_ids(message_ids), send_request(make_tl_object<td_api::forwardMessages>(chat, as_chat_id(from_chat_id), as_message_ids(message_ids),
false, false, op == "fmg")); false, false, op == "fmg"));
} else if (op == "csc" || op == "CreateSecretChat") { } else if (op == "csc" || op == "CreateSecretChat") {
send_request(make_tl_object<td_api::createSecretChat>(to_integer<int32>(args))); send_request(make_tl_object<td_api::createSecretChat>(as_secret_chat_id(args)));
} else if (op == "cnsc" || op == "CreateNewSecretChat") { } else if (op == "cnsc" || op == "CreateNewSecretChat") {
send_request(make_tl_object<td_api::createNewSecretChat>(as_user_id(args))); send_request(make_tl_object<td_api::createNewSecretChat>(as_user_id(args)));
} else if (op == "scstn") { } else if (op == "scstn") {
@ -2366,7 +2397,7 @@ class CliClient final : public Actor {
send_request(make_tl_object<td_api::sendChatSetTtlMessage>(as_chat_id(chat_id), to_integer<int32>(ttl))); send_request(make_tl_object<td_api::sendChatSetTtlMessage>(as_chat_id(chat_id), to_integer<int32>(ttl)));
} else if (op == "closeSC" || op == "cancelSC") { } else if (op == "closeSC" || op == "cancelSC") {
send_request(make_tl_object<td_api::closeSecretChat>(to_integer<int32>(args))); send_request(make_tl_object<td_api::closeSecretChat>(as_secret_chat_id(args)));
} else if (op == "cc" || op == "CreateCall") { } else if (op == "cc" || op == "CreateCall") {
send_request(make_tl_object<td_api::createCall>(as_user_id(args), send_request(make_tl_object<td_api::createCall>(as_user_id(args),
make_tl_object<td_api::callProtocol>(true, true, 65, 65))); make_tl_object<td_api::callProtocol>(true, true, 65, 65)));
@ -3061,7 +3092,7 @@ class CliClient final : public Actor {
} else if (op == "UpgradeBasicGroupChatToSupergroupChat") { } else if (op == "UpgradeBasicGroupChatToSupergroupChat") {
send_request(make_tl_object<td_api::upgradeBasicGroupChatToSupergroupChat>(as_chat_id(args))); send_request(make_tl_object<td_api::upgradeBasicGroupChatToSupergroupChat>(as_chat_id(args)));
} else if (op == "DeleteSupergroup") { } else if (op == "DeleteSupergroup") {
send_request(make_tl_object<td_api::deleteSupergroup>(to_integer<int32>(args))); send_request(make_tl_object<td_api::deleteSupergroup>(as_supergroup_id(args)));
} else if (op == "gcpc") { } else if (op == "gcpc") {
send_request(make_tl_object<td_api::getCreatedPublicChats>()); send_request(make_tl_object<td_api::getCreatedPublicChats>());
} else if (op == "cpc") { } else if (op == "cpc") {
@ -3075,13 +3106,13 @@ class CliClient final : public Actor {
string force; string force;
std::tie(basic_group_id, force) = split(args); std::tie(basic_group_id, force) = split(args);
send_request(make_tl_object<td_api::createBasicGroupChat>(to_integer<int32>(basic_group_id), as_bool(force))); send_request(make_tl_object<td_api::createBasicGroupChat>(as_basic_group_id(basic_group_id), as_bool(force)));
} else if (op == "csgc" || op == "cchc") { } else if (op == "csgc" || op == "cchc") {
string supergroup_id; string supergroup_id;
string force; string force;
std::tie(supergroup_id, force) = split(args); std::tie(supergroup_id, force) = split(args);
send_request(make_tl_object<td_api::createSupergroupChat>(to_integer<int32>(supergroup_id), as_bool(force))); send_request(make_tl_object<td_api::createSupergroupChat>(as_supergroup_id(supergroup_id), as_bool(force)));
} else if (op == "sct") { } else if (op == "sct") {
string chat_id; string chat_id;
string title; string title;
@ -3203,7 +3234,7 @@ class CliClient final : public Actor {
string everyone_is_administrator; string everyone_is_administrator;
std::tie(group_id, everyone_is_administrator) = split(args); std::tie(group_id, everyone_is_administrator) = split(args);
send_request(make_tl_object<td_api::toggleBasicGroupAdministrators>(to_integer<int32>(group_id), send_request(make_tl_object<td_api::toggleBasicGroupAdministrators>(as_basic_group_id(group_id),
as_bool(everyone_is_administrator))); as_bool(everyone_is_administrator)));
} else if (op == "ccun") { } else if (op == "ccun") {
string chat_id; string chat_id;
@ -3216,57 +3247,57 @@ class CliClient final : public Actor {
string username; string username;
std::tie(supergroup_id, username) = split(args); std::tie(supergroup_id, username) = split(args);
send_request(make_tl_object<td_api::setSupergroupUsername>(to_integer<int32>(supergroup_id), username)); send_request(make_tl_object<td_api::setSupergroupUsername>(as_supergroup_id(supergroup_id), username));
} else if (op == "ssgss") { } else if (op == "ssgss") {
string supergroup_id; string supergroup_id;
string sticker_set_id; string sticker_set_id;
std::tie(supergroup_id, sticker_set_id) = split(args); std::tie(supergroup_id, sticker_set_id) = split(args);
send_request(make_tl_object<td_api::setSupergroupStickerSet>(to_integer<int32>(supergroup_id), send_request(make_tl_object<td_api::setSupergroupStickerSet>(as_supergroup_id(supergroup_id),
to_integer<int64>(sticker_set_id))); to_integer<int64>(sticker_set_id)));
} else if (op == "tsgi") { } else if (op == "tsgi") {
string supergroup_id; string supergroup_id;
string anyone_can_invite; string anyone_can_invite;
std::tie(supergroup_id, anyone_can_invite) = split(args); std::tie(supergroup_id, anyone_can_invite) = split(args);
send_request(make_tl_object<td_api::toggleSupergroupInvites>(to_integer<int32>(supergroup_id), send_request(
as_bool(anyone_can_invite))); make_tl_object<td_api::toggleSupergroupInvites>(as_supergroup_id(supergroup_id), as_bool(anyone_can_invite)));
} else if (op == "tsgp") { } else if (op == "tsgp") {
string supergroup_id; string supergroup_id;
string is_all_history_available; string is_all_history_available;
std::tie(supergroup_id, is_all_history_available) = split(args); std::tie(supergroup_id, is_all_history_available) = split(args);
send_request(make_tl_object<td_api::toggleSupergroupIsAllHistoryAvailable>(to_integer<int32>(supergroup_id), send_request(make_tl_object<td_api::toggleSupergroupIsAllHistoryAvailable>(as_supergroup_id(supergroup_id),
as_bool(is_all_history_available))); as_bool(is_all_history_available)));
} else if (op == "tsgsm") { } else if (op == "tsgsm") {
string supergroup_id; string supergroup_id;
string sign_messages; string sign_messages;
std::tie(supergroup_id, sign_messages) = split(args); std::tie(supergroup_id, sign_messages) = split(args);
send_request(make_tl_object<td_api::toggleSupergroupSignMessages>(to_integer<int32>(supergroup_id), send_request(make_tl_object<td_api::toggleSupergroupSignMessages>(as_supergroup_id(supergroup_id),
as_bool(sign_messages))); as_bool(sign_messages)));
} else if (op == "csgd" || op == "cchd") { } else if (op == "csgd" || op == "cchd") {
string supergroup_id; string supergroup_id;
string description; string description;
std::tie(supergroup_id, description) = split(args); std::tie(supergroup_id, description) = split(args);
send_request(make_tl_object<td_api::setSupergroupDescription>(to_integer<int32>(supergroup_id), description)); send_request(make_tl_object<td_api::setSupergroupDescription>(as_supergroup_id(supergroup_id), description));
} else if (op == "psgm" || op == "pchm") { } else if (op == "psgm" || op == "pchm") {
string supergroup_id; string supergroup_id;
string message_id; string message_id;
std::tie(supergroup_id, message_id) = split(args); std::tie(supergroup_id, message_id) = split(args);
send_request(make_tl_object<td_api::pinSupergroupMessage>(to_integer<int32>(supergroup_id), send_request(make_tl_object<td_api::pinSupergroupMessage>(as_supergroup_id(supergroup_id),
as_message_id(message_id), false)); as_message_id(message_id), false));
} else if (op == "psgms" || op == "pchms") { } else if (op == "psgms" || op == "pchms") {
string supergroup_id; string supergroup_id;
string message_id; string message_id;
std::tie(supergroup_id, message_id) = split(args); std::tie(supergroup_id, message_id) = split(args);
send_request(make_tl_object<td_api::pinSupergroupMessage>(to_integer<int32>(supergroup_id), send_request(make_tl_object<td_api::pinSupergroupMessage>(as_supergroup_id(supergroup_id),
as_message_id(message_id), true)); as_message_id(message_id), true));
} else if (op == "upsgm" || op == "upchm") { } else if (op == "upsgm" || op == "upchm") {
send_request(make_tl_object<td_api::unpinSupergroupMessage>(to_integer<int32>(args))); send_request(make_tl_object<td_api::unpinSupergroupMessage>(as_supergroup_id(args)));
} else if (op == "grib") { } else if (op == "grib") {
send_request(make_tl_object<td_api::getRecentInlineBots>()); send_request(make_tl_object<td_api::getRecentInlineBots>());
} else if (op == "spc" || op == "su" || op == "sch") { } else if (op == "spc" || op == "su" || op == "sch") {
@ -3422,7 +3453,7 @@ class CliClient final : public Actor {
std::tie(supergroup_id, args) = split(args); std::tie(supergroup_id, args) = split(args);
std::tie(user_id, message_ids) = split(args); std::tie(user_id, message_ids) = split(args);
send_request(make_tl_object<td_api::reportSupergroupSpam>(to_integer<int32>(supergroup_id), as_user_id(user_id), send_request(make_tl_object<td_api::reportSupergroupSpam>(as_supergroup_id(supergroup_id), as_user_id(user_id),
as_message_ids(message_ids))); as_message_ids(message_ids)));
} else if (op == "gdiff") { } else if (op == "gdiff") {
send_request(make_tl_object<td_api::testGetDifference>()); send_request(make_tl_object<td_api::testGetDifference>());