Replace SetGameScoreRequest with promise.

This commit is contained in:
levlam 2021-09-07 12:05:44 +03:00
parent 989b0c26f0
commit 546898e199
3 changed files with 20 additions and 32 deletions

View File

@ -204,7 +204,7 @@ void GameManager::tear_down() {
} }
void GameManager::set_game_score(FullMessageId full_message_id, bool edit_message, UserId user_id, int32 score, void GameManager::set_game_score(FullMessageId full_message_id, bool edit_message, UserId user_id, int32 score,
bool force, Promise<Unit> &&promise) { bool force, Promise<td_api::object_ptr<td_api::message>> &&promise) {
CHECK(td_->auth_manager_->is_bot()); CHECK(td_->auth_manager_->is_bot());
if (!td_->messages_manager_->have_message_force(full_message_id, "set_game_score")) { if (!td_->messages_manager_->have_message_force(full_message_id, "set_game_score")) {
@ -225,11 +225,23 @@ void GameManager::set_game_score(FullMessageId full_message_id, bool edit_messag
return promise.set_error(Status::Error(5, "Game score can't be set")); return promise.set_error(Status::Error(5, "Game score can't be set"));
} }
send_closure(td_->create_net_actor<SetGameScoreActor>(std::move(promise)), &SetGameScoreActor::send, dialog_id, auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), full_message_id, promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
send_closure(actor_id, &GameManager::on_set_game_score, full_message_id, std::move(promise));
});
send_closure(td_->create_net_actor<SetGameScoreActor>(std::move(query_promise)), &SetGameScoreActor::send, dialog_id,
full_message_id.get_message_id(), edit_message, std::move(input_user), score, force, full_message_id.get_message_id(), edit_message, std::move(input_user), score, force,
MessagesManager::get_sequence_dispatcher_id(dialog_id, MessageContentType::None)); MessagesManager::get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
} }
void GameManager::on_set_game_score(FullMessageId full_message_id,
Promise<td_api::object_ptr<td_api::message>> &&promise) {
promise.set_value(td_->messages_manager_->get_message_object(full_message_id));
}
void GameManager::set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score, void GameManager::set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score,
bool force, Promise<Unit> &&promise) { bool force, Promise<Unit> &&promise) {
CHECK(td_->auth_manager_->is_bot()); CHECK(td_->auth_manager_->is_bot());

View File

@ -30,7 +30,7 @@ class GameManager final : public Actor {
~GameManager() final; ~GameManager() final;
void set_game_score(FullMessageId full_message_id, bool edit_message, UserId user_id, int32 score, bool force, void set_game_score(FullMessageId full_message_id, bool edit_message, UserId user_id, int32 score, bool force,
Promise<Unit> &&promise); Promise<td_api::object_ptr<td_api::message>> &&promise);
void set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score, void set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score,
bool force, Promise<Unit> &&promise); bool force, Promise<Unit> &&promise);
@ -47,6 +47,8 @@ class GameManager final : public Actor {
private: private:
void tear_down() final; void tear_down() final;
void on_set_game_score(FullMessageId full_message_id, Promise<td_api::object_ptr<td_api::message>> &&promise);
Td *td_; Td *td_;
ActorShared<> parent_; ActorShared<> parent_;
}; };

View File

@ -1265,33 +1265,6 @@ class EditMessageReplyMarkupRequest final : public RequestOnceActor {
} }
}; };
class SetGameScoreRequest final : public RequestOnceActor {
FullMessageId full_message_id_;
bool edit_message_;
UserId user_id_;
int32 score_;
bool force_;
void do_run(Promise<Unit> &&promise) final {
td->game_manager_->set_game_score(full_message_id_, edit_message_, user_id_, score_, force_, std::move(promise));
}
void do_send_result() final {
send_result(td->messages_manager_->get_message_object(full_message_id_));
}
public:
SetGameScoreRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id, int64 message_id, bool edit_message,
int32 user_id, int32 score, bool force)
: RequestOnceActor(std::move(td), request_id)
, full_message_id_(DialogId(dialog_id), MessageId(message_id))
, edit_message_(edit_message)
, user_id_(user_id)
, score_(score)
, force_(force) {
}
};
class GetChatHistoryRequest final : public RequestActor<> { class GetChatHistoryRequest final : public RequestActor<> {
DialogId dialog_id_; DialogId dialog_id_;
MessageId from_message_id_; MessageId from_message_id_;
@ -5717,8 +5690,9 @@ void Td::on_request(uint64 id, td_api::editMessageSchedulingState &request) {
void Td::on_request(uint64 id, td_api::setGameScore &request) { void Td::on_request(uint64 id, td_api::setGameScore &request) {
CHECK_IS_BOT(); CHECK_IS_BOT();
CREATE_REQUEST(SetGameScoreRequest, request.chat_id_, request.message_id_, request.edit_message_, request.user_id_, CREATE_REQUEST_PROMISE();
request.score_, request.force_); game_manager_->set_game_score({DialogId(request.chat_id_), MessageId(request.message_id_)}, request.edit_message_,
UserId(request.user_id_), request.score_, request.force_, std::move(promise));
} }
void Td::on_request(uint64 id, td_api::setInlineGameScore &request) { void Td::on_request(uint64 id, td_api::setInlineGameScore &request) {