type Actions (#7862)

* type ViewHomPage action

Signed-off-by: Kerry Archibald <kerrya@element.io>

* type spacestore actions

Signed-off-by: Kerry Archibald <kerrya@element.io>

* lint

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add action types

Signed-off-by: Kerry Archibald <kerrya@element.io>

* use new action types in stores

Signed-off-by: Kerry Archibald <kerrya@element.io>

* remove debug change

Signed-off-by: Kerry Archibald <kerrya@element.io>

* stricter keyboard shortcut types

Signed-off-by: Kerry Archibald <kerrya@element.io>

* action comments

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-02-22 11:04:27 +01:00 committed by GitHub
parent 57595bc593
commit 5b8d440406
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 304 additions and 73 deletions

View file

@ -119,6 +119,10 @@ import { SummarizedNotificationState } from "../../stores/notifications/Summariz
import GenericToast from '../views/toasts/GenericToast';
import Views from '../../Views';
import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
import { ViewHomePagePayload } from '../../dispatcher/payloads/ViewHomePagePayload';
import { AfterLeaveRoomPayload } from '../../dispatcher/payloads/AfterLeaveRoomPayload';
import { DoAfterSyncPreparedPayload } from '../../dispatcher/payloads/DoAfterSyncPreparedPayload';
import { ViewStartChatOrReusePayload } from '../../dispatcher/payloads/ViewStartChatOrReusePayload';
// legacy export
export { default as Views } from "../../Views";
@ -541,7 +545,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// will cause a full login and sync and finally the deferred
// action will be dispatched.
dis.dispatch({
action: 'do_after_sync_prepared',
action: Action.DoAfterSyncPrepared,
deferred_action: payload,
});
dis.dispatch({ action: 'require_registration' });
@ -632,7 +636,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
MatrixClientPeg.get().leave(payload.room_id).then(() => {
modal.close();
if (this.state.currentRoomId === payload.room_id) {
dis.dispatch({ action: 'view_home_page' });
dis.dispatch({ action: Action.ViewHomePage });
}
}, (err) => {
modal.close();
@ -705,10 +709,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
case 'view_welcome_page':
this.viewWelcome();
break;
case 'view_home_page':
case Action.ViewHomePage:
this.viewHome(payload.justRegistered);
break;
case 'view_start_chat_or_reuse':
case Action.ViewStartChatOrReuse:
this.chatCreateOrReuse(payload.user_id);
break;
case 'view_create_chat':
@ -1057,10 +1061,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// No point in making 2 DMs with welcome bot. This assumes view_set_mxid will
// result in a new DM with the welcome user.
if (userId !== this.props.config.welcomeUserId) {
dis.dispatch({
action: 'do_after_sync_prepared',
dis.dispatch<DoAfterSyncPreparedPayload<ViewStartChatOrReusePayload>>({
action: Action.DoAfterSyncPrepared,
deferred_action: {
action: 'view_start_chat_or_reuse',
action: Action.ViewStartChatOrReuse,
user_id: userId,
},
});
@ -1162,8 +1166,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
if (shouldLeave) {
leaveRoomBehaviour(roomId);
dis.dispatch({
action: "after_leave_room",
dis.dispatch<AfterLeaveRoomPayload>({
action: Action.AfterLeaveRoom,
room_id: roomId,
});
}
@ -1176,7 +1180,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
MatrixClientPeg.get().forget(roomId).then(() => {
// Switch to home page if we're currently viewing the forgotten room
if (this.state.currentRoomId === roomId) {
dis.dispatch({ action: "view_home_page" });
dis.dispatch({ action: Action.ViewHomePage });
}
// We have to manually update the room list because the forgotten room will not
@ -1275,7 +1279,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
if (welcomeUserRoom === null) {
// We didn't redirect to the welcome user room, so show
// the homepage.
dis.dispatch({ action: 'view_home_page', justRegistered: true });
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage, justRegistered: true });
}
} else if (ThreepidInviteStore.instance.pickBestInvite()) {
// The user has a 3pid invite pending - show them that
@ -1288,7 +1292,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} else {
// The user has just logged in after registering,
// so show the homepage.
dis.dispatch({ action: 'view_home_page', justRegistered: true });
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage, justRegistered: true });
}
} else {
this.showScreenAfterLogin();
@ -1353,7 +1357,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
if (MatrixClientPeg.get().isGuest()) {
dis.dispatch({ action: 'view_welcome_page' });
} else {
dis.dispatch({ action: 'view_home_page' });
dis.dispatch({ action: Action.ViewHomePage });
}
}
}
@ -1666,7 +1670,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
const isLoggedOutOrGuest = !cli || cli.isGuest();
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
dis.dispatch({ action: "view_home_page" });
dis.dispatch({ action: Action.ViewHomePage });
return;
}
@ -1714,7 +1718,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
});
} else if (screen === 'home') {
dis.dispatch({
action: 'view_home_page',
action: Action.ViewHomePage,
});
} else if (screen === 'start') {
this.showScreen('home');
@ -1737,7 +1741,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
PlatformPeg.get().startSingleSignOn(cli, type, this.getFragmentAfterLogin());
} else if (screen === 'groups') {
if (SpaceStore.spacesEnabled) {
dis.dispatch({ action: "view_home_page" });
dis.dispatch({ action: Action.ViewHomePage });
return;
}
dis.dispatch({