From c29da883db07aa67fbecccdead249037c69e07b7 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 16 Jul 2020 14:43:43 -0600 Subject: [PATCH] Convert room list log setting to a real setting To debug https://github.com/vector-im/riot-web/issues/14554 and https://github.com/vector-im/riot-web/issues/14508 --- src/@types/global.d.ts | 3 -- src/components/views/rooms/RoomList2.tsx | 3 +- .../settings/tabs/user/LabsUserSettingsTab.js | 1 + src/i18n/strings/en_EN.json | 1 + src/settings/Settings.js | 6 +++ src/stores/room-list/RoomListStore2.ts | 48 ++++++++++++------- src/stores/room-list/algorithms/Algorithm.ts | 35 +++++++------- 7 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 3e4eb13766..2d895e12eb 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -39,9 +39,6 @@ declare global { mx_RoomListStore2: RoomListStore2; mx_RoomListLayoutStore: RoomListLayoutStore; mxPlatformPeg: PlatformPeg; - - // TODO: Remove flag before launch: https://github.com/vector-im/riot-web/issues/14231 - mx_LoudRoomListLogging: boolean; } // workaround for https://github.com/microsoft/TypeScript/issues/30933 diff --git a/src/components/views/rooms/RoomList2.tsx b/src/components/views/rooms/RoomList2.tsx index 757e57fcc7..86becc2fca 100644 --- a/src/components/views/rooms/RoomList2.tsx +++ b/src/components/views/rooms/RoomList2.tsx @@ -40,6 +40,7 @@ import { NotificationColor } from "../../../stores/notifications/NotificationCol import { Action } from "../../../dispatcher/actions"; import { ViewRoomDeltaPayload } from "../../../dispatcher/payloads/ViewRoomDeltaPayload"; import { RoomNotificationStateStore } from "../../../stores/notifications/RoomNotificationStateStore"; +import SettingsStore from "../../../settings/SettingsStore"; // TODO: Rename on launch: https://github.com/vector-im/riot-web/issues/14367 @@ -210,7 +211,7 @@ export default class RoomList2 extends React.Component { private updateLists = () => { const newLists = RoomListStore.instance.orderedLists; - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log("new lists", newLists); } diff --git a/src/components/views/settings/tabs/user/LabsUserSettingsTab.js b/src/components/views/settings/tabs/user/LabsUserSettingsTab.js index 9724b9934f..2b8d7c5d3f 100644 --- a/src/components/views/settings/tabs/user/LabsUserSettingsTab.js +++ b/src/components/views/settings/tabs/user/LabsUserSettingsTab.js @@ -66,6 +66,7 @@ export default class LabsUserSettingsTab extends React.Component { + ); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index d81c0c717b..964207e79a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -492,6 +492,7 @@ "Try out new ways to ignore people (experimental)": "Try out new ways to ignore people (experimental)", "Use the improved room list (will refresh to apply changes)": "Use the improved room list (will refresh to apply changes)", "Support adding custom themes": "Support adding custom themes", + "Enable advanced debugging for the room list": "Enable advanced debugging for the room list", "Show info about bridges in room settings": "Show info about bridges in room settings", "Font size": "Font size", "Use custom size": "Use custom size", diff --git a/src/settings/Settings.js b/src/settings/Settings.js index 3b1218c0d3..b3f70f3c97 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -154,6 +154,12 @@ export const SETTINGS = { supportedLevels: LEVELS_FEATURE, default: false, }, + "advancedRoomListLogging": { + // TODO: Remove flag before launch: https://github.com/vector-im/riot-web/issues/14231 + displayName: _td("Enable advanced debugging for the room list"), + supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS, + default: false, + }, "mjolnirRooms": { supportedLevels: ['account'], default: [], diff --git a/src/stores/room-list/RoomListStore2.ts b/src/stores/room-list/RoomListStore2.ts index 4368120a2e..6f0fbb5afa 100644 --- a/src/stores/room-list/RoomListStore2.ts +++ b/src/stores/room-list/RoomListStore2.ts @@ -60,6 +60,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { private readonly watchedSettings = [ 'feature_custom_tags', + 'advancedRoomListLogging', // TODO: Remove watch: https://github.com/vector-im/riot-web/issues/14367 ]; constructor() { @@ -126,6 +127,9 @@ export class RoomListStore2 extends AsyncStoreWithClient { if (this.enabled) { console.log("⚡ new room list store engaged"); } + if (SettingsStore.getValue("advancedRoomListLogging")) { + console.warn("Advanced room list logging is enabled"); + } } private async readAndCacheSettingsFromStore() { @@ -154,7 +158,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { console.warn(`${activeRoomId} is current in RVS but missing from client - clearing sticky room`); await this.algorithm.setStickyRoom(null); } else if (activeRoom !== this.algorithm.stickyRoom) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Changing sticky room to ${activeRoomId}`); } @@ -196,6 +200,14 @@ export class RoomListStore2 extends AsyncStoreWithClient { if (payload.action === 'setting_updated') { if (this.watchedSettings.includes(payload.settingName)) { + // TODO: Remove with https://github.com/vector-im/riot-web/issues/14367 + if (payload.settingName === "advancedRoomListLogging") { + // Log when the setting changes so we know when it was turned on in the rageshake + const enabled = SettingsStore.getValue("advancedRoomListLogging"); + console.warn("Advanced room list logging is enabled? " + enabled); + return; + } + console.log("Regenerating room lists: Settings changed"); await this.readAndCacheSettingsFromStore(); @@ -218,7 +230,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { console.warn(`Own read receipt was in unknown room ${room.roomId}`); return; } - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Got own read receipt in ${room.roomId}`); } @@ -228,7 +240,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { } } else if (payload.action === 'MatrixActions.Room.tags') { const roomPayload = (payload); // TODO: Type out the dispatcher types - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Got tag change in ${roomPayload.room.roomId}`); } @@ -243,13 +255,13 @@ export class RoomListStore2 extends AsyncStoreWithClient { const roomId = eventPayload.event.getRoomId(); const room = this.matrixClient.getRoom(roomId); const tryUpdate = async (updatedRoom: Room) => { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Live timeline event ${eventPayload.event.getId()}` + ` in ${updatedRoom.roomId}`); } if (eventPayload.event.getType() === 'm.room.tombstone' && eventPayload.event.getStateKey() === '') { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Got tombstone event - trying to remove now-dead room`); } @@ -282,7 +294,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { console.warn(`Event ${eventPayload.event.getId()} was decrypted in an unknown room ${roomId}`); return; } - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Decrypted timeline event ${eventPayload.event.getId()} in ${roomId}`); } @@ -290,7 +302,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { this.updateFn.trigger(); } else if (payload.action === 'MatrixActions.accountData' && payload.event_type === 'm.direct') { const eventPayload = (payload); // TODO: Type out the dispatcher types - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Received updated DM map`); } @@ -317,7 +329,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { const oldMembership = getEffectiveMembership(membershipPayload.oldMembership); const newMembership = getEffectiveMembership(membershipPayload.membership); if (oldMembership !== EffectiveMembership.Join && newMembership === EffectiveMembership.Join) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Handling new room ${membershipPayload.room.roomId}`); } @@ -326,7 +338,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { // the dead room in the list. const createEvent = membershipPayload.room.currentState.getStateEvents("m.room.create", ""); if (createEvent && createEvent.getContent()['predecessor']) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Room has a predecessor`); } @@ -334,7 +346,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { if (prevRoom) { const isSticky = this.algorithm.stickyRoom === prevRoom; if (isSticky) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Clearing sticky room due to room upgrade`); } @@ -343,7 +355,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { // Note: we hit the algorithm instead of our handleRoomUpdate() function to // avoid redundant updates. - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Removing previous room from room list`); } @@ -351,7 +363,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { } } - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Adding new room to room list`); } @@ -361,7 +373,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { } if (oldMembership !== EffectiveMembership.Invite && newMembership === EffectiveMembership.Invite) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Handling invite to ${membershipPayload.room.roomId}`); } @@ -372,7 +384,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { // If it's not a join, it's transitioning into a different list (possibly historical) if (oldMembership !== newMembership) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Handling membership change in ${membershipPayload.room.roomId}`); } @@ -386,7 +398,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { private async handleRoomUpdate(room: Room, cause: RoomUpdateCause): Promise { const shouldUpdate = await this.algorithm.handleRoomUpdate(room, cause); if (shouldUpdate) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[DEBUG] Room "${room.name}" (${room.roomId}) triggered by ${cause} requires list update`); } @@ -509,7 +521,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { } private onAlgorithmListUpdated = () => { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log("Underlying algorithm has triggered a list update - marking"); } @@ -559,7 +571,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { } public addFilter(filter: IFilterCondition): void { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log("Adding filter condition:", filter); } @@ -571,7 +583,7 @@ export class RoomListStore2 extends AsyncStoreWithClient { } public removeFilter(filter: IFilterCondition): void { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log("Removing filter condition:", filter); } diff --git a/src/stores/room-list/algorithms/Algorithm.ts b/src/stores/room-list/algorithms/Algorithm.ts index 6f718c09b2..c6f42aa979 100644 --- a/src/stores/room-list/algorithms/Algorithm.ts +++ b/src/stores/room-list/algorithms/Algorithm.ts @@ -33,6 +33,7 @@ import { FILTER_CHANGED, FilterPriority, IFilterCondition } from "../filters/IFi import { EffectiveMembership, getEffectiveMembership, splitRoomsByMembership } from "../../../utils/membership"; import { OrderingAlgorithm } from "./list-ordering/OrderingAlgorithm"; import { getListAlgorithmInstance } from "./list-ordering"; +import SettingsStore from "../../../settings/SettingsStore"; /** * Fired when the Algorithm has determined a list has been updated. @@ -321,7 +322,7 @@ export class Algorithm extends EventEmitter { } newMap[tagId] = allowedRoomsInThisTag; - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[DEBUG] ${newMap[tagId].length}/${rooms.length} rooms filtered into ${tagId}`); } @@ -336,7 +337,7 @@ export class Algorithm extends EventEmitter { protected recalculateFilteredRoomsForTag(tagId: TagID): void { if (!this.hasFilters) return; // don't bother doing work if there's nothing to do - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Recalculating filtered rooms for ${tagId}`); } @@ -348,7 +349,7 @@ export class Algorithm extends EventEmitter { this.filteredRooms[tagId] = filteredRooms; } - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[DEBUG] ${filteredRooms.length}/${rooms.length} rooms filtered into ${tagId}`); } @@ -390,7 +391,7 @@ export class Algorithm extends EventEmitter { } if (!this._cachedStickyRooms || !updatedTag) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Generating clone of cached rooms for sticky room handling`); } @@ -404,7 +405,7 @@ export class Algorithm extends EventEmitter { if (updatedTag) { // Update the tag indicated by the caller, if possible. This is mostly to ensure // our cache is up to date. - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Replacing cached sticky rooms for ${updatedTag}`); } @@ -416,7 +417,7 @@ export class Algorithm extends EventEmitter { // we might have updated from the cache is also our sticky room. const sticky = this._stickyRoom; if (!updatedTag || updatedTag === sticky.tag) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Inserting sticky room ${sticky.room.roomId} at position ${sticky.position} in ${sticky.tag}`); } @@ -644,7 +645,7 @@ export class Algorithm extends EventEmitter { * processing. */ public async handleRoomUpdate(room: Room, cause: RoomUpdateCause): Promise { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Handle room update for ${room.roomId} called with cause ${cause}`); } @@ -704,7 +705,7 @@ export class Algorithm extends EventEmitter { const diff = arrayDiff(oldTags, newTags); if (diff.removed.length > 0 || diff.added.length > 0) { for (const rmTag of diff.removed) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Removing ${room.roomId} from ${rmTag}`); } @@ -714,7 +715,7 @@ export class Algorithm extends EventEmitter { this.cachedRooms[rmTag] = algorithm.orderedRooms; } for (const addTag of diff.added) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Adding ${room.roomId} to ${addTag}`); } @@ -727,14 +728,14 @@ export class Algorithm extends EventEmitter { // Update the tag map so we don't regen it in a moment this.roomIdsToTags[room.roomId] = newTags; - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Changing update cause for ${room.roomId} to Timeline to sort rooms`); } cause = RoomUpdateCause.Timeline; didTagChange = true; } else { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`Received no-op update for ${room.roomId} - changing to Timeline update`); } @@ -763,7 +764,7 @@ export class Algorithm extends EventEmitter { // as the sticky room relies on this. if (cause !== RoomUpdateCause.NewRoom && cause !== RoomUpdateCause.RoomRemoved) { if (this.stickyRoom === room) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.warn(`[RoomListDebug] Received ${cause} update for sticky room ${room.roomId} - ignoring`); } @@ -773,14 +774,14 @@ export class Algorithm extends EventEmitter { if (!this.roomIdsToTags[room.roomId]) { if (CAUSES_REQUIRING_ROOM.includes(cause)) { - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.warn(`Skipping tag update for ${room.roomId} because we don't know about the room`); } return false; } - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Updating tags for room ${room.roomId} (${room.name})`); } @@ -794,13 +795,13 @@ export class Algorithm extends EventEmitter { this.roomIdsToTags[room.roomId] = roomTags; - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Updated tags for ${room.roomId}:`, roomTags); } } - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Reached algorithmic handling for ${room.roomId} and cause ${cause}`); } @@ -825,7 +826,7 @@ export class Algorithm extends EventEmitter { changed = true; } - if (window.mx_LoudRoomListLogging) { + if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035 console.log(`[RoomListDebug] Finished handling ${room.roomId} with cause ${cause} (changed=${changed})`); }