Add main_chat_list_position to updateChatFilters.
This commit is contained in:
parent
d4b6d08268
commit
9f8de1d146
@ -4073,8 +4073,8 @@ updateChatIsBlocked chat_id:int53 is_blocked:Bool = 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
|
//@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;
|
updateChatIsMarkedAsUnread chat_id:int53 is_marked_as_unread:Bool = Update;
|
||||||
|
|
||||||
//@description The list of chat filters or a chat filter has changed @chat_filters The new list of chat filters
|
//@description The list of chat filters or a chat filter has changed @chat_filters The new list of chat filters @main_chat_list_position Position of the main chat list among chat filters, 0-based
|
||||||
updateChatFilters chat_filters:vector<chatFilterInfo> = Update;
|
updateChatFilters chat_filters:vector<chatFilterInfo> main_chat_list_position:int32 = Update;
|
||||||
|
|
||||||
//@description The number of online group members has changed. This update with non-zero number of online group members is sent only for currently opened chats. There is no guarantee that it will be sent just after the number of online users has changed @chat_id Identifier of the chat @online_member_count New number of online members in the chat, or 0 if unknown
|
//@description The number of online group members has changed. This update with non-zero number of online group members is sent only for currently opened chats. There is no guarantee that it will be sent just after the number of online users 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;
|
updateChatOnlineMemberCount chat_id:int53 online_member_count:int32 = Update;
|
||||||
@ -6213,7 +6213,7 @@ addStickerToSet user_id:int53 name:string sticker:inputSticker = StickerSet;
|
|||||||
setStickerSetThumbnail user_id:int53 name:string thumbnail:InputFile = StickerSet;
|
setStickerSetThumbnail user_id:int53 name:string thumbnail:InputFile = StickerSet;
|
||||||
|
|
||||||
//@description Changes the position of a sticker in the set to which it belongs; for bots only. The sticker set must have been created by the bot
|
//@description Changes the position of a sticker in the set to which it belongs; for bots only. The sticker set must have been created by the bot
|
||||||
//@sticker Sticker @position New position of the sticker in the set, zero-based
|
//@sticker Sticker @position New position of the sticker in the set, 0-based
|
||||||
setStickerPositionInSet sticker:InputFile position:int32 = Ok;
|
setStickerPositionInSet sticker:InputFile position:int32 = Ok;
|
||||||
|
|
||||||
//@description Removes a sticker from the set to which it belongs; for bots only. The sticker set must have been created by the bot @sticker Sticker
|
//@description Removes a sticker from the set to which it belongs; for bots only. The sticker set must have been created by the bot @sticker Sticker
|
||||||
|
@ -13049,6 +13049,7 @@ void MessagesManager::loop() {
|
|||||||
|
|
||||||
class MessagesManager::DialogFiltersLogEvent {
|
class MessagesManager::DialogFiltersLogEvent {
|
||||||
public:
|
public:
|
||||||
|
int32 main_dialog_list_position = 0;
|
||||||
int32 updated_date = 0;
|
int32 updated_date = 0;
|
||||||
const vector<unique_ptr<DialogFilter>> *server_dialog_filters_in;
|
const vector<unique_ptr<DialogFilter>> *server_dialog_filters_in;
|
||||||
const vector<unique_ptr<DialogFilter>> *dialog_filters_in;
|
const vector<unique_ptr<DialogFilter>> *dialog_filters_in;
|
||||||
@ -13057,17 +13058,49 @@ class MessagesManager::DialogFiltersLogEvent {
|
|||||||
|
|
||||||
template <class StorerT>
|
template <class StorerT>
|
||||||
void store(StorerT &storer) const {
|
void store(StorerT &storer) const {
|
||||||
|
bool has_main_dialog_list_position = main_dialog_list_position != 0;
|
||||||
|
bool has_server_dialog_filters = !server_dialog_filters_in->empty();
|
||||||
|
bool has_dialog_filters = !dialog_filters_in->empty();
|
||||||
|
BEGIN_STORE_FLAGS();
|
||||||
|
STORE_FLAG(has_main_dialog_list_position);
|
||||||
|
STORE_FLAG(has_server_dialog_filters);
|
||||||
|
STORE_FLAG(has_dialog_filters);
|
||||||
|
END_STORE_FLAGS();
|
||||||
td::store(updated_date, storer);
|
td::store(updated_date, storer);
|
||||||
|
if (has_server_dialog_filters) {
|
||||||
td::store(*server_dialog_filters_in, storer);
|
td::store(*server_dialog_filters_in, storer);
|
||||||
|
}
|
||||||
|
if (has_dialog_filters) {
|
||||||
td::store(*dialog_filters_in, storer);
|
td::store(*dialog_filters_in, storer);
|
||||||
}
|
}
|
||||||
|
if (has_main_dialog_list_position) {
|
||||||
|
td::store(main_dialog_list_position, storer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class ParserT>
|
template <class ParserT>
|
||||||
void parse(ParserT &parser) {
|
void parse(ParserT &parser) {
|
||||||
|
bool has_main_dialog_list_position = false;
|
||||||
|
bool has_server_dialog_filters = true;
|
||||||
|
bool has_dialog_filters = true;
|
||||||
|
if (parser.version() >= static_cast<int32>(Version::AddMainDialogListPosition)) {
|
||||||
|
BEGIN_PARSE_FLAGS();
|
||||||
|
PARSE_FLAG(has_main_dialog_list_position);
|
||||||
|
PARSE_FLAG(has_server_dialog_filters);
|
||||||
|
PARSE_FLAG(has_dialog_filters);
|
||||||
|
END_PARSE_FLAGS();
|
||||||
|
}
|
||||||
td::parse(updated_date, parser);
|
td::parse(updated_date, parser);
|
||||||
|
if (has_server_dialog_filters) {
|
||||||
td::parse(server_dialog_filters_out, parser);
|
td::parse(server_dialog_filters_out, parser);
|
||||||
|
}
|
||||||
|
if (has_dialog_filters) {
|
||||||
td::parse(dialog_filters_out, parser);
|
td::parse(dialog_filters_out, parser);
|
||||||
}
|
}
|
||||||
|
if (has_main_dialog_list_position) {
|
||||||
|
td::parse(main_dialog_list_position, parser);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void MessagesManager::tear_down() {
|
void MessagesManager::tear_down() {
|
||||||
@ -13124,6 +13157,12 @@ void MessagesManager::init() {
|
|||||||
if (!dialog_filters.empty()) {
|
if (!dialog_filters.empty()) {
|
||||||
DialogFiltersLogEvent log_event;
|
DialogFiltersLogEvent log_event;
|
||||||
if (log_event_parse(log_event, dialog_filters).is_ok()) {
|
if (log_event_parse(log_event, dialog_filters).is_ok()) {
|
||||||
|
main_dialog_list_position_ = log_event.main_dialog_list_position;
|
||||||
|
if (main_dialog_list_position_ != 0 && !G()->shared_config().get_option_boolean("is_premium")) {
|
||||||
|
LOG(INFO) << "Ignore main chat list position " << main_dialog_list_position_;
|
||||||
|
main_dialog_list_position_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
dialog_filters_updated_date_ = G()->ignore_background_updates() ? 0 : log_event.updated_date;
|
dialog_filters_updated_date_ = G()->ignore_background_updates() ? 0 : log_event.updated_date;
|
||||||
std::unordered_set<DialogFilterId, DialogFilterIdHash> server_dialog_filter_ids;
|
std::unordered_set<DialogFilterId, DialogFilterIdHash> server_dialog_filter_ids;
|
||||||
for (auto &dialog_filter : log_event.server_dialog_filters_out) {
|
for (auto &dialog_filter : log_event.server_dialog_filters_out) {
|
||||||
@ -17121,7 +17160,17 @@ void MessagesManager::on_get_dialog_filters(Result<vector<tl_object_ptr<telegram
|
|||||||
vector<unique_ptr<DialogFilter>> new_server_dialog_filters;
|
vector<unique_ptr<DialogFilter>> new_server_dialog_filters;
|
||||||
LOG(INFO) << "Receive " << filters.size() << " chat filters from server";
|
LOG(INFO) << "Receive " << filters.size() << " chat filters from server";
|
||||||
std::unordered_set<DialogFilterId, DialogFilterIdHash> new_dialog_filter_ids;
|
std::unordered_set<DialogFilterId, DialogFilterIdHash> new_dialog_filter_ids;
|
||||||
|
int32 server_main_dialog_list_position = -1;
|
||||||
|
int32 position = 0;
|
||||||
for (auto &filter : filters) {
|
for (auto &filter : filters) {
|
||||||
|
if (filter->get_id() == telegram_api::dialogFilterDefault::ID) {
|
||||||
|
if (server_main_dialog_list_position == -1) {
|
||||||
|
server_main_dialog_list_position = position;
|
||||||
|
} else {
|
||||||
|
LOG(ERROR) << "Receive duplicate dialogFilterDefault";
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto dialog_filter = DialogFilter::get_dialog_filter(std::move(filter), true);
|
auto dialog_filter = DialogFilter::get_dialog_filter(std::move(filter), true);
|
||||||
if (dialog_filter == nullptr) {
|
if (dialog_filter == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
@ -17133,10 +17182,20 @@ void MessagesManager::on_get_dialog_filters(Result<vector<tl_object_ptr<telegram
|
|||||||
|
|
||||||
sort_dialog_filter_input_dialog_ids(dialog_filter.get(), "on_get_dialog_filters 1");
|
sort_dialog_filter_input_dialog_ids(dialog_filter.get(), "on_get_dialog_filters 1");
|
||||||
new_server_dialog_filters.push_back(std::move(dialog_filter));
|
new_server_dialog_filters.push_back(std::move(dialog_filter));
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
if (server_main_dialog_list_position == -1) {
|
||||||
|
LOG(ERROR) << "Receive no dialogFilterDefault";
|
||||||
|
server_main_dialog_list_position = 0;
|
||||||
|
}
|
||||||
|
if (server_main_dialog_list_position != 0 && !G()->shared_config().get_option_boolean("is_premium")) {
|
||||||
|
LOG(INFO) << "Ignore server main chat list position " << server_main_dialog_list_position;
|
||||||
|
server_main_dialog_list_position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_changed = false;
|
bool is_changed = false;
|
||||||
dialog_filters_updated_date_ = G()->unix_time();
|
dialog_filters_updated_date_ = G()->unix_time();
|
||||||
|
auto old_server_main_dialog_list_position = get_server_main_dialog_list_position();
|
||||||
if (server_dialog_filters_ != new_server_dialog_filters) {
|
if (server_dialog_filters_ != new_server_dialog_filters) {
|
||||||
LOG(INFO) << "Change server chat filters from " << get_dialog_filter_ids(server_dialog_filters_) << " to "
|
LOG(INFO) << "Change server chat filters from " << get_dialog_filter_ids(server_dialog_filters_) << " to "
|
||||||
<< get_dialog_filter_ids(new_server_dialog_filters);
|
<< get_dialog_filter_ids(new_server_dialog_filters);
|
||||||
@ -17225,6 +17284,35 @@ void MessagesManager::on_get_dialog_filters(Result<vector<tl_object_ptr<telegram
|
|||||||
|
|
||||||
server_dialog_filters_ = std::move(new_server_dialog_filters);
|
server_dialog_filters_ = std::move(new_server_dialog_filters);
|
||||||
}
|
}
|
||||||
|
if (old_server_main_dialog_list_position != server_main_dialog_list_position) {
|
||||||
|
int32 main_dialog_list_position = -1;
|
||||||
|
if (server_main_dialog_list_position == 0) {
|
||||||
|
main_dialog_list_position = 0;
|
||||||
|
} else {
|
||||||
|
int32 current_position = 0;
|
||||||
|
int32 current_server_position = 0;
|
||||||
|
for (const auto &dialog_filter : dialog_filters_) {
|
||||||
|
current_position++;
|
||||||
|
if (!dialog_filter->is_empty(true)) {
|
||||||
|
current_server_position++;
|
||||||
|
}
|
||||||
|
if (current_server_position == server_main_dialog_list_position) {
|
||||||
|
main_dialog_list_position = current_position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (main_dialog_list_position == -1) {
|
||||||
|
LOG(INFO) << "Failed to find server position " << server_main_dialog_list_position << " in chat filters";
|
||||||
|
main_dialog_list_position = static_cast<int32>(dialog_filters_.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (main_dialog_list_position != main_dialog_list_position_) {
|
||||||
|
LOG(INFO) << "Change main chat list position from " << main_dialog_list_position_ << " to "
|
||||||
|
<< main_dialog_list_position;
|
||||||
|
main_dialog_list_position_ = main_dialog_list_position;
|
||||||
|
is_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (is_changed || !is_update_chat_filters_sent_) {
|
if (is_changed || !is_update_chat_filters_sent_) {
|
||||||
send_update_chat_filters();
|
send_update_chat_filters();
|
||||||
}
|
}
|
||||||
@ -30365,6 +30453,7 @@ void MessagesManager::save_dialog_filters() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DialogFiltersLogEvent log_event;
|
DialogFiltersLogEvent log_event;
|
||||||
|
log_event.main_dialog_list_position = main_dialog_list_position_;
|
||||||
log_event.updated_date = dialog_filters_updated_date_;
|
log_event.updated_date = dialog_filters_updated_date_;
|
||||||
log_event.server_dialog_filters_in = &server_dialog_filters_;
|
log_event.server_dialog_filters_in = &server_dialog_filters_;
|
||||||
log_event.dialog_filters_in = &dialog_filters_;
|
log_event.dialog_filters_in = &dialog_filters_;
|
||||||
@ -37351,6 +37440,25 @@ const DialogFilter *MessagesManager::get_dialog_filter(DialogFilterId dialog_fil
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 MessagesManager::get_server_main_dialog_list_position() const {
|
||||||
|
int32 current_position = 0;
|
||||||
|
int32 current_server_position = 0;
|
||||||
|
if (current_position == main_dialog_list_position_) {
|
||||||
|
return current_server_position;
|
||||||
|
}
|
||||||
|
for (const auto &dialog_filter : dialog_filters_) {
|
||||||
|
current_position++;
|
||||||
|
if (!dialog_filter->is_empty(true)) {
|
||||||
|
current_server_position++;
|
||||||
|
}
|
||||||
|
if (current_position == main_dialog_list_position_) {
|
||||||
|
return current_server_position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG(WARNING) << "Failed to find server position for " << main_dialog_list_position_ << " in chat filters";
|
||||||
|
return current_server_position;
|
||||||
|
}
|
||||||
|
|
||||||
vector<DialogFilterId> MessagesManager::get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters) {
|
vector<DialogFilterId> MessagesManager::get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters) {
|
||||||
return transform(dialog_filters, [](const auto &dialog_filter) { return dialog_filter->dialog_filter_id; });
|
return transform(dialog_filters, [](const auto &dialog_filter) { return dialog_filter->dialog_filter_id; });
|
||||||
}
|
}
|
||||||
@ -39823,6 +39931,7 @@ td_api::object_ptr<td_api::updateChatFilters> MessagesManager::get_update_chat_f
|
|||||||
for (const auto &filter : dialog_filters_) {
|
for (const auto &filter : dialog_filters_) {
|
||||||
update->chat_filters_.push_back(filter->get_chat_filter_info_object());
|
update->chat_filters_.push_back(filter->get_chat_filter_info_object());
|
||||||
}
|
}
|
||||||
|
update->main_chat_list_position_ = main_dialog_list_position_;
|
||||||
return update;
|
return update;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2794,6 +2794,8 @@ class MessagesManager final : public Actor {
|
|||||||
DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id);
|
DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id);
|
||||||
const DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id) const;
|
const DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id) const;
|
||||||
|
|
||||||
|
int32 get_server_main_dialog_list_position() const;
|
||||||
|
|
||||||
static vector<DialogFilterId> get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters);
|
static vector<DialogFilterId> get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters);
|
||||||
|
|
||||||
static vector<FolderId> get_dialog_filter_folder_ids(const DialogFilter *filter);
|
static vector<FolderId> get_dialog_filter_folder_ids(const DialogFilter *filter);
|
||||||
@ -3540,6 +3542,7 @@ class MessagesManager final : public Actor {
|
|||||||
vector<unique_ptr<DialogFilter>> dialog_filters_;
|
vector<unique_ptr<DialogFilter>> dialog_filters_;
|
||||||
vector<RecommendedDialogFilter> recommended_dialog_filters_;
|
vector<RecommendedDialogFilter> recommended_dialog_filters_;
|
||||||
vector<Promise<Unit>> dialog_filter_reload_queries_;
|
vector<Promise<Unit>> dialog_filter_reload_queries_;
|
||||||
|
int32 main_dialog_list_position_ = 0;
|
||||||
|
|
||||||
FlatHashMap<DialogId, string, DialogIdHash> active_get_channel_differencies_;
|
FlatHashMap<DialogId, string, DialogIdHash> active_get_channel_differencies_;
|
||||||
FlatHashMap<DialogId, uint64, DialogIdHash> get_channel_difference_to_log_event_id_;
|
FlatHashMap<DialogId, uint64, DialogIdHash> get_channel_difference_to_log_event_id_;
|
||||||
|
@ -51,6 +51,7 @@ enum class Version : int32 {
|
|||||||
AddKeyboardButtonFlags, // 35
|
AddKeyboardButtonFlags, // 35
|
||||||
AddAudioFlags,
|
AddAudioFlags,
|
||||||
UseServerForwardAsCopy,
|
UseServerForwardAsCopy,
|
||||||
|
AddMainDialogListPosition,
|
||||||
Next
|
Next
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user