Add td_api::chatPosition instead of order, is_pinned and source.

GitOrigin-RevId: b1abfde7442368e062a505e179d5510daea7335a
This commit is contained in:
levlam 2020-05-08 15:48:25 +03:00
parent 86440b8a7b
commit 0613614651
4 changed files with 76 additions and 63 deletions

View File

@ -658,7 +658,7 @@ chatListMain = ChatList;
chatListArchive = ChatList;
//@class ChatSource @description Describes a reason why the chat is shown in a chat list
//@class ChatSource @description Describes a reason why an external chat is shown in a chat list
//@description The chat is sponsored by the user's MTProxy server
chatSourceMtprotoProxy = ChatSource;
@ -667,6 +667,14 @@ chatSourceMtprotoProxy = ChatSource;
chatSourcePublicServiceAnnouncement type:string text:string = ChatSource;
//@description Describes a position of a chat in a chat list
//@list The chat list
//@order A parameter used to determine order of the chat in the chat list. Chats must be sorted by the pair (order, chat.id) in descending order. If 0, the position of the chat in the list is undetermined
//@is_pinned True, if the chat is pinned in the chat list
//@source Source of the chat in the chat list; may be null
chatPosition list:ChatList order:int64 is_pinned:Bool source:ChatSource = ChatPosition;
//@description A chat. (Can be a private chat, basic group, supergroup, or secret chat)
//@id Chat unique identifier
//@type Type of the chat
@ -675,9 +683,7 @@ chatSourcePublicServiceAnnouncement type:string text:string = ChatSource;
//@photo Chat photo; may be null
//@permissions Actions that non-administrator chat members are allowed to take in the chat
//@last_message Last message in the chat; may be null
//@order Descending parameter by which chats are sorted in the main chat list. If the order number of two chats is the same, they must be sorted in descending order by ID. If 0, the position of the chat in the list is undetermined
//@source Source of the chat in a chat list; may be null
//@is_pinned True, if the chat is pinned
//@positions Positions of the chat in chat lists
//@is_marked_as_unread True, if the chat is marked as unread
//@has_scheduled_messages True, if the chat has scheduled messages
//@can_be_deleted_only_for_self True, if the chat messages can be deleted only for the current user while other users will continue to see the messages
@ -693,8 +699,8 @@ chatSourcePublicServiceAnnouncement type:string text:string = ChatSource;
//@pinned_message_id Identifier of the pinned message in the chat; 0 if none
//@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat
//@draft_message A draft of a message in the chat; may be null
//@client_data Contains client-specific data associated with the chat. (For example, the chat position or local chat notification settings can be stored here.) Persistent if the message database is used
chat id:int53 type:ChatType chat_list:ChatList title:string photo:chatPhoto permissions:chatPermissions last_message:message order:int64 source:ChatSource is_pinned:Bool is_marked_as_unread:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings action_bar:ChatActionBar pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
//@client_data Contains client-specific data associated with the chat. (For example, the chat scroll position or local chat notification settings can be stored here.) Persistent if the message database is used
chat id:int53 type:ChatType chat_list:ChatList title:string photo:chatPhoto permissions:chatPermissions last_message:message positions:vector<chatPosition> is_marked_as_unread:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings action_bar:ChatActionBar pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
//@description Represents a list of chats @chat_ids List of chat identifiers
chats chat_ids:vector<int53> = Chats;
@ -2879,7 +2885,7 @@ updateMessageLiveLocationViewed chat_id:int53 message_id:int53 = Update;
//@description A new chat has been loaded/created. This update is guaranteed to come before the chat identifier is returned to the client. The chat field changes will be reported through separate updates @chat The chat
updateNewChat chat:chat = Update;
//@description The list to which the chat belongs was changed. This update is guaranteed to be sent only when chat.order == 0 and the current or the new chat list is null @chat_id Chat identifier @chat_list The new chat's chat list; may be null
//@description The list to which the chat belongs was changed @chat_id Chat identifier @chat_list The new chat's chat list; may be null
updateChatChatList chat_id:int53 chat_list:ChatList = Update;
//@description The title of a chat was changed @chat_id Chat identifier @title The new chat title
@ -2891,21 +2897,15 @@ updateChatPhoto chat_id:int53 photo:chatPhoto = Update;
//@description Chat permissions was changed @chat_id Chat identifier @permissions The new chat permissions
updateChatPermissions chat_id:int53 permissions:chatPermissions = Update;
//@description The last message of a chat was changed. If last_message is null, then the last message in the chat became unknown. Some new unknown messages might be added to the chat in this case @chat_id Chat identifier @last_message The new last message in the chat; may be null @order New value of the chat order
updateChatLastMessage chat_id:int53 last_message:message order:int64 = Update;
//@description The last message of a chat was changed. If last_message is null, then the last message in the chat became unknown. Some new unknown messages might be added to the chat in this case @chat_id Chat identifier @last_message The new last message in the chat; may be null @positions The new chat positions in the chat lists
updateChatLastMessage chat_id:int53 last_message:message positions:vector<chatPosition> = Update;
//@description The order of the chat in the chat list has changed. Instead of this update updateChatLastMessage, updateChatIsPinned, updateChatDraftMessage, or updateChatSource might be sent @chat_id Chat identifier @order New value of the order
updateChatOrder chat_id:int53 order:int64 = Update;
//@description A chat was pinned or unpinned @chat_id Chat identifier @is_pinned New value of is_pinned @order New value of the chat order
updateChatIsPinned chat_id:int53 is_pinned:Bool order:int64 = Update;
//@description The position of a chat in a chat list has changed. Instead of this update updateChatLastMessage or updateChatDraftMessage might be sent @chat_id Chat identifier @position New chat position
updateChatPosition chat_id:int53 position:chatPosition = Update;
//@description A chat was marked as unread or was read @chat_id Chat identifier @is_marked_as_unread New value of is_marked_as_unread
updateChatIsMarkedAsUnread chat_id:int53 is_marked_as_unread:Bool = Update;
//@description A chat's source in the chat list has changed @chat_id Chat identifier @source New chat's source; may be null @order New value of chat order
updateChatSource chat_id:int53 source:ChatSource order:int64 = Update;
//@description A chat's has_scheduled_messages field has changed @chat_id Chat identifier @has_scheduled_messages New value of has_scheduled_messages
updateChatHasScheduledMessages chat_id:int53 has_scheduled_messages:Bool = Update;
@ -2937,8 +2937,8 @@ updateChatPinnedMessage chat_id:int53 pinned_message_id:int53 = Update;
//@chat_id Chat identifier @reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat
updateChatReplyMarkup chat_id:int53 reply_markup_message_id:int53 = Update;
//@description A chat draft has changed. Be aware that the update may come in the currently opened chat but with old content of the draft. If the user has changed the content of the draft, this update shouldn't be applied @chat_id Chat identifier @draft_message The new draft message; may be null @order New value of the chat order
updateChatDraftMessage chat_id:int53 draft_message:draftMessage order:int64 = Update;
//@description A chat draft has changed. Be aware that the update may come in the currently opened chat but with old content of the draft. If the user has changed the content of the draft, this update shouldn't be applied @chat_id Chat identifier @draft_message The new draft message; may be null @positions The new chat positions in the chat lists
updateChatDraftMessage chat_id:int53 draft_message:draftMessage positions:vector<chatPosition> = Update;
//@description The number of online group members has changed. This update with non-zero count is sent only for currently opened chats. There is no guarantee that it will be sent just after the count has changed @chat_id Identifier of the chat @online_member_count New number of online members in the chat, or 0 if unknown
updateChatOnlineMemberCount chat_id:int53 online_member_count:int32 = Update;
@ -3295,7 +3295,7 @@ getFile file_id:int32 = File;
//@remote_file_id Remote identifier of the file to get @file_type File type, if known
getRemoteFile remote_file_id:string file_type:FileType = File;
//@description Returns an ordered list of chats in a chat list. Chats are sorted by the pair (order, chat_id) in decreasing order. (For example, to get a list of chats from the beginning, the offset_order should be equal to a biggest signed 64-bit number 9223372036854775807 == 2^63 - 1).
//@description Returns an ordered list of chats in a chat list. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. (For example, to get a list of chats from the beginning, the offset_order should be equal to a biggest signed 64-bit number 9223372036854775807 == 2^63 - 1).
//-For optimal performance the number of returned chats is chosen by the library
//@chat_list The chat list in which to return chats
//@offset_order Chat order to return chats from @offset_chat_id Chat identifier to return chats from
@ -3308,10 +3308,10 @@ searchPublicChat username:string = Chat;
//@description Searches public chats by looking for specified query in their username and title. Currently only private chats, supergroups and channels can be public. Returns a meaningful number of results. Returns nothing if the length of the searched username prefix is less than 5. Excludes private chats with contacts and chats from the chat list from the results @query Query to search for
searchPublicChats query:string = Chats;
//@description Searches for the specified query in the title and username of already known chats, this is an offline request. Returns chats in the order seen in the chat list @query Query to search for. If the query is empty, returns up to 20 recently found chats @limit The maximum number of chats to be returned
//@description Searches for the specified query in the title and username of already known chats, this is an offline request. Returns chats in the order seen in the main chat list @query Query to search for. If the query is empty, returns up to 20 recently found chats @limit The maximum number of chats to be returned
searchChats query:string limit:int32 = Chats;
//@description Searches for the specified query in the title and username of already known chats via request to the server. Returns chats in the order seen in the chat list @query Query to search for @limit The maximum number of chats to be returned
//@description Searches for the specified query in the title and username of already known chats via request to the server. Returns chats in the order seen in the main chat list @query Query to search for @limit The maximum number of chats to be returned
searchChatsOnServer query:string limit:int32 = Chats;
//@description Returns a list of users and location-based supergroups nearby. The list of users nearby will be updated for 60 seconds after the request by the updates updateUsersNearby. The request should be sent again every 25 seconds with adjusted location to not miss new chats @location Current user location
@ -3703,7 +3703,7 @@ setChatDraftMessage chat_id:int53 draft_message:draftMessage = Ok;
//@chat_id Chat identifier @notification_settings New notification settings for the chat. If the chat is muted for more than 1 week, it is considered to be muted forever
setChatNotificationSettings chat_id:int53 notification_settings:chatNotificationSettings = Ok;
//@description Changes the pinned state of a chat. You can pin up to GetOption("pinned_chat_count_max")/GetOption("pinned_archived_chat_count_max") non-secret chats and the same number of secret chats in the main/archive chat list @chat_id Chat identifier @is_pinned New value of is_pinned
//@description Changes the pinned state of a chat. You can pin up to GetOption("pinned_chat_count_max")/GetOption("pinned_archived_chat_count_max") non-secret chats and the same number of secret chats in the main/archive chat list @chat_id Chat identifier @is_pinned True, if the chat is pinned
toggleChatIsPinned chat_id:int53 is_pinned:Bool = Ok;
//@description Changes the marked as unread state of a chat @chat_id Chat identifier @is_marked_as_unread New value of is_marked_as_unread

