MatrixChat: add a load of logging for view transitions

This stuff was essentially impossible to follow and debug. I think a load of
logging will help.
This commit is contained in:
Richard van der Hoff 2025-11-20 12:36:19 +00:00
parent 16e71ffd58
commit 142a66d584

View File

@ -473,6 +473,9 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
| (Pick<IState, K> | IState | null), | (Pick<IState, K> | IState | null),
callback?: () => void, callback?: () => void,
): void { ): void {
if (state && "view" in state) {
logger.debug(`MatrixChat: Queuing change of view from ${Views[this.state.view]} to ${Views[state.view]}`);
}
if (this.shouldTrackPageChange(this.state, { ...this.state, ...state })) { if (this.shouldTrackPageChange(this.state, { ...this.state, ...state })) {
this.startPageChangeTimer(); this.startPageChangeTimer();
} }
@ -648,9 +651,15 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private onAction = (payload: ActionPayload): void => { private onAction = (payload: ActionPayload): void => {
// once the session lock has been stolen, don't try to do anything. // once the session lock has been stolen, don't try to do anything.
if (this.state.view === Views.LOCK_STOLEN) { if (this.state.view === Views.LOCK_STOLEN) {
logger.warn(`MatrixChat: ignoring action ${payload.action} as session lock has been stolen`);
return; return;
} }
// Exclude some rather spammy actions from being logged.
if (payload.action != Action.UserActivity) {
logger.debug(`MatrixChat: handling action ${payload.action}`);
}
// Start the onboarding process for certain actions // Start the onboarding process for certain actions
if ( if (
MatrixClientPeg.get()?.isGuest() && MatrixClientPeg.get()?.isGuest() &&
@ -1391,10 +1400,13 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
* In other words, whenever we think we have completed the login and E2E setup tasks. * In other words, whenever we think we have completed the login and E2E setup tasks.
*/ */
private async onShowPostLoginScreen(): Promise<void> { private async onShowPostLoginScreen(): Promise<void> {
logger.debug("onShowPostLoginScreen: Transitioning to logged in view.");
this.setStateForNewView({ view: Views.LOGGED_IN }); this.setStateForNewView({ view: Views.LOGGED_IN });
// If a specific screen is set to be shown after login, show that above // If a specific screen is set to be shown after login, show that above
// all else, as it probably means the user clicked on something already. // all else, as it probably means the user clicked on something already.
if (this.screenAfterLogin?.screen) { if (this.screenAfterLogin?.screen) {
logger.debug(`onShowPostLoginScreen: showing screen ${this.screenAfterLogin.screen}`);
this.showScreen(this.screenAfterLogin.screen, this.screenAfterLogin.params); this.showScreen(this.screenAfterLogin.screen, this.screenAfterLogin.params);
this.screenAfterLogin = undefined; this.screenAfterLogin = undefined;
} else if (MatrixClientPeg.currentUserIsJustRegistered()) { } else if (MatrixClientPeg.currentUserIsJustRegistered()) {
@ -1403,6 +1415,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
if (ThreepidInviteStore.instance.pickBestInvite()) { if (ThreepidInviteStore.instance.pickBestInvite()) {
// The user has a 3pid invite pending - show them that // The user has a 3pid invite pending - show them that
const threepidInvite = ThreepidInviteStore.instance.pickBestInvite(); const threepidInvite = ThreepidInviteStore.instance.pickBestInvite();
logger.debug(`onShowPostLoginScreen: showing room ${threepidInvite.roomId} after registration`);
// HACK: This is a pretty brutal way of threading the invite back through // HACK: This is a pretty brutal way of threading the invite back through
// our systems, but it's the safest we have for now. // our systems, but it's the safest we have for now.
@ -1411,9 +1424,11 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} else { } else {
// The user has just logged in after registering, // The user has just logged in after registering,
// so show the homepage. // so show the homepage.
logger.debug("onShowPostLoginScreen: Showing home page after registration");
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage, justRegistered: true }); dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage, justRegistered: true });
} }
} else if (!(await this.shouldForceVerification())) { } else if (!(await this.shouldForceVerification())) {
logger.debug("onShowPostLoginScreen: showScreenAfterLogin");
this.showScreenAfterLogin(); this.showScreenAfterLogin();
} }
@ -1477,15 +1492,19 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// If screenAfterLogin is set, use that, then null it so that a second login will // If screenAfterLogin is set, use that, then null it so that a second login will
// result in view_home_page, _user_settings or _room_directory // result in view_home_page, _user_settings or _room_directory
if (this.screenAfterLogin && this.screenAfterLogin.screen) { if (this.screenAfterLogin && this.screenAfterLogin.screen) {
logger.debug(`showScreenAfterLogin: showing screen ${this.screenAfterLogin.screen}`);
this.showScreen(this.screenAfterLogin.screen, this.screenAfterLogin.params); this.showScreen(this.screenAfterLogin.screen, this.screenAfterLogin.params);
this.screenAfterLogin = undefined; this.screenAfterLogin = undefined;
} else if (localStorage && localStorage.getItem("mx_last_room_id")) { } else if (localStorage && localStorage.getItem("mx_last_room_id")) {
// Before defaulting to directory, show the last viewed room // Before defaulting to directory, show the last viewed room
logger.debug("showScreenAfterLogin: showing last room");
this.viewLastRoom(); this.viewLastRoom();
} else { } else {
if (MatrixClientPeg.safeGet().isGuest()) { if (MatrixClientPeg.safeGet().isGuest()) {
logger.debug("showScreenAfterLogin: showing guest welcome page");
dis.dispatch({ action: "view_welcome_page" }); dis.dispatch({ action: "view_welcome_page" });
} else { } else {
logger.debug("showScreenAfterLogin: showing home page");
dis.dispatch({ action: Action.ViewHomePage }); dis.dispatch({ action: Action.ViewHomePage });
} }
} }
@ -1778,10 +1797,15 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} }
public showScreen(screen: string, params?: { [key: string]: any }): void { public showScreen(screen: string, params?: { [key: string]: any }): void {
logger.debug(`showScreen ${screen}`);
const cli = MatrixClientPeg.get(); const cli = MatrixClientPeg.get();
const isLoggedOutOrGuest = !cli || cli.isGuest(); const isLoggedOutOrGuest = !cli || cli.isGuest();
if (!isLoggedOutOrGuest && AUTH_SCREENS.includes(screen)) { if (!isLoggedOutOrGuest && AUTH_SCREENS.includes(screen)) {
// user is logged in and landing on an auth page which will uproot their session, redirect them home instead // user is logged in and landing on an auth page which will uproot their session, redirect them home instead
logger.info(
`showScreen: suppressing change to AuthScreen ${screen} for logged-in user, and going to home screen instead`,
);
dis.dispatch({ action: Action.ViewHomePage }); dis.dispatch({ action: Action.ViewHomePage });
return; return;
} }