Add chatFilterInfo.has_my_invite_links.

This commit is contained in:
levlam 2023-04-03 15:06:37 +03:00
parent 45a6d9864c
commit 613ab34f09
5 changed files with 29 additions and 5 deletions

View File

@ -1319,7 +1319,8 @@ chatFilter title:string icon:chatFilterIcon is_shareable:Bool pinned_chat_ids:ve
//@id Unique chat filter identifier //@id Unique chat filter identifier
//@title The title of the filter; 1-12 characters without line feeds //@title The title of the filter; 1-12 characters without line feeds
//@icon The chosen or default icon for the chat filter //@icon The chosen or default icon for the chat filter
chatFilterInfo id:int32 title:string icon:chatFilterIcon = ChatFilterInfo; //@has_my_invite_links True, if the chat filter has invite links created by the current user
chatFilterInfo id:int32 title:string icon:chatFilterIcon has_my_invite_links:Bool = ChatFilterInfo;
//@description Contains a chat filter invite link //@description Contains a chat filter invite link
//@invite_link The chat filter invite link //@invite_link The chat filter invite link

View File

@ -83,6 +83,7 @@ unique_ptr<DialogFilter> DialogFilter::get_dialog_filter(
dialog_filter->included_dialog_ids_ = dialog_filter->included_dialog_ids_ =
InputDialogId::get_input_dialog_ids(filter->include_peers_, &added_dialog_ids); InputDialogId::get_input_dialog_ids(filter->include_peers_, &added_dialog_ids);
dialog_filter->is_shareable_ = true; dialog_filter->is_shareable_ = true;
dialog_filter->has_my_invites_ = filter->has_my_invites_;
return dialog_filter; return dialog_filter;
} }
default: default:
@ -140,6 +141,7 @@ Result<unique_ptr<DialogFilter>> DialogFilter::create_dialog_filter(Td *td, Dial
dialog_filter->include_groups_ = filter->include_groups_; dialog_filter->include_groups_ = filter->include_groups_;
dialog_filter->include_channels_ = filter->include_channels_; dialog_filter->include_channels_ = filter->include_channels_;
dialog_filter->is_shareable_ = filter->is_shareable_; dialog_filter->is_shareable_ = filter->is_shareable_;
dialog_filter->has_my_invites_ = false;
TRY_STATUS(dialog_filter->check_limits()); TRY_STATUS(dialog_filter->check_limits());
dialog_filter->sort_input_dialog_ids(td, "create_dialog_filter"); dialog_filter->sort_input_dialog_ids(td, "create_dialog_filter");
@ -290,6 +292,8 @@ Status DialogFilter::check_limits() const {
exclude_archived_ || exclude_read_ || exclude_muted_) { exclude_archived_ || exclude_read_ || exclude_muted_) {
return Status::Error(400, "Shareable folders can't have chat filters"); return Status::Error(400, "Shareable folders can't have chat filters");
} }
} else if (has_my_invites_) {
LOG(ERROR) << "Have shareable folder with invite links";
} }
if (include_contacts_ && include_non_contacts_ && include_bots_ && include_groups_ && include_channels_ && if (include_contacts_ && include_non_contacts_ && include_bots_ && include_groups_ && include_channels_ &&
@ -300,6 +304,10 @@ Status DialogFilter::check_limits() const {
return Status::OK(); return Status::OK();
} }
void DialogFilter::update_from(const DialogFilter &old_filter) {
has_my_invites_ = old_filter.has_my_invites_;
}
string DialogFilter::get_emoji_by_icon_name(const string &icon_name) { string DialogFilter::get_emoji_by_icon_name(const string &icon_name) {
init_icon_names(); init_icon_names();
auto it = icon_name_to_emoji_.find(icon_name); auto it = icon_name_to_emoji_.find(icon_name);
@ -404,6 +412,9 @@ telegram_api::object_ptr<telegram_api::DialogFilter> DialogFilter::get_input_dia
if (!emoji_.empty()) { if (!emoji_.empty()) {
flags |= telegram_api::dialogFilterChatlist::EMOTICON_MASK; flags |= telegram_api::dialogFilterChatlist::EMOTICON_MASK;
} }
if (has_my_invites_) {
flags |= telegram_api::dialogFilterChatlist::HAS_MY_INVITES_MASK;
}
return telegram_api::make_object<telegram_api::dialogFilterChatlist>( return telegram_api::make_object<telegram_api::dialogFilterChatlist>(
flags, false /*ignored*/, dialog_filter_id_.get(), title_, emoji_, flags, false /*ignored*/, dialog_filter_id_.get(), title_, emoji_,
InputDialogId::get_input_peers(pinned_dialog_ids_), InputDialogId::get_input_peers(included_dialog_ids_)); InputDialogId::get_input_peers(pinned_dialog_ids_), InputDialogId::get_input_peers(included_dialog_ids_));
@ -471,7 +482,8 @@ td_api::object_ptr<td_api::chatFilter> DialogFilter::get_chat_filter_object(
td_api::object_ptr<td_api::chatFilterInfo> DialogFilter::get_chat_filter_info_object() const { td_api::object_ptr<td_api::chatFilterInfo> DialogFilter::get_chat_filter_info_object() const {
return td_api::make_object<td_api::chatFilterInfo>( return td_api::make_object<td_api::chatFilterInfo>(
dialog_filter_id_.get(), title_, td_api::make_object<td_api::chatFilterIcon>(get_chosen_or_default_icon_name())); dialog_filter_id_.get(), title_, td_api::make_object<td_api::chatFilterIcon>(get_chosen_or_default_icon_name()),
has_my_invites_);
} }
void DialogFilter::for_each_dialog(std::function<void(const InputDialogId &)> callback) const { void DialogFilter::for_each_dialog(std::function<void(const InputDialogId &)> callback) const {
@ -618,6 +630,7 @@ unique_ptr<DialogFilter> DialogFilter::merge_dialog_filter_changes(const DialogF
update_value(new_filter->include_channels_, old_server_filter->include_channels_, update_value(new_filter->include_channels_, old_server_filter->include_channels_,
new_server_filter->include_channels_); new_server_filter->include_channels_);
update_value(new_filter->is_shareable_, old_server_filter->is_shareable_, new_server_filter->is_shareable_); update_value(new_filter->is_shareable_, old_server_filter->is_shareable_, new_server_filter->is_shareable_);
update_value(new_filter->has_my_invites_, old_server_filter->has_my_invites_, new_server_filter->has_my_invites_);
if (new_filter->is_shareable_) { if (new_filter->is_shareable_) {
new_filter->exclude_muted_ = false; new_filter->exclude_muted_ = false;
@ -629,6 +642,8 @@ unique_ptr<DialogFilter> DialogFilter::merge_dialog_filter_changes(const DialogF
new_filter->include_groups_ = false; new_filter->include_groups_ = false;
new_filter->include_channels_ = false; new_filter->include_channels_ = false;
new_filter->excluded_dialog_ids_.clear(); new_filter->excluded_dialog_ids_.clear();
} else {
new_filter->has_my_invites_ = false;
} }
if (new_filter->check_limits().is_error()) { if (new_filter->check_limits().is_error()) {
@ -819,6 +834,7 @@ bool DialogFilter::are_similar(const DialogFilter &lhs, const DialogFilter &rhs)
bool DialogFilter::are_equivalent(const DialogFilter &lhs, const DialogFilter &rhs) { bool DialogFilter::are_equivalent(const DialogFilter &lhs, const DialogFilter &rhs) {
return lhs.title_ == rhs.title_ && lhs.emoji_ == rhs.emoji_ && lhs.is_shareable_ == rhs.is_shareable_ && return lhs.title_ == rhs.title_ && lhs.emoji_ == rhs.emoji_ && lhs.is_shareable_ == rhs.is_shareable_ &&
lhs.has_my_invites_ == rhs.has_my_invites_ &&
InputDialogId::are_equivalent(lhs.pinned_dialog_ids_, rhs.pinned_dialog_ids_) && InputDialogId::are_equivalent(lhs.pinned_dialog_ids_, rhs.pinned_dialog_ids_) &&
InputDialogId::are_equivalent(lhs.included_dialog_ids_, rhs.included_dialog_ids_) && InputDialogId::are_equivalent(lhs.included_dialog_ids_, rhs.included_dialog_ids_) &&
InputDialogId::are_equivalent(lhs.excluded_dialog_ids_, rhs.excluded_dialog_ids_) && are_flags_equal(lhs, rhs); InputDialogId::are_equivalent(lhs.excluded_dialog_ids_, rhs.excluded_dialog_ids_) && are_flags_equal(lhs, rhs);

View File

@ -67,6 +67,8 @@ class DialogFilter {
Status check_limits() const; Status check_limits() const;
void update_from(const DialogFilter &old_filter);
static string get_emoji_by_icon_name(const string &icon_name); static string get_emoji_by_icon_name(const string &icon_name);
static string get_icon_name_by_emoji(const string &emoji); static string get_icon_name_by_emoji(const string &emoji);
@ -104,8 +106,6 @@ class DialogFilter {
static bool are_equivalent(const DialogFilter &lhs, const DialogFilter &rhs); static bool are_equivalent(const DialogFilter &lhs, const DialogFilter &rhs);
static bool are_flags_equal(const DialogFilter &lhs, const DialogFilter &rhs);
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;
@ -128,10 +128,13 @@ class DialogFilter {
bool include_groups_ = false; bool include_groups_ = false;
bool include_channels_ = false; bool include_channels_ = false;
bool is_shareable_ = false; bool is_shareable_ = false;
bool has_my_invites_ = false;
static FlatHashMap<string, string> emoji_to_icon_name_; static FlatHashMap<string, string> emoji_to_icon_name_;
static FlatHashMap<string, string> icon_name_to_emoji_; static FlatHashMap<string, string> icon_name_to_emoji_;
static bool are_flags_equal(const DialogFilter &lhs, const DialogFilter &rhs);
static void init_icon_names(); static void init_icon_names();
string get_chosen_or_default_icon_name() const; string get_chosen_or_default_icon_name() const;
@ -143,6 +146,7 @@ class DialogFilter {
inline bool operator==(const DialogFilter &lhs, const DialogFilter &rhs) { inline bool operator==(const DialogFilter &lhs, const DialogFilter &rhs) {
return lhs.dialog_filter_id_ == rhs.dialog_filter_id_ && lhs.title_ == rhs.title_ && lhs.emoji_ == rhs.emoji_ && return lhs.dialog_filter_id_ == rhs.dialog_filter_id_ && lhs.title_ == rhs.title_ && lhs.emoji_ == rhs.emoji_ &&
lhs.is_shareable_ == rhs.is_shareable_ && lhs.has_my_invites_ == rhs.has_my_invites_ &&
lhs.pinned_dialog_ids_ == rhs.pinned_dialog_ids_ && lhs.included_dialog_ids_ == rhs.included_dialog_ids_ && lhs.pinned_dialog_ids_ == rhs.pinned_dialog_ids_ && lhs.included_dialog_ids_ == rhs.included_dialog_ids_ &&
lhs.excluded_dialog_ids_ == rhs.excluded_dialog_ids_ && DialogFilter::are_flags_equal(lhs, rhs); lhs.excluded_dialog_ids_ == rhs.excluded_dialog_ids_ && DialogFilter::are_flags_equal(lhs, rhs);
} }

View File

@ -32,6 +32,7 @@ void DialogFilter::store(StorerT &storer) const {
STORE_FLAG(has_included_dialog_ids); STORE_FLAG(has_included_dialog_ids);
STORE_FLAG(has_excluded_dialog_ids); STORE_FLAG(has_excluded_dialog_ids);
STORE_FLAG(is_shareable_); STORE_FLAG(is_shareable_);
STORE_FLAG(has_my_invites_);
END_STORE_FLAGS(); END_STORE_FLAGS();
store(dialog_filter_id_, storer); store(dialog_filter_id_, storer);
@ -67,6 +68,7 @@ void DialogFilter::parse(ParserT &parser) {
PARSE_FLAG(has_included_dialog_ids); PARSE_FLAG(has_included_dialog_ids);
PARSE_FLAG(has_excluded_dialog_ids); PARSE_FLAG(has_excluded_dialog_ids);
PARSE_FLAG(is_shareable_); PARSE_FLAG(is_shareable_);
PARSE_FLAG(has_my_invites_);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
parse(dialog_filter_id_, parser); parse(dialog_filter_id_, parser);

View File

@ -1405,6 +1405,7 @@ void DialogFilterManager::edit_dialog_filter(DialogFilterId dialog_filter_id,
if (new_dialog_filter->is_shareable() != old_dialog_filter->is_shareable()) { if (new_dialog_filter->is_shareable() != old_dialog_filter->is_shareable()) {
return promise.set_error(Status::Error(400, "Can't convert a shareable folder to a non-shareable")); return promise.set_error(Status::Error(400, "Can't convert a shareable folder to a non-shareable"));
} }
new_dialog_filter->update_from(*old_dialog_filter);
auto chat_filter_info = new_dialog_filter->get_chat_filter_info_object(); auto chat_filter_info = new_dialog_filter->get_chat_filter_info_object();
if (*new_dialog_filter == *old_dialog_filter) { if (*new_dialog_filter == *old_dialog_filter) {
@ -1852,7 +1853,7 @@ void DialogFilterManager::on_get_chatlist_invite(
icon_name = "Custom"; icon_name = "Custom";
} }
info = td_api::make_object<td_api::chatFilterInfo>(0, invite->title_, info = td_api::make_object<td_api::chatFilterInfo>(0, invite->title_,
td_api::make_object<td_api::chatFilterIcon>(icon_name)); td_api::make_object<td_api::chatFilterIcon>(icon_name), false);
missing_peers = std::move(invite->peers_); missing_peers = std::move(invite->peers_);
chats = std::move(invite->chats_); chats = std::move(invite->chats_);
users = std::move(invite->users_); users = std::move(invite->users_);