Binary file not shown.

View File

@ -12047,9 +12047,7 @@ bool MessagesManager::set_dialog_is_pinned(FolderId folder_id, Dialog *d, bool i
LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in set_dialog_is_pinned";
update_dialog_pos(d, "set_dialog_is_pinned", false);
send_closure(
G()->td(), &Td::send_update,
make_tl_object<td_api::updateChatIsPinned>(d->dialog_id.get(), is_pinned, get_dialog_public_order(folder_id, d)));
send_update_chat_position(folder_id, d);
return true;
}
@ -15798,8 +15796,7 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *
d->dialog_id.get(), get_chat_type_object(d->dialog_id), get_chat_list_object(d), get_dialog_title(d->dialog_id),
get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
get_dialog_permissions(d->dialog_id).get_chat_permissions_object(),
get_message_object(d->dialog_id, get_message(d, d->last_message_id)), get_dialog_order_object(d),
std::move(chat_source), get_dialog_pinned_order(d->folder_id, d->dialog_id) != DEFAULT_ORDER,
get_message_object(d->dialog_id, get_message(d, d->last_message_id)), get_chat_positions_object(d),
d->is_marked_as_unread, get_dialog_has_scheduled_messages(d), can_delete_for_self, can_delete_for_all_users,
can_report_dialog(d->dialog_id), d->notification_settings.silent_send_message,
d->server_unread_count + d->local_unread_count, d->last_read_inbox_message_id.get(),
@ -23111,7 +23108,7 @@ void MessagesManager::send_update_chat_draft_message(const Dialog *d) {
if (d->draft_message == nullptr || can_send_message(d->dialog_id).is_ok()) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateChatDraftMessage>(
d->dialog_id.get(), get_draft_message_object(d->draft_message), get_dialog_order_object(d)));
d->dialog_id.get(), get_draft_message_object(d->draft_message), get_chat_positions_object(d)));
}
}
@ -23127,7 +23124,7 @@ void MessagesManager::send_update_chat_last_message_impl(const Dialog *d, const
LOG(INFO) << "Send updateChatLastMessage in " << d->dialog_id << " to " << d->last_message_id << " from " << source;
auto update = make_tl_object<td_api::updateChatLastMessage>(
d->dialog_id.get(), get_message_object(d->dialog_id, get_message(d, d->last_message_id)),
get_dialog_order_object(d));
get_chat_positions_object(d));
send_closure(G()->td(), &Td::send_update, std::move(update));
}
@ -23269,19 +23266,16 @@ void MessagesManager::send_update_chat_unread_mention_count(const Dialog *d) {
make_tl_object<td_api::updateChatUnreadMentionCount>(d->dialog_id.get(), d->unread_mention_count));
}
void MessagesManager::send_update_chat_source(const Dialog *d) const {
void MessagesManager::send_update_chat_position(FolderId folder_id, const Dialog *d) const {
if (td_->auth_manager_->is_bot()) {
return;
}
CHECK(d != nullptr);
LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in send_update_chat_source";
LOG(INFO) << "Update chat is sponsored for " << d->dialog_id;
send_closure(
G()->td(), &Td::send_update,
make_tl_object<td_api::updateChatSource>(
d->dialog_id.get(), is_dialog_sponsored(d) ? sponsored_dialog_source_.get_chat_source_object() : nullptr,
get_dialog_order_object(d)));
LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in send_update_chat_position";
LOG(INFO) << "Update chat position for " << d->dialog_id;
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateChatPosition>(d->dialog_id.get(), get_chat_position_object(folder_id, d)));
}
void MessagesManager::send_update_chat_online_member_count(DialogId dialog_id, int32 online_member_count) const {
@ -24298,18 +24292,12 @@ void MessagesManager::set_dialog_folder_id(Dialog *d, FolderId folder_id) {
// first remove the dialog from the old chat list
// this will send updateChatChatList if needed
DialogId sponsored_dialog_id = sponsored_dialog_id_;
if (d->dialog_id == sponsored_dialog_id_ && d->order != DEFAULT_ORDER) {
sponsored_dialog_id_ = DialogId(); // supress updateChatSource
}
set_dialog_order(d, DEFAULT_ORDER, true, false, "set_dialog_folder_id old");
// change the folder
d->folder_id = folder_id;
d->is_folder_id_inited = true;
sponsored_dialog_id_ = sponsored_dialog_id;
// update dialog position in the new folder
// this will send updateChatChatList if needed
update_dialog_pos(d, "set_dialog_folder_id new");
@ -28649,8 +28637,37 @@ int64 MessagesManager::get_dialog_public_order(const DialogList *list, const Dia
return dialog_date <= list->last_dialog_date_ ? order : 0;
}
int64 MessagesManager::get_dialog_order_object(const Dialog *d) const {
return get_dialog_public_order(d->folder_id, d);
td_api::object_ptr<td_api::chatPosition> MessagesManager::get_chat_position_object(FolderId folder_id,
const Dialog *d) const {
if (td_->auth_manager_->is_bot()) {
return nullptr;
}
auto *list = get_dialog_list(folder_id);
if (list == nullptr) {
return nullptr;
}
auto order = get_dialog_private_order(list, d);
DialogDate dialog_date(order, d->dialog_id);
if (list->last_dialog_date_ < dialog_date || order == 0) {
return nullptr;
}
bool is_pinned = get_dialog_pinned_order(list, d->dialog_id) != DEFAULT_ORDER;
return td_api::make_object<td_api::chatPosition>(get_chat_list_object(folder_id), order, is_pinned,
sponsored_dialog_source_.get_chat_source_object());
}
vector<td_api::object_ptr<td_api::chatPosition>> MessagesManager::get_chat_positions_object(const Dialog *d) const {
vector<td_api::object_ptr<td_api::chatPosition>> positions;
if (!td_->auth_manager_->is_bot()) {
auto position = get_chat_position_object(d->folder_id, d);
if (position != nullptr) {
positions.push_back(std::move(position));
}
}
return positions;
}
int64 MessagesManager::get_next_pinned_dialog_order() {
@ -28819,8 +28836,6 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
}
list.pinned_dialog_id_orders_.erase(d->dialog_id);
on_pinned_dialogs_updated(d->folder_id);
send_closure(G()->td(), &Td::send_update, make_tl_object<td_api::updateChatIsPinned>(d->dialog_id.get(), false, 0));
old_public_order = 0;
}
bool need_update_unread_chat_count = old_dialog_total_count != get_dialog_total_count(list);
@ -28888,8 +28903,7 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
auto new_public_order = get_dialog_public_order(&list, d);
if (is_removed_from_folder && d->folder_id != FolderId::main()) {
if (new_public_order != old_public_order) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateChatOrder>(dialog_id.get(), new_public_order));
send_update_chat_position(d->folder_id, d);
old_public_order = new_public_order;
}
@ -28910,7 +28924,7 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
send_update_chat_chat_list(d);
}
if (was_sponsored != is_dialog_sponsored(d)) {
send_update_chat_source(d);
send_update_chat_position(FolderId::main(), d);
if (!is_loaded_from_database && !was_sponsored) {
// channel is sponsored only if user isn't a channel member
remove_all_dialog_notifications(d, false, "set_dialog_order 3");
@ -28919,8 +28933,7 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
old_public_order = new_public_order;
}
if (old_public_order != new_public_order && need_send_update_chat_order) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateChatOrder>(dialog_id.get(), new_public_order));
send_update_chat_position(d->folder_id, d);
}
if (is_removed_from_folder && !(dialog_id == sponsored_dialog_id_ && d->folder_id == FolderId::main())) {
send_update_chat_chat_list(d);
@ -28945,9 +28958,7 @@ void MessagesManager::update_last_dialog_date(FolderId folder_id) {
auto dialog_id = it->get_dialog_id();
auto d = get_dialog(dialog_id);
CHECK(d != nullptr);
send_closure(
G()->td(), &Td::send_update,
make_tl_object<td_api::updateChatIsPinned>(d->dialog_id.get(), true, get_dialog_public_order(folder_id, d)));
send_update_chat_position(folder_id, d);
}
for (auto it = list.ordered_dialogs_.upper_bound(old_last_dialog_date);
@ -28955,7 +28966,7 @@ void MessagesManager::update_last_dialog_date(FolderId folder_id) {
auto dialog_id = it->get_dialog_id();
auto d = get_dialog(dialog_id);
CHECK(d != nullptr);
send_closure(G()->td(), &Td::send_update, make_tl_object<td_api::updateChatOrder>(d->dialog_id.get(), d->order));
send_update_chat_position(folder_id, d);
}
if (list.last_dialog_date_ == MAX_DIALOG_DATE) {
@ -30974,7 +30985,7 @@ void MessagesManager::add_sponsored_dialog(const Dialog *d, DialogSource source)
}
if (is_dialog_sponsored(d)) {
send_update_chat_source(d);
send_update_chat_position(FolderId::main(), d);
// the sponsored dialog must not be saved there
}
}
@ -31009,7 +31020,7 @@ void MessagesManager::set_sponsored_dialog(DialogId dialog_id, DialogSource sour
sponsored_dialog_source_ = std::move(source);
const Dialog *d = get_dialog(sponsored_dialog_id_);
CHECK(d != nullptr);
send_update_chat_source(d);
send_update_chat_position(FolderId::main(), d);
save_sponsored_dialog();
}
return;
@ -31023,8 +31034,8 @@ void MessagesManager::set_sponsored_dialog(DialogId dialog_id, DialogSource sour
sponsored_dialog_id_ = DialogId();
sponsored_dialog_source_ = DialogSource();
if (is_sponsored) {
send_update_chat_source(d);
send_update_chat_chat_list(d);
send_update_chat_position(FolderId::main(), d);
need_update_total_chat_count = true;
}
}
@ -31108,7 +31119,7 @@ void MessagesManager::get_current_state(vector<td_api::object_ptr<td_api::Update
auto update = td_api::make_object<td_api::updateNewChat>(get_chat_object(d));
if (update->chat_->last_message_ != nullptr && update->chat_->last_message_->forward_info_ != nullptr) {
last_message_updates.push_back(td_api::make_object<td_api::updateChatLastMessage>(
d->dialog_id.get(), std::move(update->chat_->last_message_), get_dialog_order_object(d)));
d->dialog_id.get(), std::move(update->chat_->last_message_), get_chat_positions_object(d)));
}
updates.push_back(std::move(update));

View File

@ -1976,7 +1976,7 @@ class MessagesManager : public Actor {
void send_update_chat_unread_mention_count(const Dialog *d);
void send_update_chat_source(const Dialog *d) const;
void send_update_chat_position(FolderId folder_id, const Dialog *d) const;
void send_update_chat_online_member_count(DialogId dialog_id, int32 online_member_count) const;
@ -2329,7 +2329,9 @@ class MessagesManager : public Actor {
int64 get_dialog_public_order(const DialogList *list, const Dialog *d) const;
int64 get_dialog_order_object(const Dialog *d) const;
td_api::object_ptr<td_api::chatPosition> get_chat_position_object(FolderId folder_id, const Dialog *d) const;
vector<td_api::object_ptr<td_api::chatPosition>> get_chat_positions_object(const Dialog *d) const;
bool update_dialog_draft_message(Dialog *d, unique_ptr<DraftMessage> &&draft_message, bool from_update,
bool need_update_dialog_pos);