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:
@@ -268,7 +268,7 @@ ToolBar {
|
|||||||
|
|
||||||
completionMenu.completionType = completionInfo.type
|
completionMenu.completionType = completionInfo.type
|
||||||
if (completionInfo.type === ChatDocumentHandler.User) {
|
if (completionInfo.type === ChatDocumentHandler.User) {
|
||||||
completionMenu.model = currentRoom.getUsers(completionInfo.keyword);
|
completionMenu.model = currentRoom.getUsers(completionInfo.keyword, 10);
|
||||||
} else if (completionInfo.type === ChatDocumentHandler.Command) {
|
} else if (completionInfo.type === ChatDocumentHandler.Command) {
|
||||||
completionMenu.model = CommandModel.filterModel(completionInfo.keyword);
|
completionMenu.model = CommandModel.filterModel(completionInfo.keyword);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -276,10 +276,11 @@ void NeoChatRoom::saveViewport(int topIndex, int bottomIndex)
|
|||||||
setLastDisplayedEvent(maxTimelineIndex() - bottomIndex);
|
setLastDisplayedEvent(maxTimelineIndex() - bottomIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList NeoChatRoom::getUsers(const QString &keyword) const
|
QVariantList NeoChatRoom::getUsers(const QString &keyword, int limit) const
|
||||||
{
|
{
|
||||||
const auto userList = users();
|
const auto userList = users();
|
||||||
QVariantList matchedList;
|
QVariantList matchedList;
|
||||||
|
int count = 0;
|
||||||
for (const auto u : userList) {
|
for (const auto u : userList) {
|
||||||
if (u->displayname(this).contains(keyword, Qt::CaseInsensitive)) {
|
if (u->displayname(this).contains(keyword, Qt::CaseInsensitive)) {
|
||||||
NeoChatUser user(u->id(), u->connection());
|
NeoChatUser user(u->id(), u->connection());
|
||||||
@@ -289,6 +290,10 @@ QVariantList NeoChatRoom::getUsers(const QString &keyword) const
|
|||||||
{QStringLiteral("color"), user.color()}};
|
{QStringLiteral("color"), user.color()}};
|
||||||
|
|
||||||
matchedList.append(QVariant::fromValue(userVariant));
|
matchedList.append(QVariant::fromValue(userVariant));
|
||||||
|
count++;
|
||||||
|
if (count == limit) { // -1 is infinite
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public:
|
|||||||
Q_INVOKABLE [[nodiscard]] int savedBottomVisibleIndex() const;
|
Q_INVOKABLE [[nodiscard]] int savedBottomVisibleIndex() const;
|
||||||
Q_INVOKABLE void saveViewport(int topIndex, int bottomIndex);
|
Q_INVOKABLE void saveViewport(int topIndex, int bottomIndex);
|
||||||
|
|
||||||
Q_INVOKABLE [[nodiscard]] QVariantList getUsers(const QString &keyword) const;
|
Q_INVOKABLE [[nodiscard]] QVariantList getUsers(const QString &keyword, int limit = -1) const;
|
||||||
Q_INVOKABLE [[nodiscard]] QVariantMap getUser(const QString &userID) const;
|
Q_INVOKABLE [[nodiscard]] QVariantMap getUser(const QString &userID) const;
|
||||||
|
|
||||||
Q_INVOKABLE QUrl urlToMxcUrl(const QUrl &mxcUrl);
|
Q_INVOKABLE QUrl urlToMxcUrl(const QUrl &mxcUrl);
|
||||||
|
|||||||
Reference in New Issue
Block a user