Update layer to 118. Support message forward count.

GitOrigin-RevId: 10f59fede8b4a86c871949fc721fedd1d615c4bf
This commit is contained in:
levlam 2020-07-31 05:50:11 +03:00
parent 6d379b0fd5
commit 23b3eb4931
14 changed files with 226 additions and 96 deletions

View File

@ -633,6 +633,11 @@ messageForwardOriginChannel chat_id:int53 message_id:int53 author_signature:stri
//@from_message_id For messages forwarded to the chat with the current user (Saved Messages) or to the channel's discussion group, the identifier of the original message from which the new message was forwarded last time; 0 if unknown
messageForwardInfo origin:MessageForwardOrigin date:int32 public_service_announcement_type:string from_chat_id:int53 from_message_id:int53 = MessageForwardInfo;
//@description Contains information about interactions with a message
//@view_count Number of times the message was viewed
//@forward_count Number of times the message was forwarded
messageInteractionInfo view_count:int32 forward_count:int32 = MessageInteractionInfo;
//@class MessageSendingState @description Contains information about the sending state of the message
@ -660,17 +665,17 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
//@date Point in time (Unix timestamp) when the message was sent
//@edit_date Point in time (Unix timestamp) when the message was last edited
//@forward_info Information about the initial message sender; may be null
//@interaction_info Information about interactions with the message; may be null
//@reply_to_message_id If non-zero, the identifier of the message this message is replying to; can be the identifier of a deleted message
//@ttl For self-destructing messages, the message's TTL (Time To Live), in seconds; 0 if none. TDLib will send updateDeleteMessages or updateMessageContent once the TTL expires
//@ttl_expires_in Time left before the message expires, in seconds
//@via_bot_user_id If non-zero, the user identifier of the bot through which this message was sent
//@author_signature For channel posts, optional author signature
//@views Number of times this message was viewed
//@media_album_id Unique identifier of an album this message belongs to. Only photos and videos can be grouped together in albums
//@restriction_reason If non-empty, contains a human-readable description of the reason why access to this message must be restricted
//@content Content of the message
//@reply_markup Reply markup for the message; may be null
message id:int53 sender_user_id:int32 chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool is_channel_post:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo reply_to_message_id:int53 ttl:int32 ttl_expires_in:double via_bot_user_id:int32 author_signature:string views:int32 media_album_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message;
message id:int53 sender_user_id:int32 chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool is_channel_post:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo interaction_info:messageInteractionInfo reply_to_message_id:int53 ttl:int32 ttl_expires_in:double via_bot_user_id:int32 author_signature:string media_album_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message;
//@description Contains a list of messages @total_count Approximate total count of messages found @messages List of messages; messages may be null
messages total_count:int32 messages:vector<message> = Messages;
@ -3052,8 +3057,8 @@ updateMessageContent chat_id:int53 message_id:int53 new_content:MessageContent =
//@description A message was edited. Changes in the message content will come in a separate updateMessageContent @chat_id Chat identifier @message_id Message identifier @edit_date Point in time (Unix timestamp) when the message was edited @reply_markup New message reply markup; may be null
updateMessageEdited chat_id:int53 message_id:int53 edit_date:int32 reply_markup:ReplyMarkup = Update;
//@description The view count of the message has changed @chat_id Chat identifier @message_id Message identifier @views New value of the view count
updateMessageViews chat_id:int53 message_id:int53 views:int32 = Update;
//@description The information about interactions with a message has changed @chat_id Chat identifier @message_id Message identifier @interaction_info New information about interactions with the message
updateMessageInteractionInfo chat_id:int53 message_id:int53 interaction_info:messageInteractionInfo = Update;
//@description The message content was opened. Updates voice note messages to "listened", video note messages to "viewed" and starts the TTL timer for self-destructing messages @chat_id Chat identifier @message_id Message identifier
updateMessageContentOpened chat_id:int53 message_id:int53 = Update;

Binary file not shown.

View File

