Remove lag when starting user autocompletion

We realistically don't need to interate over every user when typing '@',
since this is not usefull for the user and create some lag.
This commit is contained in:
Carl Schwan
2021-12-25 18:31:22 +01:00
parent 26f0cd4cf4
commit ca2b5fde8e
3 changed files with 8 additions and 3 deletions

View File

@@ -276,10 +276,11 @@ void NeoChatRoom::saveViewport(int topIndex, int bottomIndex)
setLastDisplayedEvent(maxTimelineIndex() - bottomIndex);
}
QVariantList NeoChatRoom::getUsers(const QString &keyword) const
QVariantList NeoChatRoom::getUsers(const QString &keyword, int limit) const
{
const auto userList = users();
QVariantList matchedList;
int count = 0;
for (const auto u : userList) {
if (u->displayname(this).contains(keyword, Qt::CaseInsensitive)) {
NeoChatUser user(u->id(), u->connection());
@@ -289,6 +290,10 @@ QVariantList NeoChatRoom::getUsers(const QString &keyword) const
{QStringLiteral("color"), user.color()}};
matchedList.append(QVariant::fromValue(userVariant));
count++;
if (count == limit) { // -1 is infinite
break;
}
}
}