Merge commit '4d47247fc135d63ec13b7521c74460bfda03e557'

This commit is contained in:
Andrea Cavalli 2020-10-01 11:46:07 +02:00
commit 503488a801
16 changed files with 433 additions and 292 deletions

View File

@ -617,6 +617,9 @@ secretChat id:int32 user_id:int32 state:SecretChatState is_outbound:Bool ttl:int
//@description The message was originally written by a known user @sender_user_id Identifier of the user that originally sent the message //@description The message was originally written by a known user @sender_user_id Identifier of the user that originally sent the message
messageForwardOriginUser sender_user_id:int32 = MessageForwardOrigin; messageForwardOriginUser sender_user_id:int32 = MessageForwardOrigin;
//@description The message was originally written by an anonimous chat administrator on behalf of the chat @sender_chat_id Identifier of the chat that originally sent the message
messageForwardOriginChat sender_chat_id:int53 = MessageForwardOrigin;
//@description The message was originally written by a user, which is hidden by their privacy settings @sender_name Name of the sender //@description The message was originally written by a user, which is hidden by their privacy settings @sender_name Name of the sender
messageForwardOriginHiddenUser sender_name:string = MessageForwardOrigin; messageForwardOriginHiddenUser sender_name:string = MessageForwardOrigin;
@ -655,7 +658,8 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
//@description Describes a message //@description Describes a message
//@id Message identifier, unique for the chat to which the message belongs //@id Message identifier, unique for the chat to which the message belongs
//@sender_user_id Identifier of the user who sent the message; 0 if unknown. Currently, it is unknown for channel posts and for channel posts automatically forwarded to discussion group //@sender_user_id Identifier of the user who sent the message; 0 if unknown. Currently, it is unknown for channel posts, for channel posts automatically forwarded to discussion group and for anonimously sent supergroup messages
//@sender_chat_id Identifier of the chat on behalf of which the message was sent; 0 if none
//@chat_id Chat identifier //@chat_id Chat identifier
//@sending_state Information about the sending state of the message; may be null //@sending_state Information about the sending state of the message; may be null
//@scheduling_state Information about the scheduling state of the message; may be null //@scheduling_state Information about the scheduling state of the message; may be null
@ -681,7 +685,7 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
//@restriction_reason If non-empty, contains a human-readable description of the reason why access to this message must be restricted //@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 //@content Content of the message
//@reply_markup Reply markup for the message; may be null //@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 can_get_statistics:Bool can_get_replies: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; message id:int53 sender_user_id:int32 sender_chat_id:int53 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 can_get_statistics:Bool can_get_replies: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 //@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; messages total_count:int32 messages:vector<message> = Messages;
@ -1842,7 +1846,7 @@ searchMessagesFilterVoiceAndVideoNote = SearchMessagesFilter;
//@description Returns only messages with mentions of the current user, or messages that are replies to their messages //@description Returns only messages with mentions of the current user, or messages that are replies to their messages
searchMessagesFilterMention = SearchMessagesFilter; searchMessagesFilterMention = SearchMessagesFilter;
//@description Returns only messages with unread mentions of the current user, or messages that are replies to their messages. When using this filter the results can't be additionally filtered by a query or by the sending user //@description Returns only messages with unread mentions of the current user, or messages that are replies to their messages. When using this filter the results can't be additionally filtered by a query, a message thread or by the sending user
searchMessagesFilterUnreadMention = SearchMessagesFilter; searchMessagesFilterUnreadMention = SearchMessagesFilter;
//@description Returns only failed to send messages. This filter can be used only if the message database is used //@description Returns only failed to send messages. This filter can be used only if the message database is used
@ -2535,10 +2539,11 @@ notificationTypeNewCall call_id:int32 = NotificationType;
//@description New message was received through a push notification //@description New message was received through a push notification
//@message_id The message identifier. The message will not be available in the chat history, but the ID can be used in viewMessages and as reply_to_message_id //@message_id The message identifier. The message will not be available in the chat history, but the ID can be used in viewMessages and as reply_to_message_id
//@sender_user_id Sender of the message; 0 if unknown. Corresponding user may be inaccessible //@sender_user_id Sender of the message; 0 if unknown. Corresponding user may be inaccessible
//@sender_chat_id Sender chat of the message; 0 if none
//@sender_name Name of the sender; can be different from the name of the sender user //@sender_name Name of the sender; can be different from the name of the sender user
//@is_outgoing True, if the message is outgoing //@is_outgoing True, if the message is outgoing
//@content Push message content //@content Push message content
notificationTypeNewPushMessage message_id:int53 sender_user_id:int32 sender_name:string is_outgoing:Bool content:PushMessageContent = NotificationType; notificationTypeNewPushMessage message_id:int53 sender_user_id:int32 sender_chat_id:int53 sender_name:string is_outgoing:Bool content:PushMessageContent = NotificationType;
//@class NotificationGroupType @description Describes the type of notifications in a notification group //@class NotificationGroupType @description Describes the type of notifications in a notification group
@ -3610,7 +3615,8 @@ deleteChatHistory chat_id:int53 remove_from_chat_list:Bool revoke:Bool = Ok;
//@offset Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages //@offset Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages
//@limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached //@limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
//@filter Filter for message content in the search results //@filter Filter for message content in the search results
searchChatMessages chat_id:int53 query:string sender_user_id:int32 from_message_id:int53 offset:int32 limit:int32 filter:SearchMessagesFilter = Messages; //@message_thread_id If not 0, only messages in the specified thread will be returned; supergroups only
searchChatMessages chat_id:int53 query:string sender_user_id:int32 from_message_id:int53 offset:int32 limit:int32 filter:SearchMessagesFilter message_thread_id:int53 = Messages;
//@description Searches for messages in all chats except secret chats. Returns the results in reverse chronological order (i.e., in order of decreasing (date, chat_id, message_id)). //@description Searches for messages in all chats except secret chats. Returns the results in reverse chronological order (i.e., in order of decreasing (date, chat_id, message_id)).
//-For optimal performance the number of returned messages is chosen by the library //-For optimal performance the number of returned messages is chosen by the library
@ -3621,7 +3627,9 @@ searchChatMessages chat_id:int53 query:string sender_user_id:int32 from_message_
//@offset_message_id The message identifier of the last found message, or 0 for the first request //@offset_message_id The message identifier of the last found message, or 0 for the first request
//@limit The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached //@limit The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
//@filter Filter for message content in the search results; searchMessagesFilterCall, searchMessagesFilterMissedCall, searchMessagesFilterMention, searchMessagesFilterUnreadMention and searchMessagesFilterFailedToSend are unsupported in this function //@filter Filter for message content in the search results; searchMessagesFilterCall, searchMessagesFilterMissedCall, searchMessagesFilterMention, searchMessagesFilterUnreadMention and searchMessagesFilterFailedToSend are unsupported in this function
searchMessages chat_list:ChatList query:string offset_date:int32 offset_chat_id:int53 offset_message_id:int53 limit:int32 filter:SearchMessagesFilter = Messages; //@min_date If not 0, the minimum date of the messages to return
//@max_date If not 0, the maximum date of the messages to return
searchMessages chat_list:ChatList query:string offset_date:int32 offset_chat_id:int53 offset_message_id:int53 limit:int32 filter:SearchMessagesFilter min_date:int32 max_date:int32 = Messages;
//@description Searches for messages in secret chats. Returns the results in reverse chronological order. For optimal performance the number of returned messages is chosen by the library //@description Searches for messages in secret chats. Returns the results in reverse chronological order. For optimal performance the number of returned messages is chosen by the library
//@chat_id Identifier of the chat in which to search. Specify 0 to search in all secret chats //@chat_id Identifier of the chat in which to search. Specify 0 to search in all secret chats

Binary file not shown.

View File

@ -128,8 +128,8 @@ chatPhotoEmpty#37c1011c = ChatPhoto;
chatPhoto#d20b9f3c flags:# has_video:flags.0?true photo_small:FileLocation photo_big:FileLocation dc_id:int = ChatPhoto; chatPhoto#d20b9f3c flags:# has_video:flags.0?true photo_small:FileLocation photo_big:FileLocation dc_id:int = ChatPhoto;
messageEmpty#83e5de54 id:int = Message; messageEmpty#83e5de54 id:int = Message;
message#8a7e027d 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 reply_to_top_id:flags.24?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 replies:flags.23?MessageReplies edit_date:flags.15?int post_author:flags.16?string grouped_id:flags.17?long restriction_reason:flags.22?Vector<RestrictionReason> = Message; message#58ae39c9 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?Peer peer_id:Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int reply_to:flags.3?MessageReplyHeader 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 replies:flags.23?MessageReplies 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; messageService#286fa604 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?Peer peer_id:Peer reply_to:flags.3?MessageReplyHeader date:int action:MessageAction = Message;
messageMediaEmpty#3ded6320 = MessageMedia; messageMediaEmpty#3ded6320 = MessageMedia;
messageMediaPhoto#695150d7 flags:# photo:flags.0?Photo ttl_seconds:flags.2?int = MessageMedia; messageMediaPhoto#695150d7 flags:# photo:flags.0?Photo ttl_seconds:flags.2?int = MessageMedia;
@ -357,8 +357,8 @@ updates.differenceSlice#a8fb1981 new_messages:Vector<Message> new_encrypted_mess
updates.differenceTooLong#4afe8f6d pts:int = updates.Difference; updates.differenceTooLong#4afe8f6d pts:int = updates.Difference;
updatesTooLong#e317af7e = Updates; updatesTooLong#e317af7e = Updates;
updateShortMessage#914fbf11 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true id:int user_id:int message:string pts:int pts_count:int date:int fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int reply_to_msg_id:flags.3?int entities:flags.7?Vector<MessageEntity> = Updates; updateShortMessage#2296d2c8 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true id:int user_id:int message:string pts:int pts_count:int date:int fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int reply_to:flags.3?MessageReplyHeader entities:flags.7?Vector<MessageEntity> = Updates;
updateShortChatMessage#16812688 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true id:int from_id:int chat_id:int message:string pts:int pts_count:int date:int fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int reply_to_msg_id:flags.3?int entities:flags.7?Vector<MessageEntity> = Updates; updateShortChatMessage#402d5dbb flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true id:int from_id:int chat_id:int message:string pts:int pts_count:int date:int fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int reply_to:flags.3?MessageReplyHeader entities:flags.7?Vector<MessageEntity> = Updates;
updateShort#78d4dec1 update:Update date:int = Updates; updateShort#78d4dec1 update:Update date:int = Updates;
updatesCombined#725b04c3 updates:Vector<Update> users:Vector<User> chats:Vector<Chat> date:int seq_start:int seq:int = Updates; updatesCombined#725b04c3 updates:Vector<Update> users:Vector<User> chats:Vector<Chat> date:int seq_start:int seq:int = Updates;
updates#74ae4240 updates:Vector<Update> users:Vector<User> chats:Vector<Chat> date:int seq:int = Updates; updates#74ae4240 updates:Vector<Update> users:Vector<User> chats:Vector<Chat> date:int seq:int = Updates;
@ -591,7 +591,7 @@ channelMessagesFilter#cd77d957 flags:# exclude_new_messages:flags.1?true ranges:
channelParticipant#15ebac1d user_id:int date:int = ChannelParticipant; channelParticipant#15ebac1d user_id:int date:int = ChannelParticipant;
channelParticipantSelf#a3289a6d user_id:int inviter_id:int date:int = ChannelParticipant; channelParticipantSelf#a3289a6d user_id:int inviter_id:int date:int = ChannelParticipant;
channelParticipantCreator#808d15a4 flags:# user_id:int rank:flags.0?string = ChannelParticipant; channelParticipantCreator#447dca4b flags:# user_id:int admin_rights:ChatAdminRights rank:flags.0?string = ChannelParticipant;
channelParticipantAdmin#ccbebbaf flags:# can_edit:flags.0?true self:flags.1?true user_id:int inviter_id:flags.1?int promoted_by:int date:int admin_rights:ChatAdminRights rank:flags.2?string = ChannelParticipant; channelParticipantAdmin#ccbebbaf flags:# can_edit:flags.0?true self:flags.1?true user_id:int inviter_id:flags.1?int promoted_by:int date:int admin_rights:ChatAdminRights rank:flags.2?string = ChannelParticipant;
channelParticipantBanned#1c0facaf flags:# left:flags.0?true user_id:int kicked_by:int date:int banned_rights:ChatBannedRights = ChannelParticipant; channelParticipantBanned#1c0facaf flags:# left:flags.0?true user_id:int kicked_by:int date:int banned_rights:ChatBannedRights = ChannelParticipant;
@ -638,7 +638,7 @@ messages.botResults#947ca848 flags:# gallery:flags.0?true query_id:long next_off
exportedMessageLink#5dab1af4 link:string html:string = ExportedMessageLink; exportedMessageLink#5dab1af4 link:string html:string = ExportedMessageLink;
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; messageFwdHeader#5f777dce flags:# from_id:flags.0?Peer from_name:flags.5?string date: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.codeTypeSms#72a3158c = auth.CodeType;
auth.codeTypeCall#741cd3e3 = auth.CodeType; auth.codeTypeCall#741cd3e3 = auth.CodeType;
@ -1019,7 +1019,7 @@ chatOnlines#f041e250 onlines:int = ChatOnlines;
statsURL#47a971e0 url:string = StatsURL; statsURL#47a971e0 url:string = StatsURL;
chatAdminRights#5fb224d5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true pin_messages:flags.7?true add_admins:flags.9?true = ChatAdminRights; chatAdminRights#5fb224d5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true pin_messages:flags.7?true add_admins:flags.9?true anonymous:flags.10?true = ChatAdminRights;
chatBannedRights#9f120418 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true send_polls:flags.8?true change_info:flags.10?true invite_users:flags.15?true pin_messages:flags.17?true until_date:int = ChatBannedRights; chatBannedRights#9f120418 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true send_polls:flags.8?true change_info:flags.10?true invite_users:flags.15?true pin_messages:flags.17?true until_date:int = ChatBannedRights;
@ -1147,8 +1147,6 @@ help.country#c3878e23 flags:# hidden:flags.0?true iso2:string default_name:strin
help.countriesListNotModified#93cc1f32 = help.CountriesList; help.countriesListNotModified#93cc1f32 = help.CountriesList;
help.countriesList#87d0759e countries:Vector<help.Country> hash:int = help.CountriesList; help.countriesList#87d0759e countries:Vector<help.Country> hash:int = help.CountriesList;
messageReplies#82e3c815 flags:# comments:flags.0?true replies:int replies_pts:int recent_repliers:flags.1?Vector<int> channel_id:flags.0?int = MessageReplies;
messageViews#455b853d flags:# views:flags.0?int forwards:flags.1?int replies:flags.2?MessageReplies = MessageViews; messageViews#455b853d flags:# views:flags.0?int forwards:flags.1?int replies:flags.2?MessageReplies = MessageViews;
messages.messageViews#2c3f2ae2 views:Vector<MessageViews> users:Vector<User> = messages.MessageViews; messages.messageViews#2c3f2ae2 views:Vector<MessageViews> users:Vector<User> = messages.MessageViews;
@ -1157,6 +1155,10 @@ stats.messageStats#8999f295 views_graph:StatsGraph = stats.MessageStats;
messages.discussionMessage#d25fad90 message:Message read_max_id:int chats:Vector<Chat> users:Vector<User> = messages.DiscussionMessage; messages.discussionMessage#d25fad90 message:Message read_max_id:int chats:Vector<Chat> users:Vector<User> = messages.DiscussionMessage;
messageReplyHeader#a6d57763 flags:# reply_to_msg_id:int reply_to_peer_id:flags.0?Peer reply_to_top_id:flags.1?int = MessageReplyHeader;
messageReplies#4128faac flags:# comments:flags.0?true replies:int replies_pts:int recent_repliers:flags.1?Vector<Peer> channel_id:flags.0?int max_id:flags.2?int read_max_id:flags.3?int = MessageReplies;
---functions--- ---functions---
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@ -1289,7 +1291,7 @@ messages.receivedMessages#5a954c0 max_id:int = Vector<ReceivedNotifyMessage>;
messages.setTyping#a3825e50 peer:InputPeer action:SendMessageAction = Bool; messages.setTyping#a3825e50 peer:InputPeer action:SendMessageAction = Bool;
messages.sendMessage#520c3870 flags:# no_webpage:flags.1?true silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.10?int = Updates; messages.sendMessage#520c3870 flags:# no_webpage:flags.1?true silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.10?int = Updates;
messages.sendMedia#3491eba9 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.10?int = Updates; messages.sendMedia#3491eba9 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.10?int = Updates;
messages.forwardMessages#d9fee60e flags:# silent:flags.5?true background:flags.6?true with_my_score:flags.8?true grouped:flags.9?true from_peer:InputPeer id:Vector<int> random_id:Vector<long> to_peer:InputPeer schedule_date:flags.10?int = Updates; messages.forwardMessages#d9fee60e flags:# silent:flags.5?true background:flags.6?true with_my_score:flags.8?true from_peer:InputPeer id:Vector<int> random_id:Vector<long> to_peer:InputPeer schedule_date:flags.10?int = Updates;
messages.reportSpam#cf1592db peer:InputPeer = Bool; messages.reportSpam#cf1592db peer:InputPeer = Bool;
messages.getPeerSettings#3672e09c peer:InputPeer = PeerSettings; messages.getPeerSettings#3672e09c peer:InputPeer = PeerSettings;
messages.report#bd82b658 peer:InputPeer id:Vector<int> reason:ReportReason = Bool; messages.report#bd82b658 peer:InputPeer id:Vector<int> reason:ReportReason = Bool;

