mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-17 04:39:47 +00:00
Improve AddSpecial box for legacy groups.
This commit is contained in:
parent
07e010dfb5
commit
215856adc3
@ -791,12 +791,7 @@ bool AddSpecialBoxSearchController::loadMoreRows() {
|
|||||||
requestGlobal();
|
requestGlobal();
|
||||||
}
|
}
|
||||||
} else if (const auto chat = _peer->asChat()) {
|
} else if (const auto chat = _peer->asChat()) {
|
||||||
if (chat->participants.empty()) {
|
addChatMembers(chat);
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
addChatMembers();
|
|
||||||
_participantsLoaded = true;
|
|
||||||
}
|
|
||||||
} else if (!isLoading()) {
|
} else if (!isLoading()) {
|
||||||
requestParticipants();
|
requestParticipants();
|
||||||
}
|
}
|
||||||
@ -951,26 +946,79 @@ void AddSpecialBoxSearchController::searchGlobalDone(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddSpecialBoxSearchController::addChatMembers() {
|
void AddSpecialBoxSearchController::addChatMembers(
|
||||||
// #TODO groups
|
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() {
|
void AddSpecialBoxSearchController::addChatsContacts() {
|
||||||
_chatsContactsAdded = true;
|
_chatsContactsAdded = true;
|
||||||
|
|
||||||
auto wordList = TextUtilities::PrepareSearchWords(_query);
|
const auto wordList = TextUtilities::PrepareSearchWords(_query);
|
||||||
if (wordList.empty()) {
|
if (wordList.empty()) {
|
||||||
return;
|
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()) {
|
if (list->isEmpty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = (const Dialogs::List*)nullptr;
|
auto result = (const Dialogs::List*)nullptr;
|
||||||
for_const (auto &word, wordList) {
|
for (const auto &word : wordList) {
|
||||||
auto found = list->filtered(word[0]);
|
const auto found = list->filtered(word[0]);
|
||||||
if (found->isEmpty()) {
|
if (found->isEmpty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -980,27 +1028,10 @@ void AddSpecialBoxSearchController::addChatsContacts() {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
auto dialogsIndex = getSmallestIndex(App::main()->dialogsList());
|
const auto dialogsIndex = getSmallestIndex(App::main()->dialogsList());
|
||||||
auto contactsIndex = getSmallestIndex(App::main()->contactsNoDialogsList());
|
const auto contactsIndex = getSmallestIndex(App::main()->contactsNoDialogsList());
|
||||||
|
|
||||||
auto allWordsAreFound = [&](const base::flat_set<QString> &nameWords) {
|
const auto filterAndAppend = [&](const Dialogs::List *list) {
|
||||||
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) {
|
|
||||||
if (!list) {
|
if (!list) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ private:
|
|||||||
mtpRequestId requestId,
|
mtpRequestId requestId,
|
||||||
const MTPcontacts_Found &result);
|
const MTPcontacts_Found &result);
|
||||||
void requestParticipants();
|
void requestParticipants();
|
||||||
void addChatMembers();
|
void addChatMembers(not_null<ChatData*> chat);
|
||||||
void addChatsContacts();
|
void addChatsContacts();
|
||||||
void requestGlobal();
|
void requestGlobal();
|
||||||
|
|
||||||
|
@ -1109,7 +1109,7 @@ void Controller::saveUsername() {
|
|||||||
if (!_savingData.username || *_savingData.username == username) {
|
if (!_savingData.username || *_savingData.username == username) {
|
||||||
return continueSave();
|
return continueSave();
|
||||||
} else if (!channel) {
|
} else if (!channel) {
|
||||||
// #TODO groups convert and save.
|
// #TODO groups autoconv
|
||||||
return continueSave();
|
return continueSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1226,7 +1226,7 @@ void Controller::saveHistoryVisibility() {
|
|||||||
|| *_savingData.hiddenPreHistory == hidden) {
|
|| *_savingData.hiddenPreHistory == hidden) {
|
||||||
return continueSave();
|
return continueSave();
|
||||||
} else if (!channel) {
|
} else if (!channel) {
|
||||||
// #TODO groups convert and save.
|
// #TODO groups autoconv
|
||||||
return continueSave();
|
return continueSave();
|
||||||
}
|
}
|
||||||
request(MTPchannels_TogglePreHistoryHidden(
|
request(MTPchannels_TogglePreHistoryHidden(
|
||||||
|
@ -240,13 +240,13 @@ void EditPeerPermissionsBox::prepare() {
|
|||||||
const auto restrictions = [&] {
|
const auto restrictions = [&] {
|
||||||
if (const auto chat = _peer->asChat()) {
|
if (const auto chat = _peer->asChat()) {
|
||||||
return chat->defaultRestrictions()
|
return chat->defaultRestrictions()
|
||||||
| disabledByAdminRights; // #TODO groups
|
| disabledByAdminRights;
|
||||||
} else if (const auto channel = _peer->asChannel()) {
|
} else if (const auto channel = _peer->asChannel()) {
|
||||||
return (channel->defaultRestrictions()
|
return channel->defaultRestrictions()
|
||||||
| (channel->isPublic()
|
| (channel->isPublic()
|
||||||
? (Flag::f_change_info | Flag::f_pin_messages)
|
? (Flag::f_change_info | Flag::f_pin_messages)
|
||||||
: Flags(0))
|
: Flags(0))
|
||||||
| disabledByAdminRights); // #TODO groups
|
| disabledByAdminRights;
|
||||||
}
|
}
|
||||||
Unexpected("User in EditPeerPermissionsBox.");
|
Unexpected("User in EditPeerPermissionsBox.");
|
||||||
}();
|
}();
|
||||||
|
Loading…
Reference in New Issue
Block a user