Display rooms list
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { APIClient } from "../ApiClient";
|
||||
import type { UserInfo } from "../AuthApi";
|
||||
import type { MatrixEvent } from "./MatrixApiEvent";
|
||||
import type { UsersMap } from "./MatrixApiProfile";
|
||||
|
||||
export interface Room {
|
||||
id: string;
|
||||
@@ -12,6 +14,32 @@ export interface Room {
|
||||
latest_event?: MatrixEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find main member of room
|
||||
*/
|
||||
export function mainRoomMember(user: UserInfo, r: Room): string | undefined {
|
||||
if (r.members.length <= 1) return r.members[0];
|
||||
|
||||
if (r.members.length < 2)
|
||||
return r.members[0] == user.matrix_user_id ? r.members[1] : r.members[0];
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find room name
|
||||
*/
|
||||
export function roomName(user: UserInfo, r: Room, users: UsersMap): string {
|
||||
if (r.name) return r.name;
|
||||
|
||||
const name = r.members
|
||||
.filter((m) => m !== user.matrix_user_id)
|
||||
.map((m) => users.get(m)?.display_name ?? m)
|
||||
.join(",");
|
||||
|
||||
return name === "" ? "Empty room" : name;
|
||||
}
|
||||
|
||||
export class MatrixApiRoom {
|
||||
/**
|
||||
* Get the list of joined rooms
|
||||
|
||||
Reference in New Issue
Block a user