Update layer to 113. Replace chat.is_sponsored with chat.source.
GitOrigin-RevId: 777a646b9639ed14d2ee1c304c6f0574c1d5ce5e
This commit is contained in:
parent
3d17513852
commit
4498067221
@ -398,6 +398,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/DialogId.cpp
|
||||
td/telegram/DialogLocation.cpp
|
||||
td/telegram/DialogParticipant.cpp
|
||||
td/telegram/DialogSource.cpp
|
||||
td/telegram/Document.cpp
|
||||
td/telegram/DocumentsManager.cpp
|
||||
td/telegram/DraftMessage.cpp
|
||||
@ -549,6 +550,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/DialogId.h
|
||||
td/telegram/DialogLocation.h
|
||||
td/telegram/DialogParticipant.h
|
||||
td/telegram/DialogSource.h
|
||||
td/telegram/Document.h
|
||||
td/telegram/DocumentsManager.h
|
||||
td/telegram/DraftMessage.h
|
||||
|
@ -649,6 +649,15 @@ chatListMain = ChatList;
|
||||
chatListArchive = ChatList;
|
||||
|
||||
|
||||
//@class ChatSource @description Describes a reason why the chat is shown in a chat list
|
||||
|
||||
//@description The chat is sponsored by the user's MTProxy server
|
||||
chatSourceMtprotoProxy = ChatSource;
|
||||
|
||||
//@description The chat contains a public service announcement @type The type of the announcement @text The text of the announcement
|
||||
chatSourcePublicServiceAnnouncement type:string text:string = ChatSource;
|
||||
|
||||
|
||||
//@description A chat. (Can be a private chat, basic group, supergroup, or secret chat)
|
||||
//@id Chat unique identifier
|
||||
//@type Type of the chat
|
||||
@ -658,9 +667,9 @@ chatListArchive = ChatList;
|
||||
//@permissions Actions that non-administrator chat members are allowed to take in the chat
|
||||
//@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
|
||||
//@source Source of the chat in a chat list; may be null
|
||||
//@is_pinned True, if the chat is pinned
|
||||
//@is_marked_as_unread True, if the chat is marked as unread
|
||||
//@is_sponsored True, if the chat is sponsored by the user's MTProxy server
|
||||
//@has_scheduled_messages True, if the chat has scheduled messages
|
||||
//@can_be_deleted_only_for_self True, if the chat messages can be deleted only for the current user while other users will continue to see the messages
|
||||
//@can_be_deleted_for_all_users True, if the chat messages can be deleted for all users
|
||||
@ -676,7 +685,7 @@ chatListArchive = ChatList;
|
||||
//@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
|
||||
//@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 the message database is used
|
||||
chat id:int53 type:ChatType chat_list:ChatList title:string photo:chatPhoto permissions:chatPermissions last_message:message order:int64 is_pinned:Bool is_marked_as_unread:Bool is_sponsored:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users: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 action_bar:ChatActionBar pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
|
||||
chat id:int53 type:ChatType chat_list:ChatList title:string photo:chatPhoto permissions:chatPermissions last_message:message order:int64 source:ChatSource is_pinned:Bool is_marked_as_unread:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users: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 action_bar:ChatActionBar pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
|
||||
|
||||
//@description Represents a list of chats @chat_ids List of chat identifiers
|
||||
chats chat_ids:vector<int53> = Chats;
|
||||
@ -2875,7 +2884,7 @@ updateChatPermissions chat_id:int53 permissions:chatPermissions = Update;
|
||||
//@description The last message of a chat was changed. If last_message is null, then the last message in the chat became unknown. Some new unknown messages might be added to the chat in this case @chat_id Chat identifier @last_message The new last message in the chat; may be null @order New value of the chat order
|
||||
updateChatLastMessage chat_id:int53 last_message:message order:int64 = Update;
|
||||
|
||||
//@description The order of the chat in the chat list has changed. Instead of this update updateChatLastMessage, updateChatIsPinned, updateChatDraftMessage, or updateChatIsSponsored might be sent @chat_id Chat identifier @order New value of the order
|
||||
//@description The order of the chat in the chat list has changed. Instead of this update updateChatLastMessage, updateChatIsPinned, updateChatDraftMessage, or updateChatSource might be sent @chat_id Chat identifier @order New value of the order
|
||||
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
|
||||
@ -2884,8 +2893,8 @@ updateChatIsPinned chat_id:int53 is_pinned:Bool order:int64 = Update;
|
||||
//@description A chat was marked as unread or was read @chat_id Chat identifier @is_marked_as_unread New value of is_marked_as_unread
|
||||
updateChatIsMarkedAsUnread chat_id:int53 is_marked_as_unread:Bool = Update;
|
||||
|
||||
//@description A chat's 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 chat's source in the chat list has changed @chat_id Chat identifier @source New chat's source; may be null @order New value of chat order
|
||||
updateChatSource chat_id:int53 source:ChatSource order:int64 = Update;
|
||||
|
||||
//@description A chat's has_scheduled_messages field has changed @chat_id Chat identifier @has_scheduled_messages New value of has_scheduled_messages
|
||||
updateChatHasScheduledMessages chat_id:int53 has_scheduled_messages:Bool = Update;
|
||||
|
Binary file not shown.
@ -638,7 +638,7 @@ messages.botResults#947ca848 flags:# gallery:flags.0?true query_id:long next_off
|
||||
|
||||
exportedMessageLink#5dab1af4 link:string html:string = ExportedMessageLink;
|
||||
|
||||
messageFwdHeader#ec338270 flags:# from_id:flags.0?int from_name:flags.5?string date:int channel_id:flags.1?int channel_post:flags.2?int post_author:flags.3?string saved_from_peer:flags.4?Peer saved_from_msg_id:flags.4?int = MessageFwdHeader;
|
||||
messageFwdHeader#353a686b flags:# from_id:flags.0?int from_name:flags.5?string date:int channel_id:flags.1?int channel_post:flags.2?int post_author:flags.3?string saved_from_peer:flags.4?Peer saved_from_msg_id:flags.4?int psa_type:flags.6?string = MessageFwdHeader;
|
||||
|
||||
auth.codeTypeSms#72a3158c = auth.CodeType;
|
||||
auth.codeTypeCall#741cd3e3 = auth.CodeType;
|
||||
@ -899,9 +899,6 @@ fileHash#6242c773 offset:int limit:int hash:bytes = FileHash;
|
||||
|
||||
inputClientProxy#75588b3f address:string port:int = InputClientProxy;
|
||||
|
||||
help.proxyDataEmpty#e09e1fb8 expires:int = help.ProxyData;
|
||||
help.proxyDataPromo#2bf7ee23 expires:int peer:Peer chats:Vector<Chat> users:Vector<User> = help.ProxyData;
|
||||
|
||||
help.termsOfServiceUpdateEmpty#e3309f7f expires:int = help.TermsOfServiceUpdate;
|
||||
help.termsOfServiceUpdate#28ecf961 expires:int terms_of_service:help.TermsOfService = help.TermsOfServiceUpdate;
|
||||
|
||||
@ -1127,6 +1124,9 @@ messageInteractionCounters#ad4fc9bd msg_id:int views:int forwards:int = MessageI
|
||||
|
||||
stats.broadcastStats#bdf78394 period:StatsDateRangeDays followers:StatsAbsValueAndPrev views_per_post:StatsAbsValueAndPrev shares_per_post:StatsAbsValueAndPrev enabled_notifications:StatsPercentValue growth_graph:StatsGraph followers_graph:StatsGraph mute_graph:StatsGraph top_hours_graph:StatsGraph interactions_graph:StatsGraph iv_interactions_graph:StatsGraph views_by_source_graph:StatsGraph new_followers_by_source_graph:StatsGraph languages_graph:StatsGraph recent_message_interactions:Vector<MessageInteractionCounters> = stats.BroadcastStats;
|
||||
|
||||
help.promoDataEmpty#98f6ac75 expires:int = help.PromoData;
|
||||
help.promoData#8c39793f flags:# proxy:flags.0?true expires:int peer:Peer chats:Vector<Chat> users:Vector<User> psa_type:flags.1?string psa_message:flags.2?string = help.PromoData;
|
||||
|
||||
---functions---
|
||||
|
||||
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
|
||||
@ -1398,7 +1398,6 @@ help.getAppChangelog#9010ef6f prev_app_version:string = Updates;
|
||||
help.setBotUpdatesStatus#ec22cfcd pending_updates_count:int message:string = Bool;
|
||||
help.getCdnConfig#52029342 = CdnConfig;
|
||||
help.getRecentMeUrls#3dc0f114 referer:string = help.RecentMeUrls;
|
||||
help.getProxyData#3d7758e1 = help.ProxyData;
|
||||
help.getTermsOfServiceUpdate#2ca51fd1 = help.TermsOfServiceUpdate;
|
||||
help.acceptTermsOfService#ee72f79a id:DataJSON = Bool;
|
||||
help.getDeepLinkInfo#3fedc75f path:string = help.DeepLinkInfo;
|
||||
@ -1408,6 +1407,8 @@ help.getPassportConfig#c661ad08 hash:int = help.PassportConfig;
|
||||
help.getSupportName#d360e72c = help.SupportName;
|
||||
help.getUserInfo#38a08d3 user_id:InputUser = help.UserInfo;
|
||||
help.editUserInfo#66b91b70 user_id:InputUser message:string entities:Vector<MessageEntity> = help.UserInfo;
|
||||
help.getPromoData#c0977421 = help.PromoData;
|
||||
help.hidePromoData#1e251c95 peer:InputPeer = Bool;
|
||||
|
||||
channels.readHistory#cc104937 channel:InputChannel max_id:int = Bool;
|
||||
channels.deleteMessages#84c1fd4e channel:InputChannel id:Vector<int> = messages.AffectedMessages;
|
||||
|
Binary file not shown.
97
td/telegram/DialogSource.cpp
Normal file
97
td/telegram/DialogSource.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#include "td/telegram/DialogSource.h"
|
||||
|
||||
#include "td/utils/misc.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
DialogSource DialogSource::mtproto_proxy() {
|
||||
DialogSource result;
|
||||
result.type_ = Type::MtprotoProxy;
|
||||
return result;
|
||||
}
|
||||
|
||||
DialogSource DialogSource::public_service_announcement(string psa_type, string psa_text) {
|
||||
DialogSource result;
|
||||
result.type_ = Type::PublicServiceAnnouncement;
|
||||
result.psa_type_ = std::move(psa_type);
|
||||
result.psa_text_ = std::move(psa_text);
|
||||
return result;
|
||||
}
|
||||
|
||||
Result<DialogSource> DialogSource::unserialize(Slice str) {
|
||||
if (str.empty()) {
|
||||
// legacy
|
||||
return mtproto_proxy();
|
||||
}
|
||||
auto type_data = split(str);
|
||||
TRY_RESULT(type, to_integer_safe<int32>(type_data.first));
|
||||
switch (type) {
|
||||
case static_cast<int32>(Type::MtprotoProxy):
|
||||
return mtproto_proxy();
|
||||
case static_cast<int32>(Type::PublicServiceAnnouncement): {
|
||||
auto data = split(type_data.second, '\x01');
|
||||
return public_service_announcement(data.first.str(), data.second.str());
|
||||
}
|
||||
default:
|
||||
return Status::Error("Unexpected chat source type");
|
||||
}
|
||||
}
|
||||
|
||||
string DialogSource::serialize() const {
|
||||
switch (type_) {
|
||||
case DialogSource::Type::Membership:
|
||||
UNREACHABLE();
|
||||
return "";
|
||||
case DialogSource::Type::MtprotoProxy:
|
||||
return "1";
|
||||
case DialogSource::Type::PublicServiceAnnouncement:
|
||||
return PSTRING() << "2 " << psa_type_ << '\x01' << psa_text_;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::ChatSource> DialogSource::get_chat_source_object() const {
|
||||
switch (type_) {
|
||||
case DialogSource::Type::Membership:
|
||||
return nullptr;
|
||||
case DialogSource::Type::MtprotoProxy:
|
||||
return td_api::make_object<td_api::chatSourceMtprotoProxy>();
|
||||
case DialogSource::Type::PublicServiceAnnouncement:
|
||||
return td_api::make_object<td_api::chatSourcePublicServiceAnnouncement>(psa_type_, psa_text_);
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const DialogSource &lhs, const DialogSource &rhs) {
|
||||
return lhs.type_ == rhs.type_ && lhs.psa_type_ == rhs.psa_type_ && lhs.psa_text_ == rhs.psa_text_;
|
||||
}
|
||||
|
||||
bool operator!=(const DialogSource &lhs, const DialogSource &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const DialogSource &source) {
|
||||
switch (source.type_) {
|
||||
case DialogSource::Type::Membership:
|
||||
return string_builder << "chat list";
|
||||
case DialogSource::Type::MtprotoProxy:
|
||||
return string_builder << "MTProto proxy sponsor";
|
||||
case DialogSource::Type::PublicServiceAnnouncement:
|
||||
return string_builder << "public service announcement of type " << source.psa_type_;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return string_builder;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace td
|
41
td/telegram/DialogSource.h
Normal file
41
td/telegram/DialogSource.h
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
struct DialogSource {
|
||||
enum class Type : int32 { Membership, MtprotoProxy, PublicServiceAnnouncement };
|
||||
Type type_ = Type::Membership;
|
||||
string psa_type_;
|
||||
string psa_text_;
|
||||
|
||||
static DialogSource mtproto_proxy();
|
||||
|
||||
static DialogSource public_service_announcement(string psa_type, string psa_text);
|
||||
|
||||
static Result<DialogSource> unserialize(Slice str);
|
||||
|
||||
string serialize() const;
|
||||
|
||||
td_api::object_ptr<td_api::ChatSource> get_chat_source_object() const;
|
||||
};
|
||||
|
||||
bool operator==(const DialogSource &lhs, const DialogSource &rhs);
|
||||
|
||||
bool operator!=(const DialogSource &lhs, const DialogSource &rhs);
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const DialogSource &source);
|
||||
|
||||
} // namespace td
|
@ -10344,15 +10344,17 @@ void MessagesManager::init() {
|
||||
|
||||
auto sponsored_dialog_id_string = G()->td_db()->get_binlog_pmc()->get("sponsored_dialog_id");
|
||||
if (!sponsored_dialog_id_string.empty()) {
|
||||
auto r_dialog_id = to_integer_safe<int64>(sponsored_dialog_id_string);
|
||||
if (r_dialog_id.is_error()) {
|
||||
auto dialog_id_source = split(Slice(sponsored_dialog_id_string));
|
||||
auto r_dialog_id = to_integer_safe<int64>(dialog_id_source.first);
|
||||
auto r_source = DialogSource::unserialize(dialog_id_source.second);
|
||||
if (r_dialog_id.is_error() || r_source.is_error()) {
|
||||
LOG(ERROR) << "Can't parse " << sponsored_dialog_id_string;
|
||||
} else {
|
||||
DialogId dialog_id(r_dialog_id.ok());
|
||||
|
||||
const Dialog *d = get_dialog_force(dialog_id);
|
||||
if (d != nullptr) {
|
||||
add_sponsored_dialog(d);
|
||||
add_sponsored_dialog(d, r_source.move_as_ok());
|
||||
} else {
|
||||
LOG(ERROR) << "Can't load " << dialog_id;
|
||||
}
|
||||
@ -15454,11 +15456,11 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *
|
||||
get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
|
||||
get_dialog_permissions(d->dialog_id).get_chat_permissions_object(),
|
||||
get_message_object(d->dialog_id, get_message(d, d->last_message_id)), get_dialog_order_object(d),
|
||||
d->pinned_order != DEFAULT_ORDER, d->is_marked_as_unread, is_dialog_sponsored(d),
|
||||
get_dialog_has_scheduled_messages(d), can_delete_for_self, can_delete_for_all_users,
|
||||
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->last_read_outbox_message_id.get(), d->unread_mention_count,
|
||||
is_dialog_sponsored(d) ? sponsored_dialog_source_.get_chat_source_object() : nullptr,
|
||||
d->pinned_order != DEFAULT_ORDER, d->is_marked_as_unread, get_dialog_has_scheduled_messages(d),
|
||||
can_delete_for_self, can_delete_for_all_users, 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->last_read_outbox_message_id.get(), d->unread_mention_count,
|
||||
get_chat_notification_settings_object(&d->notification_settings), get_chat_action_bar_object(d),
|
||||
d->pinned_message_id.get(), d->reply_markup_message_id.get(), std::move(draft_message), d->client_data);
|
||||
}
|
||||
@ -22850,16 +22852,18 @@ void MessagesManager::send_update_chat_unread_mention_count(const Dialog *d) {
|
||||
make_tl_object<td_api::updateChatUnreadMentionCount>(d->dialog_id.get(), d->unread_mention_count));
|
||||
}
|
||||
|
||||
void MessagesManager::send_update_chat_is_sponsored(const Dialog *d) const {
|
||||
void MessagesManager::send_update_chat_source(const Dialog *d) const {
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK(d != nullptr);
|
||||
LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in send_update_chat_is_sponsored";
|
||||
LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in send_update_chat_source";
|
||||
LOG(INFO) << "Update chat is sponsored for " << d->dialog_id;
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
make_tl_object<td_api::updateChatIsSponsored>(d->dialog_id.get(), is_dialog_sponsored(d),
|
||||
send_closure(
|
||||
G()->td(), &Td::send_update,
|
||||
make_tl_object<td_api::updateChatSource>(
|
||||
d->dialog_id.get(), is_dialog_sponsored(d) ? sponsored_dialog_source_.get_chat_source_object() : nullptr,
|
||||
get_dialog_order_object(d)));
|
||||
}
|
||||
|
||||
@ -23862,7 +23866,7 @@ void MessagesManager::set_dialog_folder_id(Dialog *d, FolderId folder_id) {
|
||||
// this will send updateChatChatList if needed
|
||||
DialogId sponsored_dialog_id = sponsored_dialog_id_;
|
||||
if (d->dialog_id == sponsored_dialog_id_ && d->order != DEFAULT_ORDER) {
|
||||
sponsored_dialog_id_ = DialogId(); // supress updateChatIsSponsored
|
||||
sponsored_dialog_id_ = DialogId(); // supress updateChatSource
|
||||
}
|
||||
set_dialog_order(d, DEFAULT_ORDER, true, false, "set_dialog_folder_id old");
|
||||
|
||||
@ -28440,7 +28444,7 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
|
||||
send_update_chat_chat_list(d);
|
||||
}
|
||||
if (was_sponsored != is_dialog_sponsored(d)) {
|
||||
send_update_chat_is_sponsored(d);
|
||||
send_update_chat_source(d);
|
||||
if (!is_loaded_from_database && !was_sponsored) {
|
||||
// channel is sponsored only if user isn't a channel member
|
||||
remove_all_dialog_notifications(d, false, "set_dialog_order 3");
|
||||
@ -30447,23 +30451,24 @@ void MessagesManager::get_payment_receipt(FullMessageId full_message_id,
|
||||
}
|
||||
|
||||
void MessagesManager::remove_sponsored_dialog() {
|
||||
set_sponsored_dialog_id(DialogId());
|
||||
set_sponsored_dialog(DialogId(), DialogSource());
|
||||
}
|
||||
|
||||
void MessagesManager::on_get_sponsored_dialog_id(tl_object_ptr<telegram_api::Peer> peer,
|
||||
void MessagesManager::on_get_sponsored_dialog(tl_object_ptr<telegram_api::Peer> peer, DialogSource source,
|
||||
vector<tl_object_ptr<telegram_api::User>> users,
|
||||
vector<tl_object_ptr<telegram_api::Chat>> chats) {
|
||||
CHECK(peer != nullptr);
|
||||
|
||||
td_->contacts_manager_->on_get_users(std::move(users), "on_get_sponsored_dialog_id");
|
||||
td_->contacts_manager_->on_get_chats(std::move(chats), "on_get_sponsored_dialog_id");
|
||||
td_->contacts_manager_->on_get_users(std::move(users), "on_get_sponsored_dialog");
|
||||
td_->contacts_manager_->on_get_chats(std::move(chats), "on_get_sponsored_dialog");
|
||||
|
||||
set_sponsored_dialog_id(DialogId(peer));
|
||||
set_sponsored_dialog(DialogId(peer), std::move(source));
|
||||
}
|
||||
|
||||
void MessagesManager::add_sponsored_dialog(const Dialog *d) {
|
||||
void MessagesManager::add_sponsored_dialog(const Dialog *d, DialogSource source) {
|
||||
CHECK(!sponsored_dialog_id_.is_valid());
|
||||
sponsored_dialog_id_ = d->dialog_id;
|
||||
sponsored_dialog_source_ = std::move(source);
|
||||
|
||||
if (is_dialog_sponsored(d)) {
|
||||
send_update_chat_chat_list(d);
|
||||
@ -30474,12 +30479,36 @@ void MessagesManager::add_sponsored_dialog(const Dialog *d) {
|
||||
list.last_server_dialog_date_ = max_dialog_date;
|
||||
update_last_dialog_date(folder_id);
|
||||
}
|
||||
send_update_chat_is_sponsored(d);
|
||||
send_update_chat_source(d);
|
||||
// the sponsored dialog must not be saved there
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesManager::set_sponsored_dialog_id(DialogId dialog_id) {
|
||||
void MessagesManager::save_sponsored_dialog() {
|
||||
if (!G()->parameters().use_message_db) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Save sponsored " << sponsored_dialog_id_ << " with source " << sponsored_dialog_source_;
|
||||
if (sponsored_dialog_id_.is_valid()) {
|
||||
G()->td_db()->get_binlog_pmc()->set(
|
||||
"sponsored_dialog_id",
|
||||
PSTRING() << sponsored_dialog_id_.get() << ' ' << sponsored_dialog_source_.DialogSource::serialize());
|
||||
} else {
|
||||
G()->td_db()->get_binlog_pmc()->erase("sponsored_dialog_id");
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesManager::set_sponsored_dialog(DialogId dialog_id, DialogSource source) {
|
||||
if (sponsored_dialog_id_ == dialog_id) {
|
||||
if (sponsored_dialog_source_ != source) {
|
||||
CHECK(sponsored_dialog_id_.is_valid());
|
||||
sponsored_dialog_source_ = std::move(source);
|
||||
const Dialog *d = get_dialog(sponsored_dialog_id_);
|
||||
CHECK(d != nullptr);
|
||||
send_update_chat_source(d);
|
||||
save_sponsored_dialog();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -30489,8 +30518,9 @@ void MessagesManager::set_sponsored_dialog_id(DialogId dialog_id) {
|
||||
CHECK(d != nullptr);
|
||||
bool is_sponsored = is_dialog_sponsored(d);
|
||||
sponsored_dialog_id_ = DialogId();
|
||||
sponsored_dialog_source_ = DialogSource();
|
||||
if (is_sponsored) {
|
||||
send_update_chat_is_sponsored(d);
|
||||
send_update_chat_source(d);
|
||||
send_update_chat_chat_list(d);
|
||||
need_update_total_chat_count = true;
|
||||
}
|
||||
@ -30500,7 +30530,7 @@ void MessagesManager::set_sponsored_dialog_id(DialogId dialog_id) {
|
||||
force_create_dialog(dialog_id, "set_sponsored_dialog_id");
|
||||
const Dialog *d = get_dialog(dialog_id);
|
||||
CHECK(d != nullptr);
|
||||
add_sponsored_dialog(d);
|
||||
add_sponsored_dialog(d, std::move(source));
|
||||
if (is_dialog_sponsored(d)) {
|
||||
need_update_total_chat_count = !need_update_total_chat_count;
|
||||
}
|
||||
@ -30514,14 +30544,7 @@ void MessagesManager::set_sponsored_dialog_id(DialogId dialog_id) {
|
||||
}
|
||||
}
|
||||
|
||||
if (G()->parameters().use_message_db) {
|
||||
if (sponsored_dialog_id_.is_valid()) {
|
||||
G()->td_db()->get_binlog_pmc()->set("sponsored_dialog_id", to_string(sponsored_dialog_id_.get()));
|
||||
} else {
|
||||
G()->td_db()->get_binlog_pmc()->erase("sponsored_dialog_id");
|
||||
}
|
||||
LOG(INFO) << "Save sponsored " << sponsored_dialog_id_;
|
||||
}
|
||||
save_sponsored_dialog();
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::updateUnreadMessageCount> MessagesManager::get_update_unread_message_count_object(
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/DialogLocation.h"
|
||||
#include "td/telegram/DialogParticipant.h"
|
||||
#include "td/telegram/DialogSource.h"
|
||||
#include "td/telegram/files/FileId.h"
|
||||
#include "td/telegram/files/FileSourceId.h"
|
||||
#include "td/telegram/FolderId.h"
|
||||
@ -764,7 +765,7 @@ class MessagesManager : public Actor {
|
||||
|
||||
void remove_sponsored_dialog();
|
||||
|
||||
void on_get_sponsored_dialog_id(tl_object_ptr<telegram_api::Peer> peer,
|
||||
void on_get_sponsored_dialog(tl_object_ptr<telegram_api::Peer> peer, DialogSource source,
|
||||
vector<tl_object_ptr<telegram_api::User>> users,
|
||||
vector<tl_object_ptr<telegram_api::Chat>> chats);
|
||||
|
||||
@ -1922,7 +1923,7 @@ class MessagesManager : public Actor {
|
||||
|
||||
void send_update_chat_unread_mention_count(const Dialog *d);
|
||||
|
||||
void send_update_chat_is_sponsored(const Dialog *d) const;
|
||||
void send_update_chat_source(const Dialog *d) const;
|
||||
|
||||
void send_update_chat_online_member_count(DialogId dialog_id, int32 online_member_count) const;
|
||||
|
||||
@ -2389,9 +2390,11 @@ class MessagesManager : public Actor {
|
||||
tl_object_ptr<telegram_api::InputChatPhoto> &&input_chat_photo,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void add_sponsored_dialog(const Dialog *d);
|
||||
void add_sponsored_dialog(const Dialog *d, DialogSource source);
|
||||
|
||||
void set_sponsored_dialog_id(DialogId dialog_id);
|
||||
void save_sponsored_dialog();
|
||||
|
||||
void set_sponsored_dialog(DialogId dialog_id, DialogSource source);
|
||||
|
||||
static uint64 get_sequence_dispatcher_id(DialogId dialog_id, MessageContentType message_content_type);
|
||||
|
||||
@ -2768,6 +2771,7 @@ class MessagesManager : public Actor {
|
||||
uint32 scheduled_messages_sync_generation_ = 1;
|
||||
|
||||
DialogId sponsored_dialog_id_;
|
||||
DialogSource sponsored_dialog_source_;
|
||||
|
||||
FullMessageId being_readded_message_id_;
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
constexpr int32 MTPROTO_LAYER = 112;
|
||||
constexpr int32 MTPROTO_LAYER = 113;
|
||||
|
||||
enum class Version : int32 {
|
||||
Initial,
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "td/telegram/ConfigManager.h"
|
||||
#include "td/telegram/ConfigShared.h"
|
||||
#include "td/telegram/DialogSource.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/logevent/LogEvent.h"
|
||||
#include "td/telegram/MessagesManager.h"
|
||||
@ -439,7 +440,7 @@ void ConnectionCreator::enable_proxy_impl(int32 proxy_id) {
|
||||
|
||||
void ConnectionCreator::disable_proxy_impl() {
|
||||
if (active_proxy_id_ == 0) {
|
||||
on_get_proxy_info(make_tl_object<telegram_api::help_proxyDataEmpty>(0));
|
||||
on_get_proxy_info(make_tl_object<telegram_api::help_promoDataEmpty>(0));
|
||||
return;
|
||||
}
|
||||
CHECK(proxies_.count(active_proxy_id_) == 1);
|
||||
@ -474,7 +475,7 @@ void ConnectionCreator::on_proxy_changed(bool from_db) {
|
||||
get_proxy_info_query_token_ = 0;
|
||||
get_proxy_info_timestamp_ = Timestamp();
|
||||
if (active_proxy_id_ == 0 || !from_db) {
|
||||
on_get_proxy_info(make_tl_object<telegram_api::help_proxyDataEmpty>(0));
|
||||
on_get_proxy_info(make_tl_object<telegram_api::help_promoDataEmpty>(0));
|
||||
} else {
|
||||
schedule_get_proxy_info(0);
|
||||
}
|
||||
@ -1238,7 +1239,7 @@ void ConnectionCreator::loop() {
|
||||
if (get_proxy_info_timestamp_.is_in_past()) {
|
||||
if (get_proxy_info_query_token_ == 0) {
|
||||
get_proxy_info_query_token_ = next_token();
|
||||
auto query = G()->net_query_creator().create(telegram_api::help_getProxyData());
|
||||
auto query = G()->net_query_creator().create(telegram_api::help_getPromoData());
|
||||
G()->net_query_dispatcher().dispatch_with_callback(std::move(query),
|
||||
actor_shared(this, get_proxy_info_query_token_));
|
||||
}
|
||||
@ -1282,38 +1283,36 @@ void ConnectionCreator::on_result(NetQueryPtr query) {
|
||||
}
|
||||
|
||||
get_proxy_info_query_token_ = 0;
|
||||
auto res = fetch_result<telegram_api::help_getProxyData>(std::move(query));
|
||||
auto res = fetch_result<telegram_api::help_getPromoData>(std::move(query));
|
||||
if (res.is_error()) {
|
||||
if (G()->close_flag()) {
|
||||
return;
|
||||
}
|
||||
if (res.error().message() == "BOT_METHOD_INVALID") {
|
||||
get_proxy_info_timestamp_ = Timestamp::in(30 * 86400);
|
||||
return;
|
||||
} else {
|
||||
LOG(ERROR) << "Receive error for getProxyData: " << res.error();
|
||||
return schedule_get_proxy_info(60);
|
||||
}
|
||||
}
|
||||
on_get_proxy_info(res.move_as_ok());
|
||||
}
|
||||
|
||||
void ConnectionCreator::on_get_proxy_info(telegram_api::object_ptr<telegram_api::help_ProxyData> proxy_data_ptr) {
|
||||
CHECK(proxy_data_ptr != nullptr);
|
||||
LOG(DEBUG) << "Receive " << to_string(proxy_data_ptr);
|
||||
void ConnectionCreator::on_get_proxy_info(telegram_api::object_ptr<telegram_api::help_PromoData> promo_data_ptr) {
|
||||
CHECK(promo_data_ptr != nullptr);
|
||||
LOG(DEBUG) << "Receive " << to_string(promo_data_ptr);
|
||||
int32 expires = 0;
|
||||
switch (proxy_data_ptr->get_id()) {
|
||||
case telegram_api::help_proxyDataEmpty::ID: {
|
||||
auto proxy = telegram_api::move_object_as<telegram_api::help_proxyDataEmpty>(proxy_data_ptr);
|
||||
expires = proxy->expires_;
|
||||
switch (promo_data_ptr->get_id()) {
|
||||
case telegram_api::help_promoDataEmpty::ID: {
|
||||
auto promo = telegram_api::move_object_as<telegram_api::help_promoDataEmpty>(promo_data_ptr);
|
||||
expires = promo->expires_;
|
||||
send_closure(G()->messages_manager(), &MessagesManager::remove_sponsored_dialog);
|
||||
break;
|
||||
}
|
||||
case telegram_api::help_proxyDataPromo::ID: {
|
||||
auto proxy = telegram_api::move_object_as<telegram_api::help_proxyDataPromo>(proxy_data_ptr);
|
||||
expires = proxy->expires_;
|
||||
send_closure(G()->messages_manager(), &MessagesManager::on_get_sponsored_dialog_id, std::move(proxy->peer_),
|
||||
std::move(proxy->users_), std::move(proxy->chats_));
|
||||
case telegram_api::help_promoData::ID: {
|
||||
auto promo = telegram_api::move_object_as<telegram_api::help_promoData>(promo_data_ptr);
|
||||
expires = promo->expires_;
|
||||
bool is_proxy = (promo->flags_ & telegram_api::help_promoData::PROXY_MASK) != 0;
|
||||
send_closure(G()->messages_manager(), &MessagesManager::on_get_sponsored_dialog, std::move(promo->peer_),
|
||||
is_proxy ? DialogSource::mtproto_proxy()
|
||||
: DialogSource::public_service_announcement(promo->psa_type_, promo->psa_message_),
|
||||
std::move(promo->users_), std::move(promo->chats_));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -229,7 +229,7 @@ class ConnectionCreator : public NetQueryCallback {
|
||||
uint64 auth_data_generation, int64 session_id);
|
||||
void client_set_timeout_at(ClientInfo &client, double wakeup_at);
|
||||
|
||||
void on_get_proxy_info(telegram_api::object_ptr<telegram_api::help_ProxyData> proxy_data_ptr);
|
||||
void on_get_proxy_info(telegram_api::object_ptr<telegram_api::help_PromoData> proxy_data_ptr);
|
||||
|
||||
void schedule_get_proxy_info(int32 expires);
|
||||
|
||||
|
@ -54,8 +54,7 @@ void NetQuery::set_error(Status status, string source) {
|
||||
}
|
||||
if (status.message() == "BOT_METHOD_INVALID") {
|
||||
auto id = tl_constructor();
|
||||
if (id != telegram_api::help_getNearestDc::ID && id != telegram_api::help_getProxyData::ID &&
|
||||
id != telegram_api::help_getAppConfig::ID) {
|
||||
if (id != telegram_api::help_getNearestDc::ID && id != telegram_api::help_getAppConfig::ID) {
|
||||
LOG(ERROR) << "Receive BOT_METHOD_INVALID for query " << format::as_hex(id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user