Add td_api::chatListFilter.
GitOrigin-RevId: 4682d96fbaa160f1af9213d65c99c67de4d1764e
This commit is contained in:
parent
f96714b254
commit
0edc0721ef
@ -686,6 +686,9 @@ chatListMain = ChatList;
|
|||||||
//@description A list of chats usually located at the top of the main chat list. Unmuted chats are automatically moved from the Archive to the Main chat list when a new message arrives
|
//@description A list of chats usually located at the top of the main chat list. Unmuted chats are automatically moved from the Archive to the Main chat list when a new message arrives
|
||||||
chatListArchive = ChatList;
|
chatListArchive = ChatList;
|
||||||
|
|
||||||
|
//@description A list of chats belonging to a chat filter @chat_filter_id Chat filter identifier
|
||||||
|
chatListFilter chat_filter_id:int32 = ChatList;
|
||||||
|
|
||||||
|
|
||||||
//@class ChatSource @description Describes a reason why an external chat is shown in a chat list
|
//@class ChatSource @description Describes a reason why an external chat is shown in a chat list
|
||||||
|
|
||||||
|
Binary file not shown.
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/DialogFilterId.h"
|
||||||
#include "td/telegram/FolderId.h"
|
#include "td/telegram/FolderId.h"
|
||||||
#include "td/telegram/td_api.h"
|
#include "td/telegram/td_api.h"
|
||||||
|
|
||||||
@ -20,6 +21,8 @@ namespace td {
|
|||||||
class DialogListId {
|
class DialogListId {
|
||||||
int64 id = 0;
|
int64 id = 0;
|
||||||
|
|
||||||
|
static constexpr int64 FILTER_ID_SHIFT = static_cast<int64>(1) << 32;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DialogListId() = default;
|
DialogListId() = default;
|
||||||
|
|
||||||
@ -28,6 +31,8 @@ class DialogListId {
|
|||||||
template <class T, typename = std::enable_if_t<std::is_convertible<T, int32>::value>>
|
template <class T, typename = std::enable_if_t<std::is_convertible<T, int32>::value>>
|
||||||
DialogListId(T dialog_list_id) = delete;
|
DialogListId(T dialog_list_id) = delete;
|
||||||
|
|
||||||
|
explicit DialogListId(DialogFilterId dialog_filter_id) : id(dialog_filter_id.get() + FILTER_ID_SHIFT) {
|
||||||
|
}
|
||||||
explicit DialogListId(FolderId folder_id) : id(folder_id.get()) {
|
explicit DialogListId(FolderId folder_id) : id(folder_id.get()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +48,13 @@ class DialogListId {
|
|||||||
case td_api::chatListMain::ID:
|
case td_api::chatListMain::ID:
|
||||||
CHECK(id == FolderId::main().get());
|
CHECK(id == FolderId::main().get());
|
||||||
break;
|
break;
|
||||||
|
case td_api::chatListFilter::ID: {
|
||||||
|
DialogFilterId filter_id(static_cast<const td_api::chatListFilter *>(chat_list.get())->chat_filter_id_);
|
||||||
|
if (filter_id.is_valid()) {
|
||||||
|
*this = DialogListId(filter_id);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
break;
|
break;
|
||||||
@ -66,7 +78,8 @@ class DialogListId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool is_filter() const {
|
bool is_filter() const {
|
||||||
return false;
|
return std::numeric_limits<int32>::min() + FILTER_ID_SHIFT <= id &&
|
||||||
|
id <= std::numeric_limits<int32>::max() + FILTER_ID_SHIFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderId get_folder_id() const {
|
FolderId get_folder_id() const {
|
||||||
@ -74,6 +87,11 @@ class DialogListId {
|
|||||||
return FolderId(static_cast<int32>(id));
|
return FolderId(static_cast<int32>(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DialogFilterId get_filter_id() const {
|
||||||
|
CHECK(is_filter());
|
||||||
|
return DialogFilterId(static_cast<int32>(id - FILTER_ID_SHIFT));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
template <class StorerT>
|
template <class StorerT>
|
||||||
void store(StorerT &storer) const {
|
void store(StorerT &storer) const {
|
||||||
@ -94,6 +112,12 @@ struct DialogListIdHash {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline StringBuilder &operator<<(StringBuilder &string_builder, DialogListId dialog_list_id) {
|
inline StringBuilder &operator<<(StringBuilder &string_builder, DialogListId dialog_list_id) {
|
||||||
|
if (dialog_list_id.is_folder()) {
|
||||||
|
return string_builder << "chat list " << dialog_list_id.get_folder_id();
|
||||||
|
}
|
||||||
|
if (dialog_list_id.is_filter()) {
|
||||||
|
return string_builder << "chat list " << dialog_list_id.get_filter_id();
|
||||||
|
}
|
||||||
return string_builder << "chat list " << dialog_list_id.get();
|
return string_builder << "chat list " << dialog_list_id.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16581,13 +16581,20 @@ td_api::object_ptr<td_api::ChatType> MessagesManager::get_chat_type_object(Dialo
|
|||||||
}
|
}
|
||||||
|
|
||||||
td_api::object_ptr<td_api::ChatList> MessagesManager::get_chat_list_object(DialogListId dialog_list_id) {
|
td_api::object_ptr<td_api::ChatList> MessagesManager::get_chat_list_object(DialogListId dialog_list_id) {
|
||||||
if (dialog_list_id == DialogListId(FolderId::archive())) {
|
if (dialog_list_id.is_folder()) {
|
||||||
return td_api::make_object<td_api::chatListArchive>();
|
if (dialog_list_id == DialogListId(FolderId::archive())) {
|
||||||
}
|
return td_api::make_object<td_api::chatListArchive>();
|
||||||
if (dialog_list_id == DialogListId(FolderId::main())) {
|
}
|
||||||
|
if (dialog_list_id == DialogListId(FolderId::main())) {
|
||||||
|
return td_api::make_object<td_api::chatListMain>();
|
||||||
|
}
|
||||||
return td_api::make_object<td_api::chatListMain>();
|
return td_api::make_object<td_api::chatListMain>();
|
||||||
}
|
}
|
||||||
return td_api::make_object<td_api::chatListMain>();
|
if (dialog_list_id.is_filter()) {
|
||||||
|
return td_api::make_object<td_api::chatListFilter>(dialog_list_id.get_filter_id().get());
|
||||||
|
}
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
td_api::object_ptr<td_api::ChatActionBar> MessagesManager::get_chat_action_bar_object(const Dialog *d) const {
|
td_api::object_ptr<td_api::ChatActionBar> MessagesManager::get_chat_action_bar_object(const Dialog *d) const {
|
||||||
@ -30128,6 +30135,15 @@ vector<FolderId> MessagesManager::get_dialog_list_folder_ids(const DialogList &l
|
|||||||
if (list.dialog_list_id.is_folder()) {
|
if (list.dialog_list_id.is_folder()) {
|
||||||
return {list.dialog_list_id.get_folder_id()};
|
return {list.dialog_list_id.get_folder_id()};
|
||||||
}
|
}
|
||||||
|
if (list.dialog_list_id.is_filter()) {
|
||||||
|
auto dialog_filter_id = list.dialog_list_id.get_filter_id();
|
||||||
|
auto *filter = get_dialog_filter(dialog_filter_id);
|
||||||
|
CHECK(filter != nullptr);
|
||||||
|
if (filter->exclude_archived) {
|
||||||
|
return {FolderId::main()};
|
||||||
|
}
|
||||||
|
return {FolderId::main(), FolderId::archive()};
|
||||||
|
}
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -30136,6 +30152,15 @@ bool MessagesManager::has_dialogs_from_folder(const DialogList &list, const Dial
|
|||||||
if (list.dialog_list_id.is_folder()) {
|
if (list.dialog_list_id.is_folder()) {
|
||||||
return list.dialog_list_id.get_folder_id() == folder.folder_id;
|
return list.dialog_list_id.get_folder_id() == folder.folder_id;
|
||||||
}
|
}
|
||||||
|
if (list.dialog_list_id.is_filter()) {
|
||||||
|
auto dialog_filter_id = list.dialog_list_id.get_filter_id();
|
||||||
|
auto *filter = get_dialog_filter(dialog_filter_id);
|
||||||
|
CHECK(filter != nullptr);
|
||||||
|
if (filter->exclude_archived) {
|
||||||
|
return folder.folder_id == FolderId::main();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -30151,6 +30176,81 @@ bool MessagesManager::need_dialog_in_list(const Dialog *d, const DialogList &lis
|
|||||||
if (list.dialog_list_id.is_folder()) {
|
if (list.dialog_list_id.is_folder()) {
|
||||||
return d->folder_id == list.dialog_list_id.get_folder_id();
|
return d->folder_id == list.dialog_list_id.get_folder_id();
|
||||||
}
|
}
|
||||||
|
if (list.dialog_list_id.is_filter()) {
|
||||||
|
auto dialog_filter_id = list.dialog_list_id.get_filter_id();
|
||||||
|
auto *filter = get_dialog_filter(dialog_filter_id);
|
||||||
|
CHECK(filter != nullptr);
|
||||||
|
auto matches = [](const vector<InputDialogId> input_dialog_ids, DialogId dialog_id) {
|
||||||
|
for (auto &input_dialog_id : input_dialog_ids) {
|
||||||
|
if (input_dialog_id.get_dialog_id() == dialog_id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
if (matches(filter->pinned_dialog_ids, d->dialog_id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (matches(filter->included_dialog_ids, d->dialog_id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (matches(filter->excluded_dialog_ids, d->dialog_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (d->dialog_id.get_type() == DialogType::SecretChat) {
|
||||||
|
auto user_id = td_->contacts_manager_->get_secret_chat_user_id(d->dialog_id.get_secret_chat_id());
|
||||||
|
if (user_id.is_valid()) {
|
||||||
|
auto dialog_id = DialogId(user_id);
|
||||||
|
if (matches(filter->pinned_dialog_ids, dialog_id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (matches(filter->included_dialog_ids, dialog_id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (matches(filter->excluded_dialog_ids, dialog_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filter->exclude_muted && is_dialog_muted(d)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (filter->exclude_read && d->server_unread_count + d->local_unread_count == 0 && !d->is_marked_as_unread) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (filter->exclude_archived && d->folder_id == FolderId::archive()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (d->dialog_id.get_type()) {
|
||||||
|
case DialogType::User: {
|
||||||
|
auto user_id = d->dialog_id.get_user_id();
|
||||||
|
if (td_->contacts_manager_->is_user_bot(user_id)) {
|
||||||
|
return filter->include_bots;
|
||||||
|
}
|
||||||
|
if (td_->contacts_manager_->is_user_contact(user_id)) {
|
||||||
|
return filter->include_contacts;
|
||||||
|
}
|
||||||
|
return filter->include_non_contacts;
|
||||||
|
}
|
||||||
|
case DialogType::Chat:
|
||||||
|
return filter->include_groups;
|
||||||
|
case DialogType::Channel:
|
||||||
|
return is_broadcast_channel(d->dialog_id) ? filter->include_channels : filter->include_groups;
|
||||||
|
case DialogType::SecretChat: {
|
||||||
|
auto user_id = td_->contacts_manager_->get_secret_chat_user_id(d->dialog_id.get_secret_chat_id());
|
||||||
|
if (td_->contacts_manager_->is_user_bot(user_id)) {
|
||||||
|
return filter->include_bots;
|
||||||
|
}
|
||||||
|
if (td_->contacts_manager_->is_user_contact(user_id)) {
|
||||||
|
return filter->include_contacts;
|
||||||
|
}
|
||||||
|
return filter->include_non_contacts;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -467,19 +467,22 @@ class CliClient final : public Actor {
|
|||||||
return to_integer<int64>(str);
|
return to_integer<int64>(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 as_chat_filter_id(Slice str) const {
|
static int32 as_chat_filter_id(Slice str) {
|
||||||
return to_integer<int32>(trim(str));
|
return to_integer<int32>(trim(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int32> as_chat_filter_ids(Slice chat_filter_ids) const {
|
static vector<int32> as_chat_filter_ids(Slice chat_filter_ids) {
|
||||||
return transform(full_split(trim(chat_filter_ids), get_delimiter(chat_filter_ids)),
|
return transform(full_split(trim(chat_filter_ids), get_delimiter(chat_filter_ids)),
|
||||||
[this](Slice str) { return as_chat_filter_id(str); });
|
[](Slice str) { return as_chat_filter_id(str); });
|
||||||
}
|
}
|
||||||
|
|
||||||
static td_api::object_ptr<td_api::ChatList> as_chat_list(string chat_list) {
|
static td_api::object_ptr<td_api::ChatList> as_chat_list(string chat_list) {
|
||||||
if (!chat_list.empty() && chat_list.back() == 'a') {
|
if (!chat_list.empty() && chat_list.back() == 'a') {
|
||||||
return td_api::make_object<td_api::chatListArchive>();
|
return td_api::make_object<td_api::chatListArchive>();
|
||||||
}
|
}
|
||||||
|
if (chat_list.find('-') != string::npos) {
|
||||||
|
return td_api::make_object<td_api::chatListFilter>(as_chat_filter_id(chat_list.substr(chat_list.find('-') + 1)));
|
||||||
|
}
|
||||||
return td_api::make_object<td_api::chatListMain>();
|
return td_api::make_object<td_api::chatListMain>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1758,7 +1761,7 @@ class CliClient final : public Actor {
|
|||||||
op_not_found_count++;
|
op_not_found_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (op == "gc" || op == "GetChats" || op == "gca") {
|
if (op == "gc" || op == "GetChats" || op == "gca" || begins_with(op, "gc-")) {
|
||||||
string offset_order_string;
|
string offset_order_string;
|
||||||
string offset_chat_id;
|
string offset_chat_id;
|
||||||
string limit;
|
string limit;
|
||||||
@ -2842,7 +2845,7 @@ class CliClient final : public Actor {
|
|||||||
send_request(td_api::make_object<td_api::setChatDraftMessage>(as_chat_id(chat_id), std::move(draft_message)));
|
send_request(td_api::make_object<td_api::setChatDraftMessage>(as_chat_id(chat_id), std::move(draft_message)));
|
||||||
} else if (op == "cadm") {
|
} else if (op == "cadm") {
|
||||||
send_request(td_api::make_object<td_api::clearAllDraftMessages>());
|
send_request(td_api::make_object<td_api::clearAllDraftMessages>());
|
||||||
} else if (op == "tcip" || op == "tcipa") {
|
} else if (op == "tcip" || op == "tcipa" || begins_with(op, "tcip-")) {
|
||||||
string chat_id;
|
string chat_id;
|
||||||
string is_pinned;
|
string is_pinned;
|
||||||
std::tie(chat_id, is_pinned) = split(args);
|
std::tie(chat_id, is_pinned) = split(args);
|
||||||
@ -2860,7 +2863,7 @@ class CliClient final : public Actor {
|
|||||||
std::tie(chat_id, default_disable_notification) = split(args);
|
std::tie(chat_id, default_disable_notification) = split(args);
|
||||||
send_request(td_api::make_object<td_api::toggleChatDefaultDisableNotification>(
|
send_request(td_api::make_object<td_api::toggleChatDefaultDisableNotification>(
|
||||||
as_chat_id(chat_id), as_bool(default_disable_notification)));
|
as_chat_id(chat_id), as_bool(default_disable_notification)));
|
||||||
} else if (op == "spchats" || op == "spchatsa") {
|
} else if (op == "spchats" || op == "spchatsa" || begins_with(op, "spchats-")) {
|
||||||
vector<string> chat_ids_str = full_split(args, ' ');
|
vector<string> chat_ids_str = full_split(args, ' ');
|
||||||
vector<int64> chat_ids;
|
vector<int64> chat_ids;
|
||||||
for (auto &chat_id_str : chat_ids_str) {
|
for (auto &chat_id_str : chat_ids_str) {
|
||||||
@ -3507,7 +3510,7 @@ class CliClient final : public Actor {
|
|||||||
|
|
||||||
std::tie(supergroup_id, force) = split(args);
|
std::tie(supergroup_id, force) = split(args);
|
||||||
send_request(td_api::make_object<td_api::createSupergroupChat>(as_supergroup_id(supergroup_id), as_bool(force)));
|
send_request(td_api::make_object<td_api::createSupergroupChat>(as_supergroup_id(supergroup_id), as_bool(force)));
|
||||||
} else if (op == "sccl" || op == "sccla") {
|
} else if (op == "sccl" || op == "sccla" || begins_with(op, "sccl-")) {
|
||||||
string chat_id = args;
|
string chat_id = args;
|
||||||
send_request(td_api::make_object<td_api::setChatChatList>(as_chat_id(chat_id), as_chat_list(op)));
|
send_request(td_api::make_object<td_api::setChatChatList>(as_chat_id(chat_id), as_chat_list(op)));
|
||||||
} else if (op == "gcf") {
|
} else if (op == "gcf") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user