mirror of https://github.com/vector-im/riot-web
Implement MSC3973: Search users in the user directory with the Widget API (#10269)
* Add an action to search for users in the user directory according to MSC3973 Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> * Fix linter errors Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> * Update the matrix-widget-api package to version 1.3.0 Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> * Improve the test Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> --------- Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net>pull/28788/head^2
parent
aee4aeb90c
commit
ef68650594
|
@ -31,6 +31,7 @@ import {
|
|||
WidgetDriver,
|
||||
WidgetEventCapability,
|
||||
WidgetKind,
|
||||
ISearchUserDirectoryResult,
|
||||
} from "matrix-widget-api";
|
||||
import { ClientEvent, ITurnServer as IClientTurnServer } from "matrix-js-sdk/src/client";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
|
@ -486,4 +487,19 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||
prevBatch: prevBatch ?? undefined,
|
||||
};
|
||||
}
|
||||
|
||||
public async searchUserDirectory(searchTerm: string, limit?: number): Promise<ISearchUserDirectoryResult> {
|
||||
const client = MatrixClientPeg.get();
|
||||
|
||||
const { limited, results } = await client.searchUserDirectory({ term: searchTerm, limit });
|
||||
|
||||
return {
|
||||
limited,
|
||||
results: results.map((r) => ({
|
||||
userId: r.user_id,
|
||||
displayName: r.display_name,
|
||||
avatarUrl: r.avatar_url,
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -394,4 +394,40 @@ describe("StopGapWidgetDriver", () => {
|
|||
expect(client.getVisibleRooms).toHaveBeenCalledWith(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("searchUserDirectory", () => {
|
||||
let driver: WidgetDriver;
|
||||
|
||||
beforeEach(() => {
|
||||
driver = mkDefaultDriver();
|
||||
});
|
||||
|
||||
it("searches for users in the user directory", async () => {
|
||||
client.searchUserDirectory.mockResolvedValue({
|
||||
limited: false,
|
||||
results: [{ user_id: "@user", display_name: "Name", avatar_url: "mxc://" }],
|
||||
});
|
||||
|
||||
await expect(driver.searchUserDirectory("foo")).resolves.toEqual({
|
||||
limited: false,
|
||||
results: [{ userId: "@user", displayName: "Name", avatarUrl: "mxc://" }],
|
||||
});
|
||||
|
||||
expect(client.searchUserDirectory).toHaveBeenCalledWith({ term: "foo", limit: undefined });
|
||||
});
|
||||
|
||||
it("searches for users with a custom limit", async () => {
|
||||
client.searchUserDirectory.mockResolvedValue({
|
||||
limited: true,
|
||||
results: [],
|
||||
});
|
||||
|
||||
await expect(driver.searchUserDirectory("foo", 25)).resolves.toEqual({
|
||||
limited: true,
|
||||
results: [],
|
||||
});
|
||||
|
||||
expect(client.searchUserDirectory).toHaveBeenCalledWith({ term: "foo", limit: 25 });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -231,6 +231,8 @@ export function createTestClient(): MatrixClient {
|
|||
room_id: roomId,
|
||||
});
|
||||
}),
|
||||
|
||||
searchUserDirectory: jest.fn().mockResolvedValue({ limited: false, results: [] }),
|
||||
} as unknown as MatrixClient;
|
||||
|
||||
client.reEmitter = new ReEmitter(client);
|
||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -6510,15 +6510,7 @@ matrix-web-i18n@^1.3.0:
|
|||
"@babel/traverse" "^7.18.5"
|
||||
walk "^2.3.15"
|
||||
|
||||
matrix-widget-api@^1.0.0:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.1.1.tgz#d3fec45033d0cbc14387a38ba92dac4dbb1be962"
|
||||
integrity sha512-gNSgmgSwvOsOcWK9k2+tOhEMYBiIMwX95vMZu0JqY7apkM02xrOzUBuPRProzN8CnbIALH7e3GAhatF6QCNvtA==
|
||||
dependencies:
|
||||
"@types/events" "^3.0.0"
|
||||
events "^3.2.0"
|
||||
|
||||
matrix-widget-api@^1.3.1:
|
||||
matrix-widget-api@^1.0.0, matrix-widget-api@^1.3.1:
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.3.1.tgz#e38f404c76bb15c113909505c1c1a5b4d781c2f5"
|
||||
integrity sha512-+rN6vGvnXm+fn0uq9r2KWSL/aPtehD6ObC50jYmUcEfgo8CUpf9eUurmjbRlwZkWq3XHXFuKQBUCI9UzqWg37Q==
|
||||
|
|
Loading…
Reference in New Issue