Binary file not shown.

View File

@ -158,7 +158,7 @@ tl_object_ptr<telegram_api::chatAdminRights> DialogParticipantStatus::get_chat_a
LOG(INFO) << "Create chat admin rights " << flags; LOG(INFO) << "Create chat admin rights " << flags;
return make_tl_object<telegram_api::chatAdminRights>(flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, return make_tl_object<telegram_api::chatAdminRights>(flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/); false /*ignored*/, false /*ignored*/, false /*ignored*/);
} }
tl_object_ptr<telegram_api::chatBannedRights> DialogParticipantStatus::get_chat_banned_rights() const { tl_object_ptr<telegram_api::chatBannedRights> DialogParticipantStatus::get_chat_banned_rights() const {

View File

@ -22,12 +22,12 @@ MessageReplyInfo::MessageReplyInfo(tl_object_ptr<telegram_api::messageReplies> &
pts = reply_info->replies_pts_; pts = reply_info->replies_pts_;
if (!is_bot) { if (!is_bot) {
for (auto &user_id_int : reply_info->recent_repliers_) { for (auto &peer : reply_info->recent_repliers_) {
UserId user_id(user_id_int); DialogId dialog_id(peer);
if (user_id.is_valid()) { if (dialog_id.is_valid()) {
recent_replier_user_ids.push_back(user_id); recent_replier_dialog_ids.push_back(dialog_id);
} else { } else {
LOG(ERROR) << "Receive " << user_id << " as a recent replier"; LOG(ERROR) << "Receive " << dialog_id << " as a recent replier";
} }
} }
} }
@ -50,7 +50,7 @@ bool MessageReplyInfo::need_update_to(const MessageReplyInfo &other) const {
} }
StringBuilder &operator<<(StringBuilder &string_builder, const MessageReplyInfo &reply_info) { StringBuilder &operator<<(StringBuilder &string_builder, const MessageReplyInfo &reply_info) {
return string_builder << reply_info.reply_count << " replies by " << reply_info.recent_replier_user_ids; return string_builder << reply_info.reply_count << " replies by " << reply_info.recent_replier_dialog_ids;
} }
} // namespace td } // namespace td

View File

@ -7,8 +7,8 @@
#pragma once #pragma once
#include "td/telegram/ChannelId.h" #include "td/telegram/ChannelId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/StringBuilder.h" #include "td/utils/StringBuilder.h"
@ -19,7 +19,7 @@ namespace td {
struct MessageReplyInfo { struct MessageReplyInfo {
int32 reply_count = -1; int32 reply_count = -1;
int32 pts = -1; int32 pts = -1;
vector<UserId> recent_replier_user_ids; vector<DialogId> recent_replier_dialog_ids;
ChannelId channel_id; ChannelId channel_id;
bool is_comment = false; bool is_comment = false;
@ -36,17 +36,17 @@ struct MessageReplyInfo {
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const { void store(StorerT &storer) const {
CHECK(!is_empty()); CHECK(!is_empty());
bool has_recent_replier_user_ids = !recent_replier_user_ids.empty(); bool has_recent_replier_dialog_ids = !recent_replier_dialog_ids.empty();
bool has_channel_id = channel_id.is_valid(); bool has_channel_id = channel_id.is_valid();
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(is_comment); STORE_FLAG(is_comment);
STORE_FLAG(has_recent_replier_user_ids); STORE_FLAG(has_recent_replier_dialog_ids);
STORE_FLAG(has_channel_id); STORE_FLAG(has_channel_id);
END_STORE_FLAGS(); END_STORE_FLAGS();
td::store(reply_count, storer); td::store(reply_count, storer);
td::store(pts, storer); td::store(pts, storer);
if (has_recent_replier_user_ids) { if (has_recent_replier_dialog_ids) {
td::store(recent_replier_user_ids, storer); td::store(recent_replier_dialog_ids, storer);
} }
if (has_channel_id) { if (has_channel_id) {
td::store(channel_id, storer); td::store(channel_id, storer);
@ -55,18 +55,17 @@ struct MessageReplyInfo {
template <class ParserT> template <class ParserT>
void parse(ParserT &parser) { void parse(ParserT &parser) {
CHECK(!is_empty()); bool has_recent_replier_dialog_ids = !recent_replier_dialog_ids.empty();
bool has_recent_replier_user_ids = !recent_replier_user_ids.empty();
bool has_channel_id = channel_id.is_valid(); bool has_channel_id = channel_id.is_valid();
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_comment); PARSE_FLAG(is_comment);
PARSE_FLAG(has_recent_replier_user_ids); PARSE_FLAG(has_recent_replier_dialog_ids);
PARSE_FLAG(has_channel_id); PARSE_FLAG(has_channel_id);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
td::parse(reply_count, parser); td::parse(reply_count, parser);
td::parse(pts, parser); td::parse(pts, parser);
if (has_recent_replier_user_ids) { if (has_recent_replier_dialog_ids) {
td::parse(recent_replier_user_ids, parser); td::parse(recent_replier_dialog_ids, parser);
} }
if (has_channel_id) { if (has_channel_id) {
td::parse(channel_id, parser); td::parse(channel_id, parser);

View File

@ -1593,6 +1593,7 @@ class SearchMessagesQuery : public Td::ResultHandler {
int32 offset_; int32 offset_;
int32 limit_; int32 limit_;
MessageSearchFilter filter_; MessageSearchFilter filter_;
MessageId top_thread_message_id_;
int64 random_id_; int64 random_id_;
public: public:
@ -1601,7 +1602,7 @@ class SearchMessagesQuery : public Td::ResultHandler {
void send(DialogId dialog_id, const string &query, UserId sender_user_id, void send(DialogId dialog_id, const string &query, UserId sender_user_id,
telegram_api::object_ptr<telegram_api::InputUser> &&sender_input_user, MessageId from_message_id, telegram_api::object_ptr<telegram_api::InputUser> &&sender_input_user, MessageId from_message_id,
int32 offset, int32 limit, MessageSearchFilter filter, int64 random_id) { int32 offset, int32 limit, MessageSearchFilter filter, MessageId top_thread_message_id, int64 random_id) {
auto input_peer = dialog_id.is_valid() ? td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read) auto input_peer = dialog_id.is_valid() ? td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read)
: make_tl_object<telegram_api::inputPeerEmpty>(); : make_tl_object<telegram_api::inputPeerEmpty>();
if (input_peer == nullptr) { if (input_peer == nullptr) {
@ -1616,6 +1617,7 @@ class SearchMessagesQuery : public Td::ResultHandler {
offset_ = offset; offset_ = offset;
limit_ = limit; limit_ = limit;
filter_ = filter; filter_ = filter;
top_thread_message_id_ = top_thread_message_id;
random_id_ = random_id; random_id_ = random_id;
if (filter == MessageSearchFilter::UnreadMention) { if (filter == MessageSearchFilter::UnreadMention) {
@ -1627,9 +1629,13 @@ class SearchMessagesQuery : public Td::ResultHandler {
if (sender_input_user != nullptr) { if (sender_input_user != nullptr) {
flags |= telegram_api::messages_search::FROM_ID_MASK; flags |= telegram_api::messages_search::FROM_ID_MASK;
} }
if (top_thread_message_id.is_valid()) {
flags |= telegram_api::messages_search::TOP_MSG_ID_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::messages_search( send_query(G()->net_query_creator().create(telegram_api::messages_search(
flags, std::move(input_peer), query, std::move(sender_input_user), 0, get_input_messages_filter(filter), 0, flags, std::move(input_peer), query, std::move(sender_input_user),
top_thread_message_id.get_server_message_id().get(), get_input_messages_filter(filter), 0,
std::numeric_limits<int32>::max(), from_message_id.get_server_message_id().get(), offset, limit, std::numeric_limits<int32>::max(), from_message_id.get_server_message_id().get(), offset, limit,
std::numeric_limits<int32>::max(), 0, 0))); std::numeric_limits<int32>::max(), 0, 0)));
} }
@ -1646,8 +1652,8 @@ class SearchMessagesQuery : public Td::ResultHandler {
auto info = td->messages_manager_->on_get_messages(result_ptr.move_as_ok(), "SearchMessagesQuery"); auto info = td->messages_manager_->on_get_messages(result_ptr.move_as_ok(), "SearchMessagesQuery");
td->messages_manager_->on_get_dialog_messages_search_result(dialog_id_, query_, sender_user_id_, from_message_id_, td->messages_manager_->on_get_dialog_messages_search_result(dialog_id_, query_, sender_user_id_, from_message_id_,
offset_, limit_, filter_, random_id_, info.total_count, offset_, limit_, filter_, top_thread_message_id_,
std::move(info.messages)); random_id_, info.total_count, std::move(info.messages));
promise_.set_value(Unit()); promise_.set_value(Unit());
} }
@ -1667,6 +1673,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
MessageId offset_message_id_; MessageId offset_message_id_;
int32 limit_; int32 limit_;
MessageSearchFilter filter_; MessageSearchFilter filter_;
int32 min_date_;
int32 max_date_;
int64 random_id_; int64 random_id_;
public: public:
@ -1675,7 +1683,7 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
void send(FolderId folder_id, bool ignore_folder_id, const string &query, int32 offset_date, void send(FolderId folder_id, bool ignore_folder_id, const string &query, int32 offset_date,
DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, MessageSearchFilter filter, DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, MessageSearchFilter filter,
int64 random_id) { int32 min_date, int32 max_date, int64 random_id) {
query_ = query; query_ = query;
offset_date_ = offset_date; offset_date_ = offset_date;
offset_dialog_id_ = offset_dialog_id; offset_dialog_id_ = offset_dialog_id;
@ -1683,6 +1691,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
limit_ = limit; limit_ = limit;
random_id_ = random_id; random_id_ = random_id;
filter_ = filter; filter_ = filter;
min_date_ = min_date;
max_date_ = max_date;
auto input_peer = MessagesManager::get_input_peer_force(offset_dialog_id); auto input_peer = MessagesManager::get_input_peer_force(offset_dialog_id);
CHECK(input_peer != nullptr); CHECK(input_peer != nullptr);
@ -1692,8 +1702,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
flags |= telegram_api::messages_searchGlobal::FOLDER_ID_MASK; flags |= telegram_api::messages_searchGlobal::FOLDER_ID_MASK;
} }
send_query(G()->net_query_creator().create(telegram_api::messages_searchGlobal( send_query(G()->net_query_creator().create(telegram_api::messages_searchGlobal(
flags, folder_id.get(), query, get_input_messages_filter(filter), 0, 0, offset_date_, std::move(input_peer), flags, folder_id.get(), query, get_input_messages_filter(filter), min_date_, max_date_, offset_date_,
offset_message_id.get_server_message_id().get(), limit))); std::move(input_peer), offset_message_id.get_server_message_id().get(), limit)));
} }
void on_result(uint64 id, BufferSlice packet) override { void on_result(uint64 id, BufferSlice packet) override {
@ -1704,8 +1714,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
auto info = td->messages_manager_->on_get_messages(result_ptr.move_as_ok(), "SearchMessagesGlobalQuery"); auto info = td->messages_manager_->on_get_messages(result_ptr.move_as_ok(), "SearchMessagesGlobalQuery");
td->messages_manager_->on_get_messages_search_result(query_, offset_date_, offset_dialog_id_, offset_message_id_, td->messages_manager_->on_get_messages_search_result(query_, offset_date_, offset_dialog_id_, offset_message_id_,
limit_, filter_, random_id_, info.total_count, limit_, filter_, min_date_, max_date_, random_id_,
std::move(info.messages)); info.total_count, std::move(info.messages));
promise_.set_value(Unit()); promise_.set_value(Unit());
} }
@ -4198,6 +4208,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
bool has_forward_psa_type = is_forwarded && !forward_info->psa_type.empty(); bool has_forward_psa_type = is_forwarded && !forward_info->psa_type.empty();
bool has_forward_count = forward_count > 0; bool has_forward_count = forward_count > 0;
bool has_reply_info = !reply_info.is_empty(); bool has_reply_info = !reply_info.is_empty();
bool has_sender_dialog_id = sender_dialog_id.is_valid();
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(is_channel_post); STORE_FLAG(is_channel_post);
STORE_FLAG(is_outgoing); STORE_FLAG(is_outgoing);
@ -4248,6 +4259,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
STORE_FLAG(has_forward_psa_type); STORE_FLAG(has_forward_psa_type);
STORE_FLAG(has_forward_count); STORE_FLAG(has_forward_count);
STORE_FLAG(has_reply_info); STORE_FLAG(has_reply_info);
STORE_FLAG(has_sender_dialog_id);
END_STORE_FLAGS(); END_STORE_FLAGS();
} }
@ -4268,7 +4280,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
if (is_forwarded) { if (is_forwarded) {
store(forward_info->sender_user_id, storer); store(forward_info->sender_user_id, storer);
store(forward_info->date, storer); store(forward_info->date, storer);
store(forward_info->dialog_id, storer); store(forward_info->sender_dialog_id, storer);
store(forward_info->message_id, storer); store(forward_info->message_id, storer);
if (has_forward_author_signature) { if (has_forward_author_signature) {
store(forward_info->author_signature, storer); store(forward_info->author_signature, storer);
@ -4332,6 +4344,9 @@ void MessagesManager::Message::store(StorerT &storer) const {
if (has_restriction_reasons) { if (has_restriction_reasons) {
store(restriction_reasons, storer); store(restriction_reasons, storer);
} }
if (has_sender_dialog_id) {
store(sender_dialog_id, storer);
}
store_message_content(content.get(), storer); store_message_content(content.get(), storer);
if (has_reply_markup) { if (has_reply_markup) {
store(reply_markup, storer); store(reply_markup, storer);
@ -4367,6 +4382,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
bool has_forward_psa_type = false; bool has_forward_psa_type = false;
bool has_forward_count = false; bool has_forward_count = false;
bool has_reply_info = false; bool has_reply_info = false;
bool has_sender_dialog_id = false;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_channel_post); PARSE_FLAG(is_channel_post);
PARSE_FLAG(is_outgoing); PARSE_FLAG(is_outgoing);
@ -4417,6 +4433,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
PARSE_FLAG(has_forward_psa_type); PARSE_FLAG(has_forward_psa_type);
PARSE_FLAG(has_forward_count); PARSE_FLAG(has_forward_count);
PARSE_FLAG(has_reply_info); PARSE_FLAG(has_reply_info);
PARSE_FLAG(has_sender_dialog_id);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
} }
@ -4443,7 +4460,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
forward_info = make_unique<MessageForwardInfo>(); forward_info = make_unique<MessageForwardInfo>();
parse(forward_info->sender_user_id, parser); parse(forward_info->sender_user_id, parser);
parse(forward_info->date, parser); parse(forward_info->date, parser);
parse(forward_info->dialog_id, parser); parse(forward_info->sender_dialog_id, parser);
parse(forward_info->message_id, parser); parse(forward_info->message_id, parser);
if (has_forward_author_signature) { if (has_forward_author_signature) {
parse(forward_info->author_signature, parser); parse(forward_info->author_signature, parser);
@ -4507,6 +4524,9 @@ void MessagesManager::Message::parse(ParserT &parser) {
if (has_restriction_reasons) { if (has_restriction_reasons) {
parse(restriction_reasons, parser); parse(restriction_reasons, parser);
} }
if (has_sender_dialog_id) {
parse(sender_dialog_id, parser);
}
parse_message_content(content, parser); parse_message_content(content, parser);
if (has_reply_markup) { if (has_reply_markup) {
parse(reply_markup, parser); parse(reply_markup, parser);
@ -6128,10 +6148,15 @@ td_api::object_ptr<td_api::messageInteractionInfo> MessagesManager::get_message_
return nullptr; return nullptr;
} }
vector<UserId> recent_replier_user_ids;
for (auto recent_replier_dialog_id : m->reply_info.recent_replier_dialog_ids) {
if (dialog_id.get_type() == DialogType::User) {
recent_replier_user_ids.push_back(recent_replier_dialog_id.get_user_id());
}
}
return td_api::make_object<td_api::messageInteractionInfo>( return td_api::make_object<td_api::messageInteractionInfo>(
m->view_count, m->forward_count, m->reply_info.reply_count, m->view_count, m->forward_count, m->reply_info.reply_count,
td_->contacts_manager_->get_user_ids_object(m->reply_info.recent_replier_user_ids, td_->contacts_manager_->get_user_ids_object(recent_replier_user_ids, "get_message_interaction_info_object"));
"get_message_interaction_info_object"));
} }
bool MessagesManager::update_message_interaction_info(DialogId dialog_id, Message *m, int32 view_count, bool MessagesManager::update_message_interaction_info(DialogId dialog_id, Message *m, int32 view_count,
@ -8653,12 +8678,14 @@ void MessagesManager::on_failed_public_dialogs_search(const string &query, Statu
void MessagesManager::on_get_dialog_messages_search_result(DialogId dialog_id, const string &query, void MessagesManager::on_get_dialog_messages_search_result(DialogId dialog_id, const string &query,
UserId sender_user_id, MessageId from_message_id, UserId sender_user_id, MessageId from_message_id,
int32 offset, int32 limit, MessageSearchFilter filter, int32 offset, int32 limit, MessageSearchFilter filter,
int64 random_id, int32 total_count, MessageId top_thread_message_id, int64 random_id,
int32 total_count,
vector<tl_object_ptr<telegram_api::Message>> &&messages) { vector<tl_object_ptr<telegram_api::Message>> &&messages) {
LOG(INFO) << "Receive " << messages.size() << " found messages in " << dialog_id; LOG(INFO) << "Receive " << messages.size() << " found messages in " << dialog_id;
if (!dialog_id.is_valid()) { if (!dialog_id.is_valid()) {
CHECK(query.empty()); CHECK(query.empty());
CHECK(!sender_user_id.is_valid()); CHECK(!sender_user_id.is_valid());
CHECK(!top_thread_message_id.is_valid());
auto it = found_call_messages_.find(random_id); auto it = found_call_messages_.find(random_id);
CHECK(it != found_call_messages_.end()); CHECK(it != found_call_messages_.end());
@ -8764,7 +8791,7 @@ void MessagesManager::on_get_dialog_messages_search_result(DialogId dialog_id, c
total_count = static_cast<int32>(result.size()); total_count = static_cast<int32>(result.size());
} }
if (query.empty() && !sender_user_id.is_valid() && filter != MessageSearchFilter::Empty && if (query.empty() && !sender_user_id.is_valid() && filter != MessageSearchFilter::Empty &&
G()->parameters().use_message_db) { !top_thread_message_id.is_valid() && G()->parameters().use_message_db) {
bool update_dialog = false; bool update_dialog = false;
auto &old_message_count = d->message_count_by_index[message_search_filter_index(filter)]; auto &old_message_count = d->message_count_by_index[message_search_filter_index(filter)];
@ -8809,7 +8836,8 @@ void MessagesManager::on_failed_dialog_messages_search(DialogId dialog_id, int64
void MessagesManager::on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id, void MessagesManager::on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id,
MessageId offset_message_id, int32 limit, MessageId offset_message_id, int32 limit,
MessageSearchFilter filter, int64 random_id, int32 total_count, MessageSearchFilter filter, int32 min_date, int32 max_date,
int64 random_id, int32 total_count,
vector<tl_object_ptr<telegram_api::Message>> &&messages) { vector<tl_object_ptr<telegram_api::Message>> &&messages) {
LOG(INFO) << "Receive " << messages.size() << " found messages"; LOG(INFO) << "Receive " << messages.size() << " found messages";
auto it = found_messages_.find(random_id); auto it = found_messages_.find(random_id);
@ -9096,7 +9124,7 @@ bool MessagesManager::can_get_message_statistics(DialogId dialog_id, const Messa
return false; return false;
} }
if (m == nullptr || m->message_id.is_scheduled() || !m->message_id.is_server() || m->view_count == 0 || if (m == nullptr || m->message_id.is_scheduled() || !m->message_id.is_server() || m->view_count == 0 ||
m->had_forward_info || (m->forward_info != nullptr && m->forward_info->dialog_id.is_valid())) { m->had_forward_info || (m->forward_info != nullptr && m->forward_info->message_id.is_valid())) {
return false; return false;
} }
return td_->contacts_manager_->can_get_channel_message_statistics(dialog_id); return td_->contacts_manager_->can_get_channel_message_statistics(dialog_id);
@ -10807,37 +10835,21 @@ MessageId MessagesManager::get_message_id(const tl_object_ptr<telegram_api::Mess
} }
DialogId MessagesManager::get_message_dialog_id(const tl_object_ptr<telegram_api::Message> &message_ptr) const { DialogId MessagesManager::get_message_dialog_id(const tl_object_ptr<telegram_api::Message> &message_ptr) const {
DialogId dialog_id;
UserId sender_user_id;
switch (message_ptr->get_id()) { switch (message_ptr->get_id()) {
case telegram_api::messageEmpty::ID: case telegram_api::messageEmpty::ID:
return DialogId(); return DialogId();
case telegram_api::message::ID: { case telegram_api::message::ID: {
auto message = static_cast<const telegram_api::message *>(message_ptr.get()); auto message = static_cast<const telegram_api::message *>(message_ptr.get());
dialog_id = DialogId(message->to_id_); return DialogId(message->peer_id_);
if (message->flags_ & MESSAGE_FLAG_HAS_FROM_ID) {
sender_user_id = UserId(message->from_id_);
}
break;
} }
case telegram_api::messageService::ID: { case telegram_api::messageService::ID: {
auto message = static_cast<const telegram_api::messageService *>(message_ptr.get()); auto message = static_cast<const telegram_api::messageService *>(message_ptr.get());
dialog_id = DialogId(message->to_id_); return DialogId(message->peer_id_);
if (message->flags_ & MESSAGE_FLAG_HAS_FROM_ID) {
sender_user_id = UserId(message->from_id_);
}
break;
} }
default: default:
UNREACHABLE(); UNREACHABLE();
break; return DialogId();
} }
if (dialog_id == get_my_dialog_id()) {
LOG_IF(ERROR, !sender_user_id.is_valid()) << "Receive invalid " << sender_user_id;
return DialogId(sender_user_id);
}
return dialog_id;
} }
FullMessageId MessagesManager::get_full_message_id(const tl_object_ptr<telegram_api::Message> &message_ptr, FullMessageId MessagesManager::get_full_message_id(const tl_object_ptr<telegram_api::Message> &message_ptr,
@ -11984,22 +11996,6 @@ void MessagesManager::finish_add_secret_message(unique_ptr<PendingSecretMessage>
pending_secret_message->success_promise.set_value(Unit()); // TODO: set after message is saved pending_secret_message->success_promise.set_value(Unit()); // TODO: set after message is saved
} }
void MessagesManager::fix_message_info_dialog_id(MessageInfo &message_info) const {
if (message_info.dialog_id != get_my_dialog_id()) {
return;
}
UserId sender_user_id = message_info.sender_user_id;
if (!sender_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid sender user id in private chat";
return;
}
message_info.dialog_id = DialogId(sender_user_id);
LOG_IF(ERROR, !message_info.message_id.is_scheduled() && (message_info.flags & MESSAGE_FLAG_IS_OUT) != 0)
<< "Receive message out flag for incoming " << message_info.message_id << " in " << message_info.dialog_id;
}
MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message( MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
tl_object_ptr<telegram_api::Message> message_ptr, bool is_scheduled, const char *source) const { tl_object_ptr<telegram_api::Message> message_ptr, bool is_scheduled, const char *source) const {
LOG(DEBUG) << "Receive from " << source << " " << to_string(message_ptr); LOG(DEBUG) << "Receive from " << source << " " << to_string(message_ptr);
@ -12014,14 +12010,13 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
case telegram_api::message::ID: { case telegram_api::message::ID: {
auto message = move_tl_object_as<telegram_api::message>(message_ptr); auto message = move_tl_object_as<telegram_api::message>(message_ptr);
message_info.dialog_id = DialogId(message->to_id_); message_info.dialog_id = DialogId(message->peer_id_);
if (message->flags_ & MESSAGE_FLAG_HAS_FROM_ID) { if (message->flags_ & MESSAGE_FLAG_HAS_FROM_ID) {
message_info.sender_user_id = UserId(message->from_id_); message_info.sender_dialog_id = DialogId(message->from_id_);
} }
message_info.date = message->date_; message_info.date = message->date_;
message_info.forward_header = std::move(message->fwd_from_); message_info.forward_header = std::move(message->fwd_from_);
message_info.reply_to_message_id = MessageId(ServerMessageId( message_info.reply_header = std::move(message->reply_to_);
message->flags_ & MESSAGE_FLAG_IS_REPLY ? message->reply_to_msg_id_ : 0)); // TODO zero init in fetch
if (message->flags_ & MESSAGE_FLAG_IS_SENT_VIA_BOT) { if (message->flags_ & MESSAGE_FLAG_IS_SENT_VIA_BOT) {
message_info.via_bot_user_id = UserId(message->via_bot_id_); message_info.via_bot_user_id = UserId(message->via_bot_id_);
if (!message_info.via_bot_user_id.is_valid()) { if (!message_info.via_bot_user_id.is_valid()) {
@ -12043,7 +12038,6 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
message_info.media_album_id = message->grouped_id_; message_info.media_album_id = message->grouped_id_;
} }
message_info.flags = message->flags_; message_info.flags = message->flags_;
fix_message_info_dialog_id(message_info);
bool is_content_read = (message->flags_ & MESSAGE_FLAG_HAS_UNREAD_CONTENT) == 0; bool is_content_read = (message->flags_ & MESSAGE_FLAG_HAS_UNREAD_CONTENT) == 0;
if (is_message_auto_read(message_info.dialog_id, (message->flags_ & MESSAGE_FLAG_IS_OUT) != 0)) { if (is_message_auto_read(message_info.dialog_id, (message->flags_ & MESSAGE_FLAG_IS_OUT) != 0)) {
is_content_read = true; is_content_read = true;
@ -12069,15 +12063,15 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
case telegram_api::messageService::ID: { case telegram_api::messageService::ID: {
auto message = move_tl_object_as<telegram_api::messageService>(message_ptr); auto message = move_tl_object_as<telegram_api::messageService>(message_ptr);
message_info.dialog_id = DialogId(message->to_id_); message_info.dialog_id = DialogId(message->peer_id_);
if (message->flags_ & MESSAGE_FLAG_HAS_FROM_ID) { if (message->flags_ & MESSAGE_FLAG_HAS_FROM_ID) {
message_info.sender_user_id = UserId(message->from_id_); message_info.sender_dialog_id = DialogId(message->from_id_);
} }
message_info.date = message->date_; message_info.date = message->date_;
message_info.flags = message->flags_; message_info.flags = message->flags_;
fix_message_info_dialog_id(message_info); message_info.reply_header = std::move(message->reply_to_);
MessageId reply_to_message_id = MessageId(ServerMessageId( auto reply_to_message_id = MessageId(
message->flags_ & MESSAGE_FLAG_IS_REPLY ? message->reply_to_msg_id_ : 0)); // TODO zero init in fetch ServerMessageId(message_info.reply_header == nullptr ? 0 : message_info.reply_header->reply_to_msg_id_));
message_info.content = message_info.content =
get_action_message_content(td_, std::move(message->action_), message_info.dialog_id, reply_to_message_id); get_action_message_content(td_, std::move(message->action_), message_info.dialog_id, reply_to_message_id);
break; break;
@ -12086,6 +12080,10 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
UNREACHABLE(); UNREACHABLE();
break; break;
} }
if (message_info.sender_dialog_id.is_valid() && message_info.sender_dialog_id.get_type() == DialogType::User) {
message_info.sender_user_id = message_info.sender_dialog_id.get_user_id();
message_info.sender_dialog_id = DialogId();
}
return message_info; return message_info;
} }
@ -12108,6 +12106,7 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
auto dialog_type = dialog_id.get_type(); auto dialog_type = dialog_id.get_type();
UserId sender_user_id = message_info.sender_user_id; UserId sender_user_id = message_info.sender_user_id;
DialogId sender_dialog_id = message_info.sender_dialog_id;
if (!sender_user_id.is_valid()) { if (!sender_user_id.is_valid()) {
if (!is_broadcast_channel(dialog_id) && td_->auth_manager_->is_bot()) { if (!is_broadcast_channel(dialog_id) && td_->auth_manager_->is_bot()) {
sender_user_id = td_->contacts_manager_->get_service_notifications_user_id(); sender_user_id = td_->contacts_manager_->get_service_notifications_user_id();
@ -12116,6 +12115,16 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
sender_user_id = UserId(); sender_user_id = UserId();
} }
} }
if (sender_dialog_id.is_valid()) {
CHECK(!sender_user_id.is_valid());
if (dialog_type == DialogType::User || dialog_type == DialogType::SecretChat) {
LOG(ERROR) << "Receive " << message_id << " sent by " << sender_dialog_id << " in " << dialog_id;
return {DialogId(), nullptr};
}
} else if (sender_dialog_id != DialogId()) {
LOG(ERROR) << "Receive invalid " << sender_dialog_id;
sender_dialog_id = DialogId();
}
if (message_id.is_scheduled()) { if (message_id.is_scheduled()) {
is_channel_message = (dialog_type == DialogType::Channel); is_channel_message = (dialog_type == DialogType::Channel);
} }
@ -12135,9 +12144,11 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
UserId my_id = td_->contacts_manager_->get_my_id(); UserId my_id = td_->contacts_manager_->get_my_id();
DialogId my_dialog_id = DialogId(my_id); DialogId my_dialog_id = DialogId(my_id);
if (dialog_id == my_dialog_id) { if (dialog_id == my_dialog_id && (sender_user_id != my_id || sender_dialog_id.is_valid())) {
// dialog_id should be already fixed LOG(ERROR) << "Receive " << sender_user_id << "/" << sender_dialog_id << " as a sender of " << message_id
CHECK(sender_user_id == my_id); << " instead of self";
sender_user_id = my_id;
sender_dialog_id = DialogId();
} }
bool supposed_to_be_outgoing = sender_user_id == my_id && !(dialog_id == my_dialog_id && !message_id.is_scheduled()); bool supposed_to_be_outgoing = sender_user_id == my_id && !(dialog_id == my_dialog_id && !message_id.is_scheduled());
@ -12158,14 +12169,31 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
} }
MessageId reply_to_message_id = message_info.reply_to_message_id; MessageId reply_to_message_id = message_info.reply_to_message_id;
CHECK(!reply_to_message_id.is_scheduled()); DialogId reply_in_dialog_id;
if (!message_id.is_scheduled() && reply_to_message_id != MessageId() && if (message_info.reply_header != nullptr) {
(!reply_to_message_id.is_valid() || reply_to_message_id >= message_id)) { reply_to_message_id = MessageId(ServerMessageId(message_info.reply_header->reply_to_msg_id_));
if (!reply_to_message_id.is_valid() || auto reply_to_peer_id = std::move(message_info.reply_header->reply_to_peer_id_);
reply_to_message_id.get() - message_id.get() <= MessageId(ServerMessageId(2000000000)).get()) { if (reply_to_peer_id != nullptr) {
LOG(ERROR) << "Receive reply to wrong " << reply_to_message_id << " in " << message_id; reply_in_dialog_id = DialogId(reply_to_peer_id);
if (!reply_in_dialog_id.is_valid()) {
LOG(ERROR) << " Receive reply in invalid " << to_string(reply_to_peer_id);
reply_to_message_id = MessageId();
}
}
}
CHECK(!reply_to_message_id.is_scheduled());
if (reply_to_message_id != MessageId()) {
if (!reply_to_message_id.is_valid()) {
LOG(ERROR) << "Receive reply to " << reply_to_message_id << " for " << message_id << " in " << dialog_id;
reply_to_message_id = MessageId();
} else {
if (!message_id.is_scheduled() && !reply_in_dialog_id.is_valid() && reply_to_message_id >= message_id) {
if (reply_to_message_id.get() - message_id.get() <= MessageId(ServerMessageId(2000000000)).get()) {
LOG(ERROR) << "Receive reply to wrong " << reply_to_message_id << " in " << message_id;
}
reply_to_message_id = MessageId();
}
} }
reply_to_message_id = MessageId();
} }
UserId via_bot_user_id = message_info.via_bot_user_id; UserId via_bot_user_id = message_info.via_bot_user_id;
@ -12216,11 +12244,12 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
bool has_forward_info = message_info.forward_header != nullptr; bool has_forward_info = message_info.forward_header != nullptr;
LOG(INFO) << "Receive " << message_id << " in " << dialog_id << " from " << sender_user_id; LOG(INFO) << "Receive " << message_id << " in " << dialog_id << " from " << sender_user_id << "/" << sender_dialog_id;
auto message = make_unique<Message>(); auto message = make_unique<Message>();
set_message_id(message, message_id); set_message_id(message, message_id);
message->sender_user_id = sender_user_id; message->sender_user_id = sender_user_id;
message->sender_dialog_id = sender_dialog_id;
message->date = date; message->date = date;
message->ttl = ttl; message->ttl = ttl;
message->edit_date = edit_date; message->edit_date = edit_date;
@ -12369,7 +12398,8 @@ FullMessageId MessagesManager::on_get_message(MessageInfo &&message_info, bool f
if (!new_message->is_outgoing && dialog_id != get_my_dialog_id()) { if (!new_message->is_outgoing && dialog_id != get_my_dialog_id()) {
// sent message is not from me // sent message is not from me
LOG(ERROR) << "Sent in " << dialog_id << " " << message_id << " is sent by " << new_message->sender_user_id; LOG(ERROR) << "Sent in " << dialog_id << " " << message_id << " is sent by " << new_message->sender_user_id << "/"
<< new_message->sender_dialog_id;
return FullMessageId(); return FullMessageId();
} }
@ -18479,7 +18509,8 @@ void MessagesManager::on_read_history_finished(DialogId dialog_id, uint64 genera
std::pair<int32, vector<MessageId>> MessagesManager::search_dialog_messages( std::pair<int32, vector<MessageId>> MessagesManager::search_dialog_messages(
DialogId dialog_id, const string &query, UserId sender_user_id, MessageId from_message_id, int32 offset, DialogId dialog_id, const string &query, UserId sender_user_id, MessageId from_message_id, int32 offset,
int32 limit, MessageSearchFilter filter, int64 &random_id, bool use_db, Promise<Unit> &&promise) { int32 limit, MessageSearchFilter filter, MessageId top_thread_message_id, int64 &random_id, bool use_db,
Promise<Unit> &&promise) {
if (random_id != 0) { if (random_id != 0) {
// request has already been sent before // request has already been sent before
auto it = found_dialog_messages_.find(random_id); auto it = found_dialog_messages_.find(random_id);
@ -18492,8 +18523,8 @@ std::pair<int32, vector<MessageId>> MessagesManager::search_dialog_messages(
random_id = 0; random_id = 0;
} }
LOG(INFO) << "Search messages with query \"" << query << "\" in " << dialog_id << " sent by " << sender_user_id LOG(INFO) << "Search messages with query \"" << query << "\" in " << dialog_id << " sent by " << sender_user_id
<< " filtered by " << filter << " from " << from_message_id << " with offset " << offset << " and limit " << " in thread of " << top_thread_message_id << " filtered by " << filter << " from " << from_message_id
<< limit; << " with offset " << offset << " and limit " << limit;
std::pair<int32, vector<MessageId>> result; std::pair<int32, vector<MessageId>> result;
if (limit <= 0) { if (limit <= 0) {
@ -18542,6 +18573,17 @@ std::pair<int32, vector<MessageId>> MessagesManager::search_dialog_messages(
return result; return result;
} }
if (top_thread_message_id != MessageId()) {
if (!top_thread_message_id.is_valid() || !top_thread_message_id.is_server()) {
promise.set_error(Status::Error(400, "Invalid message thread ID specified"));
return result;
}
if (dialog_id.get_type() != DialogType::Channel || is_broadcast_channel(dialog_id)) {
promise.set_error(Status::Error(400, "Can't filter by message thread ID in the chat"));
return result;
}
}
do { do {
random_id = Random::secure_int64(); random_id = Random::secure_int64();
} while (random_id == 0 || found_dialog_messages_.find(random_id) != found_dialog_messages_.end()); } while (random_id == 0 || found_dialog_messages_.find(random_id) != found_dialog_messages_.end());
@ -18553,14 +18595,18 @@ std::pair<int32, vector<MessageId>> MessagesManager::search_dialog_messages(
return result; return result;
} }
if (input_user != nullptr) { if (input_user != nullptr) {
promise.set_error(Status::Error(6, "Non-empty sender user is unsupported with the specified filter")); promise.set_error(Status::Error(6, "Filtering by sender user is unsupported with the specified filter"));
return result;
}
if (top_thread_message_id != MessageId()) {
promise.set_error(Status::Error(6, "Filtering by message thread is unsupported with the specified filter"));
return result; return result;
} }
} }
// Trying to use database // Trying to use database
if (use_db && query.empty() && G()->parameters().use_message_db && filter != MessageSearchFilter::Empty && if (use_db && query.empty() && G()->parameters().use_message_db && filter != MessageSearchFilter::Empty &&
input_user == nullptr) { // TODO support filter by users in the database input_user == nullptr && top_thread_message_id == MessageId()) { // TODO support filter by users in the database
MessageId first_db_message_id = get_first_database_message_id_by_index(d, filter); MessageId first_db_message_id = get_first_database_message_id_by_index(d, filter);
int32 message_count = d->message_count_by_index[message_search_filter_index(filter)]; int32 message_count = d->message_count_by_index[message_search_filter_index(filter)];
auto fixed_from_message_id = from_message_id; auto fixed_from_message_id = from_message_id;
@ -18596,7 +18642,8 @@ std::pair<int32, vector<MessageId>> MessagesManager::search_dialog_messages(
} }
LOG(DEBUG) << "Search messages on server in " << dialog_id << " with query \"" << query << "\" from user " LOG(DEBUG) << "Search messages on server in " << dialog_id << " with query \"" << query << "\" from user "
<< sender_user_id << " from " << from_message_id << " and with limit " << limit; << sender_user_id << " in thread of " << top_thread_message_id << " from " << from_message_id
<< " and with limit " << limit;
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::None: case DialogType::None:
@ -18605,7 +18652,7 @@ std::pair<int32, vector<MessageId>> MessagesManager::search_dialog_messages(
case DialogType::Channel: case DialogType::Channel:
td_->create_handler<SearchMessagesQuery>(std::move(promise)) td_->create_handler<SearchMessagesQuery>(std::move(promise))
->send(dialog_id, query, sender_user_id, std::move(input_user), from_message_id, offset, limit, filter, ->send(dialog_id, query, sender_user_id, std::move(input_user), from_message_id, offset, limit, filter,
random_id); top_thread_message_id, random_id);
break; break;
case DialogType::SecretChat: case DialogType::SecretChat:
if (filter == MessageSearchFilter::UnreadMention) { if (filter == MessageSearchFilter::UnreadMention) {
@ -18694,7 +18741,7 @@ std::pair<int32, vector<FullMessageId>> MessagesManager::search_call_messages(Me
LOG(DEBUG) << "Search call messages on server from " << from_message_id << " and with limit " << limit; LOG(DEBUG) << "Search call messages on server from " << from_message_id << " and with limit " << limit;
td_->create_handler<SearchMessagesQuery>(std::move(promise)) td_->create_handler<SearchMessagesQuery>(std::move(promise))
->send(DialogId(), "", UserId(), nullptr, from_message_id, 0, limit, filter, random_id); ->send(DialogId(), "", UserId(), nullptr, from_message_id, 0, limit, filter, MessageId(), random_id);
return result; return result;
} }
@ -19298,7 +19345,8 @@ void MessagesManager::on_messages_db_calls_result(Result<MessagesDbCallsResult>
std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages( std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages(
FolderId folder_id, bool ignore_folder_id, const string &query, int32 offset_date, DialogId offset_dialog_id, FolderId folder_id, bool ignore_folder_id, const string &query, int32 offset_date, DialogId offset_dialog_id,
MessageId offset_message_id, int32 limit, MessageSearchFilter filter, int64 &random_id, Promise<Unit> &&promise) { MessageId offset_message_id, int32 limit, MessageSearchFilter filter, int32 min_date, int32 max_date,
int64 &random_id, Promise<Unit> &&promise) {
if (random_id != 0) { if (random_id != 0) {
// request has already been sent before // request has already been sent before
auto it = found_messages_.find(random_id); auto it = found_messages_.find(random_id);
@ -19355,7 +19403,7 @@ std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages(
td_->create_handler<SearchMessagesGlobalQuery>(std::move(promise)) td_->create_handler<SearchMessagesGlobalQuery>(std::move(promise))
->send(folder_id, ignore_folder_id, query, offset_date, offset_dialog_id, offset_message_id, limit, filter, ->send(folder_id, ignore_folder_id, query, offset_date, offset_dialog_id, offset_message_id, limit, filter,
random_id); min_date, max_date, random_id);
return {}; return {};
} }
@ -19568,7 +19616,7 @@ int32 MessagesManager::get_dialog_message_count(DialogId dialog_id, MessageSearc
case DialogType::Chat: case DialogType::Chat:
case DialogType::Channel: case DialogType::Channel:
td_->create_handler<SearchMessagesQuery>(std::move(promise)) td_->create_handler<SearchMessagesQuery>(std::move(promise))
->send(dialog_id, "", UserId(), nullptr, MessageId(), 0, 1, filter, random_id); ->send(dialog_id, "", UserId(), nullptr, MessageId(), 0, 1, filter, MessageId(), random_id);
break; break;
case DialogType::None: case DialogType::None:
case DialogType::SecretChat: case DialogType::SecretChat:
@ -20315,11 +20363,12 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
auto edit_date = m->hide_edit_date ? 0 : m->edit_date; auto edit_date = m->hide_edit_date ? 0 : m->edit_date;
return make_tl_object<td_api::message>( 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"), 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, m->sender_dialog_id.get(), dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing,
can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_replies, can_be_edited, can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics,
m->is_channel_post, contains_unread_mention, date, edit_date, get_message_forward_info_object(m->forward_info), can_get_replies, m->is_channel_post, contains_unread_mention, date, edit_date,
get_message_interaction_info_object(dialog_id, m), reply_to_message_id, ttl, ttl_expires_in, via_bot_user_id, get_message_forward_info_object(m->forward_info), get_message_interaction_info_object(dialog_id, m),
m->author_signature, media_album_id, get_restriction_reason_description(m->restriction_reasons), reply_to_message_id, ttl, ttl_expires_in, 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_message_content_object(m->content.get(), td_, live_location_date, m->is_content_secret),
get_reply_markup_object(m->reply_markup)); get_reply_markup_object(m->reply_markup));
} }
@ -20836,19 +20885,25 @@ bool MessagesManager::is_message_auto_read(DialogId dialog_id, bool is_outgoing)
void MessagesManager::add_message_dependencies(Dependencies &dependencies, DialogId dialog_id, const Message *m) { void MessagesManager::add_message_dependencies(Dependencies &dependencies, DialogId dialog_id, const Message *m) {
dependencies.user_ids.insert(m->sender_user_id); dependencies.user_ids.insert(m->sender_user_id);
if (m->sender_dialog_id.is_valid() && dependencies.dialog_ids.insert(m->sender_dialog_id).second) {
add_dialog_dependencies(dependencies, m->sender_dialog_id);
}
dependencies.user_ids.insert(m->via_bot_user_id); dependencies.user_ids.insert(m->via_bot_user_id);
if (m->forward_info != nullptr) { if (m->forward_info != nullptr) {
dependencies.user_ids.insert(m->forward_info->sender_user_id); dependencies.user_ids.insert(m->forward_info->sender_user_id);
if (m->forward_info->dialog_id.is_valid() && dependencies.dialog_ids.insert(m->forward_info->dialog_id).second) { if (m->forward_info->sender_dialog_id.is_valid() &&
add_dialog_dependencies(dependencies, m->forward_info->dialog_id); dependencies.dialog_ids.insert(m->forward_info->sender_dialog_id).second) {
add_dialog_dependencies(dependencies, m->forward_info->sender_dialog_id);
} }
if (m->forward_info->from_dialog_id.is_valid() && if (m->forward_info->from_dialog_id.is_valid() &&
dependencies.dialog_ids.insert(m->forward_info->from_dialog_id).second) { dependencies.dialog_ids.insert(m->forward_info->from_dialog_id).second) {
add_dialog_dependencies(dependencies, m->forward_info->from_dialog_id); add_dialog_dependencies(dependencies, m->forward_info->from_dialog_id);
} }
} }
for (auto recent_replier_user_id : m->reply_info.recent_replier_user_ids) { for (auto recent_replier_dialog_id : m->reply_info.recent_replier_dialog_ids) {
dependencies.user_ids.insert(recent_replier_user_id); if (dialog_id.get_type() == DialogType::User) {
dependencies.user_ids.insert(recent_replier_dialog_id.get_user_id());
}
} }
add_message_content_dependencies(dependencies, m->content.get()); add_message_content_dependencies(dependencies, m->content.get());
} }
@ -23073,7 +23128,7 @@ bool MessagesManager::is_forward_info_sender_hidden(const MessageForwardInfo *fo
return true; return true;
} }
DialogId hidden_sender_dialog_id(static_cast<int64>(G()->is_test_dc() ? -1000010460537ll : -1001228946795ll)); DialogId hidden_sender_dialog_id(static_cast<int64>(G()->is_test_dc() ? -1000010460537ll : -1001228946795ll));
return forward_info->dialog_id == hidden_sender_dialog_id && !forward_info->author_signature.empty() && return forward_info->sender_dialog_id == hidden_sender_dialog_id && !forward_info->author_signature.empty() &&
!forward_info->message_id.is_valid(); !forward_info->message_id.is_valid();
} }
@ -23089,24 +23144,17 @@ unique_ptr<MessagesManager::MessageForwardInfo> MessagesManager::get_message_for
} }
auto flags = forward_header->flags_; auto flags = forward_header->flags_;
UserId sender_user_id; DialogId sender_dialog_id;
ChannelId channel_id;
MessageId message_id; MessageId message_id;
string author_signature; string author_signature;
DialogId from_dialog_id; DialogId from_dialog_id;
MessageId from_message_id; MessageId from_message_id;
string sender_name; string sender_name;
if ((flags & telegram_api::messageFwdHeader::FROM_ID_MASK) != 0) { if ((flags & telegram_api::messageFwdHeader::FROM_ID_MASK) != 0) {
sender_user_id = UserId(forward_header->from_id_); sender_dialog_id = DialogId(forward_header->from_id_);
if (!sender_user_id.is_valid()) { if (!sender_dialog_id.is_valid()) {
LOG(ERROR) << "Receive invalid sender id in message forward header: " << oneline(to_string(forward_header)); LOG(ERROR) << "Receive invalid sender id in message forward header: " << oneline(to_string(forward_header));
sender_user_id = UserId(); sender_dialog_id = DialogId();
}
}
if ((flags & telegram_api::messageFwdHeader::CHANNEL_ID_MASK) != 0) {
channel_id = ChannelId(forward_header->channel_id_);
if (!channel_id.is_valid()) {
LOG(ERROR) << "Receive invalid channel id in message forward header: " << oneline(to_string(forward_header));
} }
} }
constexpr int32 MESSAGE_FORWARD_HEADER_FLAG_HAS_MESSAGE_ID = telegram_api::messageFwdHeader::CHANNEL_POST_MASK; constexpr int32 MESSAGE_FORWARD_HEADER_FLAG_HAS_MESSAGE_ID = telegram_api::messageFwdHeader::CHANNEL_POST_MASK;
@ -23135,8 +23183,12 @@ unique_ptr<MessagesManager::MessageForwardInfo> MessagesManager::get_message_for
sender_name = std::move(forward_header->from_name_); sender_name = std::move(forward_header->from_name_);
} }
DialogId dialog_id; UserId sender_user_id;
if (!channel_id.is_valid()) { if (sender_dialog_id.get_type() == DialogType::User) {
sender_user_id = sender_dialog_id.get_user_id();
sender_dialog_id = DialogId();
}
if (!sender_dialog_id.is_valid()) {
if (sender_user_id.is_valid()) { if (sender_user_id.is_valid()) {
if (message_id.is_valid()) { if (message_id.is_valid()) {
LOG(ERROR) << "Receive non-empty message identifier in message forward header: " LOG(ERROR) << "Receive non-empty message identifier in message forward header: "
@ -23147,20 +23199,21 @@ unique_ptr<MessagesManager::MessageForwardInfo> MessagesManager::get_message_for
LOG(ERROR) << "Receive wrong message forward header: " << oneline(to_string(forward_header)); LOG(ERROR) << "Receive wrong message forward header: " << oneline(to_string(forward_header));
return nullptr; return nullptr;
} }
} else if (sender_dialog_id.get_type() != DialogType::Channel) {
LOG(ERROR) << "Receive wrong message forward header with non-channel sender: "
<< oneline(to_string(forward_header));
return nullptr;
} else { } else {
LOG_IF(ERROR, td_->contacts_manager_->have_min_channel(channel_id)) << "Receive forward from min channel"; auto channel_id = sender_dialog_id.get_channel_id();
dialog_id = DialogId(channel_id); LOG_IF(ERROR, td_->contacts_manager_->have_min_channel(channel_id)) << "Receive forward from min " << channel_id;
force_create_dialog(dialog_id, "message forward info", true); force_create_dialog(sender_dialog_id, "message forward info", true);
if (sender_user_id.is_valid()) { CHECK(!sender_user_id.is_valid());
LOG(ERROR) << "Receive valid sender user id in message forward header: " << oneline(to_string(forward_header));
sender_user_id = UserId();
}
} }
if (from_dialog_id.is_valid()) { if (from_dialog_id.is_valid()) {
force_create_dialog(from_dialog_id, "message forward from info", true); force_create_dialog(from_dialog_id, "message forward from info", true);
} }
return td::make_unique<MessageForwardInfo>(sender_user_id, forward_header->date_, dialog_id, message_id, return td::make_unique<MessageForwardInfo>(sender_user_id, forward_header->date_, sender_dialog_id, message_id,
std::move(author_signature), std::move(sender_name), from_dialog_id, std::move(author_signature), std::move(sender_name), from_dialog_id,
from_message_id, std::move(forward_header->psa_type_)); from_message_id, std::move(forward_header->psa_type_));
} }
@ -23176,9 +23229,12 @@ td_api::object_ptr<td_api::messageForwardInfo> MessagesManager::get_message_forw
return td_api::make_object<td_api::messageForwardOriginHiddenUser>( return td_api::make_object<td_api::messageForwardOriginHiddenUser>(
forward_info->sender_name.empty() ? forward_info->author_signature : forward_info->sender_name); forward_info->sender_name.empty() ? forward_info->author_signature : forward_info->sender_name);
} }
if (forward_info->dialog_id.is_valid()) { if (forward_info->message_id.is_valid()) {
return td_api::make_object<td_api::messageForwardOriginChannel>( return td_api::make_object<td_api::messageForwardOriginChannel>(
forward_info->dialog_id.get(), forward_info->message_id.get(), forward_info->author_signature); forward_info->sender_dialog_id.get(), forward_info->message_id.get(), forward_info->author_signature);
}
if (forward_info->sender_dialog_id.is_valid()) {
return td_api::make_object<td_api::messageForwardOriginChat>(forward_info->sender_dialog_id.get());
} }
return td_api::make_object<td_api::messageForwardOriginUser>( return td_api::make_object<td_api::messageForwardOriginUser>(
td_->contacts_manager_->get_user_id_object(forward_info->sender_user_id, "messageForwardOriginUser")); td_->contacts_manager_->get_user_id_object(forward_info->sender_user_id, "messageForwardOriginUser"));
@ -23444,10 +23500,10 @@ Result<vector<MessageId>> MessagesManager::forward_messages(DialogId to_dialog_i
} else { } else {
LOG(ERROR) << "Don't know how to forward a channel post not from a channel"; LOG(ERROR) << "Don't know how to forward a channel post not from a channel";
} }
} else if (forwarded_message->sender_user_id.is_valid()) { } else if (forwarded_message->sender_user_id.is_valid() || forwarded_message->sender_dialog_id.is_valid()) {
forward_info = forward_info = make_unique<MessageForwardInfo>(forwarded_message->sender_user_id, forwarded_message->date,
make_unique<MessageForwardInfo>(forwarded_message->sender_user_id, forwarded_message->date, DialogId(), forwarded_message->sender_dialog_id, MessageId(), "", "",
MessageId(), "", "", saved_from_dialog_id, saved_from_message_id, ""); saved_from_dialog_id, saved_from_message_id, "");
} else { } else {
LOG(ERROR) << "Don't know how to forward a non-channel post message without forward info and sender"; LOG(ERROR) << "Don't know how to forward a non-channel post message without forward info and sender";
} }
@ -24053,8 +24109,8 @@ NotificationGroupId MessagesManager::get_dialog_notification_group_id(DialogId d
} }
Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_message_push_notification_info( Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_message_push_notification_info(
DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id, int32 date, DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id, DialogId sender_dialog_id,
bool is_from_scheduled, bool contains_mention, bool is_pinned, bool is_from_binlog) { int32 date, bool is_from_scheduled, bool contains_mention, bool is_pinned, bool is_from_binlog) {
init(); init();
if (!is_from_scheduled && dialog_id == get_my_dialog_id()) { if (!is_from_scheduled && dialog_id == get_my_dialog_id()) {
@ -24068,6 +24124,9 @@ Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_messag
if (d == nullptr) { if (d == nullptr) {
return Status::Error(406, "Ignore notification in unknown chat"); return Status::Error(406, "Ignore notification in unknown chat");
} }
if (sender_dialog_id.is_valid() && !have_dialog_force(sender_dialog_id)) {
return Status::Error(406, "Ignore notification sent by unknown chat");
}
if (is_from_scheduled && dialog_id != get_my_dialog_id() && if (is_from_scheduled && dialog_id != get_my_dialog_id() &&
G()->shared_config().get_option_boolean("disable_sent_scheduled_message_notifications")) { G()->shared_config().get_option_boolean("disable_sent_scheduled_message_notifications")) {
@ -24114,9 +24173,14 @@ Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_messag
DialogId settings_dialog_id = dialog_id; DialogId settings_dialog_id = dialog_id;
Dialog *settings_dialog = d; Dialog *settings_dialog = d;
if (contains_mention && sender_user_id.is_valid()) { if (contains_mention) {
settings_dialog_id = DialogId(sender_user_id); if (sender_user_id.is_valid()) {
settings_dialog = get_dialog_force(settings_dialog_id); settings_dialog_id = DialogId(sender_user_id);
settings_dialog = get_dialog_force(settings_dialog_id);
} else if (sender_dialog_id.is_valid()) {
settings_dialog_id = sender_dialog_id;
settings_dialog = get_dialog_force(settings_dialog_id);
}
} }
bool have_settings; bool have_settings;
@ -25009,10 +25073,15 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f
DialogId settings_dialog_id = d->dialog_id; DialogId settings_dialog_id = d->dialog_id;
Dialog *settings_dialog = d; Dialog *settings_dialog = d;
if (m->contains_mention && !m->is_mention_notification_disabled && m->sender_user_id.is_valid()) { if (m->contains_mention && !m->is_mention_notification_disabled) {
// have a mention, so use notification settings from the dialog with the sender // have a mention, so use notification settings from the dialog with the sender
settings_dialog_id = DialogId(m->sender_user_id); if (m->sender_user_id.is_valid()) {
settings_dialog = get_dialog_force(settings_dialog_id); settings_dialog_id = DialogId(m->sender_user_id);
settings_dialog = get_dialog_force(settings_dialog_id);
} else if (m->sender_dialog_id.is_valid()) {
settings_dialog_id = m->sender_dialog_id;
settings_dialog = get_dialog_force(settings_dialog_id);
}
} }
bool have_settings; bool have_settings;
@ -29471,8 +29540,8 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
} }
} }
if (!td_->auth_manager_->is_bot() && from_update && m->forward_info != nullptr && if (!td_->auth_manager_->is_bot() && from_update && m->forward_info != nullptr &&
m->forward_info->dialog_id.is_valid() && m->forward_info->message_id.is_valid()) { m->forward_info->sender_dialog_id.is_valid() && m->forward_info->message_id.is_valid()) {
update_forward_count(m->forward_info->dialog_id, m->forward_info->message_id); update_forward_count(m->forward_info->sender_dialog_id, m->forward_info->message_id);
} }
return result_message; return result_message;
@ -29959,25 +30028,38 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
if (old_message->author_signature != new_message->author_signature) { if (old_message->author_signature != new_message->author_signature) {
LOG(DEBUG) << "Author signature has changed for " << message_id << " in " << dialog_id << " sent by " LOG(DEBUG) << "Author signature has changed for " << message_id << " in " << dialog_id << " sent by "
<< old_message->sender_user_id << "/" << new_message->sender_user_id << " from " << old_message->sender_user_id << "/" << new_message->sender_user_id << " or "
<< old_message->sender_dialog_id << "/" << new_message->sender_dialog_id << " from "
<< old_message->author_signature << " to " << new_message->author_signature; << old_message->author_signature << " to " << new_message->author_signature;
old_message->author_signature = std::move(new_message->author_signature); old_message->author_signature = std::move(new_message->author_signature);
need_send_update = true; need_send_update = true;
} }
if (old_message->sender_user_id != new_message->sender_user_id) { if (old_message->sender_user_id != new_message->sender_user_id) {
// there can be race for sent signed posts // there can be race for sent signed posts or changed anonymous flag
LOG_IF(ERROR, old_message->sender_user_id != UserId() && new_message->sender_user_id != UserId()) LOG_IF(ERROR, old_message->sender_user_id != UserId() && new_message->sender_user_id != UserId())
<< message_id << " in " << dialog_id << " has changed sender from " << old_message->sender_user_id << " to " << message_id << " in " << dialog_id << " has changed sender from " << old_message->sender_user_id << " to "
<< new_message->sender_user_id << ", message content type is " << old_message->content->get_type() << '/' << new_message->sender_user_id << ", message content type is " << old_message->content->get_type() << '/'
<< new_message->content->get_type(); << new_message->content->get_type();
LOG_IF(WARNING, new_message->sender_user_id.is_valid() || old_message->author_signature.empty()) LOG_IF(WARNING, (new_message->sender_user_id.is_valid() || old_message->author_signature.empty()) &&
!old_message->sender_dialog_id.is_valid() && !new_message->sender_dialog_id.is_valid())
<< "Update message sender from " << old_message->sender_user_id << " to " << new_message->sender_user_id << "Update message sender from " << old_message->sender_user_id << " to " << new_message->sender_user_id
<< " in " << dialog_id; << " in " << dialog_id;
LOG(DEBUG) << "Change message sender"; LOG(DEBUG) << "Change message sender";
old_message->sender_user_id = new_message->sender_user_id; old_message->sender_user_id = new_message->sender_user_id;
need_send_update = true; need_send_update = true;
} }
if (old_message->sender_dialog_id != new_message->sender_dialog_id) {
// there can be race for changed anonymous flag
LOG_IF(ERROR, old_message->sender_dialog_id != DialogId() && new_message->sender_dialog_id != DialogId())
<< message_id << " in " << dialog_id << " has changed sender from " << old_message->sender_dialog_id << " to "
<< new_message->sender_dialog_id << ", message content type is " << old_message->content->get_type() << '/'
<< new_message->content->get_type();
LOG(DEBUG) << "Change message sender";
old_message->sender_dialog_id = new_message->sender_dialog_id;
need_send_update = true;
}
if (old_message->forward_info == nullptr) { if (old_message->forward_info == nullptr) {
if (new_message->forward_info != nullptr) { if (new_message->forward_info != nullptr) {
if (!replace_legacy) { if (!replace_legacy) {
@ -30007,10 +30089,11 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
need_send_update = true; need_send_update = true;
} }
} else if (is_new_available) { } else if (is_new_available) {
LOG(ERROR) << message_id << " in " << dialog_id << " sent by " << old_message->sender_user_id LOG(ERROR) << message_id << " in " << dialog_id << " sent by " << old_message->sender_user_id << "/"
<< " has lost forward info " << *old_message->forward_info << ", really forwarded from " << old_message->sender_dialog_id << " has lost forward info " << *old_message->forward_info
<< old_message->real_forward_from_dialog_id << ", message content type is " << ", really forwarded from " << old_message->real_forward_from_dialog_id
<< old_message->content->get_type() << '/' << new_message->content->get_type(); << ", message content type is " << old_message->content->get_type() << '/'
<< new_message->content->get_type();
old_message->forward_info = nullptr; old_message->forward_info = nullptr;
need_send_update = true; need_send_update = true;
} }
@ -30198,8 +30281,8 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
} else { } else {
// if the message is not accessible anymore, then we don't need a warning // if the message is not accessible anymore, then we don't need a warning
if (need_message_changed_warning(old_message) && is_new_available) { if (need_message_changed_warning(old_message) && is_new_available) {
LOG(ERROR) << message_id << " in " << dialog_id << " sent by " << old_message->sender_user_id LOG(ERROR) << message_id << " in " << dialog_id << " sent by " << old_message->sender_user_id << "/"
<< " has lost reply markup " << *old_message->reply_markup << old_message->sender_dialog_id << " has lost reply markup " << *old_message->reply_markup
<< ". Old message: " << to_string(get_message_object(dialog_id, old_message)) << ". Old message: " << to_string(get_message_object(dialog_id, old_message))
<< ". New message: " << to_string(get_message_object(dialog_id, new_message.get())); << ". New message: " << to_string(get_message_object(dialog_id, new_message.get()));
} }
@ -30775,7 +30858,7 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
if (last_database_message != nullptr) { if (last_database_message != nullptr) {
int32 dependent_dialog_count = 0; int32 dependent_dialog_count = 0;
if (last_database_message->forward_info != nullptr) { if (last_database_message->forward_info != nullptr) {
auto other_dialog_id = last_database_message->forward_info->dialog_id; auto other_dialog_id = last_database_message->forward_info->sender_dialog_id;
if (other_dialog_id.is_valid() && !have_dialog(other_dialog_id)) { if (other_dialog_id.is_valid() && !have_dialog(other_dialog_id)) {
LOG(INFO) << "Postpone adding of last message in " << dialog_id << " because of cyclic dependency with " LOG(INFO) << "Postpone adding of last message in " << dialog_id << " because of cyclic dependency with "
<< other_dialog_id; << other_dialog_id;
@ -30789,6 +30872,13 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
pending_add_dialog_last_database_message_dependent_dialogs_[other_dialog_id].push_back(dialog_id); pending_add_dialog_last_database_message_dependent_dialogs_[other_dialog_id].push_back(dialog_id);
dependent_dialog_count++; dependent_dialog_count++;
} }
other_dialog_id = last_database_message->sender_dialog_id;
if (other_dialog_id.is_valid() && !have_dialog(other_dialog_id)) {
LOG(INFO) << "Postpone adding of last message in " << dialog_id << " because of cyclic dependency with "
<< other_dialog_id;
pending_add_dialog_last_database_message_dependent_dialogs_[other_dialog_id].push_back(dialog_id);
dependent_dialog_count++;
}
} }
if (dependent_dialog_count == 0) { if (dependent_dialog_count == 0) {

View File

@ -165,7 +165,6 @@ class MessagesManager : public Actor {
static constexpr int32 MESSAGE_FLAG_HIDE_EDIT_DATE = 1 << 21; static constexpr int32 MESSAGE_FLAG_HIDE_EDIT_DATE = 1 << 21;
static constexpr int32 MESSAGE_FLAG_IS_RESTRICTED = 1 << 22; static constexpr int32 MESSAGE_FLAG_IS_RESTRICTED = 1 << 22;
static constexpr int32 MESSAGE_FLAG_HAS_REPLY_INFO = 1 << 23; static constexpr int32 MESSAGE_FLAG_HAS_REPLY_INFO = 1 << 23;
static constexpr int32 MESSAGE_FLAG_HAS_RECENT_REPLIERS = 1 << 24;
static constexpr int32 SEND_MESSAGE_FLAG_IS_REPLY = 1 << 0; static constexpr int32 SEND_MESSAGE_FLAG_IS_REPLY = 1 << 0;
static constexpr int32 SEND_MESSAGE_FLAG_DISABLE_WEB_PAGE_PREVIEW = 1 << 1; static constexpr int32 SEND_MESSAGE_FLAG_DISABLE_WEB_PAGE_PREVIEW = 1 << 1;
@ -234,13 +233,14 @@ class MessagesManager : public Actor {
void on_get_dialog_messages_search_result(DialogId dialog_id, const string &query, UserId sender_user_id, void on_get_dialog_messages_search_result(DialogId dialog_id, const string &query, UserId sender_user_id,
MessageId from_message_id, int32 offset, int32 limit, MessageId from_message_id, int32 offset, int32 limit,
MessageSearchFilter filter, int64 random_id, int32 total_count, MessageSearchFilter filter, MessageId top_thread_message_id,
int64 random_id, int32 total_count,
vector<tl_object_ptr<telegram_api::Message>> &&messages); vector<tl_object_ptr<telegram_api::Message>> &&messages);
void on_failed_dialog_messages_search(DialogId dialog_id, int64 random_id); void on_failed_dialog_messages_search(DialogId dialog_id, int64 random_id);
void on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id, void on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id,
MessageId offset_message_id, int32 limit, MessageSearchFilter filter, MessageId offset_message_id, int32 limit, MessageSearchFilter filter,
int64 random_id, int32 total_count, int32 min_date, int32 max_date, int64 random_id, int32 total_count,
vector<tl_object_ptr<telegram_api::Message>> &&messages); vector<tl_object_ptr<telegram_api::Message>> &&messages);
void on_failed_messages_search(int64 random_id); void on_failed_messages_search(int64 random_id);
@ -661,7 +661,8 @@ class MessagesManager : public Actor {
std::pair<int32, vector<MessageId>> search_dialog_messages(DialogId dialog_id, const string &query, std::pair<int32, vector<MessageId>> search_dialog_messages(DialogId dialog_id, const string &query,
UserId sender_user_id, MessageId from_message_id, UserId sender_user_id, MessageId from_message_id,
int32 offset, int32 limit, MessageSearchFilter filter, int32 offset, int32 limit, MessageSearchFilter filter,
int64 &random_id, bool use_db, Promise<Unit> &&promise); MessageId top_thread_message_id, int64 &random_id,
bool use_db, Promise<Unit> &&promise);
struct FoundMessages { struct FoundMessages {
vector<FullMessageId> full_message_ids; vector<FullMessageId> full_message_ids;
@ -677,8 +678,8 @@ class MessagesManager : public Actor {
std::pair<int32, vector<FullMessageId>> search_messages(FolderId folder_id, bool ignore_folder_id, std::pair<int32, vector<FullMessageId>> search_messages(FolderId folder_id, bool ignore_folder_id,
const string &query, int32 offset_date, const string &query, int32 offset_date,
DialogId offset_dialog_id, MessageId offset_message_id, DialogId offset_dialog_id, MessageId offset_message_id,
int32 limit, MessageSearchFilter filter, int64 &random_id, int32 limit, MessageSearchFilter filter, int32 min_date,
Promise<Unit> &&promise); int32 max_date, int64 &random_id, Promise<Unit> &&promise);
std::pair<int32, vector<FullMessageId>> search_call_messages(MessageId from_message_id, int32 limit, bool only_missed, std::pair<int32, vector<FullMessageId>> search_call_messages(MessageId from_message_id, int32 limit, bool only_missed,
int64 &random_id, bool use_db, Promise<Unit> &&promise); int64 &random_id, bool use_db, Promise<Unit> &&promise);
@ -832,9 +833,9 @@ class MessagesManager : public Actor {
}; };
Result<MessagePushNotificationInfo> get_message_push_notification_info(DialogId dialog_id, MessageId message_id, Result<MessagePushNotificationInfo> get_message_push_notification_info(DialogId dialog_id, MessageId message_id,
int64 random_id, UserId sender_user_id, int64 random_id, UserId sender_user_id,
int32 date, bool is_from_scheduled, DialogId sender_dialog_id, int32 date,
bool contains_mention, bool is_pinned, bool is_from_scheduled, bool contains_mention,
bool is_from_binlog); bool is_pinned, bool is_from_binlog);
struct MessageNotificationGroup { struct MessageNotificationGroup {
DialogId dialog_id; DialogId dialog_id;
@ -904,11 +905,13 @@ class MessagesManager : public Actor {
DialogId dialog_id; DialogId dialog_id;
MessageId message_id; MessageId message_id;
UserId sender_user_id; UserId sender_user_id;
DialogId sender_dialog_id;
int32 date = 0; int32 date = 0;
int32 ttl = 0; int32 ttl = 0;
int64 random_id = 0; int64 random_id = 0;
tl_object_ptr<telegram_api::messageFwdHeader> forward_header; tl_object_ptr<telegram_api::messageFwdHeader> forward_header;
MessageId reply_to_message_id; MessageId reply_to_message_id;
tl_object_ptr<telegram_api::messageReplyHeader> reply_header;
UserId via_bot_user_id; UserId via_bot_user_id;
int32 view_count = 0; int32 view_count = 0;
int32 forward_count = 0; int32 forward_count = 0;
@ -926,7 +929,7 @@ class MessagesManager : public Actor {
struct MessageForwardInfo { struct MessageForwardInfo {
UserId sender_user_id; UserId sender_user_id;
int32 date = 0; int32 date = 0;
DialogId dialog_id; DialogId sender_dialog_id;
MessageId message_id; MessageId message_id;
string author_signature; string author_signature;
string sender_name; string sender_name;
@ -936,12 +939,12 @@ class MessagesManager : public Actor {
MessageForwardInfo() = default; MessageForwardInfo() = default;
MessageForwardInfo(UserId sender_user_id, int32 date, DialogId dialog_id, MessageId message_id, MessageForwardInfo(UserId sender_user_id, int32 date, DialogId sender_dialog_id, MessageId message_id,
string author_signature, string sender_name, DialogId from_dialog_id, MessageId from_message_id, string author_signature, string sender_name, DialogId from_dialog_id, MessageId from_message_id,
string psa_type) string psa_type)
: sender_user_id(sender_user_id) : sender_user_id(sender_user_id)
, date(date) , date(date)
, dialog_id(dialog_id) , sender_dialog_id(sender_dialog_id)
, message_id(message_id) , message_id(message_id)
, author_signature(std::move(author_signature)) , author_signature(std::move(author_signature))
, sender_name(std::move(sender_name)) , sender_name(std::move(sender_name))
@ -951,7 +954,7 @@ class MessagesManager : public Actor {
} }
bool operator==(const MessageForwardInfo &rhs) const { bool operator==(const MessageForwardInfo &rhs) const {
return sender_user_id == rhs.sender_user_id && date == rhs.date && dialog_id == rhs.dialog_id && return sender_user_id == rhs.sender_user_id && date == rhs.date && sender_dialog_id == rhs.sender_dialog_id &&
message_id == rhs.message_id && author_signature == rhs.author_signature && message_id == rhs.message_id && author_signature == rhs.author_signature &&
sender_name == rhs.sender_name && from_dialog_id == rhs.from_dialog_id && sender_name == rhs.sender_name && from_dialog_id == rhs.from_dialog_id &&
from_message_id == rhs.from_message_id && psa_type == rhs.psa_type; from_message_id == rhs.from_message_id && psa_type == rhs.psa_type;
@ -964,7 +967,7 @@ class MessagesManager : public Actor {
friend StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInfo &forward_info) { friend StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInfo &forward_info) {
return string_builder << "MessageForwardInfo[sender " << forward_info.sender_user_id << "(" return string_builder << "MessageForwardInfo[sender " << forward_info.sender_user_id << "("
<< forward_info.author_signature << "/" << forward_info.sender_name << "), psa_type " << forward_info.author_signature << "/" << forward_info.sender_name << "), psa_type "
<< forward_info.psa_type << ", source " << forward_info.dialog_id << ", source " << forward_info.psa_type << ", source " << forward_info.sender_dialog_id << ", source "
<< forward_info.message_id << ", from " << forward_info.from_dialog_id << ", from " << forward_info.message_id << ", from " << forward_info.from_dialog_id << ", from "
<< forward_info.from_message_id << " at " << forward_info.date << "]"; << forward_info.from_message_id << " at " << forward_info.date << "]";
} }
@ -976,6 +979,7 @@ class MessagesManager : public Actor {
MessageId message_id; MessageId message_id;
UserId sender_user_id; UserId sender_user_id;
DialogId sender_dialog_id;
int32 date = 0; int32 date = 0;
int32 edit_date = 0; int32 edit_date = 0;
int32 send_date = 0; int32 send_date = 0;
@ -1664,8 +1668,6 @@ class MessagesManager : public Actor {
void finish_delete_secret_chat_history(DialogId dialog_id, MessageId last_message_id, Promise<> promise); void finish_delete_secret_chat_history(DialogId dialog_id, MessageId last_message_id, Promise<> promise);
void fix_message_info_dialog_id(MessageInfo &message_info) const;
MessageInfo parse_telegram_api_message(tl_object_ptr<telegram_api::Message> message_ptr, bool is_scheduled, MessageInfo parse_telegram_api_message(tl_object_ptr<telegram_api::Message> message_ptr, bool is_scheduled,
const char *source) const; const char *source) const;

View File

@ -3133,7 +3133,20 @@ Status NotificationManager::process_push_notification_payload(string payload, bo
TRY_RESULT(random_id, get_json_object_long_field(custom, "random_id")); TRY_RESULT(random_id, get_json_object_long_field(custom, "random_id"));
UserId sender_user_id; UserId sender_user_id;
if (has_json_object_field(custom, "chat_from_id")) { DialogId sender_dialog_id;
if (has_json_object_field(custom, "chat_from_broadcast_id")) {
TRY_RESULT(sender_channel_id_int, get_json_object_int_field(custom, "chat_from_broadcast_id"));
sender_dialog_id = DialogId(ChannelId(sender_channel_id_int));
if (!sender_dialog_id.is_valid()) {
return Status::Error("Receive invalid chat_from_broadcast_id");
}
} else if (has_json_object_field(custom, "chat_from_group_id")) {
TRY_RESULT(sender_channel_id_int, get_json_object_int_field(custom, "chat_from_group_id"));
sender_dialog_id = DialogId(ChannelId(sender_channel_id_int));
if (!sender_dialog_id.is_valid()) {
return Status::Error("Receive invalid chat_from_group_id");
}
} else if (has_json_object_field(custom, "chat_from_id")) {
TRY_RESULT(sender_user_id_int, get_json_object_int_field(custom, "chat_from_id")); TRY_RESULT(sender_user_id_int, get_json_object_int_field(custom, "chat_from_id"));
sender_user_id = UserId(sender_user_id_int); sender_user_id = UserId(sender_user_id_int);
if (!sender_user_id.is_valid()) { if (!sender_user_id.is_valid()) {
@ -3199,7 +3212,7 @@ Status NotificationManager::process_push_notification_payload(string payload, bo
} }
if (dialog_id.get_type() == DialogType::User) { if (dialog_id.get_type() == DialogType::User) {
sender_name = std::move(loc_args[0]); sender_name = std::move(loc_args[0]);
} else if (sender_user_id.is_valid() && begins_with(loc_key, "PINNED_")) { } else if ((sender_user_id.is_valid() || sender_dialog_id.is_valid()) && begins_with(loc_key, "PINNED_")) {
if (loc_args.size() < 2) { if (loc_args.size() < 2) {
return Status::Error("Expected chat title as the last argument"); return Status::Error("Expected chat title as the last argument");
} }
@ -3398,7 +3411,7 @@ Status NotificationManager::process_push_notification_payload(string payload, bo
} else { } else {
bool is_from_scheduled = has_json_object_field(custom, "schedule"); bool is_from_scheduled = has_json_object_field(custom, "schedule");
bool is_silent = has_json_object_field(custom, "silent"); bool is_silent = has_json_object_field(custom, "silent");
add_message_push_notification(dialog_id, MessageId(server_message_id), random_id, sender_user_id, add_message_push_notification(dialog_id, MessageId(server_message_id), random_id, sender_user_id, sender_dialog_id,
std::move(sender_name), sent_date, is_from_scheduled, contains_mention, is_silent, std::move(sender_name), sent_date, is_from_scheduled, contains_mention, is_silent,
is_silent, std::move(loc_key), std::move(arg), std::move(attached_photo), is_silent, std::move(loc_key), std::move(arg), std::move(attached_photo),
std::move(attached_document), NotificationId(), 0, std::move(promise)); std::move(attached_document), NotificationId(), 0, std::move(promise));
@ -3412,6 +3425,7 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
MessageId message_id_; MessageId message_id_;
int64 random_id_; int64 random_id_;
UserId sender_user_id_; UserId sender_user_id_;
DialogId sender_dialog_id_;
string sender_name_; string sender_name_;
int32 date_; int32 date_;
bool is_from_scheduled_; bool is_from_scheduled_;
@ -3432,6 +3446,7 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
bool has_arg = !arg_.empty(); bool has_arg = !arg_.empty();
bool has_photo = !photo_.is_empty(); bool has_photo = !photo_.is_empty();
bool has_document = !document_.empty(); bool has_document = !document_.empty();
bool has_sender_dialog_id = sender_dialog_id_.is_valid();
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(contains_mention_); STORE_FLAG(contains_mention_);
STORE_FLAG(is_silent_); STORE_FLAG(is_silent_);
@ -3443,6 +3458,7 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
STORE_FLAG(has_photo); STORE_FLAG(has_photo);
STORE_FLAG(has_document); STORE_FLAG(has_document);
STORE_FLAG(is_from_scheduled_); STORE_FLAG(is_from_scheduled_);
STORE_FLAG(has_sender_dialog_id);
END_STORE_FLAGS(); END_STORE_FLAGS();
td::store(dialog_id_, storer); td::store(dialog_id_, storer);
if (has_message_id) { if (has_message_id) {
@ -3469,6 +3485,9 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
td::store(document_, storer); td::store(document_, storer);
} }
td::store(notification_id_, storer); td::store(notification_id_, storer);
if (has_sender_dialog_id) {
td::store(sender_dialog_id_, storer);
}
} }
template <class ParserT> template <class ParserT>
@ -3480,6 +3499,7 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
bool has_arg; bool has_arg;
bool has_photo; bool has_photo;
bool has_document; bool has_document;
bool has_sender_dialog_id;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(contains_mention_); PARSE_FLAG(contains_mention_);
PARSE_FLAG(is_silent_); PARSE_FLAG(is_silent_);
@ -3491,6 +3511,7 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
PARSE_FLAG(has_photo); PARSE_FLAG(has_photo);
PARSE_FLAG(has_document); PARSE_FLAG(has_document);
PARSE_FLAG(is_from_scheduled_); PARSE_FLAG(is_from_scheduled_);
PARSE_FLAG(has_sender_dialog_id);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
td::parse(dialog_id_, parser); td::parse(dialog_id_, parser);
if (has_message_id) { if (has_message_id) {
@ -3519,20 +3540,27 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
td::parse(document_, parser); td::parse(document_, parser);
} }
td::parse(notification_id_, parser); td::parse(notification_id_, parser);
if (has_sender_dialog_id) {
td::parse(sender_dialog_id_, parser);
}
} }
}; };
void NotificationManager::add_message_push_notification( void NotificationManager::add_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id,
DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id, string sender_name, int32 date, UserId sender_user_id, DialogId sender_dialog_id,
bool is_from_scheduled, bool contains_mention, bool initial_is_silent, bool is_silent, string loc_key, string arg, string sender_name, int32 date, bool is_from_scheduled,
Photo photo, Document document, NotificationId notification_id, uint64 logevent_id, Promise<Unit> promise) { bool contains_mention, bool initial_is_silent, bool is_silent,
string loc_key, string arg, Photo photo, Document document,
NotificationId notification_id, uint64 logevent_id,
Promise<Unit> promise) {
auto is_pinned = begins_with(loc_key, "PINNED_"); auto is_pinned = begins_with(loc_key, "PINNED_");
auto r_info = td_->messages_manager_->get_message_push_notification_info( auto r_info = td_->messages_manager_->get_message_push_notification_info(
dialog_id, message_id, random_id, sender_user_id, date, is_from_scheduled, contains_mention, is_pinned, dialog_id, message_id, random_id, sender_user_id, sender_dialog_id, date, is_from_scheduled, contains_mention,
logevent_id != 0); is_pinned, logevent_id != 0);
if (r_info.is_error()) { if (r_info.is_error()) {
VLOG(notifications) << "Don't need message push notification for " << message_id << "/" << random_id << " from " VLOG(notifications) << "Don't need message push notification for " << message_id << "/" << random_id << " from "
<< dialog_id << " sent by " << sender_user_id << " at " << date << ": " << r_info.error(); << dialog_id << " sent by " << sender_user_id << "/" << sender_dialog_id << " at " << date
<< ": " << r_info.error();
if (logevent_id != 0) { if (logevent_id != 0) {
binlog_erase(G()->td_db()->get_binlog(), logevent_id); binlog_erase(G()->td_db()->get_binlog(), logevent_id);
} }
@ -3585,9 +3613,9 @@ void NotificationManager::add_message_push_notification(
if (logevent_id == 0 && G()->parameters().use_message_db) { if (logevent_id == 0 && G()->parameters().use_message_db) {
AddMessagePushNotificationLogEvent logevent{ AddMessagePushNotificationLogEvent logevent{
dialog_id, message_id, random_id, sender_user_id, sender_name, date, dialog_id, message_id, random_id, sender_user_id, sender_dialog_id, sender_name,
is_from_scheduled, contains_mention, initial_is_silent, loc_key, arg, photo, date, is_from_scheduled, contains_mention, initial_is_silent, loc_key, arg,
document, notification_id}; photo, document, notification_id};
auto storer = LogEventStorerImpl<AddMessagePushNotificationLogEvent>(logevent); auto storer = LogEventStorerImpl<AddMessagePushNotificationLogEvent>(logevent);
logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::AddMessagePushNotification, storer); logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::AddMessagePushNotification, storer);
} }
@ -3600,8 +3628,8 @@ void NotificationManager::add_message_push_notification(
if (logevent_id != 0) { if (logevent_id != 0) {
VLOG(notifications) << "Register temporary " << notification_id << " with logevent " << logevent_id; VLOG(notifications) << "Register temporary " << notification_id << " with logevent " << logevent_id;
temporary_notification_logevent_ids_[notification_id] = logevent_id; temporary_notification_logevent_ids_[notification_id] = logevent_id;
temporary_notifications_[FullMessageId(dialog_id, message_id)] = {group_id, notification_id, sender_user_id, temporary_notifications_[FullMessageId(dialog_id, message_id)] = {group_id, notification_id, sender_user_id,
sender_name, is_outgoing}; sender_dialog_id, sender_name, is_outgoing};
temporary_notification_message_ids_[notification_id] = FullMessageId(dialog_id, message_id); temporary_notification_message_ids_[notification_id] = FullMessageId(dialog_id, message_id);
} }
push_notification_promises_[notification_id].push_back(std::move(promise)); push_notification_promises_[notification_id].push_back(std::move(promise));
@ -3609,15 +3637,15 @@ void NotificationManager::add_message_push_notification(
auto group_type = info.group_type; auto group_type = info.group_type;
auto settings_dialog_id = info.settings_dialog_id; auto settings_dialog_id = info.settings_dialog_id;
VLOG(notifications) << "Add message push " << notification_id << " of type " << loc_key << " for " << message_id VLOG(notifications) << "Add message push " << notification_id << " of type " << loc_key << " for " << message_id
<< "/" << random_id << " in " << dialog_id << ", sent by " << sender_user_id << "/\"" << "/" << random_id << " in " << dialog_id << ", sent by " << sender_user_id << "/"
<< sender_name << "\" at " << date << " with arg " << arg << ", photo " << photo << sender_dialog_id << "/\"" << sender_name << "\" at " << date << " with arg " << arg
<< " and document " << document << " to " << group_id << " of type " << group_type << ", photo " << photo << " and document " << document << " to " << group_id << " of type "
<< " with settings from " << settings_dialog_id; << group_type << " with settings from " << settings_dialog_id;
add_notification( add_notification(
group_id, group_type, dialog_id, date, settings_dialog_id, initial_is_silent, is_silent, 0, notification_id, group_id, group_type, dialog_id, date, settings_dialog_id, initial_is_silent, is_silent, 0, notification_id,
create_new_push_message_notification(sender_user_id, sender_name, is_outgoing, message_id, std::move(loc_key), create_new_push_message_notification(sender_user_id, sender_dialog_id, sender_name, is_outgoing, message_id,
std::move(arg), std::move(photo), std::move(document)), std::move(loc_key), std::move(arg), std::move(photo), std::move(document)),
"add_message_push_notification"); "add_message_push_notification");
} }
@ -3708,6 +3736,7 @@ void NotificationManager::edit_message_push_notification(DialogId dialog_id, Mes
auto group_id = it->second.group_id; auto group_id = it->second.group_id;
auto notification_id = it->second.notification_id; auto notification_id = it->second.notification_id;
auto sender_user_id = it->second.sender_user_id; auto sender_user_id = it->second.sender_user_id;
auto sender_dialog_id = it->second.sender_dialog_id;
auto sender_name = it->second.sender_name; auto sender_name = it->second.sender_name;
auto is_outgoing = it->second.is_outgoing; auto is_outgoing = it->second.is_outgoing;
CHECK(group_id.is_valid()); CHECK(group_id.is_valid());
@ -3734,10 +3763,10 @@ void NotificationManager::edit_message_push_notification(DialogId dialog_id, Mes
push_notification_promises_[notification_id].push_back(std::move(promise)); push_notification_promises_[notification_id].push_back(std::move(promise));
edit_notification( edit_notification(group_id, notification_id,
group_id, notification_id, create_new_push_message_notification(sender_user_id, sender_dialog_id, std::move(sender_name),
create_new_push_message_notification(sender_user_id, std::move(sender_name), is_outgoing, message_id, is_outgoing, message_id, std::move(loc_key), std::move(arg),
std::move(loc_key), std::move(arg), std::move(photo), std::move(document))); std::move(photo), std::move(document)));
} }
Result<int64> NotificationManager::get_push_receiver_id(string payload) { Result<int64> NotificationManager::get_push_receiver_id(string payload) {
@ -4063,9 +4092,10 @@ void NotificationManager::on_binlog_events(vector<BinlogEvent> &&events) {
add_message_push_notification( add_message_push_notification(
log_event.dialog_id_, log_event.message_id_, log_event.random_id_, log_event.sender_user_id_, log_event.dialog_id_, log_event.message_id_, log_event.random_id_, log_event.sender_user_id_,
log_event.sender_name_, log_event.date_, log_event.is_from_scheduled_, log_event.contains_mention_, log_event.sender_dialog_id_, log_event.sender_name_, log_event.date_, log_event.is_from_scheduled_,
log_event.is_silent_, true, log_event.loc_key_, log_event.arg_, log_event.photo_, log_event.document_, log_event.contains_mention_, log_event.is_silent_, true, log_event.loc_key_, log_event.arg_,
log_event.notification_id_, event.id_, PromiseCreator::lambda([](Result<Unit> result) { log_event.photo_, log_event.document_, log_event.notification_id_, event.id_,
PromiseCreator::lambda([](Result<Unit> result) {
if (result.is_error() && result.error().code() != 200 && result.error().code() != 406) { if (result.is_error() && result.error().code() != 200 && result.error().code() != 406) {
LOG(ERROR) << "Receive error " << result.error() << ", while processing message push notification"; LOG(ERROR) << "Receive error " << result.error() << ", while processing message push notification";
} }

View File

@ -307,10 +307,10 @@ class NotificationManager : public Actor {
Status process_push_notification_payload(string payload, bool was_encrypted, Promise<Unit> &promise); Status process_push_notification_payload(string payload, bool was_encrypted, Promise<Unit> &promise);
void add_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id, void add_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id,
string sender_name, int32 date, bool is_from_scheduled, bool contains_mention, DialogId sender_dialog_id, string sender_name, int32 date, bool is_from_scheduled,
bool initial_is_silent, bool is_silent, string loc_key, string arg, Photo photo, bool contains_mention, bool initial_is_silent, bool is_silent, string loc_key,
Document document, NotificationId notification_id, uint64 logevent_id, string arg, Photo photo, Document document, NotificationId notification_id,
Promise<Unit> promise); uint64 logevent_id, Promise<Unit> promise);
void edit_message_push_notification(DialogId dialog_id, MessageId message_id, int32 edit_date, string loc_key, void edit_message_push_notification(DialogId dialog_id, MessageId message_id, int32 edit_date, string loc_key,
string arg, Photo photo, Document document, uint64 logevent_id, string arg, Photo photo, Document document, uint64 logevent_id,
@ -388,6 +388,7 @@ class NotificationManager : public Actor {
NotificationGroupId group_id; NotificationGroupId group_id;
NotificationId notification_id; NotificationId notification_id;
UserId sender_user_id; UserId sender_user_id;
DialogId sender_dialog_id;
string sender_name; string sender_name;
bool is_outgoing; bool is_outgoing;
}; };

View File

@ -321,16 +321,18 @@ class NotificationTypePushMessage : public NotificationType {
auto sender_user_id = G()->td().get_actor_unsafe()->contacts_manager_->get_user_id_object( auto sender_user_id = G()->td().get_actor_unsafe()->contacts_manager_->get_user_id_object(
sender_user_id_, "get_notification_type_object"); sender_user_id_, "get_notification_type_object");
return td_api::make_object<td_api::notificationTypeNewPushMessage>( return td_api::make_object<td_api::notificationTypeNewPushMessage>(
message_id_.get(), sender_user_id, sender_name_, is_outgoing_, message_id_.get(), sender_user_id, sender_dialog_id_.get(), sender_name_, is_outgoing_,
get_push_message_content_object(key_, arg_, photo_, document_)); get_push_message_content_object(key_, arg_, photo_, document_));
} }
StringBuilder &to_string_builder(StringBuilder &string_builder) const override { StringBuilder &to_string_builder(StringBuilder &string_builder) const override {
return string_builder << "NewPushMessageNotification[" << sender_user_id_ << "/\"" << sender_name_ << "\", " return string_builder << "NewPushMessageNotification[" << sender_user_id_ << "/" << sender_dialog_id_ << "/\""
<< message_id_ << ", " << key_ << ", " << arg_ << ", " << photo_ << ", " << document_ << ']'; << sender_name_ << "\", " << message_id_ << ", " << key_ << ", " << arg_ << ", " << photo_
<< ", " << document_ << ']';
} }
UserId sender_user_id_; UserId sender_user_id_;
DialogId sender_dialog_id_;
MessageId message_id_; MessageId message_id_;
string sender_name_; string sender_name_;
string key_; string key_;
@ -340,9 +342,10 @@ class NotificationTypePushMessage : public NotificationType {
bool is_outgoing_; bool is_outgoing_;
public: public:
NotificationTypePushMessage(UserId sender_user_id, string sender_name, bool is_outgoing, MessageId message_id, NotificationTypePushMessage(UserId sender_user_id, DialogId sender_dialog_id, string sender_name, bool is_outgoing,
string key, string arg, Photo photo, Document document) MessageId message_id, string key, string arg, Photo photo, Document document)
: sender_user_id_(std::move(sender_user_id)) : sender_user_id_(sender_user_id)
, sender_dialog_id_(sender_dialog_id)
, message_id_(message_id) , message_id_(message_id)
, sender_name_(std::move(sender_name)) , sender_name_(std::move(sender_name))
, key_(std::move(key)) , key_(std::move(key))
@ -365,12 +368,13 @@ unique_ptr<NotificationType> create_new_call_notification(CallId call_id) {
return make_unique<NotificationTypeCall>(call_id); return make_unique<NotificationTypeCall>(call_id);
} }
unique_ptr<NotificationType> create_new_push_message_notification(UserId sender_user_id, string sender_name, unique_ptr<NotificationType> create_new_push_message_notification(UserId sender_user_id, DialogId sender_dialog_id,
bool is_outgoing, MessageId message_id, string key, string sender_name, bool is_outgoing,
string arg, Photo photo, Document document) { MessageId message_id, string key, string arg,
return td::make_unique<NotificationTypePushMessage>(sender_user_id, std::move(sender_name), is_outgoing, message_id, Photo photo, Document document) {
std::move(key), std::move(arg), std::move(photo), return td::make_unique<NotificationTypePushMessage>(sender_user_id, sender_dialog_id, std::move(sender_name),
std::move(document)); is_outgoing, message_id, std::move(key), std::move(arg),
std::move(photo), std::move(document));
} }
} // namespace td } // namespace td

View File

@ -59,8 +59,9 @@ unique_ptr<NotificationType> create_new_secret_chat_notification();
unique_ptr<NotificationType> create_new_call_notification(CallId call_id); unique_ptr<NotificationType> create_new_call_notification(CallId call_id);
unique_ptr<NotificationType> create_new_push_message_notification(UserId sender_user_id, string sender_name, unique_ptr<NotificationType> create_new_push_message_notification(UserId sender_user_id, DialogId sender_dialog_id,
bool is_outgoing, MessageId message_id, string key, string sender_name, bool is_outgoing,
string arg, Photo photo, Document document); MessageId message_id, string key, string arg,
Photo photo, Document document);
} // namespace td } // namespace td

View File

@ -1398,14 +1398,15 @@ class SearchChatMessagesRequest : public RequestActor<> {
int32 offset_; int32 offset_;
int32 limit_; int32 limit_;
MessageSearchFilter filter_; MessageSearchFilter filter_;
MessageId top_thread_message_id_;
int64 random_id_; int64 random_id_;
std::pair<int32, vector<MessageId>> messages_; std::pair<int32, vector<MessageId>> messages_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
messages_ = td->messages_manager_->search_dialog_messages(dialog_id_, query_, sender_user_id_, from_message_id_, messages_ = td->messages_manager_->search_dialog_messages(dialog_id_, query_, sender_user_id_, from_message_id_,
offset_, limit_, filter_, random_id_, get_tries() == 3, offset_, limit_, filter_, top_thread_message_id_,
std::move(promise)); random_id_, get_tries() == 3, std::move(promise));
} }
void do_send_result() override { void do_send_result() override {
@ -1424,7 +1425,7 @@ class SearchChatMessagesRequest : public RequestActor<> {
public: public:
SearchChatMessagesRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id, string query, int32 user_id, SearchChatMessagesRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id, string query, int32 user_id,
int64 from_message_id, int32 offset, int32 limit, int64 from_message_id, int32 offset, int32 limit,
tl_object_ptr<td_api::SearchMessagesFilter> filter) tl_object_ptr<td_api::SearchMessagesFilter> filter, int64 message_thread_id)
: RequestActor(std::move(td), request_id) : RequestActor(std::move(td), request_id)
, dialog_id_(dialog_id) , dialog_id_(dialog_id)
, query_(std::move(query)) , query_(std::move(query))
@ -1433,6 +1434,7 @@ class SearchChatMessagesRequest : public RequestActor<> {
, offset_(offset) , offset_(offset)
, limit_(limit) , limit_(limit)
, filter_(get_message_search_filter(filter)) , filter_(get_message_search_filter(filter))
, top_thread_message_id_(message_thread_id)
, random_id_(0) { , random_id_(0) {
set_tries(3); set_tries(3);
} }
@ -1479,14 +1481,16 @@ class SearchMessagesRequest : public RequestActor<> {
MessageId offset_message_id_; MessageId offset_message_id_;
int32 limit_; int32 limit_;
MessageSearchFilter filter_; MessageSearchFilter filter_;
int32 min_date_;
int32 max_date_;
int64 random_id_; int64 random_id_;
std::pair<int32, vector<FullMessageId>> messages_; std::pair<int32, vector<FullMessageId>> messages_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
messages_ = messages_ = td->messages_manager_->search_messages(folder_id_, ignore_folder_id_, query_, offset_date_,
td->messages_manager_->search_messages(folder_id_, ignore_folder_id_, query_, offset_date_, offset_dialog_id_, offset_dialog_id_, offset_message_id_, limit_, filter_,
offset_message_id_, limit_, filter_, random_id_, std::move(promise)); min_date_, max_date_, random_id_, std::move(promise));
} }
void do_send_result() override { void do_send_result() override {
@ -1505,7 +1509,7 @@ class SearchMessagesRequest : public RequestActor<> {
public: public:
SearchMessagesRequest(ActorShared<Td> td, uint64 request_id, FolderId folder_id, bool ignore_folder_id, string query, SearchMessagesRequest(ActorShared<Td> td, uint64 request_id, FolderId folder_id, bool ignore_folder_id, string query,
int32 offset_date, int64 offset_dialog_id, int64 offset_message_id, int32 limit, int32 offset_date, int64 offset_dialog_id, int64 offset_message_id, int32 limit,
tl_object_ptr<td_api::SearchMessagesFilter> &&filter) tl_object_ptr<td_api::SearchMessagesFilter> &&filter, int32 min_date, int32 max_date)
: RequestActor(std::move(td), request_id) : RequestActor(std::move(td), request_id)
, folder_id_(folder_id) , folder_id_(folder_id)
, ignore_folder_id_(ignore_folder_id) , ignore_folder_id_(ignore_folder_id)
@ -1515,6 +1519,8 @@ class SearchMessagesRequest : public RequestActor<> {
, offset_message_id_(offset_message_id) , offset_message_id_(offset_message_id)
, limit_(limit) , limit_(limit)
, filter_(get_message_search_filter(filter)) , filter_(get_message_search_filter(filter))
, min_date_(min_date)
, max_date_(max_date)
, random_id_(0) { , random_id_(0) {
} }
}; };
@ -5477,7 +5483,8 @@ void Td::on_request(uint64 id, td_api::searchChatMessages &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.query_); CLEAN_INPUT_STRING(request.query_);
CREATE_REQUEST(SearchChatMessagesRequest, request.chat_id_, std::move(request.query_), request.sender_user_id_, CREATE_REQUEST(SearchChatMessagesRequest, request.chat_id_, std::move(request.query_), request.sender_user_id_,
request.from_message_id_, request.offset_, request.limit_, std::move(request.filter_)); request.from_message_id_, request.offset_, request.limit_, std::move(request.filter_),
request.message_thread_id_);
} }
void Td::on_request(uint64 id, td_api::searchSecretMessages &request) { void Td::on_request(uint64 id, td_api::searchSecretMessages &request) {
@ -5497,7 +5504,7 @@ void Td::on_request(uint64 id, td_api::searchMessages &request) {
} }
CREATE_REQUEST(SearchMessagesRequest, dialog_list_id.get_folder_id(), request.chat_list_ == nullptr, CREATE_REQUEST(SearchMessagesRequest, dialog_list_id.get_folder_id(), request.chat_list_ == nullptr,
std::move(request.query_), request.offset_date_, request.offset_chat_id_, request.offset_message_id_, std::move(request.query_), request.offset_date_, request.offset_chat_id_, request.offset_message_id_,
request.limit_, std::move(request.filter_)); request.limit_, std::move(request.filter_), request.min_date_, request.max_date_);
} }
void Td::on_request(uint64 id, td_api::searchCallMessages &request) { void Td::on_request(uint64 id, td_api::searchCallMessages &request) {

View File

@ -400,15 +400,9 @@ bool UpdatesManager::is_acceptable_message_forward_header(
} }
auto flags = header->flags_; auto flags = header->flags_;
if (flags & telegram_api::messageFwdHeader::CHANNEL_ID_MASK) {
ChannelId channel_id(header->channel_id_);
if (!is_acceptable_channel(channel_id)) {
return false;
}
}
if (flags & telegram_api::messageFwdHeader::FROM_ID_MASK) { if (flags & telegram_api::messageFwdHeader::FROM_ID_MASK) {
UserId user_id(header->from_id_); DialogId dialog_id(header->from_id_);
if (!is_acceptable_user(user_id)) { if (!is_acceptable_dialog(dialog_id)) {
return false; return false;
} }
} }
@ -431,11 +425,11 @@ bool UpdatesManager::is_acceptable_message(const telegram_api::Message *message_
case telegram_api::message::ID: { case telegram_api::message::ID: {
auto message = static_cast<const telegram_api::message *>(message_ptr); auto message = static_cast<const telegram_api::message *>(message_ptr);
if (!is_acceptable_dialog(DialogId(message->to_id_))) { if (!is_acceptable_dialog(DialogId(message->peer_id_))) {
return false; return false;
} }
if (message->flags_ & MessagesManager::MESSAGE_FLAG_HAS_FROM_ID) { if (message->flags_ & MessagesManager::MESSAGE_FLAG_HAS_FROM_ID) {
if (!is_acceptable_user(UserId(message->from_id_))) { if (!is_acceptable_dialog(DialogId(message->from_id_))) {
return false; return false;
} }
} }
@ -522,11 +516,11 @@ bool UpdatesManager::is_acceptable_message(const telegram_api::Message *message_
case telegram_api::messageService::ID: { case telegram_api::messageService::ID: {
auto message = static_cast<const telegram_api::messageService *>(message_ptr); auto message = static_cast<const telegram_api::messageService *>(message_ptr);
if (!is_acceptable_dialog(DialogId(message->to_id_))) { if (!is_acceptable_dialog(DialogId(message->peer_id_))) {
return false; return false;
} }
if (message->flags_ & MessagesManager::MESSAGE_FLAG_HAS_FROM_ID) { if (message->flags_ & MessagesManager::MESSAGE_FLAG_HAS_FROM_ID) {
if (!is_acceptable_user(UserId(message->from_id_))) { if (!is_acceptable_dialog(DialogId(message->from_id_))) {
return false; return false;
} }
} }
@ -698,18 +692,20 @@ void UpdatesManager::on_get_updates(tl_object_ptr<telegram_api::Updates> &&updat
auto from_id = update->flags_ & MessagesManager::MESSAGE_FLAG_IS_OUT ? td_->contacts_manager_->get_my_id().get() auto from_id = update->flags_ & MessagesManager::MESSAGE_FLAG_IS_OUT ? td_->contacts_manager_->get_my_id().get()
: update->user_id_; : update->user_id_;
auto peer_id = update->flags_ & MessagesManager::MESSAGE_FLAG_IS_OUT ? update->user_id_
: td_->contacts_manager_->get_my_id().get();
update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID; update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID;
on_pending_update( on_pending_update(make_tl_object<telegram_api::updateNewMessage>(
make_tl_object<telegram_api::updateNewMessage>( make_tl_object<telegram_api::message>(
make_tl_object<telegram_api::message>( update->flags_, false /*ignored*/, false /*ignored*/, false /*ignored*/,
update->flags_, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, update->id_, from_id, false /*ignored*/, update->id_, make_tl_object<telegram_api::peerUser>(from_id),
make_tl_object<telegram_api::peerUser>(update->user_id_), std::move(update->fwd_from_), make_tl_object<telegram_api::peerUser>(peer_id), std::move(update->fwd_from_),
update->via_bot_id_, update->reply_to_msg_id_, 0, update->date_, update->message_, nullptr, nullptr, update->via_bot_id_, std::move(update->reply_to_), update->date_, update->message_,
std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, Auto()), nullptr, nullptr, std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, Auto()),
update->pts_, update->pts_count_), update->pts_, update->pts_count_),
0, "telegram_api::updatesShortMessage"); 0, "telegram_api::updatesShortMessage");
break; break;
} }
case telegram_api::updateShortChatMessage::ID: { case telegram_api::updateShortChatMessage::ID: {
@ -724,16 +720,17 @@ void UpdatesManager::on_get_updates(tl_object_ptr<telegram_api::Updates> &&updat
} }
update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID; update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID;
on_pending_update(make_tl_object<telegram_api::updateNewMessage>( on_pending_update(
make_tl_object<telegram_api::message>( make_tl_object<telegram_api::updateNewMessage>(
update->flags_, false /*ignored*/, false /*ignored*/, false /*ignored*/, make_tl_object<telegram_api::message>(
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, update->flags_, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, update->id_, update->from_id_, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, update->id_,
make_tl_object<telegram_api::peerChat>(update->chat_id_), std::move(update->fwd_from_), make_tl_object<telegram_api::peerUser>(update->from_id_),
update->via_bot_id_, update->reply_to_msg_id_, 0, update->date_, update->message_, make_tl_object<telegram_api::peerChat>(update->chat_id_), std::move(update->fwd_from_),
nullptr, nullptr, std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, Auto()), update->via_bot_id_, std::move(update->reply_to_), update->date_, update->message_, nullptr, nullptr,
update->pts_, update->pts_count_), std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, Auto()),
0, "telegram_api::updatesShortChatMessage"); update->pts_, update->pts_count_),
0, "telegram_api::updatesShortChatMessage");
break; break;
} }
case telegram_api::updateShort::ID: { case telegram_api::updateShort::ID: {

View File

@ -323,7 +323,7 @@ class CliClient final : public Actor {
LOG(ERROR) << (last_message_id >> 20); LOG(ERROR) << (last_message_id >> 20);
send_request(td_api::make_object<td_api::searchChatMessages>( send_request(td_api::make_object<td_api::searchChatMessages>(
search_chat_id_, "", 0, last_message_id, 0, 100, search_chat_id_, "", 0, last_message_id, 0, 100,
td_api::make_object<td_api::searchMessagesFilterPhotoAndVideo>())); td_api::make_object<td_api::searchMessagesFilterPhotoAndVideo>(), 0));
} else { } else {
search_chat_id_ = 0; search_chat_id_ = 0;
} }
@ -1869,7 +1869,7 @@ class CliClient final : public Actor {
search_chat_id_ = as_chat_id(args); search_chat_id_ = as_chat_id(args);
send_request(td_api::make_object<td_api::searchChatMessages>( send_request(td_api::make_object<td_api::searchChatMessages>(
search_chat_id_, "", 0, 0, 0, 100, td_api::make_object<td_api::searchMessagesFilterPhotoAndVideo>())); search_chat_id_, "", 0, 0, 0, 100, td_api::make_object<td_api::searchMessagesFilterPhotoAndVideo>(), 0));
} else if (op == "Search" || op == "SearchA" || op == "SearchM") { } else if (op == "Search" || op == "SearchA" || op == "SearchM") {
string from_date; string from_date;
string limit; string limit;
@ -1890,8 +1890,8 @@ class CliClient final : public Actor {
chat_list = td_api::make_object<td_api::chatListMain>(); chat_list = td_api::make_object<td_api::chatListMain>();
} }
send_request(td_api::make_object<td_api::searchMessages>( send_request(td_api::make_object<td_api::searchMessages>(
std::move(chat_list), query, to_integer<int32>(from_date), 2147482647, 0, to_integer<int32>(limit), std::move(chat_list), query, to_integer<int32>(from_date), 2147483647, 0, to_integer<int32>(limit),
as_search_messages_filter(filter))); as_search_messages_filter(filter), 1, 2147483647));
} else if (op == "SCM") { } else if (op == "SCM") {
string chat_id; string chat_id;
string limit; string limit;
@ -1904,7 +1904,7 @@ class CliClient final : public Actor {
} }
send_request(td_api::make_object<td_api::searchChatMessages>(as_chat_id(chat_id), query, 0, 0, 0, send_request(td_api::make_object<td_api::searchChatMessages>(as_chat_id(chat_id), query, 0, 0, 0,
to_integer<int32>(limit), nullptr)); to_integer<int32>(limit), nullptr, 0));
} else if (op == "SMME") { } else if (op == "SMME") {
string chat_id; string chat_id;
string limit; string limit;
@ -1915,7 +1915,7 @@ class CliClient final : public Actor {
} }
send_request(td_api::make_object<td_api::searchChatMessages>(as_chat_id(chat_id), "", my_id_, 0, 0, send_request(td_api::make_object<td_api::searchChatMessages>(as_chat_id(chat_id), "", my_id_, 0, 0,
to_integer<int32>(limit), nullptr)); to_integer<int32>(limit), nullptr, 0));
} else if (op == "SMU") { } else if (op == "SMU") {
string chat_id; string chat_id;
string user_id; string user_id;
@ -1928,7 +1928,7 @@ class CliClient final : public Actor {
} }
send_request(td_api::make_object<td_api::searchChatMessages>(as_chat_id(chat_id), "", as_user_id(user_id), 0, 0, send_request(td_api::make_object<td_api::searchChatMessages>(as_chat_id(chat_id), "", as_user_id(user_id), 0, 0,
to_integer<int32>(limit), nullptr)); to_integer<int32>(limit), nullptr, 0));
} else if (op == "SM") { } else if (op == "SM") {
string chat_id; string chat_id;
string filter; string filter;
@ -1952,7 +1952,7 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::searchChatMessages>( send_request(td_api::make_object<td_api::searchChatMessages>(
as_chat_id(chat_id), "", 0, as_message_id(offset_message_id), to_integer<int32>(offset), as_chat_id(chat_id), "", 0, as_message_id(offset_message_id), to_integer<int32>(offset),
to_integer<int32>(limit), as_search_messages_filter(filter))); to_integer<int32>(limit), as_search_messages_filter(filter), 0));
} else if (op == "SC") { } else if (op == "SC") {
string limit; string limit;
string offset_message_id; string offset_message_id;
@ -1997,7 +1997,7 @@ class CliClient final : public Actor {
} }
send_request(td_api::make_object<td_api::searchChatMessages>( send_request(td_api::make_object<td_api::searchChatMessages>(
as_chat_id(chat_id), query, 0, as_message_id(offset_message_id), 0, to_integer<int32>(limit), as_chat_id(chat_id), query, 0, as_message_id(offset_message_id), 0, to_integer<int32>(limit),
td_api::make_object<td_api::searchMessagesFilterAudio>())); td_api::make_object<td_api::searchMessagesFilterAudio>(), 0));
} else if (op == "SearchDocument") { } else if (op == "SearchDocument") {
string chat_id; string chat_id;
string offset_message_id; string offset_message_id;
@ -2015,7 +2015,7 @@ class CliClient final : public Actor {
} }
send_request(td_api::make_object<td_api::searchChatMessages>( send_request(td_api::make_object<td_api::searchChatMessages>(
as_chat_id(chat_id), query, 0, to_integer<int64>(offset_message_id), 0, to_integer<int32>(limit), as_chat_id(chat_id), query, 0, to_integer<int64>(offset_message_id), 0, to_integer<int32>(limit),
td_api::make_object<td_api::searchMessagesFilterDocument>())); td_api::make_object<td_api::searchMessagesFilterDocument>(), 0));
} else if (op == "SearchPhoto") { } else if (op == "SearchPhoto") {
string chat_id; string chat_id;
string offset_message_id; string offset_message_id;
@ -2033,7 +2033,7 @@ class CliClient final : public Actor {
} }
send_request(td_api::make_object<td_api::searchChatMessages>( send_request(td_api::make_object<td_api::searchChatMessages>(
as_chat_id(chat_id), query, 0, as_message_id(offset_message_id), 0, to_integer<int32>(limit), as_chat_id(chat_id), query, 0, as_message_id(offset_message_id), 0, to_integer<int32>(limit),
td_api::make_object<td_api::searchMessagesFilterPhoto>())); td_api::make_object<td_api::searchMessagesFilterPhoto>(), 0));
} else if (op == "SearchChatPhoto") { } else if (op == "SearchChatPhoto") {
string chat_id; string chat_id;
string offset_message_id; string offset_message_id;
@ -2051,7 +2051,7 @@ class CliClient final : public Actor {
} }
send_request(td_api::make_object<td_api::searchChatMessages>( send_request(td_api::make_object<td_api::searchChatMessages>(
as_chat_id(chat_id), query, 0, as_message_id(offset_message_id), 0, to_integer<int32>(limit), as_chat_id(chat_id), query, 0, as_message_id(offset_message_id), 0, to_integer<int32>(limit),
td_api::make_object<td_api::searchMessagesFilterChatPhoto>())); td_api::make_object<td_api::searchMessagesFilterChatPhoto>(), 0));
} else if (op == "gcmc") { } else if (op == "gcmc") {
string chat_id; string chat_id;
string filter; string filter;