Add td_api::getChatNotificationSettingsExceptions.

GitOrigin-RevId: f2ea5ced7cb2c62841dd961c4ce433f39c202f92
This commit is contained in:
levlam 2019-02-14 21:44:20 +03:00
parent fa89033923
commit d98aaa571f
10 changed files with 176 additions and 59 deletions

View File

@ -3047,6 +3047,9 @@ getChatAdministrators chat_id:int53 = Users;
clearAllDraftMessages exclude_secret_chats:Bool = Ok;
//@description Returns list of chats with non-default notification settings @scope If specified, only chats from the specified scope will be returned @compare_sound If true, also chats with non-default sound will be returned
getChatNotificationSettingsExceptions scope:NotificationSettingsScope compare_sound:Bool = Chats;
//@description Returns the notification settings for chats of a given type @scope Types of chats for which to return the notification settings information
getScopeNotificationSettings scope:NotificationSettingsScope = ScopeNotificationSettings;

Binary file not shown.

View File

@ -1505,7 +1505,7 @@ class ImportDialogInviteLinkQuery : public Td::ResultHandler {
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for importChatInvite: " << to_string(ptr);
auto dialog_ids = td->updates_manager_->get_chats(ptr.get());
auto dialog_ids = UpdatesManager::get_chat_dialog_ids(ptr.get());
if (dialog_ids.size() != 1u) {
LOG(ERROR) << "Receive wrong result for ImportDialogInviteLinkQuery: " << to_string(ptr);
return on_error(id, Status::Error(500, "Internal Server Error"));

View File

@ -1932,7 +1932,7 @@ class SendMultiMediaActor : public NetActorOnce {
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for sendMultiMedia for " << format::as_array(random_ids_) << ": " << to_string(ptr);
auto sent_random_ids = td->updates_manager_->get_sent_messages_random_ids(ptr.get());
auto sent_random_ids = UpdatesManager::get_sent_messages_random_ids(ptr.get());
bool is_result_wrong = false;
auto sent_random_ids_size = sent_random_ids.size();
for (auto &random_id : random_ids_) {
@ -1950,7 +1950,7 @@ class SendMultiMediaActor : public NetActorOnce {
is_result_wrong = true;
}
if (!is_result_wrong) {
auto sent_messages = td->updates_manager_->get_new_messages(ptr.get());
auto sent_messages = UpdatesManager::get_new_messages(ptr.get());
if (sent_random_ids_size != sent_messages.size()) {
is_result_wrong = true;
}
@ -2562,7 +2562,7 @@ class ForwardMessagesActor : public NetActorOnce {
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for forwardMessages for " << format::as_array(random_ids_) << ": " << to_string(ptr);
auto sent_random_ids = td->updates_manager_->get_sent_messages_random_ids(ptr.get());
auto sent_random_ids = UpdatesManager::get_sent_messages_random_ids(ptr.get());
bool is_result_wrong = false;
auto sent_random_ids_size = sent_random_ids.size();
for (auto &random_id : random_ids_) {
@ -2580,7 +2580,7 @@ class ForwardMessagesActor : public NetActorOnce {
is_result_wrong = true;
}
if (!is_result_wrong) {
auto sent_messages = td->updates_manager_->get_new_messages(ptr.get());
auto sent_messages = UpdatesManager::get_new_messages(ptr.get());
if (sent_random_ids_size != sent_messages.size()) {
is_result_wrong = true;
}
@ -2846,6 +2846,47 @@ class GetDialogNotifySettingsQuery : public Td::ResultHandler {
}
};
class GetNotifySettingsExceptionsQuery : public Td::ResultHandler {
Promise<vector<DialogId>> promise_;
public:
explicit GetNotifySettingsExceptionsQuery(Promise<vector<DialogId>> &&promise) : promise_(std::move(promise)) {
}
void send(NotificationSettingsScope scope, bool filter_scope, bool compare_sound) {
// +account.getNotifyExceptions flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates;
int32 flags = 0;
tl_object_ptr<telegram_api::InputNotifyPeer> input_notify_peer;
if (filter_scope) {
flags |= telegram_api::account_getNotifyExceptions::PEER_MASK;
input_notify_peer = get_input_notify_peer(scope);
}
if (compare_sound) {
flags |= telegram_api::account_getNotifyExceptions::COMPARE_SOUND_MASK;
}
send_query(G()->net_query_creator().create(create_storer(
telegram_api::account_getNotifyExceptions(flags, false /* ignored */, std::move(input_notify_peer)))));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::account_getNotifyExceptions>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto updates_ptr = result_ptr.move_as_ok();
auto dialog_ids = UpdatesManager::get_update_notify_settings_dialog_ids(updates_ptr.get());
td->updates_manager_->on_get_updates(std::move(updates_ptr));
promise_.set_value(std::move(dialog_ids));
}
void on_error(uint64 id, Status status) override {
promise_.set_error(std::move(status));
}
};
class GetScopeNotifySettingsQuery : public Td::ResultHandler {
Promise<Unit> promise_;
NotificationSettingsScope scope_;
@ -12863,6 +12904,12 @@ int32 MessagesManager::get_scope_mute_until(DialogId dialog_id) const {
}
}
void MessagesManager::get_dialog_notification_settings_exceptions(NotificationSettingsScope scope, bool filter_scope,
bool compare_sound,
Promise<vector<DialogId>> &&promise) {
td_->create_handler<GetNotifySettingsExceptionsQuery>(std::move(promise))->send(scope, filter_scope, compare_sound);
}
const ScopeNotificationSettings *MessagesManager::get_scope_notification_settings(NotificationSettingsScope scope,
Promise<Unit> &&promise) {
const ScopeNotificationSettings *notification_settings = get_scope_notification_settings(scope);
@ -18780,8 +18827,8 @@ void MessagesManager::check_send_message_result(int64 random_id, DialogId dialog
const telegram_api::Updates *updates_ptr, const char *source) {
CHECK(updates_ptr != nullptr);
CHECK(source != nullptr);
auto sent_messages = td_->updates_manager_->get_new_messages(updates_ptr);
auto sent_messages_random_ids = td_->updates_manager_->get_sent_messages_random_ids(updates_ptr);
auto sent_messages = UpdatesManager::get_new_messages(updates_ptr);
auto sent_messages_random_ids = UpdatesManager::get_sent_messages_random_ids(updates_ptr);
if (sent_messages.size() != 1u || sent_messages_random_ids.size() != 1u ||
*sent_messages_random_ids.begin() != random_id || get_message_dialog_id(*sent_messages[0]) != dialog_id) {
LOG(ERROR) << "Receive wrong result for sending message with random_id " << random_id << " from " << source
@ -19503,8 +19550,8 @@ void MessagesManager::set_dialog_pinned_message_id(Dialog *d, MessageId pinned_m
void MessagesManager::on_create_new_dialog_success(int64 random_id, tl_object_ptr<telegram_api::Updates> &&updates,
DialogType expected_type, Promise<Unit> &&promise) {
auto sent_messages = td_->updates_manager_->get_new_messages(updates.get());
auto sent_messages_random_ids = td_->updates_manager_->get_sent_messages_random_ids(updates.get());
auto sent_messages = UpdatesManager::get_new_messages(updates.get());
auto sent_messages_random_ids = UpdatesManager::get_sent_messages_random_ids(updates.get());
if (sent_messages.size() != 1u || sent_messages_random_ids.size() != 1u) {
LOG(ERROR) << "Receive wrong result for create group or channel chat " << oneline(to_string(updates));
return on_create_new_dialog_fail(random_id, Status::Error(500, "Unsupported server response"), std::move(promise));

View File

@ -519,7 +519,8 @@ class MessagesManager : public Actor {
td_api::object_ptr<td_api::updateScopeNotificationSettings> get_update_scope_notification_settings_object(
NotificationSettingsScope scope) const;
const DialogNotificationSettings *get_dialog_notification_settings(DialogId dialog_id, Promise<Unit> &&promise);
void get_dialog_notification_settings_exceptions(NotificationSettingsScope scope, bool filter_scope,
bool compare_sound, Promise<vector<DialogId>> &&promise);
const ScopeNotificationSettings *get_scope_notification_settings(NotificationSettingsScope scope,
Promise<Unit> &&promise);

View File

@ -2086,6 +2086,40 @@ class GetUserProfilePhotosRequest : public RequestActor<> {
}
};
class GetChatNotificationSettingsExceptionsRequest : public RequestActor<vector<DialogId>> {
NotificationSettingsScope scope_;
bool filter_scope_;
bool compare_sound_;
vector<DialogId> dialog_ids_;
void do_run(Promise<vector<DialogId>> &&promise) override {
if (get_tries() < 2) {
promise.set_value(std::move(dialog_ids_));
return;
}
td->messages_manager_->get_dialog_notification_settings_exceptions(scope_, filter_scope_, compare_sound_,
std::move(promise));
}
void do_set_result(vector<DialogId> &&result) override {
dialog_ids_ = std::move(result);
}
void do_send_result() override {
send_result(MessagesManager::get_chats_object(dialog_ids_));
}
public:
GetChatNotificationSettingsExceptionsRequest(ActorShared<Td> td, uint64 request_id, NotificationSettingsScope scope,
bool filter_scope, bool compare_sound)
: RequestActor(std::move(td), request_id)
, scope_(scope)
, filter_scope_(filter_scope)
, compare_sound_(compare_sound) {
}
};
class GetScopeNotificationSettingsRequest : public RequestActor<> {
NotificationSettingsScope scope_;
@ -6119,6 +6153,17 @@ void Td::on_request(uint64 id, td_api::removeSavedAnimation &request) {
CREATE_REQUEST(RemoveSavedAnimationRequest, std::move(request.animation_));
}
void Td::on_request(uint64 id, const td_api::getChatNotificationSettingsExceptions &request) {
CHECK_IS_USER();
bool filter_scope = false;
NotificationSettingsScope scope = NotificationSettingsScope::Private;
if (request.scope_ != nullptr) {
filter_scope = true;
scope = get_notification_settings_scope(request.scope_);
}
CREATE_REQUEST(GetChatNotificationSettingsExceptionsRequest, scope, filter_scope, request.compare_sound_);
}
void Td::on_request(uint64 id, const td_api::getScopeNotificationSettings &request) {
CHECK_IS_USER();
if (request.scope_ == nullptr) {

View File

@ -789,6 +789,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::removeFavoriteSticker &request);
void on_request(uint64 id, const td_api::getChatNotificationSettingsExceptions &request);
void on_request(uint64 id, const td_api::getScopeNotificationSettings &request);
void on_request(uint64 id, td_api::setChatNotificationSettings &request);

View File

@ -780,9 +780,8 @@ void UpdatesManager::on_get_updates_state(tl_object_ptr<telegram_api::updates_st
}
}
std::unordered_set<int64> UpdatesManager::get_sent_messages_random_ids(const telegram_api::Updates *updates_ptr) {
std::unordered_set<int64> random_ids;
const vector<tl_object_ptr<telegram_api::Update>> *updates;
const vector<tl_object_ptr<telegram_api::Update>> *UpdatesManager::get_updates(
const telegram_api::Updates *updates_ptr) {
switch (updates_ptr->get_id()) {
case telegram_api::updatesTooLong::ID:
case telegram_api::updateShortMessage::ID:
@ -790,24 +789,27 @@ std::unordered_set<int64> UpdatesManager::get_sent_messages_random_ids(const tel
case telegram_api::updateShort::ID:
case telegram_api::updateShortSentMessage::ID:
LOG(ERROR) << "Receive " << oneline(to_string(*updates_ptr)) << " instead of updates";
return random_ids;
case telegram_api::updatesCombined::ID: {
updates = &static_cast<const telegram_api::updatesCombined *>(updates_ptr)->updates_;
break;
}
case telegram_api::updates::ID: {
updates = &static_cast<const telegram_api::updates *>(updates_ptr)->updates_;
break;
}
return nullptr;
case telegram_api::updatesCombined::ID:
return &static_cast<const telegram_api::updatesCombined *>(updates_ptr)->updates_;
case telegram_api::updates::ID:
return &static_cast<const telegram_api::updates *>(updates_ptr)->updates_;
default:
UNREACHABLE();
return random_ids;
return nullptr;
}
for (auto &update : *updates) {
if (update->get_id() == telegram_api::updateMessageID::ID) {
int64 random_id = static_cast<const telegram_api::updateMessageID *>(update.get())->random_id_;
if (!random_ids.insert(random_id).second) {
LOG(ERROR) << "Receive twice updateMessageID for " << random_id;
}
std::unordered_set<int64> UpdatesManager::get_sent_messages_random_ids(const telegram_api::Updates *updates_ptr) {
std::unordered_set<int64> random_ids;
auto updates = get_updates(updates_ptr);
if (updates != nullptr) {
for (auto &update : *updates) {
if (update->get_id() == telegram_api::updateMessageID::ID) {
int64 random_id = static_cast<const telegram_api::updateMessageID *>(update.get())->random_id_;
if (!random_ids.insert(random_id).second) {
LOG(ERROR) << "Receive twice updateMessageID for " << random_id;
}
}
}
}
@ -817,39 +819,45 @@ std::unordered_set<int64> UpdatesManager::get_sent_messages_random_ids(const tel
vector<const tl_object_ptr<telegram_api::Message> *> UpdatesManager::get_new_messages(
const telegram_api::Updates *updates_ptr) {
vector<const tl_object_ptr<telegram_api::Message> *> messages;
const vector<tl_object_ptr<telegram_api::Update>> *updates;
switch (updates_ptr->get_id()) {
case telegram_api::updatesTooLong::ID:
case telegram_api::updateShortMessage::ID:
case telegram_api::updateShortChatMessage::ID:
case telegram_api::updateShort::ID:
case telegram_api::updateShortSentMessage::ID:
LOG(ERROR) << "Receive " << oneline(to_string(*updates_ptr)) << " instead of updates";
return messages;
case telegram_api::updatesCombined::ID: {
updates = &static_cast<const telegram_api::updatesCombined *>(updates_ptr)->updates_;
break;
}
case telegram_api::updates::ID: {
updates = &static_cast<const telegram_api::updates *>(updates_ptr)->updates_;
break;
}
default:
UNREACHABLE();
return messages;
}
for (auto &update : *updates) {
auto constructor_id = update->get_id();
if (constructor_id == telegram_api::updateNewMessage::ID) {
messages.emplace_back(&static_cast<const telegram_api::updateNewMessage *>(update.get())->message_);
} else if (constructor_id == telegram_api::updateNewChannelMessage::ID) {
messages.emplace_back(&static_cast<const telegram_api::updateNewChannelMessage *>(update.get())->message_);
auto updates = get_updates(updates_ptr);
if (updates != nullptr) {
for (auto &update : *updates) {
auto constructor_id = update->get_id();
if (constructor_id == telegram_api::updateNewMessage::ID) {
messages.emplace_back(&static_cast<const telegram_api::updateNewMessage *>(update.get())->message_);
} else if (constructor_id == telegram_api::updateNewChannelMessage::ID) {
messages.emplace_back(&static_cast<const telegram_api::updateNewChannelMessage *>(update.get())->message_);
}
}
}
return messages;
}
vector<DialogId> UpdatesManager::get_chats(const telegram_api::Updates *updates_ptr) {
vector<DialogId> UpdatesManager::get_update_notify_settings_dialog_ids(const telegram_api::Updates *updates_ptr) {
vector<DialogId> dialog_ids;
auto updates = get_updates(updates_ptr);
if (updates != nullptr) {
dialog_ids.reserve(updates->size());
for (auto &update : *updates) {
DialogId dialog_id;
if (update->get_id() == telegram_api::updateNotifySettings::ID) {
auto notify_peer = static_cast<const telegram_api::updateNotifySettings *>(update.get())->peer_.get();
if (notify_peer->get_id() == telegram_api::notifyPeer::ID) {
dialog_id = DialogId(static_cast<const telegram_api::notifyPeer *>(notify_peer)->peer_);
}
}
if (dialog_id.is_valid()) {
dialog_ids.push_back(dialog_id);
} else {
LOG(ERROR) << "Receive unexpected " << to_string(update);
}
}
}
return dialog_ids;
}
vector<DialogId> UpdatesManager::get_chat_dialog_ids(const telegram_api::Updates *updates_ptr) {
const vector<tl_object_ptr<telegram_api::Chat>> *chats = nullptr;
switch (updates_ptr->get_id()) {
case telegram_api::updatesTooLong::ID:

View File

@ -38,11 +38,14 @@ class UpdatesManager : public Actor {
void on_get_difference(tl_object_ptr<telegram_api::updates_Difference> &&difference_ptr);
std::unordered_set<int64> get_sent_messages_random_ids(const telegram_api::Updates *updates_ptr);
static std::unordered_set<int64> get_sent_messages_random_ids(const telegram_api::Updates *updates_ptr);
vector<const tl_object_ptr<telegram_api::Message> *> get_new_messages(const telegram_api::Updates *updates_ptr);
static vector<const tl_object_ptr<telegram_api::Message> *> get_new_messages(
const telegram_api::Updates *updates_ptr);
vector<DialogId> get_chats(const telegram_api::Updates *updates_ptr);
static vector<DialogId> get_update_notify_settings_dialog_ids(const telegram_api::Updates *updates_ptr);
static vector<DialogId> get_chat_dialog_ids(const telegram_api::Updates *updates_ptr);
void get_difference(const char *source);
@ -176,6 +179,8 @@ class UpdatesManager : public Actor {
void after_get_difference();
static const vector<tl_object_ptr<telegram_api::Update>> *get_updates(const telegram_api::Updates *updates_ptr);
bool is_acceptable_message_entities(const vector<tl_object_ptr<telegram_api::MessageEntity>> &message_entities) const;
bool is_acceptable_message(const telegram_api::Message *message_ptr) const;

View File

@ -886,6 +886,9 @@ class CliClient final : public Actor {
}
static tl_object_ptr<td_api::NotificationSettingsScope> get_notification_settings_scope(Slice scope) {
if (scope.empty()) {
return nullptr;
}
if (scope == "channels" || scope == "ch") {
return make_tl_object<td_api::notificationSettingsScopeChannelChats>();
}
@ -3397,6 +3400,9 @@ class CliClient final : public Actor {
send_request(make_tl_object<td_api::readAllChatMentions>(as_chat_id(chat_id)));
} else if (op == "dpp") {
send_request(make_tl_object<td_api::deleteProfilePhoto>(to_integer<int64>(args)));
} else if (op == "gcnse" || op == "gcnses") {
send_request(make_tl_object<td_api::getChatNotificationSettingsExceptions>(get_notification_settings_scope(args),
op == "gcnses"));
} else if (op == "gsns") {
send_request(make_tl_object<td_api::getScopeNotificationSettings>(get_notification_settings_scope(args)));
} else if (op == "scns" || op == "ssns") {