Add chat.is_sponsored field and updateChatIsSponsored.

GitOrigin-RevId: 0100c868c410f9b4324b3e0de9912bec22d172d5
This commit is contained in:
levlam 2018-06-15 22:52:52 +03:00
parent c02d4505e4
commit 70be2b6f85
7 changed files with 29 additions and 20 deletions

View File

@ -533,6 +533,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int32 = ChatType;
//@last_message Last message in the chat; may be null //@last_message Last message in the chat; may be null
//@order Descending parameter by which chats are sorted in the main chat list. If the order number of two chats is the same, they must be sorted in descending order by ID. If 0, the position of the chat in the list is undetermined //@order Descending parameter by which chats are sorted in the main chat list. If the order number of two chats is the same, they must be sorted in descending order by ID. If 0, the position of the chat in the list is undetermined
//@is_pinned True, if the chat is pinned //@is_pinned True, if the chat is pinned
//@is_sponsored True, if the chat is sponsored by enabled proxy
//@can_be_reported True, if the chat can be reported to Telegram moderators through reportChat //@can_be_reported True, if the chat can be reported to Telegram moderators through reportChat
//@default_disable_notification Default value of disable_notification parameter, used when a message is sent to the chat //@default_disable_notification Default value of disable_notification parameter, used when a message is sent to the chat
//@unread_count Number of unread messages in the chat //@unread_count Number of unread messages in the chat
@ -543,7 +544,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int32 = ChatType;
//@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat //@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat
//@draft_message A draft of a message in the chat; may be null //@draft_message A draft of a message in the chat; may be null
//@client_data Contains client-specific data associated with the chat. (For example, the chat position or local chat notification settings can be stored here.) Persistent if a message database is used //@client_data Contains client-specific data associated with the chat. (For example, the chat position or local chat notification settings can be stored here.) Persistent if a message database is used
chat id:int53 type:ChatType title:string photo:chatPhoto last_message:message order:int64 is_pinned:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat; chat id:int53 type:ChatType title:string photo:chatPhoto last_message:message order:int64 is_pinned:Bool is_sponsored:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
//@description Represents a list of chats @chat_ids List of chat identifiers //@description Represents a list of chats @chat_ids List of chat identifiers
chats chat_ids:vector<int53> = Chats; chats chat_ids:vector<int53> = Chats;
@ -2072,6 +2073,9 @@ updateChatOrder chat_id:int53 order:int64 = Update;
//@description A chat was pinned or unpinned @chat_id Chat identifier @is_pinned New value of is_pinned @order New value of the chat order //@description A chat was pinned or unpinned @chat_id Chat identifier @is_pinned New value of is_pinned @order New value of the chat order
updateChatIsPinned chat_id:int53 is_pinned:Bool order:int64 = Update; updateChatIsPinned chat_id:int53 is_pinned:Bool order:int64 = Update;
//@description A chat is_sponsored field has changed @chat_id Chat identifier @is_sponsored New value of is_sponsored @order New value of chat order
updateChatIsSponsored chat_id:int53 is_sponsored:Bool order:int64 = Update;
//@description A value of default disable_notification parameter, used when a message is sent to the chat, was changed @chat_id Chat identifier @default_disable_notification The new default_disable_notification value //@description A value of default disable_notification parameter, used when a message is sent to the chat, was changed @chat_id Chat identifier @default_disable_notification The new default_disable_notification value
updateChatDefaultDisableNotification chat_id:int53 default_disable_notification:Bool = Update; updateChatDefaultDisableNotification chat_id:int53 default_disable_notification:Bool = Update;
@ -2105,9 +2109,6 @@ updateDeleteMessages chat_id:int53 message_ids:vector<int53> is_permanent:Bool f
//@description User activity in the chat has changed @chat_id Chat identifier @user_id Identifier of a user performing an action @action The action description //@description User activity in the chat has changed @chat_id Chat identifier @user_id Identifier of a user performing an action @action The action description
updateUserChatAction chat_id:int53 user_id:int32 action:ChatAction = Update; updateUserChatAction chat_id:int53 user_id:int32 action:ChatAction = Update;
//@description A promoted by enabled proxy chat has changed @chat_id Identifier of the promoted chat or 0 if none
updatePromotedChat chat_id:int53 = Update;
//@description The user went online or offline @user_id User identifier @status New status of the user //@description The user went online or offline @user_id User identifier @status New status of the user
updateUserStatus user_id:int32 status:UserStatus = Update; updateUserStatus user_id:int32 status:UserStatus = Update;

Binary file not shown.

View File

