mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
fix(relationships): scope friend search results
Limit friends-mode search results to nodes in the friend graph so selecting an off-scope groupmate cannot replace the canvas with an empty neighborhood.
This commit is contained in:
1 parent
ac64cb72fb
commit
99de252081
2 files changed
+7
-5
No files matched your search
@@ -347,7 +347,7 @@ test('excludes silent non-friend group roster members from the close relationshi
|
||||
}
|
||||
})
|
||||
|
||||
test('returns a friends relationships graph without groupmate nodes while keeping full search results', () => {
|
||||
test('returns only friends in the friends graph and search results', () => {
|
||||
const dir = makeTempDir()
|
||||
try {
|
||||
const service = createPeopleRelationshipsService({
|
||||
@@ -400,7 +400,7 @@ test('returns a friends relationships graph without groupmate nodes while keepin
|
||||
)
|
||||
assert.equal(
|
||||
response.searchResults.some((result) => result.key === groupmate.key),
|
||||
true
|
||||
false
|
||||
)
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true })
|
||||
|
||||
@@ -292,7 +292,7 @@ class DefaultPeopleRelationshipsService implements PeopleRelationshipsService {
|
||||
const graph = includeSnapshot && snapshot ? buildGraphForScope(snapshot, graphScope) : emptyGraph()
|
||||
return {
|
||||
graph,
|
||||
searchResults: includeSnapshot && snapshot ? buildSearchResults(snapshot, options.query, graph) : [],
|
||||
searchResults: includeSnapshot && snapshot ? buildSearchResults(snapshot, options.query, graph, graphScope) : [],
|
||||
diagnostics: includeSnapshot
|
||||
? sanitizePeopleRelationshipsDiagnostics(snapshot?.diagnostics ?? createEmptyDiagnostics())
|
||||
: createEmptyDiagnostics(),
|
||||
@@ -457,12 +457,14 @@ function filterCommunitiesForNodes(
|
||||
function buildSearchResults(
|
||||
snapshot: PeopleRelationshipsSnapshot,
|
||||
queryInput: string | undefined,
|
||||
graph: PeopleRelationshipsGraphData
|
||||
graph: PeopleRelationshipsGraphData,
|
||||
graphScope: PeopleRelationshipsGraphScope
|
||||
): PeopleRelationshipsSearchResult[] {
|
||||
const query = queryInput?.trim().toLowerCase() ?? ''
|
||||
if (!query) return []
|
||||
const visibleKeys = new Set(graph.nodes.map((node) => node.key))
|
||||
return snapshot.nodes
|
||||
const searchableNodes = graphScope === 'friends' ? graph.nodes : snapshot.nodes
|
||||
return searchableNodes
|
||||
.filter((node) => node.searchText.includes(query))
|
||||
.sort(compareNodes)
|
||||
.slice(0, snapshot.limits.searchResultLimit)
|
||||
|
||||
Reference in new issue
Block a user