Use MatrixClientPeg::safeGet in src/{stores,hooks,components/structures}/* (#10988)
This commit is contained in:
parent
707fd9ccf0
commit
dd46db4817
34 changed files with 139 additions and 130 deletions
|
@ -24,7 +24,7 @@ import { filterBoolean } from "../../utils/arrays";
|
|||
|
||||
export const useRecentSearches = (): [Room[], () => void] => {
|
||||
const [rooms, setRooms] = useState(() => {
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
const recents = SettingsStore.getValue<string[]>("SpotlightSearch.recentSearches", null);
|
||||
return filterBoolean(recents.map((r) => cli.getRoom(r)));
|
||||
});
|
||||
|
|
|
@ -74,7 +74,7 @@ export const usePermalinkEvent = (
|
|||
|
||||
const fetchRoomEvent = async (): Promise<void> => {
|
||||
try {
|
||||
const eventData = await MatrixClientPeg.get().fetchRoomEvent(
|
||||
const eventData = await MatrixClientPeg.safeGet().fetchRoomEvent(
|
||||
parseResult.roomIdOrAlias!,
|
||||
parseResult.eventId!,
|
||||
);
|
||||
|
|
|
@ -59,7 +59,7 @@ const determineInitialRoom = (
|
|||
* @returns Room if found, else null.
|
||||
*/
|
||||
const findRoom = (roomIdOrAlias: string): Room | null => {
|
||||
const client = MatrixClientPeg.get();
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
|
||||
return roomIdOrAlias[0] === "#"
|
||||
? client.getRooms().find((r) => {
|
||||
|
|
|
@ -51,7 +51,7 @@ export const useProfileInfo = (): {
|
|||
|
||||
setLoading(true);
|
||||
try {
|
||||
const result = await MatrixClientPeg.get().getProfileInfo(term);
|
||||
const result = await MatrixClientPeg.safeGet().getProfileInfo(term);
|
||||
updateResult(term, {
|
||||
user_id: term,
|
||||
avatar_url: result.avatar_url,
|
||||
|
|
|
@ -72,7 +72,7 @@ export const usePublicRoomDirectory = (): {
|
|||
} else if (thirdParty) {
|
||||
setProtocols(thirdParty);
|
||||
} else {
|
||||
const response = await MatrixClientPeg.get().getThirdpartyProtocols();
|
||||
const response = await MatrixClientPeg.safeGet().getThirdpartyProtocols();
|
||||
thirdParty = response;
|
||||
setProtocols(response);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ export const usePublicRoomDirectory = (): {
|
|||
generic_search_term: query,
|
||||
room_types:
|
||||
roomTypes &&
|
||||
(await MatrixClientPeg.get().doesServerSupportUnstableFeature("org.matrix.msc3827.stable"))
|
||||
(await MatrixClientPeg.safeGet().doesServerSupportUnstableFeature("org.matrix.msc3827.stable"))
|
||||
? Array.from<RoomType | null>(roomTypes)
|
||||
: undefined,
|
||||
};
|
||||
|
@ -114,7 +114,7 @@ export const usePublicRoomDirectory = (): {
|
|||
updateQuery(opts);
|
||||
try {
|
||||
setLoading(true);
|
||||
const { chunk } = await MatrixClientPeg.get().publicRooms(opts);
|
||||
const { chunk } = await MatrixClientPeg.safeGet().publicRooms(opts);
|
||||
updateResult(opts, showNsfwPublicRooms ? chunk : chunk.filter(cheapNsfwFilter));
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
|
|
@ -62,7 +62,7 @@ export const useSlidingSyncRoomSearch = (): {
|
|||
let i = 0;
|
||||
while (roomIndexToRoomId[i]) {
|
||||
const roomId = roomIndexToRoomId[i];
|
||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
||||
const room = MatrixClientPeg.safeGet().getRoom(roomId);
|
||||
if (room) {
|
||||
rooms.push(room);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ export const useSpaceResults = (space: Room | undefined, query: string): [IHiera
|
|||
const lcQuery = trimmedQuery.toLowerCase();
|
||||
const normalizedQuery = normalize(trimmedQuery);
|
||||
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
return rooms?.filter((r) => {
|
||||
return (
|
||||
r.room_type !== RoomType.Space &&
|
||||
|
|
|
@ -49,7 +49,7 @@ export const useUserDirectory = (): {
|
|||
|
||||
try {
|
||||
setLoading(true);
|
||||
const { results } = await MatrixClientPeg.get().searchUserDirectory(opts);
|
||||
const { results } = await MatrixClientPeg.safeGet().searchUserDirectory(opts);
|
||||
updateResult(
|
||||
opts,
|
||||
results.map((user) => new DirectoryMember(user)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue