Add redimentary group support

This commit is contained in:
Jorik Schellekens
2020-09-17 15:41:32 +01:00
parent 122bb55535
commit cc175b34cb
9 changed files with 225 additions and 80 deletions
+19
View File
@@ -24,10 +24,12 @@ import {
Room,
RoomAlias,
User,
Group,
getRoomIdFromAlias,
searchPublicRooms,
getUserDetails,
convertMXCtoMediaQuery,
getGroupDetails,
} from '../matrix-cypher';
import { LinkKind, Permalink } from '../parser/types';
@@ -72,6 +74,11 @@ export const fallbackRoom = ({
};
};
export const fallbackGroup = (groupId: string): Group => ({
name: groupId,
short_description: `The ${groupId} group`,
});
/*
* Tries to fetch room details from an alias. If it fails it uses
* a `fallbackRoom`
@@ -169,3 +176,15 @@ export function getMediaQueryFromMCX(mxc?: string): string {
return '';
}
}
export async function getGroup(
clientURL: string,
groupId: string
): Promise<Group> {
try {
const resolvedClient = await client(clientURL);
return await getGroupDetails(resolvedClient, groupId);
} catch {
return fallbackGroup(groupId);
}
}