Better td_api::addLocalMessage.

GitOrigin-RevId: be6a9d27d3d683fdd7c72bca6bb8ba080bdbfc0d
This commit is contained in:
levlam 2018-03-27 17:55:33 +03:00
parent 948e416d43
commit f8efdc7b9d
7 changed files with 49 additions and 25 deletions

View File

@ -2228,9 +2228,9 @@ sendChatSetTtlMessage chat_id:int53 ttl:int32 = Message;
//@description Sends a notification about a screenshot taken in a chat. Supported only in private and secret chats @chat_id Chat identifier
sendChatScreenshotTakenNotification chat_id:int53 = Ok;
//@description Adds a local message to a chat. The message is persistent across application restarts only if the message database is used. Returns the added message @chat_id Target chat
//@reply_to_message_id Identifier of the message to reply to or 0 @input_message_content The content of the message to be added
addLocalMessage chat_id:int53 reply_to_message_id:int53 input_message_content:InputMessageContent = Message;
//@description Adds a local message to a chat. The message is persistent across application restarts only if the message database is used. Returns the added message @chat_id Target chat @sender_user_id Identifier of the user who will be shown as message sender; may be 0 for channel posts
//@reply_to_message_id Identifier of the message to reply to or 0 @disable_notification Pass true to disable notification for the message @input_message_content The content of the message to be added
addLocalMessage chat_id:int53 sender_user_id:int32 reply_to_message_id:int53 disable_notification:Bool input_message_content:InputMessageContent = Message;
//@description Deletes messages @chat_id Chat identifier @message_ids Identifiers of the messages to be deleted @revoke Pass true to try to delete outgoing messages for all chat members (may fail if messages are too old). Always true for supergroups, channels and secret chats
deleteMessages chat_id:int53 message_ids:vector<int53> revoke:Bool = Ok;

Binary file not shown.

View File

