Use UserId in PrivacyManager.
This commit is contained in:
parent
4f644ce389
commit
f5ab187bb2
@ -185,7 +185,7 @@ PrivacyManager::UserPrivacySettingRule::UserPrivacySettingRule(const td_api::Use
|
|||||||
break;
|
break;
|
||||||
case td_api::userPrivacySettingRuleAllowUsers::ID:
|
case td_api::userPrivacySettingRuleAllowUsers::ID:
|
||||||
type_ = Type::AllowUsers;
|
type_ = Type::AllowUsers;
|
||||||
user_ids_ = static_cast<const td_api::userPrivacySettingRuleAllowUsers &>(rule).user_ids_;
|
user_ids_ = UserId::get_user_ids(static_cast<const td_api::userPrivacySettingRuleAllowUsers &>(rule).user_ids_);
|
||||||
break;
|
break;
|
||||||
case td_api::userPrivacySettingRuleAllowChatMembers::ID:
|
case td_api::userPrivacySettingRuleAllowChatMembers::ID:
|
||||||
type_ = Type::AllowChatParticipants;
|
type_ = Type::AllowChatParticipants;
|
||||||
@ -199,7 +199,8 @@ PrivacyManager::UserPrivacySettingRule::UserPrivacySettingRule(const td_api::Use
|
|||||||
break;
|
break;
|
||||||
case td_api::userPrivacySettingRuleRestrictUsers::ID:
|
case td_api::userPrivacySettingRuleRestrictUsers::ID:
|
||||||
type_ = Type::RestrictUsers;
|
type_ = Type::RestrictUsers;
|
||||||
user_ids_ = static_cast<const td_api::userPrivacySettingRuleRestrictUsers &>(rule).user_ids_;
|
user_ids_ =
|
||||||
|
UserId::get_user_ids(static_cast<const td_api::userPrivacySettingRuleRestrictUsers &>(rule).user_ids_);
|
||||||
break;
|
break;
|
||||||
case td_api::userPrivacySettingRuleRestrictChatMembers::ID:
|
case td_api::userPrivacySettingRuleRestrictChatMembers::ID:
|
||||||
type_ = Type::RestrictChatParticipants;
|
type_ = Type::RestrictChatParticipants;
|
||||||
@ -220,7 +221,7 @@ PrivacyManager::UserPrivacySettingRule::UserPrivacySettingRule(const telegram_ap
|
|||||||
break;
|
break;
|
||||||
case telegram_api::privacyValueAllowUsers::ID:
|
case telegram_api::privacyValueAllowUsers::ID:
|
||||||
type_ = Type::AllowUsers;
|
type_ = Type::AllowUsers;
|
||||||
user_ids_ = static_cast<const telegram_api::privacyValueAllowUsers &>(rule).users_;
|
user_ids_ = UserId::get_user_ids(static_cast<const telegram_api::privacyValueAllowUsers &>(rule).users_);
|
||||||
break;
|
break;
|
||||||
case telegram_api::privacyValueAllowChatParticipants::ID:
|
case telegram_api::privacyValueAllowChatParticipants::ID:
|
||||||
type_ = Type::AllowChatParticipants;
|
type_ = Type::AllowChatParticipants;
|
||||||
@ -234,7 +235,7 @@ PrivacyManager::UserPrivacySettingRule::UserPrivacySettingRule(const telegram_ap
|
|||||||
break;
|
break;
|
||||||
case telegram_api::privacyValueDisallowUsers::ID:
|
case telegram_api::privacyValueDisallowUsers::ID:
|
||||||
type_ = Type::RestrictUsers;
|
type_ = Type::RestrictUsers;
|
||||||
user_ids_ = static_cast<const telegram_api::privacyValueDisallowUsers &>(rule).users_;
|
user_ids_ = UserId::get_user_ids(static_cast<const telegram_api::privacyValueDisallowUsers &>(rule).users_);
|
||||||
break;
|
break;
|
||||||
case telegram_api::privacyValueDisallowChatParticipants::ID:
|
case telegram_api::privacyValueDisallowChatParticipants::ID:
|
||||||
type_ = Type::RestrictChatParticipants;
|
type_ = Type::RestrictChatParticipants;
|
||||||
@ -253,7 +254,7 @@ PrivacyManager::UserPrivacySettingRule::get_user_privacy_setting_rule_object() c
|
|||||||
case Type::AllowAll:
|
case Type::AllowAll:
|
||||||
return make_tl_object<td_api::userPrivacySettingRuleAllowAll>();
|
return make_tl_object<td_api::userPrivacySettingRuleAllowAll>();
|
||||||
case Type::AllowUsers:
|
case Type::AllowUsers:
|
||||||
return make_tl_object<td_api::userPrivacySettingRuleAllowUsers>(vector<int32>{user_ids_});
|
return make_tl_object<td_api::userPrivacySettingRuleAllowUsers>(UserId::get_input_user_ids(user_ids_));
|
||||||
case Type::AllowChatParticipants:
|
case Type::AllowChatParticipants:
|
||||||
return make_tl_object<td_api::userPrivacySettingRuleAllowChatMembers>(chat_ids_as_dialog_ids());
|
return make_tl_object<td_api::userPrivacySettingRuleAllowChatMembers>(chat_ids_as_dialog_ids());
|
||||||
case Type::RestrictContacts:
|
case Type::RestrictContacts:
|
||||||
@ -261,7 +262,7 @@ PrivacyManager::UserPrivacySettingRule::get_user_privacy_setting_rule_object() c
|
|||||||
case Type::RestrictAll:
|
case Type::RestrictAll:
|
||||||
return make_tl_object<td_api::userPrivacySettingRuleRestrictAll>();
|
return make_tl_object<td_api::userPrivacySettingRuleRestrictAll>();
|
||||||
case Type::RestrictUsers:
|
case Type::RestrictUsers:
|
||||||
return make_tl_object<td_api::userPrivacySettingRuleRestrictUsers>(vector<int32>{user_ids_});
|
return make_tl_object<td_api::userPrivacySettingRuleRestrictUsers>(UserId::get_input_user_ids(user_ids_));
|
||||||
case Type::RestrictChatParticipants:
|
case Type::RestrictChatParticipants:
|
||||||
return make_tl_object<td_api::userPrivacySettingRuleRestrictChatMembers>(chat_ids_as_dialog_ids());
|
return make_tl_object<td_api::userPrivacySettingRuleRestrictChatMembers>(chat_ids_as_dialog_ids());
|
||||||
default:
|
default:
|
||||||
@ -298,7 +299,7 @@ Result<PrivacyManager::UserPrivacySettingRule> PrivacyManager::UserPrivacySettin
|
|||||||
UserPrivacySettingRule result(*rule);
|
UserPrivacySettingRule result(*rule);
|
||||||
auto td = G()->td().get_actor_unsafe();
|
auto td = G()->td().get_actor_unsafe();
|
||||||
for (auto user_id : result.user_ids_) {
|
for (auto user_id : result.user_ids_) {
|
||||||
if (!td->contacts_manager_->have_user(UserId(user_id))) {
|
if (!td->contacts_manager_->have_user(user_id)) {
|
||||||
return Status::Error(500, "Got inaccessible user from the server");
|
return Status::Error(500, "Got inaccessible user from the server");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,7 +321,7 @@ Result<PrivacyManager::UserPrivacySettingRule> PrivacyManager::UserPrivacySettin
|
|||||||
vector<tl_object_ptr<telegram_api::InputUser>> PrivacyManager::UserPrivacySettingRule::get_input_users() const {
|
vector<tl_object_ptr<telegram_api::InputUser>> PrivacyManager::UserPrivacySettingRule::get_input_users() const {
|
||||||
vector<tl_object_ptr<telegram_api::InputUser>> result;
|
vector<tl_object_ptr<telegram_api::InputUser>> result;
|
||||||
for (auto user_id : user_ids_) {
|
for (auto user_id : user_ids_) {
|
||||||
auto input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(UserId(user_id));
|
auto input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(user_id);
|
||||||
if (input_user != nullptr) {
|
if (input_user != nullptr) {
|
||||||
result.push_back(std::move(input_user));
|
result.push_back(std::move(input_user));
|
||||||
} else {
|
} else {
|
||||||
@ -347,7 +348,7 @@ vector<int64> PrivacyManager::UserPrivacySettingRule::chat_ids_as_dialog_ids() c
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int32> PrivacyManager::UserPrivacySettingRule::get_restricted_user_ids() const {
|
vector<UserId> PrivacyManager::UserPrivacySettingRule::get_restricted_user_ids() const {
|
||||||
if (type_ == Type::RestrictUsers) {
|
if (type_ == Type::RestrictUsers) {
|
||||||
return user_ids_;
|
return user_ids_;
|
||||||
}
|
}
|
||||||
@ -405,12 +406,13 @@ vector<tl_object_ptr<telegram_api::InputPrivacyRule>> PrivacyManager::UserPrivac
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int32> PrivacyManager::UserPrivacySettingRules::get_restricted_user_ids() const {
|
vector<UserId> PrivacyManager::UserPrivacySettingRules::get_restricted_user_ids() const {
|
||||||
vector<int32> result;
|
vector<UserId> result;
|
||||||
for (auto &rule : rules_) {
|
for (auto &rule : rules_) {
|
||||||
combine(result, rule.get_restricted_user_ids());
|
combine(result, rule.get_restricted_user_ids());
|
||||||
}
|
}
|
||||||
td::unique(result);
|
std::sort(result.begin(), result.end(), [](UserId lhs, UserId rhs) { return lhs.get() < rhs.get(); });
|
||||||
|
result.erase(std::unique(result.begin(), result.end()), result.end());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,12 +532,12 @@ void PrivacyManager::do_update_privacy(UserPrivacySetting user_privacy_setting,
|
|||||||
if (old_restricted != new_restricted) {
|
if (old_restricted != new_restricted) {
|
||||||
// if a user was unrestricted, it is not received from the server anymore
|
// if a user was unrestricted, it is not received from the server anymore
|
||||||
// we need to reget their online status manually
|
// we need to reget their online status manually
|
||||||
std::vector<int32> unrestricted;
|
std::vector<UserId> unrestricted;
|
||||||
std::set_difference(old_restricted.begin(), old_restricted.end(), new_restricted.begin(),
|
std::set_difference(old_restricted.begin(), old_restricted.end(), new_restricted.begin(),
|
||||||
new_restricted.end(), std::back_inserter(unrestricted));
|
new_restricted.end(), std::back_inserter(unrestricted),
|
||||||
|
[](UserId lhs, UserId rhs) { return lhs.get() < rhs.get(); });
|
||||||
for (auto &user_id : unrestricted) {
|
for (auto &user_id : unrestricted) {
|
||||||
send_closure_later(G()->contacts_manager(), &ContactsManager::reload_user, UserId(user_id),
|
send_closure_later(G()->contacts_manager(), &ContactsManager::reload_user, user_id, Promise<Unit>());
|
||||||
Promise<Unit>());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "td/telegram/net/NetQuery.h"
|
#include "td/telegram/net/NetQuery.h"
|
||||||
#include "td/telegram/td_api.h"
|
#include "td/telegram/td_api.h"
|
||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
|
#include "td/telegram/UserId.h"
|
||||||
|
|
||||||
#include "td/actor/actor.h"
|
#include "td/actor/actor.h"
|
||||||
#include "td/actor/PromiseFuture.h"
|
#include "td/actor/PromiseFuture.h"
|
||||||
@ -83,7 +84,7 @@ class PrivacyManager : public NetQueryCallback {
|
|||||||
return type_ == other.type_ && user_ids_ == other.user_ids_ && chat_ids_ == other.chat_ids_;
|
return type_ == other.type_ && user_ids_ == other.user_ids_ && chat_ids_ == other.chat_ids_;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int32> get_restricted_user_ids() const;
|
vector<UserId> get_restricted_user_ids() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class Type : int32 {
|
enum class Type : int32 {
|
||||||
@ -97,7 +98,7 @@ class PrivacyManager : public NetQueryCallback {
|
|||||||
RestrictChatParticipants
|
RestrictChatParticipants
|
||||||
} type_ = Type::RestrictAll;
|
} type_ = Type::RestrictAll;
|
||||||
|
|
||||||
vector<int32> user_ids_;
|
vector<UserId> user_ids_;
|
||||||
vector<int32> chat_ids_;
|
vector<int32> chat_ids_;
|
||||||
|
|
||||||
vector<tl_object_ptr<telegram_api::InputUser>> get_input_users() const;
|
vector<tl_object_ptr<telegram_api::InputUser>> get_input_users() const;
|
||||||
@ -130,7 +131,7 @@ class PrivacyManager : public NetQueryCallback {
|
|||||||
return rules_ == other.rules_;
|
return rules_ == other.rules_;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int32> get_restricted_user_ids() const;
|
vector<UserId> get_restricted_user_ids() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vector<UserPrivacySettingRule> rules_;
|
vector<UserPrivacySettingRule> rules_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user