Allow to create chats without network request.

GitOrigin-RevId: f17bbe43c58246b6ab2bd48a746b00cae5cd1865
This commit is contained in:
levlam 2018-01-24 00:45:26 +03:00
parent dbe1509a33
commit fe133efefc
11 changed files with 38 additions and 25 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
project(TDLib VERSION 1.0.4 LANGUAGES CXX C)
project(TDLib VERSION 1.0.5 LANGUAGES CXX C)
option(TD_ENABLE_JNI "Use \"ON\" to enable JNI-compatible TDLib API.")

View File

@ -81,7 +81,7 @@ target_link_library(YourLibrary Td::TdJson)
Or you could install `TDLib` and then reference it in your CMakeLists.txt like this:
```
find_package(Td 1.0.4)
find_package(Td 1.0.5)
target_link_library(YourLibrary Td::TdJson)
```
See [example/cpp/CMakeLists.txt](https://github.com/tdlib/td/tree/master/example/cpp/CMakeLists.txt).

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(TdExample VERSION 1.0 LANGUAGES CXX)
find_package(Td 1.0.4 REQUIRED)
find_package(Td 1.0.5 REQUIRED)
add_executable(tdjson_example tdjson_example.cpp)
target_link_libraries(tdjson_example PRIVATE Td::TdJson)

View File

@ -2263,16 +2263,16 @@ openMessageContent chat_id:int53 message_id:int53 = Ok;
readAllChatMentions chat_id:int53 = Ok;
//@description Returns an existing chat corresponding to a given user @user_id User identifier
createPrivateChat user_id:int32 = Chat;
//@description Returns an existing chat corresponding to a given user @user_id User identifier @force If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect
createPrivateChat user_id:int32 force:Bool = Chat;
//@description Returns an existing chat corresponding to a known basic group @basic_group_id Basic group identifier
createBasicGroupChat basic_group_id:int32 = Chat;
//@description Returns an existing chat corresponding to a known basic group @basic_group_id Basic group identifier @force If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect
createBasicGroupChat basic_group_id:int32 force:Bool = Chat;
//@description Returns an existing chat corresponding to a known supergroup or channel @supergroup_id Supergroup or channel identifier
createSupergroupChat supergroup_id:int32 = Chat;
//@description Returns an existing chat corresponding to a known supergroup or channel @supergroup_id Supergroup or channel identifier @force If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect
createSupergroupChat supergroup_id:int32 force:Bool = Chat;
//@description Returns an existing chat corresponding to a known secret chat @secret_chat_id Secret Chat identifier
//@description Returns an existing chat corresponding to a known secret chat @secret_chat_id Secret chat identifier
createSecretChat secret_chat_id:int32 = Chat;
//@description Creates a new basic group and sends a corresponding messageBasicGroupChatCreate. Returns the newly created chat @user_ids Identifiers of users to be added to the basic group @title Title of the new basic group; 1-255 characters

Binary file not shown.

View File

@ -11366,7 +11366,7 @@ Status MessagesManager::set_dialog_client_data(DialogId dialog_id, string &&clie
return Status::OK();
}
void MessagesManager::create_dialog(DialogId dialog_id, Promise<Unit> &&promise) {
void MessagesManager::create_dialog(DialogId dialog_id, bool force, Promise<Unit> &&promise) {
if (!have_input_peer(dialog_id, AccessRights::Read)) {
if (!have_dialog_info_force(dialog_id)) {
return promise.set_error(Status::Error(6, "Chat info not found"));
@ -11376,7 +11376,7 @@ void MessagesManager::create_dialog(DialogId dialog_id, Promise<Unit> &&promise)
}
}
if (td_->auth_manager_->is_bot() || dialog_id.get_type() == DialogType::SecretChat) {
if (force || td_->auth_manager_->is_bot() || dialog_id.get_type() == DialogType::SecretChat) {
force_create_dialog(dialog_id, "create dialog");
} else {
const Dialog *d = get_dialog_force(dialog_id);

View File

@ -1122,7 +1122,7 @@ class MessagesManager : public Actor {
Status set_dialog_client_data(DialogId dialog_id, string &&client_data) TD_WARN_UNUSED_RESULT;
void create_dialog(DialogId dialog_id, Promise<Unit> &&promise);
void create_dialog(DialogId dialog_id, bool force, Promise<Unit> &&promise);
DialogId create_new_group_chat(const vector<UserId> &user_ids, const string &title, int64 &random_id,
Promise<Unit> &&promise);

View File

@ -1667,9 +1667,10 @@ class GetWebPageInstantViewRequest : public RequestActor<> {
class CreateChatRequest : public RequestActor<> {
DialogId dialog_id_;
bool force_;
void do_run(Promise<Unit> &&promise) override {
td->messages_manager_->create_dialog(dialog_id_, std::move(promise));
td->messages_manager_->create_dialog(dialog_id_, force_, std::move(promise));
}
void do_send_result() override {
@ -1677,8 +1678,8 @@ class CreateChatRequest : public RequestActor<> {
}
public:
CreateChatRequest(ActorShared<Td> td, uint64 request_id, DialogId dialog_id)
: RequestActor<>(std::move(td), request_id), dialog_id_(dialog_id) {
CreateChatRequest(ActorShared<Td> td, uint64 request_id, DialogId dialog_id, bool force)
: RequestActor<>(std::move(td), request_id), dialog_id_(dialog_id), force_(force) {
}
};
@ -5344,22 +5345,22 @@ void Td::on_request(uint64 id, td_api::getWebPageInstantView &request) {
void Td::on_request(uint64 id, const td_api::createPrivateChat &request) {
CHECK_AUTH();
CREATE_REQUEST(CreateChatRequest, DialogId(UserId(request.user_id_)));
CREATE_REQUEST(CreateChatRequest, DialogId(UserId(request.user_id_)), request.force_);
}
void Td::on_request(uint64 id, const td_api::createBasicGroupChat &request) {
CHECK_AUTH();
CREATE_REQUEST(CreateChatRequest, DialogId(ChatId(request.basic_group_id_)));
CREATE_REQUEST(CreateChatRequest, DialogId(ChatId(request.basic_group_id_)), request.force_);
}
void Td::on_request(uint64 id, const td_api::createSupergroupChat &request) {
CHECK_AUTH();
CREATE_REQUEST(CreateChatRequest, DialogId(ChannelId(request.supergroup_id_)));
CREATE_REQUEST(CreateChatRequest, DialogId(ChannelId(request.supergroup_id_)), request.force_);
}
void Td::on_request(uint64 id, td_api::createSecretChat &request) {
CHECK_AUTH();
CREATE_REQUEST(CreateChatRequest, DialogId(SecretChatId(request.secret_chat_id_)));
CREATE_REQUEST(CreateChatRequest, DialogId(SecretChatId(request.secret_chat_id_)), true);
}
void Td::on_request(uint64 id, td_api::createNewBasicGroupChat &request) {

View File

@ -187,7 +187,7 @@ class Td final : public NetQueryCallback {
static td_api::object_ptr<td_api::Object> static_request(td_api::object_ptr<td_api::Function> function);
private:
static constexpr const char *tdlib_version = "1.0.4";
static constexpr const char *tdlib_version = "1.0.5";
static constexpr int32 ONLINE_TIMEOUT = 240;
void send_result(uint64 id, tl_object_ptr<td_api::Object> object);

View File

@ -2429,11 +2429,23 @@ class CliClient final : public Actor {
} else if (op == "gcpc") {
send_request(make_tl_object<td_api::getCreatedPublicChats>());
} else if (op == "cpc") {
send_request(make_tl_object<td_api::createPrivateChat>(as_user_id(args)));
string user_id;
string force;
std::tie(user_id, force) = split(args);
send_request(make_tl_object<td_api::createPrivateChat>(as_user_id(user_id), as_bool(force)));
} else if (op == "cbgc") {
send_request(make_tl_object<td_api::createBasicGroupChat>(to_integer<int32>(args)));
string basic_group_id;
string force;
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)));
} else if (op == "csgc" || op == "cchc") {
send_request(make_tl_object<td_api::createSupergroupChat>(to_integer<int32>(args)));
string supergroup_id;
string force;
std::tie(supergroup_id, force) = split(args);
send_request(make_tl_object<td_api::createSupergroupChat>(to_integer<int32>(supergroup_id), as_bool(force)));
} else if (op == "sct") {
string chat_id;
string title;

View File

@ -301,7 +301,7 @@ class SetUsername : public Task {
void send_self_message() {
tag_ = PSTRING() << format::as_hex(Random::secure_int64());
send_query(make_tl_object<td_api::createPrivateChat>(self_id_), [this](auto res) {
send_query(make_tl_object<td_api::createPrivateChat>(self_id_, false), [this](auto res) {
CHECK(res->get_id() == td_api::chat::ID);
auto chat = move_tl_object_as<td_api::chat>(res);
this->send_query(