@ -5267,12 +5267,11 @@ ContactsManager::User *ContactsManager::get_user_force(UserId user_id) {
auto u = get_user_force_impl(user_id);
if (user_id == UserId(777000) && (u == nullptr || !u->is_received)) {
int32 flags = telegram_api::user::ACCESS_HASH_MASK | telegram_api::user::FIRST_NAME_MASK |
telegram_api::user::LAST_NAME_MASK | telegram_api::user::PHONE_MASK | telegram_api::user::PHOTO_MASK |
telegram_api::user::VERIFIED_MASK;
telegram_api::user::PHONE_MASK | telegram_api::user::PHOTO_MASK | telegram_api::user::VERIFIED_MASK;
auto profile_photo = telegram_api::make_object<telegram_api::userProfilePhoto>(
3337190045231018,
telegram_api::make_object<telegram_api::fileLocation>(1, 702229962, 26779, 5859320227133863146),
telegram_api::make_object<telegram_api::fileLocation>(1, 702229962, 26781, -3695031185685824216));
3337190045231018,
telegram_api::make_object<telegram_api::fileLocation>(1, 702229962, 26779, 5859320227133863146),
telegram_api::make_object<telegram_api::fileLocation>(1, 702229962, 26781, -3695031185685824216));
if (G()->is_test_dc()) {
profile_photo = nullptr;
flags -= telegram_api::user::PHOTO_MASK;
@ -5281,8 +5280,8 @@ ContactsManager::User *ContactsManager::get_user_force(UserId user_id) {
auto user = telegram_api::make_object<telegram_api::user>(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, 777000, 1, "Telegram", "Updates", string(), "42777", std::move(profile_photo),
nullptr, 0, string(), string(), string());
false /*ignored*/, 777000, 1, "Telegram", string(), string(), "42777", std::move(profile_photo), nullptr, 0,
string(), string(), string());
on_get_user(std::move(user));
u = get_user(user_id);
CHECK(u != nullptr && u->is_received);

View File

@ -18047,7 +18047,7 @@ void MessagesManager::do_send_screenshot_taken_notification_message(DialogId dia
}
Result<MessageId> MessagesManager::add_local_message(
DialogId dialog_id, MessageId reply_to_message_id,
DialogId dialog_id, UserId sender_user_id, MessageId reply_to_message_id, bool disable_notification,
tl_object_ptr<td_api::InputMessageContent> &&input_message_content) {
if (input_message_content == nullptr) {
return Status::Error(5, "Can't add local message without content");
@ -18066,30 +18066,46 @@ Result<MessageId> MessagesManager::add_local_message(
return Status::Error(5, "Chat not found");
}
TRY_STATUS(can_send_message(dialog_id));
if (!have_input_peer(dialog_id, AccessRights::Read)) {
return Status::Error(400, "Can't access the chat");
}
TRY_RESULT(message_content, process_input_message_content(dialog_id, std::move(input_message_content)));
MessageId message_id = get_next_local_message_id(d);
bool is_channel_post = is_broadcast_channel(dialog_id);
if (!td_->contacts_manager_->have_user_force(sender_user_id) && !(is_channel_post && sender_user_id == UserId())) {
return Status::Error(400, "User not found");
}
auto dialog_type = dialog_id.get_type();
auto my_id = td_->contacts_manager_->get_my_id("add_local_message");
if (sender_user_id != my_id) {
if (dialog_type == DialogType::User && DialogId(sender_user_id) != dialog_id) {
return Status::Error(400, "Wrong sender user");
}
if (dialog_type == DialogType::SecretChat &&
sender_user_id != td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id())) {
return Status::Error(400, "Wrong sender user");
}
}
MessageId message_id = get_next_local_message_id(d);
auto m = make_unique<Message>();
m->random_y = get_random_y(message_id);
m->message_id = message_id;
bool is_channel_post = is_broadcast_channel(dialog_id);
if (is_channel_post) {
// sender of the post can be hidden
if (td_->contacts_manager_->get_channel_sign_messages(dialog_id.get_channel_id())) {
m->author_signature = td_->contacts_manager_->get_user_title(my_id);
m->author_signature = td_->contacts_manager_->get_user_title(sender_user_id);
}
} else {
m->sender_user_id = my_id;
m->sender_user_id = sender_user_id;
}
m->date = G()->unix_time();
m->reply_to_message_id = get_reply_to_message_id(d, reply_to_message_id);
m->is_channel_post = is_channel_post;
m->is_outgoing = dialog_id != DialogId(my_id);
m->is_outgoing = dialog_id != DialogId(my_id) && sender_user_id == my_id;
m->disable_notification = disable_notification;
m->from_background = false;
m->views = 0;
m->content = std::move(message_content.content);
@ -18100,7 +18116,6 @@ Result<MessageId> MessagesManager::add_local_message(
if (is_service_message_content(m->content->get_id())) {
m->ttl = 0;
}
m->is_content_secret = is_secret_message_content(m->ttl, m->content->get_id());
} else if (message_content.ttl > 0) {
m->ttl = message_content.ttl;
}

View File

@ -1032,9 +1032,9 @@ class MessagesManager : public Actor {
Status send_screenshot_taken_notification_message(DialogId dialog_id);
Result<MessageId> add_local_message(DialogId dialog_id, MessageId reply_to_message_id,
tl_object_ptr<td_api::InputMessageContent> &&input_message_content)
TD_WARN_UNUSED_RESULT;
Result<MessageId> add_local_message(
DialogId dialog_id, UserId sender_user_id, MessageId reply_to_message_id, bool disable_notification,
tl_object_ptr<td_api::InputMessageContent> &&input_message_content) TD_WARN_UNUSED_RESULT;
void edit_message_text(FullMessageId full_message_id, tl_object_ptr<td_api::ReplyMarkup> &&reply_markup,
tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Promise<Unit> &&promise);

View File

@ -5643,8 +5643,9 @@ void Td::on_request(uint64 id, td_api::addLocalMessage &request) {
CHECK_IS_USER();
DialogId dialog_id(request.chat_id_);
auto r_new_message_id = messages_manager_->add_local_message(dialog_id, MessageId(request.reply_to_message_id_),
std::move(request.input_message_content_));
auto r_new_message_id = messages_manager_->add_local_message(
dialog_id, UserId(request.sender_user_id_), MessageId(request.reply_to_message_id_),
request.disable_notification_, std::move(request.input_message_content_));
if (r_new_message_id.is_error()) {
return send_closure(actor_id(this), &Td::send_error, id, r_new_message_id.move_as_error());
}

View File

@ -2071,10 +2071,12 @@ class CliClient final : public Actor {
op == "sms", false, as_message_id(reply_to_message_id));
} else if (op == "alm" || op == "almr") {
string chat_id;
string user_id;
string reply_to_message_id;
string message;
std::tie(chat_id, message) = split(args);
std::tie(chat_id, args) = split(args);
std::tie(user_id, message) = split(args);
if (op == "smr") {
std::tie(reply_to_message_id, message) = split(message);
}
@ -2086,7 +2088,7 @@ class CliClient final : public Actor {
}
send_request(make_tl_object<td_api::addLocalMessage>(
as_chat_id(chat_id), as_message_id(reply_to_message_id),
as_chat_id(chat_id), as_user_id(user_id), as_message_id(reply_to_message_id), false,
make_tl_object<td_api::inputMessageText>(move_tl_object_as<td_api::formattedText>(parsed_text), false,
true)));
} else if (op == "smap" || op == "smapr") {
@ -2679,6 +2681,13 @@ class CliClient final : public Actor {
std::tie(supergroup_id, is_all_history_available) = split(args);
send_request(make_tl_object<td_api::toggleSupergroupIsAllHistoryAvailable>(to_integer<int32>(supergroup_id),
as_bool(is_all_history_available)));
} else if (op == "tsgsm") {
string supergroup_id;
string sign_messages;
std::tie(supergroup_id, sign_messages) = split(args);
send_request(make_tl_object<td_api::toggleSupergroupSignMessages>(to_integer<int32>(supergroup_id),
as_bool(sign_messages)));
} else if (op == "csgd" || op == "cchd") {
string supergroup_id;
string description;