Add MESSAGE_ANNOUNCEMENT support.
GitOrigin-RevId: 754a484735c1a7366796181b715d0e79f91a77c1
This commit is contained in:
parent
5a4baecf1e
commit
6235ec62b0
@ -4860,21 +4860,21 @@ MessagesManager::Dialog *MessagesManager::get_service_notifications_dialog() {
|
|||||||
|
|
||||||
void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api::updateServiceNotification> &&update) {
|
void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api::updateServiceNotification> &&update) {
|
||||||
int32 ttl = 0;
|
int32 ttl = 0;
|
||||||
|
bool has_date = (update->flags_ & telegram_api::updateServiceNotification::INBOX_DATE_MASK) != 0;
|
||||||
|
auto date = has_date ? update->inbox_date_ : G()->unix_time();
|
||||||
auto content = get_message_content(
|
auto content = get_message_content(
|
||||||
td_,
|
td_,
|
||||||
get_message_text(td_->contacts_manager_.get(), std::move(update->message_), std::move(update->entities_),
|
get_message_text(td_->contacts_manager_.get(), std::move(update->message_), std::move(update->entities_), date,
|
||||||
update->inbox_date_, "on_update_service_notification"),
|
"on_update_service_notification"),
|
||||||
std::move(update->media_),
|
std::move(update->media_),
|
||||||
td_->auth_manager_->is_bot() ? DialogId() : get_service_notifications_dialog()->dialog_id, false, UserId(), &ttl);
|
td_->auth_manager_->is_bot() ? DialogId() : get_service_notifications_dialog()->dialog_id, false, UserId(), &ttl);
|
||||||
bool is_content_secret = is_secret_message_content(ttl, content->get_type());
|
bool is_content_secret = is_secret_message_content(ttl, content->get_type());
|
||||||
if ((update->flags_ & telegram_api::updateServiceNotification::POPUP_MASK) != 0) {
|
if ((update->flags_ & telegram_api::updateServiceNotification::POPUP_MASK) != 0) {
|
||||||
send_closure(
|
send_closure(G()->td(), &Td::send_update,
|
||||||
G()->td(), &Td::send_update,
|
td_api::make_object<td_api::updateServiceNotification>(
|
||||||
make_tl_object<td_api::updateServiceNotification>(
|
update->type_, get_message_content_object(content.get(), td_, date, is_content_secret)));
|
||||||
update->type_, get_message_content_object(content.get(), td_, update->inbox_date_, is_content_secret)));
|
|
||||||
}
|
}
|
||||||
if ((update->flags_ & telegram_api::updateServiceNotification::INBOX_DATE_MASK) != 0 &&
|
if (has_date && !td_->auth_manager_->is_bot()) {
|
||||||
!td_->auth_manager_->is_bot()) {
|
|
||||||
Dialog *d = get_service_notifications_dialog();
|
Dialog *d = get_service_notifications_dialog();
|
||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
auto dialog_id = d->dialog_id;
|
auto dialog_id = d->dialog_id;
|
||||||
@ -4883,7 +4883,7 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
|
|||||||
new_message->message_id = get_next_local_message_id(d);
|
new_message->message_id = get_next_local_message_id(d);
|
||||||
new_message->random_y = get_random_y(new_message->message_id);
|
new_message->random_y = get_random_y(new_message->message_id);
|
||||||
new_message->sender_user_id = dialog_id.get_user_id();
|
new_message->sender_user_id = dialog_id.get_user_id();
|
||||||
new_message->date = update->inbox_date_;
|
new_message->date = date;
|
||||||
new_message->ttl = ttl;
|
new_message->ttl = ttl;
|
||||||
new_message->is_content_secret = is_content_secret;
|
new_message->is_content_secret = is_content_secret;
|
||||||
new_message->content = std::move(content);
|
new_message->content = std::move(content);
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "td/telegram/DeviceTokenManager.h"
|
#include "td/telegram/DeviceTokenManager.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/MessagesManager.h"
|
#include "td/telegram/MessagesManager.h"
|
||||||
|
#include "td/telegram/misc.h"
|
||||||
#include "td/telegram/net/ConnectionCreator.h"
|
#include "td/telegram/net/ConnectionCreator.h"
|
||||||
#include "td/telegram/net/DcId.h"
|
#include "td/telegram/net/DcId.h"
|
||||||
#include "td/telegram/StateManager.h"
|
#include "td/telegram/StateManager.h"
|
||||||
@ -2337,7 +2338,34 @@ Status NotificationManager::process_push_notification_payload(string payload) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (badge < 0) {
|
if (badge < 0) {
|
||||||
return Status::Error("Expected badge to be positive");
|
return Status::Error("Expected badge to be non-negative");
|
||||||
|
}
|
||||||
|
if (!clean_input_string(loc_key)) {
|
||||||
|
return Status::Error(PSLICE() << "Receive invalid loc_key " << format::escaped(loc_key));
|
||||||
|
}
|
||||||
|
if (!clean_input_string(announcement_message_text)) {
|
||||||
|
return Status::Error(PSLICE() << "Receive invalid announcement_message_text "
|
||||||
|
<< format::escaped(announcement_message_text));
|
||||||
|
}
|
||||||
|
for (auto &loc_arg : loc_args) {
|
||||||
|
if (!clean_input_string(loc_arg)) {
|
||||||
|
return Status::Error(PSLICE() << "Receive invalid loc_arg " << format::escaped(loc_arg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loc_key == "MESSAGE_ANNOUNCEMENT") {
|
||||||
|
if (announcement_message_text.empty()) {
|
||||||
|
return Status::Error("Have empty announcement message text");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto update = telegram_api::make_object<telegram_api::updateServiceNotification>(
|
||||||
|
telegram_api::updateServiceNotification::INBOX_DATE_MASK, false, G()->unix_time(), string(),
|
||||||
|
announcement_message_text, nullptr, vector<telegram_api::object_ptr<telegram_api::MessageEntity>>());
|
||||||
|
send_closure(G()->messages_manager(), &MessagesManager::on_update_service_notification, std::move(update));
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
if (!announcement_message_text.empty()) {
|
||||||
|
LOG(ERROR) << "Have non-empty announcement message text with loc_key = " << loc_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loc_key == "DC_UPDATE") {
|
if (loc_key == "DC_UPDATE") {
|
||||||
@ -2346,6 +2374,9 @@ Status NotificationManager::process_push_notification_payload(string payload) {
|
|||||||
if (!DcId::is_valid(dc_id)) {
|
if (!DcId::is_valid(dc_id)) {
|
||||||
return Status::Error("Invalid dc id");
|
return Status::Error("Invalid dc id");
|
||||||
}
|
}
|
||||||
|
if (!clean_input_string(addr)) {
|
||||||
|
return Status::Error(PSLICE() << "Receive invalid addr " << format::escaped(addr));
|
||||||
|
}
|
||||||
send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_update, DcId::internal(dc_id), std::move(addr),
|
send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_update, DcId::internal(dc_id), std::move(addr),
|
||||||
Promise<Unit>());
|
Promise<Unit>());
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
|
Reference in New Issue
Block a user