Improve AddSpecial box for legacy groups.

This commit is contained in:
John Preston 2019-01-10 17:21:24 +04:00
parent 07e010dfb5
commit 215856adc3
4 changed files with 69 additions and 38 deletions

View File

@ -791,12 +791,7 @@ bool AddSpecialBoxSearchController::loadMoreRows() {
requestGlobal();
}
} else if (const auto chat = _peer->asChat()) {
if (chat->participants.empty()) {
return true;
} else {
addChatMembers();
_participantsLoaded = true;
}
addChatMembers(chat);
} else if (!isLoading()) {
requestParticipants();
}
@ -951,26 +946,79 @@ void AddSpecialBoxSearchController::searchGlobalDone(
}
}
void AddSpecialBoxSearchController::addChatMembers() {
// #TODO groups
void AddSpecialBoxSearchController::addChatMembers(
not_null<ChatData*> chat) {
if (chat->participants.empty()) {
return;
}
_participantsLoaded = true;
const auto wordList = TextUtilities::PrepareSearchWords(_query);
if (wordList.empty()) {
return;
}
const auto allWordsAreFound = [&](
const base::flat_set<QString> &nameWords) {
const auto hasNamePartStartingWith = [&](const QString &word) {
for (const auto &nameWord : nameWords) {
if (nameWord.startsWith(word)) {
return true;
}
}
return false;
};
for (const auto &word : wordList) {
if (!hasNamePartStartingWith(word)) {
return false;
}
}
return true;
};
for (const auto [user, v] : chat->participants) {
if (allWordsAreFound(user->nameWords())) {
delegate()->peerListSearchAddRow(user);
}
}
delegate()->peerListSearchRefreshRows();
}
void AddSpecialBoxSearchController::addChatsContacts() {
_chatsContactsAdded = true;
auto wordList = TextUtilities::PrepareSearchWords(_query);
const auto wordList = TextUtilities::PrepareSearchWords(_query);
if (wordList.empty()) {
return;
}
const auto allWordsAreFound = [&](
const base::flat_set<QString> &nameWords) {
const auto hasNamePartStartingWith = [&](const QString &word) {
for (const auto &nameWord : nameWords) {
if (nameWord.startsWith(word)) {
return true;
}
}
return false;
};
auto getSmallestIndex = [&](Dialogs::IndexedList *list) -> const Dialogs::List* {
for (const auto &word : wordList) {
if (!hasNamePartStartingWith(word)) {
return false;
}
}
return true;
};
const auto getSmallestIndex = [&](
Dialogs::IndexedList *list) -> const Dialogs::List* {
if (list->isEmpty()) {
return nullptr;
}
auto result = (const Dialogs::List*)nullptr;
for_const (auto &word, wordList) {
auto found = list->filtered(word[0]);
for (const auto &word : wordList) {
const auto found = list->filtered(word[0]);
if (found->isEmpty()) {
return nullptr;
}
@ -980,27 +1028,10 @@ void AddSpecialBoxSearchController::addChatsContacts() {
}
return result;
};
auto dialogsIndex = getSmallestIndex(App::main()->dialogsList());
auto contactsIndex = getSmallestIndex(App::main()->contactsNoDialogsList());
const auto dialogsIndex = getSmallestIndex(App::main()->dialogsList());
const auto contactsIndex = getSmallestIndex(App::main()->contactsNoDialogsList());
auto allWordsAreFound = [&](const base::flat_set<QString> &nameWords) {
auto hasNamePartStartingWith = [&](const QString &word) {
for (auto &nameWord : nameWords) {
if (nameWord.startsWith(word)) {
return true;
}
}
return false;
};
for_const (auto &word, wordList) {
if (!hasNamePartStartingWith(word)) {
return false;
}
}
return true;
};
auto filterAndAppend = [&](const Dialogs::List *list) {
const auto filterAndAppend = [&](const Dialogs::List *list) {
if (!list) {
return;
}

View File

@ -152,7 +152,7 @@ private:
mtpRequestId requestId,
const MTPcontacts_Found &result);
void requestParticipants();
void addChatMembers();
void addChatMembers(not_null<ChatData*> chat);
void addChatsContacts();
void requestGlobal();

View File

@ -1109,7 +1109,7 @@ void Controller::saveUsername() {
if (!_savingData.username || *_savingData.username == username) {
return continueSave();
} else if (!channel) {
// #TODO groups convert and save.
// #TODO groups autoconv
return continueSave();
}
@ -1226,7 +1226,7 @@ void Controller::saveHistoryVisibility() {
|| *_savingData.hiddenPreHistory == hidden) {
return continueSave();
} else if (!channel) {
// #TODO groups convert and save.
// #TODO groups autoconv
return continueSave();
}
request(MTPchannels_TogglePreHistoryHidden(

View File

@ -240,13 +240,13 @@ void EditPeerPermissionsBox::prepare() {
const auto restrictions = [&] {
if (const auto chat = _peer->asChat()) {
return chat->defaultRestrictions()
| disabledByAdminRights; // #TODO groups
| disabledByAdminRights;
} else if (const auto channel = _peer->asChannel()) {
return (channel->defaultRestrictions()
return channel->defaultRestrictions()
| (channel->isPublic()
? (Flag::f_change_info | Flag::f_pin_messages)
: Flags(0))
| disabledByAdminRights); // #TODO groups
| disabledByAdminRights;
}
Unexpected("User in EditPeerPermissionsBox.");
}();