mirror of https://github.com/vector-im/riot-web
rejig the code to make types happy
parent
073127aa3c
commit
e984a4f0cd
|
@ -806,7 +806,7 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
|
||||||
let suggestedRooms = SpaceStore.instance.suggestedRooms;
|
let suggestedRooms = SpaceStore.instance.suggestedRooms;
|
||||||
if (SpaceStore.instance.activeSpace !== this.props.space) {
|
if (SpaceStore.instance.activeSpace !== this.props.space) {
|
||||||
// the space store has the suggested rooms loaded for a different space, fetch the right ones
|
// the space store has the suggested rooms loaded for a different space, fetch the right ones
|
||||||
suggestedRooms = (await SpaceStore.instance.fetchSuggestedRooms(this.props.space, 1)).rooms;
|
suggestedRooms = (await SpaceStore.instance.fetchSuggestedRooms(this.props.space, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suggestedRooms.length) {
|
if (suggestedRooms.length) {
|
||||||
|
@ -814,9 +814,11 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
|
||||||
defaultDispatcher.dispatch({
|
defaultDispatcher.dispatch({
|
||||||
action: "view_room",
|
action: "view_room",
|
||||||
room_id: room.room_id,
|
room_id: room.room_id,
|
||||||
|
room_alias: room.canonical_alias || room.aliases?.[0],
|
||||||
|
via_servers: room.viaServers,
|
||||||
oobData: {
|
oobData: {
|
||||||
avatarUrl: room.avatar_url,
|
avatarUrl: room.avatar_url,
|
||||||
name: room.name || room.canonical_alias || room.aliases.pop() || _t("Empty room"),
|
name: room.name || room.canonical_alias || room.aliases?.[0] || _t("Empty room"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -162,8 +162,21 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (space) {
|
if (space) {
|
||||||
const data = await this.fetchSuggestedRooms(space);
|
const suggestedRooms = await this.fetchSuggestedRooms(space);
|
||||||
if (this._activeSpace === space) {
|
if (this._activeSpace === space) {
|
||||||
|
this._suggestedRooms = suggestedRooms;
|
||||||
|
this.emit(SUGGESTED_ROOMS, this._suggestedRooms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fetchSuggestedRooms = async (space: Room, limit = MAX_SUGGESTED_ROOMS): Promise<ISuggestedRoom[]> => {
|
||||||
|
try {
|
||||||
|
const data: {
|
||||||
|
rooms: ISpaceSummaryRoom[];
|
||||||
|
events: ISpaceSummaryEvent[];
|
||||||
|
} = await this.matrixClient.getSpaceSummary(space.roomId, 0, true, false, limit);
|
||||||
|
|
||||||
const viaMap = new EnhancedMap<string, Set<string>>();
|
const viaMap = new EnhancedMap<string, Set<string>>();
|
||||||
data.events.forEach(ev => {
|
data.events.forEach(ev => {
|
||||||
if (ev.type === EventType.SpaceChild && ev.content.via?.length) {
|
if (ev.type === EventType.SpaceChild && ev.content.via?.length) {
|
||||||
|
@ -173,32 +186,17 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this._suggestedRooms = data.rooms.filter(roomInfo => {
|
return data.rooms.filter(roomInfo => {
|
||||||
return roomInfo.room_type !== RoomType.Space
|
return roomInfo.room_type !== RoomType.Space
|
||||||
&& this.matrixClient.getRoom(roomInfo.room_id)?.getMyMembership() !== "join";
|
&& this.matrixClient.getRoom(roomInfo.room_id)?.getMyMembership() !== "join";
|
||||||
}).map(roomInfo => ({
|
}).map(roomInfo => ({
|
||||||
...roomInfo,
|
...roomInfo,
|
||||||
viaServers: Array.from(viaMap.get(roomInfo.room_id) || []),
|
viaServers: Array.from(viaMap.get(roomInfo.room_id) || []),
|
||||||
}));
|
}));
|
||||||
this.emit(SUGGESTED_ROOMS, this._suggestedRooms);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public fetchSuggestedRooms = async (space: Room, limit = MAX_SUGGESTED_ROOMS) => {
|
|
||||||
try {
|
|
||||||
const data: {
|
|
||||||
rooms: ISpaceSummaryRoom[];
|
|
||||||
events: ISpaceSummaryEvent[];
|
|
||||||
} = await this.matrixClient.getSpaceSummary(space.roomId, 0, true, false, limit);
|
|
||||||
return data;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
return {
|
return [];
|
||||||
rooms: [],
|
|
||||||
events: [],
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public addRoomToSpace(space: Room, roomId: string, via: string[], suggested = false, autoJoin = false) {
|
public addRoomToSpace(space: Room, roomId: string, via: string[], suggested = false, autoJoin = false) {
|
||||||
|
|
Loading…
Reference in New Issue