Print port in serve-local script
This commit is contained in:
parent
4bc70d99f4
commit
7d2dd5cc68
2 changed files with 26 additions and 8 deletions
|
@ -56,6 +56,17 @@ export class HomeServer {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MSC3266 implementation
|
||||||
|
async getRoomSummary(roomIdOrAlias, viaServers) {
|
||||||
|
let query;
|
||||||
|
if (viaServers.length > 0) {
|
||||||
|
query = "?" + viaServers.map(server => `via=${encodeURIComponent(server)}`).join('&');
|
||||||
|
}
|
||||||
|
const {body, status} = await this._request(`${this.baseURL}/_matrix/client/unstable/im.nheko.summary/rooms/${encodeURIComponent(roomIdOrAlias)}/summary${query}`).response();
|
||||||
|
if (status !== 200) return;
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
async findPublicRoomById(roomId) {
|
async findPublicRoomById(roomId) {
|
||||||
const {body, status} = await this._request(`${this.baseURL}/_matrix/client/r0/directory/list/room/${encodeURIComponent(roomId)}`).response();
|
const {body, status} = await this._request(`${this.baseURL}/_matrix/client/r0/directory/list/room/${encodeURIComponent(roomId)}`).response();
|
||||||
if (status !== 200 || body.visibility !== "public") {
|
if (status !== 200 || body.visibility !== "public") {
|
||||||
|
|
|
@ -88,14 +88,21 @@ export class PreviewViewModel extends ViewModel {
|
||||||
|
|
||||||
async _loadRoomPreview(homeserver, link) {
|
async _loadRoomPreview(homeserver, link) {
|
||||||
let publicRoom;
|
let publicRoom;
|
||||||
if (link.identifierKind === IdentifierKind.RoomId) {
|
if (link.identifierKind === IdentifierKind.RoomId || link.identifierKind === IdentifierKind.RoomAlias) {
|
||||||
publicRoom = await homeserver.findPublicRoomById(link.identifier);
|
publicRoom = await homeserver.getRoomSummary(link.identifier, link.servers);
|
||||||
} else if (link.identifierKind === IdentifierKind.RoomAlias) {
|
}
|
||||||
const roomId = await homeserver.getRoomIdFromAlias(link.identifier);
|
|
||||||
if (roomId) {
|
if (!publicRoom) {
|
||||||
publicRoom = await homeserver.findPublicRoomById(roomId);
|
if (link.identifierKind === IdentifierKind.RoomId) {
|
||||||
}
|
publicRoom = await homeserver.findPublicRoomById(link.identifier);
|
||||||
}
|
} else if (link.identifierKind === IdentifierKind.RoomAlias) {
|
||||||
|
const roomId = await homeserver.getRoomIdFromAlias(link.identifier);
|
||||||
|
if (roomId) {
|
||||||
|
publicRoom = await homeserver.findPublicRoomById(roomId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.name = publicRoom?.name || publicRoom?.canonical_alias || link.identifier;
|
this.name = publicRoom?.name || publicRoom?.canonical_alias || link.identifier;
|
||||||
this.avatarUrl = publicRoom?.avatar_url ?
|
this.avatarUrl = publicRoom?.avatar_url ?
|
||||||
homeserver.mxcUrlThumbnail(publicRoom.avatar_url, 64, 64, "crop") :
|
homeserver.mxcUrlThumbnail(publicRoom.avatar_url, 64, 64, "crop") :
|
||||||
|
|
Loading…
Reference in a new issue