Show a tile for an unloaded predecessor room if it has via_servers (#10483)
* Improve typing in constructor of RoomPermalinkCreator * Provide via servers if present when navigating to predecessor room from Advanced Room Settings * Show an error tile when the predecessor room is not found * Test for MatrixToPermalinkConstructor.forRoom * Test for MatrixToPermalinkConstructor.forEvent * Display a tile for predecessor event if it contains via servers * Fix missing case where event id is provided as well as via servers * Refactor RoomPredecessor tests * Return lost filterConsole to its home * Comments for IState in AdvancedRoomSettingsTab * Explain why we might render a tile even without prevRoom * Guess the old room's via servers if they are not provided * Fix TypeScript errors * Adjust regular expression (hopefully) to avoid potential catastrophic backtracking * Another attempt at avoiding super-liner regex performance * Tests for guessServerNameFromRoomId and better implementation * Further attempt to prevent backtracking --------- Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
075cb9e622
commit
c496985ff3
8 changed files with 320 additions and 89 deletions
|
@ -96,7 +96,7 @@ export class RoomPermalinkCreator {
|
|||
// Some of the tests done by this class are relatively expensive, so normally
|
||||
// throttled to not happen on every update. Pass false as the shouldThrottle
|
||||
// param to disable this behaviour, eg. for tests.
|
||||
public constructor(private room: Room, roomId: string | null = null, shouldThrottle = true) {
|
||||
public constructor(private room: Room | null, roomId: string | null = null, shouldThrottle = true) {
|
||||
this.roomId = room ? room.roomId : roomId!;
|
||||
|
||||
if (!this.roomId) {
|
||||
|
@ -118,12 +118,12 @@ export class RoomPermalinkCreator {
|
|||
|
||||
public start(): void {
|
||||
this.load();
|
||||
this.room.currentState.on(RoomStateEvent.Update, this.onRoomStateUpdate);
|
||||
this.room?.currentState.on(RoomStateEvent.Update, this.onRoomStateUpdate);
|
||||
this.started = true;
|
||||
}
|
||||
|
||||
public stop(): void {
|
||||
this.room.currentState.removeListener(RoomStateEvent.Update, this.onRoomStateUpdate);
|
||||
this.room?.currentState.removeListener(RoomStateEvent.Update, this.onRoomStateUpdate);
|
||||
this.started = false;
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ export class RoomPermalinkCreator {
|
|||
}
|
||||
|
||||
private updateHighestPlUser(): void {
|
||||
const plEvent = this.room.currentState.getStateEvents("m.room.power_levels", "");
|
||||
const plEvent = this.room?.currentState.getStateEvents("m.room.power_levels", "");
|
||||
if (plEvent) {
|
||||
const content = plEvent.getContent();
|
||||
if (content) {
|
||||
|
@ -179,7 +179,7 @@ export class RoomPermalinkCreator {
|
|||
if (users) {
|
||||
const entries = Object.entries(users);
|
||||
const allowedEntries = entries.filter(([userId]) => {
|
||||
const member = this.room.getMember(userId);
|
||||
const member = this.room?.getMember(userId);
|
||||
if (!member || member.membership !== "join") {
|
||||
return false;
|
||||
}
|
||||
|
@ -213,8 +213,8 @@ export class RoomPermalinkCreator {
|
|||
private updateAllowedServers(): void {
|
||||
const bannedHostsRegexps: RegExp[] = [];
|
||||
let allowedHostsRegexps = [ANY_REGEX]; // default allow everyone
|
||||
if (this.room.currentState) {
|
||||
const aclEvent = this.room.currentState.getStateEvents(EventType.RoomServerAcl, "");
|
||||
if (this.room?.currentState) {
|
||||
const aclEvent = this.room?.currentState.getStateEvents(EventType.RoomServerAcl, "");
|
||||
if (aclEvent && aclEvent.getContent()) {
|
||||
const getRegex = (hostname: string): RegExp =>
|
||||
new RegExp("^" + utils.globToRegexp(hostname, false) + "$");
|
||||
|
@ -237,12 +237,14 @@ export class RoomPermalinkCreator {
|
|||
|
||||
private updatePopulationMap(): void {
|
||||
const populationMap: { [server: string]: number } = {};
|
||||
for (const member of this.room.getJoinedMembers()) {
|
||||
const serverName = getServerName(member.userId);
|
||||
if (!populationMap[serverName]) {
|
||||
populationMap[serverName] = 0;
|
||||
if (this.room) {
|
||||
for (const member of this.room.getJoinedMembers()) {
|
||||
const serverName = getServerName(member.userId);
|
||||
if (!populationMap[serverName]) {
|
||||
populationMap[serverName] = 0;
|
||||
}
|
||||
populationMap[serverName]++;
|
||||
}
|
||||
populationMap[serverName]++;
|
||||
}
|
||||
this.populationMap = populationMap;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue