Skip to content

Commit 72f017e

Browse files
authored
Merge pull request #678 from FreeFeed/autocomplete-match
Return private users/groups by the exact match
2 parents ce1f37c + df38b37 commit 72f017e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [2.23.0] - Not released
9+
### Changed
10+
- The `GET /v2/users/sparseMatches?qs=...` API endpoint now returns private
11+
users and groups when the username _exactly matches_ the query string.
912

1013
## [2.22.3] - 2024-09-19
1114
### Fixed

app/support/DbAdapter/users.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,10 @@ const usersTrait = (superClass) =>
676676
}
677677

678678
sparseMatchesUserIds(query) {
679+
query = query.toLowerCase();
679680
return this.database.getCol(
680-
`select uid from users where username like :query and not is_private`,
681-
{ query: `%${query.split('').join('%')}%` },
681+
`select uid from users where username like :sparseQuery and not is_private or username = :query`,
682+
{ sparseQuery: `%${query.split('').join('%')}%`, query },
682683
);
683684
}
684685
};

test/integration/support/DbAdapter/users-sparse-match.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('sparseMatchesUserIds', () => {
3939
expect(names, 'when sorted', 'to equal', ['antenna', 'uranus', 'saturn'].sort());
4040
});
4141

42-
describe('Lona goes private', () => {
42+
describe('Luna goes private', () => {
4343
before(() => users.find((u) => u.username === 'luna').update({ isPrivate: '1' }));
4444
after(() =>
4545
users.find((u) => u.username === 'luna').update({ isPrivate: '0', isProtected: '0' }),
@@ -50,5 +50,11 @@ describe('sparseMatchesUserIds', () => {
5050
const names = ids.map((id) => users.find((u) => u.id === id).username);
5151
expect(names, 'when sorted', 'to equal', ['uranus'].sort());
5252
});
53+
54+
it('should find Luna using the exact query', async () => {
55+
const ids = await dbAdapter.sparseMatchesUserIds('luna');
56+
const names = ids.map((id) => users.find((u) => u.id === id).username);
57+
expect(names, 'when sorted', 'to equal', ['luna'].sort());
58+
});
5359
});
5460
});

0 commit comments

Comments
 (0)