Improve typing around LoggedInView (#7384)

* Update SyncState imports

* Improve typing around LoggedInView

* Fix typing
pull/21833/head
Michael Telatynski 2021-12-16 09:57:10 +00:00 committed by GitHub
parent b952fef195
commit a968b4ce53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 40 deletions

View File

@ -26,7 +26,7 @@ import { randomUppercaseString, randomLowercaseString } from "matrix-js-sdk/src/
import EventEmitter from 'events'; import EventEmitter from 'events';
import { RuleId, TweakName, Tweaks } from "matrix-js-sdk/src/@types/PushRules"; import { RuleId, TweakName, Tweaks } from "matrix-js-sdk/src/@types/PushRules";
import { PushProcessor } from 'matrix-js-sdk/src/pushprocessor'; import { PushProcessor } from 'matrix-js-sdk/src/pushprocessor';
import { SyncState } from "matrix-js-sdk/src/sync.api"; import { SyncState } from "matrix-js-sdk/src/sync";
import { MatrixClientPeg } from './MatrixClientPeg'; import { MatrixClientPeg } from './MatrixClientPeg';
import Modal from './Modal'; import Modal from './Modal';

View File

@ -19,6 +19,8 @@ import { MatrixClient } from 'matrix-js-sdk/src/client';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event'; import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { MatrixCall } from 'matrix-js-sdk/src/webrtc/call'; import { MatrixCall } from 'matrix-js-sdk/src/webrtc/call';
import classNames from 'classnames'; import classNames from 'classnames';
import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
import { IUsageLimit } from 'matrix-js-sdk/src/@types/partials';
import { Key } from '../../Keyboard'; import { Key } from '../../Keyboard';
import PageTypes from '../../PageTypes'; import PageTypes from '../../PageTypes';
@ -104,24 +106,8 @@ interface IProps {
forceTimeline?: boolean; // see props on MatrixChat forceTimeline?: boolean; // see props on MatrixChat
} }
interface IUsageLimit {
// "hs_disabled" is NOT a specced string, but is used in Synapse
// This is tracked over at https://github.com/matrix-org/synapse/issues/9237
// eslint-disable-next-line camelcase
limit_type: "monthly_active_user" | "hs_disabled" | string;
// eslint-disable-next-line camelcase
admin_contact?: string;
}
interface IState { interface IState {
syncErrorData?: { syncErrorData?: ISyncStateData;
error: {
// This is not specced, but used in Synapse. See
// https://github.com/matrix-org/synapse/issues/9237#issuecomment-768238922
data: IUsageLimit;
errcode: string;
};
};
usageLimitDismissed: boolean; usageLimitDismissed: boolean;
usageLimitEventContent?: IUsageLimit; usageLimitEventContent?: IUsageLimit;
usageLimitEventTs?: number; usageLimitEventTs?: number;
@ -304,33 +290,23 @@ class LoggedInView extends React.Component<IProps, IState> {
}); });
}; };
onSync = (syncState, oldSyncState, data) => { private onSync = (syncState: SyncState, oldSyncState?: SyncState, data?: ISyncStateData): void => {
const oldErrCode = ( const oldErrCode = this.state.syncErrorData?.error?.errcode;
this.state.syncErrorData &&
this.state.syncErrorData.error &&
this.state.syncErrorData.error.errcode
);
const newErrCode = data && data.error && data.error.errcode; const newErrCode = data && data.error && data.error.errcode;
if (syncState === oldSyncState && oldErrCode === newErrCode) return; if (syncState === oldSyncState && oldErrCode === newErrCode) return;
if (syncState === 'ERROR') { this.setState({
this.setState({ syncErrorData: syncState === SyncState.Error ? data : null,
syncErrorData: data, });
});
} else {
this.setState({
syncErrorData: null,
});
}
if (oldSyncState === 'PREPARED' && syncState === 'SYNCING') { if (oldSyncState === SyncState.Prepared && syncState === SyncState.Syncing) {
this.updateServerNoticeEvents(); this.updateServerNoticeEvents();
} else { } else {
this.calculateServerLimitToast(this.state.syncErrorData, this.state.usageLimitEventContent); this.calculateServerLimitToast(this.state.syncErrorData, this.state.usageLimitEventContent);
} }
}; };
onRoomStateEvents = (ev, state) => { private onRoomStateEvents = (ev: MatrixEvent): void => {
const serverNoticeList = RoomListStore.instance.orderedLists[DefaultTagID.ServerNotice]; const serverNoticeList = RoomListStore.instance.orderedLists[DefaultTagID.ServerNotice];
if (serverNoticeList && serverNoticeList.some(r => r.roomId === ev.getRoomId())) { if (serverNoticeList && serverNoticeList.some(r => r.roomId === ev.getRoomId())) {
this.updateServerNoticeEvents(); this.updateServerNoticeEvents();
@ -346,7 +322,7 @@ class LoggedInView extends React.Component<IProps, IState> {
private calculateServerLimitToast(syncError: IState["syncErrorData"], usageLimitEventContent?: IUsageLimit) { private calculateServerLimitToast(syncError: IState["syncErrorData"], usageLimitEventContent?: IUsageLimit) {
const error = syncError && syncError.error && syncError.error.errcode === "M_RESOURCE_LIMIT_EXCEEDED"; const error = syncError && syncError.error && syncError.error.errcode === "M_RESOURCE_LIMIT_EXCEEDED";
if (error) { if (error) {
usageLimitEventContent = syncError.error.data; usageLimitEventContent = syncError.error.data as IUsageLimit;
} }
// usageLimitDismissed is true when the user has explicitly hidden the toast // usageLimitDismissed is true when the user has explicitly hidden the toast

View File

@ -16,8 +16,7 @@ limitations under the License.
import React from 'react'; import React from 'react';
import { EventStatus, MatrixEvent } from "matrix-js-sdk/src/models/event"; import { EventStatus, MatrixEvent } from "matrix-js-sdk/src/models/event";
import { SyncState } from "matrix-js-sdk/src/sync.api"; import { SyncState, ISyncStateData } from "matrix-js-sdk/src/sync";
import { ISyncStateData } from "matrix-js-sdk/src/sync";
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { _t, _td } from '../../languageHandler'; import { _t, _td } from '../../languageHandler';

View File

@ -22,7 +22,7 @@ import { EventTimelineSet } from "matrix-js-sdk/src/models/event-timeline-set";
import { Direction, EventTimeline } from "matrix-js-sdk/src/models/event-timeline"; import { Direction, EventTimeline } from "matrix-js-sdk/src/models/event-timeline";
import { TimelineWindow } from "matrix-js-sdk/src/timeline-window"; import { TimelineWindow } from "matrix-js-sdk/src/timeline-window";
import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event'; import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event';
import { SyncState } from 'matrix-js-sdk/src/sync.api'; import { SyncState } from 'matrix-js-sdk/src/sync';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";

View File

@ -17,7 +17,7 @@ limitations under the License.
import React, { ComponentProps, createRef } from 'react'; import React, { ComponentProps, createRef } from 'react';
import { Blurhash } from "react-blurhash"; import { Blurhash } from "react-blurhash";
import { SyncState } from 'matrix-js-sdk/src/sync.api'; import { SyncState } from 'matrix-js-sdk/src/sync';
import classNames from 'classnames'; import classNames from 'classnames';
import { CSSTransition, SwitchTransition } from 'react-transition-group'; import { CSSTransition, SwitchTransition } from 'react-transition-group';
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";