@ -905,7 +905,6 @@ auth.signUp#1b067634 phone_number:string phone_code_hash:string phone_code:strin
auth.signIn#bcd51581 phone_number:string phone_code_hash:string phone_code:string = auth.Authorization; auth.signIn#bcd51581 phone_number:string phone_code_hash:string phone_code:string = auth.Authorization;
auth.logOut#5717da40 = Bool; auth.logOut#5717da40 = Bool;
auth.resetAuthorizations#9fab0d1a = Bool; auth.resetAuthorizations#9fab0d1a = Bool;
auth.sendInvites#771c1d97 phone_numbers:Vector<string> message:string = Bool;
auth.exportAuthorization#e5bfffcd dc_id:int = auth.ExportedAuthorization; auth.exportAuthorization#e5bfffcd dc_id:int = auth.ExportedAuthorization;
auth.importAuthorization#e3ef9613 id:int bytes:bytes = auth.Authorization; auth.importAuthorization#e3ef9613 id:int bytes:bytes = auth.Authorization;
auth.bindTempAuthKey#cdd42a05 perm_auth_key_id:long nonce:long expires_at:int encrypted_message:bytes = Bool; auth.bindTempAuthKey#cdd42a05 perm_auth_key_id:long nonce:long expires_at:int encrypted_message:bytes = Bool;

Binary file not shown.

View File

@ -9646,9 +9646,6 @@ void MessagesManager::start_up() {
} }
} }
} }
if (sponsored_dialog_id_.is_valid()) {
send_update_sponsored_chat();
}
} else { } else {
G()->td_db()->get_binlog_pmc()->erase("last_server_dialog_date"); G()->td_db()->get_binlog_pmc()->erase("last_server_dialog_date");
G()->td_db()->get_binlog_pmc()->erase("unread_message_count"); G()->td_db()->get_binlog_pmc()->erase("unread_message_count");
@ -13242,7 +13239,7 @@ tl_object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *d) {
get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)), get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
get_message_object(d->dialog_id, get_message(d, d->last_message_id)), get_message_object(d->dialog_id, get_message(d, d->last_message_id)),
DialogDate(d->order, d->dialog_id) <= last_dialog_date_ ? d->order : 0, d->pinned_order != DEFAULT_ORDER, DialogDate(d->order, d->dialog_id) <= last_dialog_date_ ? d->order : 0, d->pinned_order != DEFAULT_ORDER,
can_report_dialog(d->dialog_id), d->notification_settings.silent_send_message, d->order == SPONSORED_DIALOG_ORDER, can_report_dialog(d->dialog_id), d->notification_settings.silent_send_message,
d->server_unread_count + d->local_unread_count, d->last_read_inbox_message_id.get(), d->server_unread_count + d->local_unread_count, d->last_read_inbox_message_id.get(),
d->last_read_outbox_message_id.get(), d->unread_mention_count, d->last_read_outbox_message_id.get(), d->unread_mention_count,
get_chat_notification_settings_object(&d->notification_settings), d->reply_markup_message_id.get(), get_chat_notification_settings_object(&d->notification_settings), d->reply_markup_message_id.get(),
@ -19173,10 +19170,13 @@ void MessagesManager::send_update_chat_unread_mention_count(const Dialog *d) {
} }
} }
void MessagesManager::send_update_sponsored_chat() const { void MessagesManager::send_update_chat_is_sponsored(const Dialog *d) const {
if (!td_->auth_manager_->is_bot()) { if (!td_->auth_manager_->is_bot()) {
LOG(INFO) << "Update sponsored chat to " << sponsored_dialog_id_; bool is_sponsored = d->order == SPONSORED_DIALOG_ORDER;
send_closure(G()->td(), &Td::send_update, make_tl_object<td_api::updatePromotedChat>(sponsored_dialog_id_.get())); LOG(INFO) << "Update chat is sponsored for " << d->dialog_id;
auto order = DialogDate(d->order, d->dialog_id) <= last_dialog_date_ ? d->order : 0;
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateChatIsSponsored>(d->dialog_id.get(), is_sponsored, order));
} }
} }
@ -24369,7 +24369,7 @@ void MessagesManager::update_dialog_pos(Dialog *d, bool remove_from_dialog_list,
} }
} }
if (new_order == DEFAULT_ORDER && d->dialog_id == sponsored_dialog_id_) { if (new_order == DEFAULT_ORDER && d->dialog_id == sponsored_dialog_id_) {
new_order = static_cast<int64>(2147483647) << 32; new_order = SPONSORED_DIALOG_ORDER;
} }
if (set_dialog_order(d, new_order, need_send_update_chat_order)) { if (set_dialog_order(d, new_order, need_send_update_chat_order)) {
@ -24424,6 +24424,8 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
ordered_dialogs_set->insert(new_date); ordered_dialogs_set->insert(new_date);
bool add_to_hints = (d->order == DEFAULT_ORDER); bool add_to_hints = (d->order == DEFAULT_ORDER);
bool was_sponsored = (d->order == SPONSORED_DIALOG_ORDER);
bool is_sponsored = (new_order == SPONSORED_DIALOG_ORDER);
if (!is_new && (d->order == DEFAULT_ORDER || new_order == DEFAULT_ORDER)) { if (!is_new && (d->order == DEFAULT_ORDER || new_order == DEFAULT_ORDER)) {
auto unread_count = d->server_unread_count + d->local_unread_count; auto unread_count = d->server_unread_count + d->local_unread_count;
@ -24457,6 +24459,10 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
} }
update_dialogs_hints_rating(d); update_dialogs_hints_rating(d);
if (was_sponsored != is_sponsored) {
send_update_chat_is_sponsored(d);
need_update = false;
}
if (need_update && need_send_update_chat_order) { if (need_update && need_send_update_chat_order) {
send_closure(G()->td(), &Td::send_update, make_tl_object<td_api::updateChatOrder>(d->dialog_id.get(), updated_to)); send_closure(G()->td(), &Td::send_update, make_tl_object<td_api::updateChatOrder>(d->dialog_id.get(), updated_to));
} }
@ -26022,8 +26028,6 @@ void MessagesManager::set_sponsored_dialog_id(DialogId dialog_id) {
} }
LOG(INFO) << "Save sponsored " << sponsored_dialog_id_; LOG(INFO) << "Save sponsored " << sponsored_dialog_id_;
} }
send_update_sponsored_chat();
} }
} // namespace td } // namespace td