@ -128,7 +128,7 @@ chatPhotoEmpty#37c1011c = ChatPhoto;
chatPhoto#d20b9f3c flags:# has_video:flags.0?true photo_small:FileLocation photo_big:FileLocation dc_id:int = ChatPhoto;
messageEmpty#83e5de54 id:int = Message;
message#452c0e65 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true from_scheduled:flags.18?true legacy:flags.19?true edit_hide:flags.21?true id:int from_id:flags.8?int to_id:Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int reply_to_msg_id:flags.3?int date:int message:string media:flags.9?MessageMedia reply_markup:flags.6?ReplyMarkup entities:flags.7?Vector<MessageEntity> views:flags.10?int edit_date:flags.15?int post_author:flags.16?string grouped_id:flags.17?long restriction_reason:flags.22?Vector<RestrictionReason> = Message;
message#f52e6b7f flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true from_scheduled:flags.18?true legacy:flags.19?true edit_hide:flags.21?true id:int from_id:flags.8?int to_id:Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int reply_to_msg_id:flags.3?int date:int message:string media:flags.9?MessageMedia reply_markup:flags.6?ReplyMarkup entities:flags.7?Vector<MessageEntity> views:flags.10?int forwards:flags.10?int edit_date:flags.15?int post_author:flags.16?string grouped_id:flags.17?long restriction_reason:flags.22?Vector<RestrictionReason> = Message;
messageService#9e19a1f6 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true legacy:flags.19?true id:int from_id:flags.8?int to_id:Peer reply_to_msg_id:flags.3?int date:int action:MessageAction = Message;
messageMediaEmpty#3ded6320 = MessageMedia;
@ -179,6 +179,7 @@ photoSizeEmpty#e17e23c type:string = PhotoSize;
photoSize#77bfb61b type:string location:FileLocation w:int h:int size:int = PhotoSize;
photoCachedSize#e9a734fa type:string location:FileLocation w:int h:int bytes:bytes = PhotoSize;
photoStrippedSize#e0b0bc2e type:string bytes:bytes = PhotoSize;
photoSizeProgressive#5aa86a51 type:string location:FileLocation w:int h:int sizes:Vector<int> = PhotoSize;
geoPointEmpty#1117dd5f = GeoPoint;
geoPoint#296f104 long:double lat:double access_hash:long = GeoPoint;
@ -345,6 +346,7 @@ updateDialogFilterOrder#a5d72105 order:Vector<int> = Update;
updateDialogFilters#3504914f = Update;
updatePhoneCallSignalingData#2661bf09 phone_call_id:long data:bytes = Update;
updateChannelParticipant#65d2b464 flags:# channel_id:int date:int user_id:int prev_participant:flags.0?ChannelParticipant new_participant:flags.1?ChannelParticipant qts:int = Update;
updateChannelMessageForwards#6e8a84df channel_id:int id:int forwards:int = Update;
updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
@ -534,7 +536,7 @@ botInfo#98e81d3a user_id:int description:string commands:Vector<BotCommand> = Bo
keyboardButton#a2fa4880 text:string = KeyboardButton;
keyboardButtonUrl#258aff05 text:string url:string = KeyboardButton;
keyboardButtonCallback#683a5e46 text:string data:bytes = KeyboardButton;
keyboardButtonCallback#35bbdb6b flags:# requires_password:flags.0?true text:string data:bytes = KeyboardButton;
keyboardButtonRequestPhone#b16a6c29 text:string = KeyboardButton;
keyboardButtonRequestGeoLocation#fc796b3f text:string = KeyboardButton;
keyboardButtonSwitchInline#568a748 flags:# same_peer:flags.0?true text:string query:string = KeyboardButton;
@ -1137,6 +1139,17 @@ stats.megagroupStats#ef7ff916 period:StatsDateRangeDays members:StatsAbsValueAnd
globalPrivacySettings#bea2f424 flags:# archive_and_mute_new_noncontact_peers:flags.0?Bool = GlobalPrivacySettings;
messageViews#6d24f493 views:int forwards:int = MessageViews;
stats.messageStats#8999f295 views_graph:StatsGraph = stats.MessageStats;
help.countryCode#4203c5ef flags:# country_code:string prefixes:flags.0?Vector<string> patterns:flags.1?Vector<string> = help.CountryCode;
help.country#c3878e23 flags:# hidden:flags.0?true iso2:string default_name:string name:flags.1?string country_codes:Vector<help.CountryCode> = help.Country;
help.countriesListNotModified#93cc1f32 = help.CountriesList;
help.countriesList#87d0759e countries:Vector<help.Country> hash:int = help.CountriesList;
---functions---
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@ -1286,8 +1299,8 @@ messages.acceptEncryption#3dbc0415 peer:InputEncryptedChat g_b:bytes key_fingerp
messages.discardEncryption#edd923c5 chat_id:int = Bool;
messages.setEncryptedTyping#791451ed peer:InputEncryptedChat typing:Bool = Bool;
messages.readEncryptedHistory#7f4b690a peer:InputEncryptedChat max_date:int = Bool;
messages.sendEncrypted#a9776773 peer:InputEncryptedChat random_id:long data:bytes = messages.SentEncryptedMessage;
messages.sendEncryptedFile#9a901b66 peer:InputEncryptedChat random_id:long data:bytes file:InputEncryptedFile = messages.SentEncryptedMessage;
messages.sendEncrypted#44fa7a15 flags:# silent:flags.0?true peer:InputEncryptedChat random_id:long data:bytes = messages.SentEncryptedMessage;
messages.sendEncryptedFile#5559481d flags:# silent:flags.0?true peer:InputEncryptedChat random_id:long data:bytes file:InputEncryptedFile = messages.SentEncryptedMessage;
messages.sendEncryptedService#32d439a4 peer:InputEncryptedChat random_id:long data:bytes = messages.SentEncryptedMessage;
messages.receivedQueue#55a5bb66 max_qts:int = Vector<long>;
messages.reportEncryptedSpam#4b0c8c0f peer:InputEncryptedChat = Bool;
@ -1302,10 +1315,10 @@ messages.getStickerSet#2619a90e stickerset:InputStickerSet = messages.StickerSet
messages.installStickerSet#c78fe460 stickerset:InputStickerSet archived:Bool = messages.StickerSetInstallResult;
messages.uninstallStickerSet#f96e55de stickerset:InputStickerSet = Bool;
messages.startBot#e6df7378 bot:InputUser peer:InputPeer random_id:long start_param:string = Updates;
messages.getMessagesViews#c4c8a55d peer:InputPeer id:Vector<int> increment:Bool = Vector<int>;
messages.getMessagesViews#fdac5dba peer:InputPeer id:Vector<int> increment:Bool = Vector<MessageViews>;
messages.editChatAdmin#a9e69f2e chat_id:int user_id:InputUser is_admin:Bool = Bool;
messages.migrateChat#15a3b8e3 chat_id:int = Updates;
messages.searchGlobal#bf7225a4 flags:# folder_id:flags.0?int q:string offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
messages.searchGlobal#734dd16d flags:# folder_id:flags.0?int q:string filter:MessagesFilter offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
messages.reorderStickerSets#78337739 flags:# masks:flags.0?true order:Vector<long> = Bool;
messages.getDocumentByHash#338e2464 sha256:bytes size:int mime_type:string = Document;
messages.getSavedGifs#83bf3d52 hash:int = messages.SavedGifs;
@ -1316,7 +1329,7 @@ messages.sendInlineBotResult#220815b0 flags:# silent:flags.5?true background:fla
messages.getMessageEditData#fda68d36 peer:InputPeer id:int = messages.MessageEditData;
messages.editMessage#48f71778 flags:# no_webpage:flags.1?true peer:InputPeer id:int message:flags.11?string media:flags.14?InputMedia reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.15?int = Updates;
messages.editInlineBotMessage#83557dba flags:# no_webpage:flags.1?true id:InputBotInlineMessageID message:flags.11?string media:flags.14?InputMedia reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> = Bool;
messages.getBotCallbackAnswer#810a9fec flags:# game:flags.1?true peer:InputPeer msg_id:int data:flags.0?bytes = messages.BotCallbackAnswer;
messages.getBotCallbackAnswer#9342ca07 flags:# game:flags.1?true peer:InputPeer msg_id:int data:flags.0?bytes password:flags.2?InputCheckPasswordSRP = messages.BotCallbackAnswer;
messages.setBotCallbackAnswer#d58f130a flags:# alert:flags.1?true query_id:long message:flags.0?string url:flags.2?string cache_time:int = Bool;
messages.getPeerDialogs#e470bcfd peers:Vector<InputDialogPeer> = messages.PeerDialogs;
messages.saveDraft#bc39e14b flags:# no_webpage:flags.1?true reply_to_msg_id:flags.0?int peer:InputPeer message:string entities:flags.3?Vector<MessageEntity> = Bool;
@ -1421,6 +1434,7 @@ help.editUserInfo#66b91b70 user_id:InputUser message:string entities:Vector<Mess
help.getPromoData#c0977421 = help.PromoData;
help.hidePromoData#1e251c95 peer:InputPeer = Bool;
help.dismissSuggestion#77fa99f suggestion:string = Bool;
help.getCountriesList#735787a8 lang_code:string hash:int = help.CountriesList;
channels.readHistory#cc104937 channel:InputChannel max_id:int = Bool;
channels.deleteMessages#84c1fd4e channel:InputChannel id:Vector<int> = messages.AffectedMessages;
@ -1498,3 +1512,5 @@ folders.deleteFolder#1c295881 folder_id:int = Updates;
stats.getBroadcastStats#ab42441a flags:# dark:flags.0?true channel:InputChannel = stats.BroadcastStats;
stats.loadAsyncGraph#621d5fa0 flags:# token:string x:flags.0?long = StatsGraph;
stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel = stats.MegagroupStats;
stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;

Binary file not shown.

View File

@ -62,7 +62,8 @@ class GetBotCallbackAnswerQuery : public Td::ResultHandler {
}
auto net_query = G()->net_query_creator().create(telegram_api::messages_getBotCallbackAnswer(
flags, false /*ignored*/, std::move(input_peer), message_id.get_server_message_id().get(), std::move(data)));
flags, false /*ignored*/, std::move(input_peer), message_id.get_server_message_id().get(), std::move(data),
nullptr));
net_query->need_resend_on_503_ = false;
send_query(std::move(net_query));
}

View File

@ -1264,8 +1264,8 @@ class GetMessagesViewsQuery : public Td::ResultHandler {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
LOG(ERROR) << "Can't update message views because doesn't have info about the " << dialog_id;
return on_error(0, Status::Error(500, "Can't update message views"));
LOG(ERROR) << "Can't update message view count because doesn't have info about the " << dialog_id;
return on_error(0, Status::Error(500, "Can't update message view count"));
}
LOG(INFO) << "View " << message_ids_.size() << " messages in " << dialog_id
@ -1280,14 +1280,13 @@ class GetMessagesViewsQuery : public Td::ResultHandler {
return on_error(id, result_ptr.move_as_error());
}
vector<int32> views = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetMessagesViewsQuery: " << format::as_array(views);
if (message_ids_.size() != views.size()) {
auto interaction_infos = result_ptr.move_as_ok();
if (message_ids_.size() != interaction_infos.size()) {
return on_error(id, Status::Error(500, "Wrong number of message views returned"));
}
for (size_t i = 0; i < message_ids_.size(); i++) {
td->messages_manager_->on_update_message_views({dialog_id_, message_ids_[i]}, views[i]);
td->messages_manager_->on_update_message_interaction_info(
{dialog_id_, message_ids_[i]}, interaction_infos[i]->views_, interaction_infos[i]->forwards_);
}
}
@ -1671,9 +1670,9 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
if (!ignore_folder_id) {
flags |= telegram_api::messages_searchGlobal::FOLDER_ID_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::messages_searchGlobal(flags, folder_id.get(), query, offset_date_, std::move(input_peer),
offset_message_id.get_server_message_id().get(), limit)));
send_query(G()->net_query_creator().create(telegram_api::messages_searchGlobal(
flags, folder_id.get(), query, make_tl_object<telegram_api::inputMessagesFilterEmpty>(), offset_date_,
std::move(input_peer), offset_message_id.get_server_message_id().get(), limit)));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -4107,7 +4106,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
bool is_reply = reply_to_message_id.is_valid();
bool is_reply_to_random_id = reply_to_random_id != 0;
bool is_via_bot = via_bot_user_id.is_valid();
bool has_views = views > 0;
bool has_view_count = view_count > 0;
bool has_reply_markup = reply_markup != nullptr;
bool has_ttl = ttl != 0;
bool has_author_signature = !author_signature.empty();
@ -4124,6 +4123,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
bool has_legacy_layer = legacy_layer != 0;
bool has_restriction_reasons = !restriction_reasons.empty();
bool has_forward_psa_type = is_forwarded && !forward_info->psa_type.empty();
bool has_forward_count = forward_count > 0;
BEGIN_STORE_FLAGS();
STORE_FLAG(is_channel_post);
STORE_FLAG(is_outgoing);
@ -4142,7 +4142,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
STORE_FLAG(is_reply);
STORE_FLAG(is_reply_to_random_id);
STORE_FLAG(is_via_bot);
STORE_FLAG(has_views);
STORE_FLAG(has_view_count);
STORE_FLAG(has_reply_markup);
STORE_FLAG(has_ttl);
STORE_FLAG(has_author_signature);
@ -4172,6 +4172,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
STORE_FLAG(is_from_scheduled);
STORE_FLAG(is_copy);
STORE_FLAG(has_forward_psa_type);
STORE_FLAG(has_forward_count);
END_STORE_FLAGS();
}
@ -4221,8 +4222,11 @@ void MessagesManager::Message::store(StorerT &storer) const {
if (is_via_bot) {
store(via_bot_user_id, storer);
}
if (has_views) {
store(views, storer);
if (has_view_count) {
store(view_count, storer);
}
if (has_forward_count) {
store(forward_count, storer);
}
if (has_ttl) {
store(ttl, storer);
@ -4267,7 +4271,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
bool is_reply;
bool is_reply_to_random_id;
bool is_via_bot;
bool has_views;
bool has_view_count;
bool has_reply_markup;
bool has_ttl;
bool has_author_signature;
@ -4283,6 +4287,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
bool has_legacy_layer = false;
bool has_restriction_reasons = false;
bool has_forward_psa_type = false;
bool has_forward_count = false;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_channel_post);
PARSE_FLAG(is_outgoing);
@ -4301,7 +4306,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
PARSE_FLAG(is_reply);
PARSE_FLAG(is_reply_to_random_id);
PARSE_FLAG(is_via_bot);
PARSE_FLAG(has_views);
PARSE_FLAG(has_view_count);
PARSE_FLAG(has_reply_markup);
PARSE_FLAG(has_ttl);
PARSE_FLAG(has_author_signature);
@ -4331,6 +4336,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
PARSE_FLAG(is_from_scheduled);
PARSE_FLAG(is_copy);
PARSE_FLAG(has_forward_psa_type);
PARSE_FLAG(has_forward_count);
END_PARSE_FLAGS();
}
@ -4386,8 +4392,11 @@ void MessagesManager::Message::parse(ParserT &parser) {
if (is_via_bot) {
parse(via_bot_user_id, parser);
}
if (has_views) {
parse(views, parser);
if (has_view_count) {
parse(view_count, parser);
}
if (has_forward_count) {
parse(forward_count, parser);
}
if (has_ttl) {
parse(ttl, parser);
@ -5936,27 +5945,29 @@ void MessagesManager::on_update_channel_too_long(tl_object_ptr<telegram_api::upd
}
}
void MessagesManager::on_update_message_views(FullMessageId full_message_id, int32 views) {
auto dialog_id = full_message_id.get_dialog_id();
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
LOG(INFO) << "Ignore updateMessageViews in unknown " << dialog_id;
return;
}
auto message_id = full_message_id.get_message_id();
Message *m = get_message_force(d, message_id, "on_update_message_views");
if (m == nullptr) {
LOG(INFO) << "Ignore updateMessageViews about unknown " << full_message_id;
if (!message_id.is_scheduled() && message_id > d->last_new_message_id &&
dialog_id.get_type() == DialogType::Channel) {
get_channel_difference(dialog_id, d->pts, true, "on_update_message_views");
}
void MessagesManager::on_update_message_view_count(FullMessageId full_message_id, int32 view_count) {
if (view_count < 0) {
LOG(ERROR) << "Receive " << view_count << " views in updateChannelMessageViews for " << full_message_id;
return;
}
update_message_interaction_info(full_message_id, view_count, -1);
}
if (update_message_views(dialog_id, m, views)) {
on_message_changed(d, m, true, "on_update_message_views");
void MessagesManager::on_update_message_forward_count(FullMessageId full_message_id, int32 forward_count) {
if (forward_count < 0) {
LOG(ERROR) << "Receive " << forward_count << " forwards in updateChannelMessageForwards for " << full_message_id;
return;
}
update_message_interaction_info(full_message_id, -1, forward_count);
}
void MessagesManager::on_update_message_interaction_info(FullMessageId full_message_id, int32 view_count,
int32 forward_count) {
if (view_count < 0 || forward_count < 0) {
LOG(ERROR) << "Receive " << view_count << "/" << forward_count << " interaction counters for " << full_message_id;
return;
}
update_message_interaction_info(full_message_id, view_count, forward_count);
}
void MessagesManager::on_pending_message_views_timeout(DialogId dialog_id) {
@ -5984,14 +5995,60 @@ void MessagesManager::on_pending_message_views_timeout(DialogId dialog_id) {
d->increment_view_counter = false;
}
bool MessagesManager::update_message_views(DialogId dialog_id, Message *m, int32 views) {
void MessagesManager::update_message_interaction_info(FullMessageId full_message_id, int32 view_count,
int32 forward_count) {
auto dialog_id = full_message_id.get_dialog_id();
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
return;
}
auto message_id = full_message_id.get_message_id();
Message *m = get_message_force(d, message_id, "update_message_interaction_info");
if (m == nullptr) {
LOG(INFO) << "Ignore message interaction info about unknown " << full_message_id;
if (!message_id.is_scheduled() && message_id > d->last_new_message_id &&
dialog_id.get_type() == DialogType::Channel) {
get_channel_difference(dialog_id, d->pts, true, "update_message_interaction_info");
}
return;
}
if (update_message_interaction_info(dialog_id, m, view_count >= 0 ? view_count : m->view_count,
forward_count >= 0 ? forward_count : m->forward_count)) {
on_message_changed(d, m, true, "on_update_message_view_count");
}
}
td_api::object_ptr<td_api::messageInteractionInfo> MessagesManager::get_message_interaction_info_object(
DialogId dialog_id, const Message *m) const {
if (m->view_count == 0 && m->forward_count == 0) {
return nullptr;
}
if (m->message_id.is_scheduled() && (m->forward_info == nullptr || is_broadcast_channel(dialog_id))) {
return nullptr;
}
if (m->message_id.is_local() && m->forward_info == nullptr) {
return nullptr;
}
return td_api::make_object<td_api::messageInteractionInfo>(m->view_count, m->forward_count);
}
bool MessagesManager::update_message_interaction_info(DialogId dialog_id, Message *m, int32 view_count,
int32 forward_count) {
CHECK(m != nullptr);
if (views > m->views) {
LOG(DEBUG) << "Update views of " << FullMessageId{dialog_id, m->message_id} << " from " << m->views << " to "
<< views;
m->views = views;
if (view_count > m->view_count || forward_count > m->forward_count) {
LOG(DEBUG) << "Update interaction info of " << FullMessageId{dialog_id, m->message_id} << " from " << m->view_count
<< '/' << m->forward_count << " to " << view_count << '/' << forward_count;
if (view_count > m->view_count) {
m->view_count = view_count;
}
if (forward_count > m->forward_count) {
m->forward_count = forward_count;
}
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateMessageViews>(dialog_id.get(), m->message_id.get(), m->views));
make_tl_object<td_api::updateMessageInteractionInfo>(
dialog_id.get(), m->message_id.get(), get_message_interaction_info_object(dialog_id, m)));
return true;
}
return false;
@ -11805,8 +11862,9 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
message_info.via_bot_user_id = UserId();
}
}
if (message->flags_ & MESSAGE_FLAG_HAS_VIEWS) {
message_info.views = message->views_;
if (message->flags_ & MESSAGE_FLAG_HAS_INTERACTION_INFO) {
message_info.view_count = message->views_;
message_info.forward_count = message->forwards_;
}
if (message->flags_ & MESSAGE_FLAG_HAS_EDIT_DATE) {
message_info.edit_date = message->edit_date_;
@ -11974,10 +12032,15 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
ttl = max(ttl, get_message_content_duration(message_info.content.get(), td_) + 1);
}
int32 views = message_info.views;
if (views < 0) {
LOG(ERROR) << "Wrong views = " << views << " received in " << message_id << " in " << dialog_id;
views = 0;
int32 view_count = message_info.view_count;
if (view_count < 0) {
LOG(ERROR) << "Wrong view_count = " << view_count << " received in " << message_id << " in " << dialog_id;
view_count = 0;
}
int32 forward_count = message_info.forward_count;
if (forward_count < 0) {
LOG(ERROR) << "Wrong forward_count = " << forward_count << " received in " << message_id << " in " << dialog_id;
forward_count = 0;
}
bool has_forward_info = message_info.forward_header != nullptr;
@ -12009,7 +12072,8 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
message->is_content_secret = is_content_secret;
message->hide_edit_date = hide_edit_date;
message->is_from_scheduled = is_from_scheduled;
message->views = views;
message->view_count = view_count;
message->forward_count = forward_count;
message->legacy_layer = (is_legacy ? MTPROTO_LAYER : 0);
message->content = std::move(message_info.content);
message->reply_markup = get_reply_markup(std::move(message_info.reply_markup), td_->auth_manager_->is_bot(), false,
@ -17112,7 +17176,7 @@ Status MessagesManager::view_messages(DialogId dialog_id, const vector<MessageId
auto *m = get_message_force(d, message_id, "view_messages");
if (m != nullptr) {
if (m->message_id.is_server() && m->views > 0) {
if (m->message_id.is_server() && m->view_count > 0) {
d->pending_viewed_message_ids.insert(m->message_id);
}
@ -19969,20 +20033,13 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
auto live_location_date = m->is_failed_to_send ? 0 : m->date;
auto date = is_scheduled ? 0 : m->date;
auto edit_date = m->hide_edit_date ? 0 : m->edit_date;
auto views = m->views;
if (m->message_id.is_scheduled()) {
if (m->forward_info == nullptr || is_broadcast_channel(dialog_id)) {
views = 0;
}
} else if (m->message_id.is_local() && m->forward_info == nullptr) {
views = 0;
}
return make_tl_object<td_api::message>(
m->message_id.get(), td_->contacts_manager_->get_user_id_object(m->sender_user_id, "sender_user_id"),
dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing, can_be_edited,
can_be_forwarded, can_delete_for_self, can_delete_for_all_users, m->is_channel_post, contains_unread_mention,
date, edit_date, get_message_forward_info_object(m->forward_info), reply_to_message_id, ttl, ttl_expires_in,
td_->contacts_manager_->get_user_id_object(m->via_bot_user_id, "via_bot_user_id"), m->author_signature, views,
date, edit_date, get_message_forward_info_object(m->forward_info),
get_message_interaction_info_object(dialog_id, m), reply_to_message_id, ttl, ttl_expires_in,
td_->contacts_manager_->get_user_id_object(m->via_bot_user_id, "via_bot_user_id"), m->author_signature,
media_album_id, get_restriction_reason_description(m->restriction_reasons),
get_message_content_object(m->content.get(), td_, live_location_date, m->is_content_secret),
get_reply_markup_object(m->reply_markup));
@ -20046,7 +20103,8 @@ MessagesManager::Message *MessagesManager::get_message_to_send(
m->is_channel_post = is_channel_post;
m->is_outgoing = is_scheduled || dialog_id != DialogId(my_id);
m->from_background = options.from_background;
m->views = is_channel_post && !is_scheduled ? 1 : 0;
m->view_count = is_channel_post && !is_scheduled ? 1 : 0;
m->forward_count = 0;
m->content = std::move(content);
m->forward_info = std::move(forward_info);
m->is_copy = is_copy || forward_info != nullptr;
@ -23022,7 +23080,7 @@ Result<vector<MessageId>> MessagesManager::forward_messages(DialogId to_dialog_i
for (size_t i = 0; i < message_ids.size(); i++) {
MessageId message_id = get_persistent_message_id(from_dialog, message_ids[i]);
const Message *forwarded_message = get_message_force(from_dialog, message_id, "forward_messages");
Message *forwarded_message = get_message_force(from_dialog, message_id, "forward_messages");
if (forwarded_message == nullptr) {
LOG(INFO) << "Can't find " << message_id << " to forward";
continue;
@ -23108,9 +23166,16 @@ Result<vector<MessageId>> MessagesManager::forward_messages(DialogId to_dialog_i
m->real_forward_from_message_id = message_id;
m->via_bot_user_id = forwarded_message->via_bot_user_id;
m->in_game_share = in_game_share;
if (forwarded_message->views > 0 && m->forward_info != nullptr && m->views == 0 &&
if (forwarded_message->view_count > 0 && is_broadcast_channel(from_dialog_id)) {
if (update_message_interaction_info(from_dialog_id, forwarded_message, forwarded_message->view_count,
forwarded_message->forward_count + 1)) {
on_message_changed(from_dialog, forwarded_message, true, "forward_messages");
}
}
if (forwarded_message->view_count > 0 && m->forward_info != nullptr && m->view_count == 0 &&
!(m->message_id.is_scheduled() && is_broadcast_channel(to_dialog_id))) {
m->views = forwarded_message->views;
m->view_count = forwarded_message->view_count;
m->forward_count = forwarded_message->forward_count;
}
if (is_game) {
@ -23517,7 +23582,8 @@ Result<MessageId> MessagesManager::add_local_message(
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->view_count = 0;
m->forward_count = 0;
m->content = std::move(message_content.content);
m->disable_web_page_preview = message_content.disable_web_page_preview;
m->clear_draft = message_content.clear_draft;
@ -25796,8 +25862,8 @@ void MessagesManager::fail_send_message(FullMessageId full_message_id, int error
} else {
CHECK(message->message_id.is_valid());
}
if (message->forward_info == nullptr && message->views == 1) {
message->views = 0;
if (message->forward_info == nullptr && message->view_count == 1) {
message->view_count = 0;
}
message->is_failed_to_send = true;
message->send_error_code = error_code;
@ -29863,7 +29929,7 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
update_message_contains_unread_mention(d, old_message, new_message->contains_unread_mention, "update_message")) {
need_send_update = true;
}
if (update_message_views(dialog_id, old_message, new_message->views)) {
if (update_message_interaction_info(dialog_id, old_message, new_message->view_count, new_message->forward_count)) {
need_send_update = true;
}
if (old_message->restriction_reasons != new_message->restriction_reasons) {

View File

@ -151,7 +151,7 @@ class MessagesManager : public Actor {
static constexpr int32 MESSAGE_FLAG_HAS_ENTITIES = 1 << 7;
static constexpr int32 MESSAGE_FLAG_HAS_FROM_ID = 1 << 8;
static constexpr int32 MESSAGE_FLAG_HAS_MEDIA = 1 << 9;
static constexpr int32 MESSAGE_FLAG_HAS_VIEWS = 1 << 10;
static constexpr int32 MESSAGE_FLAG_HAS_INTERACTION_INFO = 1 << 10;
static constexpr int32 MESSAGE_FLAG_IS_SENT_VIA_BOT = 1 << 11;
static constexpr int32 MESSAGE_FLAG_IS_SILENT = 1 << 13;
static constexpr int32 MESSAGE_FLAG_IS_POST = 1 << 14;
@ -323,7 +323,11 @@ class MessagesManager : public Actor {
void on_update_channel_too_long(tl_object_ptr<telegram_api::updateChannelTooLong> &&update, bool force_apply);
void on_update_message_views(FullMessageId full_message_id, int32 views);
void on_update_message_view_count(FullMessageId full_message_id, int32 view_count);
void on_update_message_forward_count(FullMessageId full_message_id, int32 forward_count);
void on_update_message_interaction_info(FullMessageId full_message_id, int32 view_count, int32 forward_count);
void on_update_live_location_viewed(FullMessageId full_message_id);
@ -887,7 +891,8 @@ class MessagesManager : public Actor {
tl_object_ptr<telegram_api::messageFwdHeader> forward_header;
MessageId reply_to_message_id;
UserId via_bot_user_id;
int32 views = 0;
int32 view_count = 0;
int32 forward_count = 0;
int32 flags = 0;
int32 edit_date = 0;
vector<RestrictionReason> restriction_reasons;
@ -999,7 +1004,8 @@ class MessagesManager : public Actor {
NotificationId notification_id;
NotificationId removed_notification_id;
int32 views = 0;
int32 view_count = 0;
int32 forward_count = 0;
int32 legacy_layer = 0;
int32 send_error_code = 0;
@ -1820,7 +1826,12 @@ class MessagesManager : public Actor {
void on_pending_message_views_timeout(DialogId dialog_id);
bool update_message_views(DialogId dialog_id, Message *m, int32 views);
void update_message_interaction_info(FullMessageId full_message_id, int32 view_count, int32 forward_count);
td_api::object_ptr<td_api::messageInteractionInfo> get_message_interaction_info_object(DialogId dialog_id,
const Message *m) const;
bool update_message_interaction_info(DialogId dialog_id, Message *m, int32 view_count, int32 forward_count);
bool update_message_contains_unread_mention(Dialog *d, Message *m, bool contains_unread_mention, const char *source);

View File

@ -395,6 +395,22 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, PhotoSizeSo
auto size = move_tl_object_as<telegram_api::photoStrippedSize>(size_ptr);
return size->bytes_.as_slice().str();
}
case telegram_api::photoSizeProgressive::ID: {
auto size = move_tl_object_as<telegram_api::photoSizeProgressive>(size_ptr);
if (size->sizes_.empty()) {
LOG(ERROR) << "Receive " << to_string(size);
return std::move(res);
}
std::sort(size->sizes_.begin(), size->sizes_.end());
type = std::move(size->type_);
location = std::move(size->location_);
res.dimensions = get_dimensions(size->w_, size->h_);
res.size = size->sizes_.back();
break;
}
default:
UNREACHABLE();
break;

View File

@ -618,7 +618,7 @@ static tl_object_ptr<telegram_api::KeyboardButton> get_inline_keyboard_button(
case InlineKeyboardButton::Type::Url:
return make_tl_object<telegram_api::keyboardButtonUrl>(keyboard_button.text, keyboard_button.data);
case InlineKeyboardButton::Type::Callback:
return make_tl_object<telegram_api::keyboardButtonCallback>(keyboard_button.text,
return make_tl_object<telegram_api::keyboardButtonCallback>(0, false /*ignored*/, keyboard_button.text,
BufferSlice(keyboard_button.data));
case InlineKeyboardButton::Type::CallbackGame:
return make_tl_object<telegram_api::keyboardButtonGame>(keyboard_button.text);

View File

@ -1468,13 +1468,13 @@ NetQueryPtr SecretChatActor::create_net_query(const logevent::OutboundSecretMess
message.encrypted_message.clone()));
} else if (message.file.empty()) {
query = create_net_query(
QueryType::Message,
telegram_api::messages_sendEncrypted(get_input_chat(), message.random_id, message.encrypted_message.clone()));
QueryType::Message, telegram_api::messages_sendEncrypted(0, false /*ignored*/, get_input_chat(),
message.random_id, message.encrypted_message.clone()));
} else {
query = create_net_query(
QueryType::Message,
telegram_api::messages_sendEncryptedFile(get_input_chat(), message.random_id, message.encrypted_message.clone(),
message.file.as_input_encrypted_file()));
query = create_net_query(QueryType::Message,
telegram_api::messages_sendEncryptedFile(
0, false /*ignored*/, get_input_chat(), message.random_id,
message.encrypted_message.clone(), message.file.as_input_encrypted_file()));
}
if (!message.is_rewritable) {
query->total_timeout_limit_ = 1000000000; // inf. We will re-sent it immediately anyway

View File

@ -696,7 +696,7 @@ void UpdatesManager::on_get_updates(tl_object_ptr<telegram_api::Updates> &&updat
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, update->id_, from_id,
make_tl_object<telegram_api::peerUser>(update->user_id_), std::move(update->fwd_from_),
update->via_bot_id_, update->reply_to_msg_id_, update->date_, update->message_, nullptr, nullptr,
std::move(update->entities_), 0, 0, "", 0, Auto()),
std::move(update->entities_), 0, 0, 0, "", 0, Auto()),
update->pts_, update->pts_count_),
0, "telegram_api::updatesShortMessage");
break;
@ -720,7 +720,7 @@ void UpdatesManager::on_get_updates(tl_object_ptr<telegram_api::Updates> &&updat
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, update->id_,
update->from_id_, make_tl_object<telegram_api::peerChat>(update->chat_id_),
std::move(update->fwd_from_), update->via_bot_id_, update->reply_to_msg_id_, update->date_,
update->message_, nullptr, nullptr, std::move(update->entities_), 0, 0, "", 0, Auto()),
update->message_, nullptr, nullptr, std::move(update->entities_), 0, 0, 0, "", 0, Auto()),
update->pts_, update->pts_count_),
0, "telegram_api::updatesShortChatMessage");
break;
@ -1684,7 +1684,19 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelMessageV
return;
}
DialogId dialog_id(channel_id);
td_->messages_manager_->on_update_message_views({dialog_id, MessageId(ServerMessageId(update->id_))}, update->views_);
td_->messages_manager_->on_update_message_view_count({dialog_id, MessageId(ServerMessageId(update->id_))},
update->views_);
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelMessageForwards> update, bool /*force_apply*/) {
ChannelId channel_id(update->channel_id_);
if (!channel_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << channel_id;
return;
}
DialogId dialog_id(channel_id);
td_->messages_manager_->on_update_message_forward_count({dialog_id, MessageId(ServerMessageId(update->id_))},
update->forwards_);
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelAvailableMessages> update,

View File

@ -243,6 +243,7 @@ class UpdatesManager : public Actor {
void on_update(tl_object_ptr<telegram_api::updateEditChannelMessage> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateDeleteChannelMessages> update, bool force_apply);
void on_update(tl_object_ptr<telegram_api::updateChannelMessageViews> update, bool force_apply);
void on_update(tl_object_ptr<telegram_api::updateChannelMessageForwards> update, bool force_apply);
void on_update(tl_object_ptr<telegram_api::updateChannelAvailableMessages> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateUserPinnedMessage> update, bool /*force_apply*/);

View File

@ -8,7 +8,7 @@
namespace td {
constexpr int32 MTPROTO_LAYER = 117;
constexpr int32 MTPROTO_LAYER = 118;
enum class Version : int32 {
Initial, // 0

View File

@ -177,6 +177,7 @@ class messages_sendEncryptedService final {
class messages_sendEncrypted final {
public:
int32 flags_;
tl_object_ptr<inputEncryptedChat> peer_;
int64 random_id_{};
BufferSlice data_;
@ -185,7 +186,8 @@ class messages_sendEncrypted final {
static const int32 ID = -1451792525;
explicit messages_sendEncrypted(TlBufferParser &p)
: peer_(TlFetchBoxed<TlFetchObject<inputEncryptedChat>, -247351839>::parse(p))
: flags_(TlFetchInt::parse(p))
, peer_(TlFetchBoxed<TlFetchObject<inputEncryptedChat>, -247351839>::parse(p))
, random_id_(TlFetchLong::parse(p))
, data_(TlFetchBytes<BufferSlice>::parse(p)) {
}