View File

@ -1872,6 +1872,7 @@ class MessagesManager : public Actor {
static constexpr int32 MAX_RECENT_FOUND_DIALOGS = 20; // some reasonable value static constexpr int32 MAX_RECENT_FOUND_DIALOGS = 20; // some reasonable value
static constexpr size_t MAX_CAPTION_LENGTH = 200; // server side limit static constexpr size_t MAX_CAPTION_LENGTH = 200; // server side limit
static constexpr size_t MAX_NAME_LENGTH = 255; // server side limit for title and description static constexpr size_t MAX_NAME_LENGTH = 255; // server side limit for title and description
static constexpr int64 SPONSORED_DIALOG_ORDER = static_cast<int64>(2147483647) << 32;
static constexpr int32 MIN_PINNED_DIALOG_DATE = 2147000000; // some big date static constexpr int32 MIN_PINNED_DIALOG_DATE = 2147000000; // some big date
static constexpr int32 MAX_PRIVATE_MESSAGE_TTL = 60; // server side limit static constexpr int32 MAX_PRIVATE_MESSAGE_TTL = 60; // server side limit
@ -2229,7 +2230,7 @@ class MessagesManager : public Actor {
void send_update_chat_unread_mention_count(const Dialog *d); void send_update_chat_unread_mention_count(const Dialog *d);
void send_update_sponsored_chat() const; void send_update_chat_is_sponsored(const Dialog *d) const;
tl_object_ptr<td_api::message> get_message_object(DialogId dialog_id, const Message *message) const; tl_object_ptr<td_api::message> get_message_object(DialogId dialog_id, const Message *message) const;

View File

@ -2893,11 +2893,15 @@ class CliClient final : public Actor {
nullptr, vector<int32>())); nullptr, vector<int32>()));
} else if (op == "dcm") { } else if (op == "dcm") {
string chat_id; string chat_id;
string user_id; string user_id_str;
std::tie(chat_id, user_id) = split(args); std::tie(chat_id, user_id_str) = split(args);
send_request(make_tl_object<td_api::setChatMemberStatus>(as_chat_id(chat_id), as_user_id(user_id), auto user_id = as_user_id(user_id_str);
make_tl_object<td_api::chatMemberStatusBanned>())); td_api::object_ptr<td_api::ChatMemberStatus> status = make_tl_object<td_api::chatMemberStatusBanned>();
if (user_id == my_id_) {
status = make_tl_object<td_api::chatMemberStatusLeft>();
}
send_request(make_tl_object<td_api::setChatMemberStatus>(as_chat_id(chat_id), user_id, std::move(status)));
} else if (op == "sn") { } else if (op == "sn") {
string first_name; string first_name;
string last_name; string last_name;