Use MatrixClientPeg::safeGet in src/{stores,hooks,components/structures}/* (#10988)
This commit is contained in:
parent
707fd9ccf0
commit
dd46db4817
34 changed files with 139 additions and 130 deletions
|
@ -74,7 +74,7 @@ class FilePanel extends React.Component<IProps, IState> {
|
||||||
if (room?.roomId !== this.props.roomId) return;
|
if (room?.roomId !== this.props.roomId) return;
|
||||||
if (toStartOfTimeline || !data || !data.liveEvent || ev.isRedacted()) return;
|
if (toStartOfTimeline || !data || !data.liveEvent || ev.isRedacted()) return;
|
||||||
|
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
client.decryptEventIfNeeded(ev);
|
client.decryptEventIfNeeded(ev);
|
||||||
|
|
||||||
if (ev.isBeingDecrypted()) {
|
if (ev.isBeingDecrypted()) {
|
||||||
|
@ -109,11 +109,11 @@ class FilePanel extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount(): Promise<void> {
|
public async componentDidMount(): Promise<void> {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
await this.updateTimelineSet(this.props.roomId);
|
await this.updateTimelineSet(this.props.roomId);
|
||||||
|
|
||||||
if (!MatrixClientPeg.get().isRoomEncrypted(this.props.roomId)) return;
|
if (!client.isRoomEncrypted(this.props.roomId)) return;
|
||||||
|
|
||||||
// The timelineSets filter makes sure that encrypted events that contain
|
// The timelineSets filter makes sure that encrypted events that contain
|
||||||
// URLs never get added to the timeline, even if they are live events.
|
// URLs never get added to the timeline, even if they are live events.
|
||||||
|
@ -133,7 +133,7 @@ class FilePanel extends React.Component<IProps, IState> {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
if (client === null) return;
|
if (client === null) return;
|
||||||
|
|
||||||
if (!MatrixClientPeg.get().isRoomEncrypted(this.props.roomId)) return;
|
if (!client.isRoomEncrypted(this.props.roomId)) return;
|
||||||
|
|
||||||
if (EventIndexPeg.get() !== null) {
|
if (EventIndexPeg.get() !== null) {
|
||||||
client.removeListener(RoomEvent.Timeline, this.onRoomTimeline);
|
client.removeListener(RoomEvent.Timeline, this.onRoomTimeline);
|
||||||
|
@ -142,9 +142,9 @@ class FilePanel extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchFileEventsServer(room: Room): Promise<EventTimelineSet> {
|
public async fetchFileEventsServer(room: Room): Promise<EventTimelineSet> {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
const filter = new Filter(client.credentials.userId);
|
const filter = new Filter(client.getSafeUserId());
|
||||||
filter.setDefinition({
|
filter.setDefinition({
|
||||||
room: {
|
room: {
|
||||||
timeline: {
|
timeline: {
|
||||||
|
@ -163,7 +163,7 @@ class FilePanel extends React.Component<IProps, IState> {
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
limit: number,
|
limit: number,
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
const eventIndex = EventIndexPeg.get();
|
const eventIndex = EventIndexPeg.get();
|
||||||
const roomId = this.props.roomId;
|
const roomId = this.props.roomId;
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ class FilePanel extends React.Component<IProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
public async updateTimelineSet(roomId: string): Promise<void> {
|
public async updateTimelineSet(roomId: string): Promise<void> {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
const room = client.getRoom(roomId);
|
const room = client.getRoom(roomId);
|
||||||
const eventIndex = EventIndexPeg.get();
|
const eventIndex = EventIndexPeg.get();
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ class FilePanel extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
if (MatrixClientPeg.get().isGuest()) {
|
if (MatrixClientPeg.safeGet().isGuest()) {
|
||||||
return (
|
return (
|
||||||
<BaseCard className="mx_FilePanel mx_RoomView_messageListWrapper" onClose={this.props.onClose}>
|
<BaseCard className="mx_FilePanel mx_RoomView_messageListWrapper" onClose={this.props.onClose}>
|
||||||
<div className="mx_RoomView_empty">
|
<div className="mx_RoomView_empty">
|
||||||
|
@ -256,7 +256,7 @@ class FilePanel extends React.Component<IProps, IState> {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const isRoomEncrypted = this.noRoom ? false : MatrixClientPeg.get().isRoomEncrypted(this.props.roomId);
|
const isRoomEncrypted = this.noRoom ? false : MatrixClientPeg.safeGet().isRoomEncrypted(this.props.roomId);
|
||||||
|
|
||||||
if (this.state.timelineSet) {
|
if (this.state.timelineSet) {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -129,7 +129,7 @@ export default class LegacyCallEventGrouper extends EventEmitter {
|
||||||
public get callWasMissed(): boolean {
|
public get callWasMissed(): boolean {
|
||||||
return (
|
return (
|
||||||
this.state === CallState.Ended &&
|
this.state === CallState.Ended &&
|
||||||
![...this.events].some((event) => event.sender?.userId === MatrixClientPeg.get().getUserId())
|
![...this.events].some((event) => event.sender?.userId === MatrixClientPeg.safeGet().getUserId())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import { throttle } from "lodash";
|
||||||
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
||||||
import { RoomType } from "matrix-js-sdk/src/@types/event";
|
import { RoomType } from "matrix-js-sdk/src/@types/event";
|
||||||
import { DecryptionError } from "matrix-js-sdk/src/crypto/algorithms";
|
import { DecryptionError } from "matrix-js-sdk/src/crypto/algorithms";
|
||||||
|
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
|
||||||
|
|
||||||
// focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by various components
|
// focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by various components
|
||||||
import "focus-visible";
|
import "focus-visible";
|
||||||
|
@ -355,7 +356,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async postLoginSetup(): Promise<void> {
|
private async postLoginSetup(): Promise<void> {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const cryptoEnabled = cli.isCryptoEnabled();
|
const cryptoEnabled = cli.isCryptoEnabled();
|
||||||
if (!cryptoEnabled) {
|
if (!cryptoEnabled) {
|
||||||
this.onLoggedIn();
|
this.onLoggedIn();
|
||||||
|
@ -574,11 +575,11 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
if (payload.event_type === "m.identity_server") {
|
if (payload.event_type === "m.identity_server") {
|
||||||
const fullUrl = payload.event_content ? payload.event_content["base_url"] : null;
|
const fullUrl = payload.event_content ? payload.event_content["base_url"] : null;
|
||||||
if (!fullUrl) {
|
if (!fullUrl) {
|
||||||
MatrixClientPeg.get().setIdentityServerUrl(undefined);
|
MatrixClientPeg.safeGet().setIdentityServerUrl(undefined);
|
||||||
localStorage.removeItem("mx_is_access_token");
|
localStorage.removeItem("mx_is_access_token");
|
||||||
localStorage.removeItem("mx_is_url");
|
localStorage.removeItem("mx_is_url");
|
||||||
} else {
|
} else {
|
||||||
MatrixClientPeg.get().setIdentityServerUrl(fullUrl);
|
MatrixClientPeg.safeGet().setIdentityServerUrl(fullUrl);
|
||||||
localStorage.removeItem("mx_is_access_token"); // clear token
|
localStorage.removeItem("mx_is_access_token"); // clear token
|
||||||
localStorage.setItem("mx_is_url", fullUrl); // XXX: Do we still need this?
|
localStorage.setItem("mx_is_url", fullUrl); // XXX: Do we still need this?
|
||||||
}
|
}
|
||||||
|
@ -625,7 +626,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
this.notifyNewScreen("forgot_password");
|
this.notifyNewScreen("forgot_password");
|
||||||
break;
|
break;
|
||||||
case "start_chat":
|
case "start_chat":
|
||||||
createRoom(MatrixClientPeg.get(), {
|
createRoom(MatrixClientPeg.safeGet(), {
|
||||||
dmUserId: payload.user_id,
|
dmUserId: payload.user_id,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -647,7 +648,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
// FIXME: controller shouldn't be loading a view :(
|
// FIXME: controller shouldn't be loading a view :(
|
||||||
const modal = Modal.createDialog(Spinner, undefined, "mx_Dialog_spinner");
|
const modal = Modal.createDialog(Spinner, undefined, "mx_Dialog_spinner");
|
||||||
|
|
||||||
MatrixClientPeg.get()
|
MatrixClientPeg.safeGet()
|
||||||
.leave(payload.room_id)
|
.leave(payload.room_id)
|
||||||
.then(
|
.then(
|
||||||
() => {
|
() => {
|
||||||
|
@ -755,7 +756,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
this.viewSomethingBehindModal();
|
this.viewSomethingBehindModal();
|
||||||
break;
|
break;
|
||||||
case "view_invite": {
|
case "view_invite": {
|
||||||
const room = MatrixClientPeg.get().getRoom(payload.roomId);
|
const room = MatrixClientPeg.safeGet().getRoom(payload.roomId);
|
||||||
if (room?.isSpaceRoom()) {
|
if (room?.isSpaceRoom()) {
|
||||||
showSpaceInvite(room);
|
showSpaceInvite(room);
|
||||||
} else {
|
} else {
|
||||||
|
@ -794,7 +795,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
Modal.createDialog(DialPadModal, {}, "mx_Dialog_dialPadWrapper");
|
Modal.createDialog(DialPadModal, {}, "mx_Dialog_dialPadWrapper");
|
||||||
break;
|
break;
|
||||||
case Action.OnLoggedIn:
|
case Action.OnLoggedIn:
|
||||||
this.stores.client = MatrixClientPeg.get();
|
this.stores.client = MatrixClientPeg.safeGet();
|
||||||
if (
|
if (
|
||||||
// Skip this handling for token login as that always calls onLoggedIn itself
|
// Skip this handling for token login as that always calls onLoggedIn itself
|
||||||
!this.tokenLogin &&
|
!this.tokenLogin &&
|
||||||
|
@ -935,7 +936,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let presentedId = roomInfo.room_alias || roomInfo.room_id!;
|
let presentedId = roomInfo.room_alias || roomInfo.room_id!;
|
||||||
const room = MatrixClientPeg.get().getRoom(roomInfo.room_id);
|
const room = MatrixClientPeg.safeGet().getRoom(roomInfo.room_id);
|
||||||
if (room) {
|
if (room) {
|
||||||
// Not all timeline events are decrypted ahead of time anymore
|
// Not all timeline events are decrypted ahead of time anymore
|
||||||
// Only the critical ones for a typical UI are
|
// Only the critical ones for a typical UI are
|
||||||
|
@ -1062,14 +1063,14 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
|
|
||||||
const [shouldCreate, opts] = await modal.finished;
|
const [shouldCreate, opts] = await modal.finished;
|
||||||
if (shouldCreate) {
|
if (shouldCreate) {
|
||||||
createRoom(MatrixClientPeg.get(), opts!);
|
createRoom(MatrixClientPeg.safeGet(), opts!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private chatCreateOrReuse(userId: string): void {
|
private chatCreateOrReuse(userId: string): void {
|
||||||
const snakedConfig = new SnakedObject<IConfigOptions>(this.props.config);
|
const snakedConfig = new SnakedObject<IConfigOptions>(this.props.config);
|
||||||
// Use a deferred action to reshow the dialog once the user has registered
|
// Use a deferred action to reshow the dialog once the user has registered
|
||||||
if (MatrixClientPeg.get().isGuest()) {
|
if (MatrixClientPeg.safeGet().isGuest()) {
|
||||||
// No point in making 2 DMs with welcome bot. This assumes view_set_mxid will
|
// No point in making 2 DMs with welcome bot. This assumes view_set_mxid will
|
||||||
// result in a new DM with the welcome user.
|
// result in a new DM with the welcome user.
|
||||||
if (userId !== snakedConfig.get("welcome_user_id")) {
|
if (userId !== snakedConfig.get("welcome_user_id")) {
|
||||||
|
@ -1098,7 +1099,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
|
|
||||||
// TODO: Immutable DMs replaces this
|
// TODO: Immutable DMs replaces this
|
||||||
|
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
const dmRoom = findDMForUser(client, userId);
|
const dmRoom = findDMForUser(client, userId);
|
||||||
|
|
||||||
if (dmRoom) {
|
if (dmRoom) {
|
||||||
|
@ -1116,7 +1117,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private leaveRoomWarnings(roomId: string): JSX.Element[] {
|
private leaveRoomWarnings(roomId: string): JSX.Element[] {
|
||||||
const roomToLeave = MatrixClientPeg.get().getRoom(roomId);
|
const roomToLeave = MatrixClientPeg.safeGet().getRoom(roomId);
|
||||||
const isSpace = roomToLeave?.isSpaceRoom();
|
const isSpace = roomToLeave?.isSpaceRoom();
|
||||||
// Show a warning if there are additional complications.
|
// Show a warning if there are additional complications.
|
||||||
const warnings: JSX.Element[] = [];
|
const warnings: JSX.Element[] = [];
|
||||||
|
@ -1154,7 +1155,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private leaveRoom(roomId: string): void {
|
private leaveRoom(roomId: string): void {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const roomToLeave = cli.getRoom(roomId);
|
const roomToLeave = cli.getRoom(roomId);
|
||||||
const warnings = this.leaveRoomWarnings(roomId);
|
const warnings = this.leaveRoomWarnings(roomId);
|
||||||
|
|
||||||
|
@ -1188,8 +1189,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private forgetRoom(roomId: string): void {
|
private forgetRoom(roomId: string): void {
|
||||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
const room = MatrixClientPeg.safeGet().getRoom(roomId);
|
||||||
MatrixClientPeg.get()
|
MatrixClientPeg.safeGet()
|
||||||
.forget(roomId)
|
.forget(roomId)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Switch to home page if we're currently viewing the forgotten room
|
// Switch to home page if we're currently viewing the forgotten room
|
||||||
|
@ -1212,7 +1213,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async copyRoom(roomId: string): Promise<void> {
|
private async copyRoom(roomId: string): Promise<void> {
|
||||||
const roomLink = makeRoomPermalink(MatrixClientPeg.get(), roomId);
|
const roomLink = makeRoomPermalink(MatrixClientPeg.safeGet(), roomId);
|
||||||
const success = await copyPlaintext(roomLink);
|
const success = await copyPlaintext(roomLink);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Modal.createDialog(ErrorDialog, {
|
Modal.createDialog(ErrorDialog, {
|
||||||
|
@ -1246,7 +1247,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
|
|
||||||
const welcomeUserRooms = DMRoomMap.shared().getDMRoomsForUserId(welcomeUserId);
|
const welcomeUserRooms = DMRoomMap.shared().getDMRoomsForUserId(welcomeUserId);
|
||||||
if (welcomeUserRooms.length === 0) {
|
if (welcomeUserRooms.length === 0) {
|
||||||
const roomId = await createRoom(MatrixClientPeg.get(), {
|
const roomId = await createRoom(MatrixClientPeg.safeGet(), {
|
||||||
dmUserId: snakedConfig.get("welcome_user_id"),
|
dmUserId: snakedConfig.get("welcome_user_id"),
|
||||||
// Only view the welcome user if we're NOT looking at a room
|
// Only view the welcome user if we're NOT looking at a room
|
||||||
andView: !this.state.currentRoomId,
|
andView: !this.state.currentRoomId,
|
||||||
|
@ -1262,11 +1263,11 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
// the saved sync to be loaded).
|
// the saved sync to be loaded).
|
||||||
const saveWelcomeUser = (ev: MatrixEvent): void => {
|
const saveWelcomeUser = (ev: MatrixEvent): void => {
|
||||||
if (ev.getType() === EventType.Direct && ev.getContent()[welcomeUserId]) {
|
if (ev.getType() === EventType.Direct && ev.getContent()[welcomeUserId]) {
|
||||||
MatrixClientPeg.get().store.save(true);
|
MatrixClientPeg.safeGet().store.save(true);
|
||||||
MatrixClientPeg.get().removeListener(ClientEvent.AccountData, saveWelcomeUser);
|
MatrixClientPeg.safeGet().removeListener(ClientEvent.AccountData, saveWelcomeUser);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MatrixClientPeg.get().on(ClientEvent.AccountData, saveWelcomeUser);
|
MatrixClientPeg.safeGet().on(ClientEvent.AccountData, saveWelcomeUser);
|
||||||
|
|
||||||
return roomId;
|
return roomId;
|
||||||
}
|
}
|
||||||
|
@ -1413,7 +1414,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
// Before defaulting to directory, show the last viewed room
|
// Before defaulting to directory, show the last viewed room
|
||||||
this.viewLastRoom();
|
this.viewLastRoom();
|
||||||
} else {
|
} else {
|
||||||
if (MatrixClientPeg.get().isGuest()) {
|
if (MatrixClientPeg.safeGet().isGuest()) {
|
||||||
dis.dispatch({ action: "view_welcome_page" });
|
dis.dispatch({ action: "view_welcome_page" });
|
||||||
} else {
|
} else {
|
||||||
dis.dispatch({ action: Action.ViewHomePage });
|
dis.dispatch({ action: Action.ViewHomePage });
|
||||||
|
@ -1468,7 +1469,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
// to do the first sync
|
// to do the first sync
|
||||||
this.firstSyncComplete = false;
|
this.firstSyncComplete = false;
|
||||||
this.firstSyncPromise = defer();
|
this.firstSyncPromise = defer();
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
// Allow the JS SDK to reap timeline events. This reduces the amount of
|
// Allow the JS SDK to reap timeline events. This reduces the amount of
|
||||||
// memory consumed as the JS SDK stores multiple distinct copies of room
|
// memory consumed as the JS SDK stores multiple distinct copies of room
|
||||||
|
@ -1588,7 +1589,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
cli.on(MatrixEventEvent.Decrypted, (e, err) => dft.eventDecrypted(e, err as DecryptionError));
|
cli.on(MatrixEventEvent.Decrypted, (e, err) => dft.eventDecrypted(e, err as DecryptionError));
|
||||||
|
|
||||||
cli.on(ClientEvent.Room, (room) => {
|
cli.on(ClientEvent.Room, (room) => {
|
||||||
if (MatrixClientPeg.get().isCryptoEnabled()) {
|
if (cli.isCryptoEnabled()) {
|
||||||
const blacklistEnabled = SettingsStore.getValueAt(
|
const blacklistEnabled = SettingsStore.getValueAt(
|
||||||
SettingLevel.ROOM_DEVICE,
|
SettingLevel.ROOM_DEVICE,
|
||||||
"blacklistUnverifiedDevices",
|
"blacklistUnverifiedDevices",
|
||||||
|
@ -1618,15 +1619,15 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cli.on(CryptoEvent.KeyBackupFailed, async (errcode): Promise<void> => {
|
cli.on(CryptoEvent.KeyBackupFailed, async (errcode): Promise<void> => {
|
||||||
let haveNewVersion;
|
let haveNewVersion: boolean | undefined;
|
||||||
let newVersionInfo;
|
let newVersionInfo: IKeyBackupInfo | null = null;
|
||||||
// if key backup is still enabled, there must be a new backup in place
|
// if key backup is still enabled, there must be a new backup in place
|
||||||
if (MatrixClientPeg.get().getKeyBackupEnabled()) {
|
if (cli.getKeyBackupEnabled()) {
|
||||||
haveNewVersion = true;
|
haveNewVersion = true;
|
||||||
} else {
|
} else {
|
||||||
// otherwise check the server to see if there's a new one
|
// otherwise check the server to see if there's a new one
|
||||||
try {
|
try {
|
||||||
newVersionInfo = await MatrixClientPeg.get().getKeyBackupVersion();
|
newVersionInfo = await cli.getKeyBackupVersion();
|
||||||
if (newVersionInfo !== null) haveNewVersion = true;
|
if (newVersionInfo !== null) haveNewVersion = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("Saw key backup error but failed to check backup version!", e);
|
logger.error("Saw key backup error but failed to check backup version!", e);
|
||||||
|
@ -1639,7 +1640,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
import(
|
import(
|
||||||
"../../async-components/views/dialogs/security/NewRecoveryMethodDialog"
|
"../../async-components/views/dialogs/security/NewRecoveryMethodDialog"
|
||||||
) as unknown as Promise<typeof NewRecoveryMethodDialog>,
|
) as unknown as Promise<typeof NewRecoveryMethodDialog>,
|
||||||
{ newVersionInfo },
|
{ newVersionInfo: newVersionInfo! },
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Modal.createDialogAsync(
|
Modal.createDialogAsync(
|
||||||
|
@ -1686,7 +1687,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private onClientStarted(): void {
|
private onClientStarted(): void {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
if (cli.isCryptoEnabled()) {
|
if (cli.isCryptoEnabled()) {
|
||||||
const blacklistEnabled = SettingsStore.getValueAt(SettingLevel.DEVICE, "blacklistUnverifiedDevices");
|
const blacklistEnabled = SettingsStore.getValueAt(SettingLevel.DEVICE, "blacklistUnverifiedDevices");
|
||||||
|
@ -1734,7 +1735,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
params: params,
|
params: params,
|
||||||
});
|
});
|
||||||
} else if (screen === "soft_logout") {
|
} else if (screen === "soft_logout") {
|
||||||
if (cli.getUserId() && !Lifecycle.isSoftLogout()) {
|
if (!!cli?.getUserId() && !Lifecycle.isSoftLogout()) {
|
||||||
// Logged in - visit a room
|
// Logged in - visit a room
|
||||||
this.viewLastRoom();
|
this.viewLastRoom();
|
||||||
} else {
|
} else {
|
||||||
|
@ -2057,7 +2058,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
{...this.props}
|
{...this.props}
|
||||||
{...this.state}
|
{...this.state}
|
||||||
ref={this.loggedInView}
|
ref={this.loggedInView}
|
||||||
matrixClient={MatrixClientPeg.get()}
|
matrixClient={MatrixClientPeg.safeGet()}
|
||||||
onRegistered={this.onRegistered}
|
onRegistered={this.onRegistered}
|
||||||
currentRoomId={this.state.currentRoomId}
|
currentRoomId={this.state.currentRoomId}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -473,7 +473,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MatrixClientPeg.get().isUserIgnored(mxEv.getSender()!)) {
|
if (MatrixClientPeg.safeGet().isUserIgnored(mxEv.getSender()!)) {
|
||||||
return false; // ignored = no show (only happens if the ignore happens after an event was received)
|
return false; // ignored = no show (only happens if the ignore happens after an event was received)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,7 +743,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
|
||||||
lastInSection =
|
lastInSection =
|
||||||
willWantDateSeparator ||
|
willWantDateSeparator ||
|
||||||
mxEv.getSender() !== nextEv.getSender() ||
|
mxEv.getSender() !== nextEv.getSender() ||
|
||||||
getEventDisplayInfo(MatrixClientPeg.get(), nextEv, this.showHiddenEvents).isInfoMessage ||
|
getEventDisplayInfo(MatrixClientPeg.safeGet(), nextEv, this.showHiddenEvents).isInfoMessage ||
|
||||||
!shouldFormContinuation(mxEv, nextEv, this.showHiddenEvents, this.context.timelineRenderingType);
|
!shouldFormContinuation(mxEv, nextEv, this.showHiddenEvents, this.context.timelineRenderingType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,7 +779,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
|
||||||
|
|
||||||
// We only want to consider "last successful" if the event is sent by us, otherwise of course
|
// We only want to consider "last successful" if the event is sent by us, otherwise of course
|
||||||
// it's successful: we received it.
|
// it's successful: we received it.
|
||||||
isLastSuccessful = isLastSuccessful && mxEv.getSender() === MatrixClientPeg.get().getUserId();
|
isLastSuccessful = isLastSuccessful && mxEv.getSender() === MatrixClientPeg.safeGet().getUserId();
|
||||||
|
|
||||||
const callEventGrouper = this.props.callEventGroupers.get(mxEv.getContent().call_id);
|
const callEventGrouper = this.props.callEventGroupers.get(mxEv.getContent().call_id);
|
||||||
// use txnId as key if available so that we don't remount during sending
|
// use txnId as key if available so that we don't remount during sending
|
||||||
|
@ -833,7 +833,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
|
||||||
// Get a list of read receipts that should be shown next to this event
|
// Get a list of read receipts that should be shown next to this event
|
||||||
// Receipts are objects which have a 'userId', 'roomMember' and 'ts'.
|
// Receipts are objects which have a 'userId', 'roomMember' and 'ts'.
|
||||||
private getReadReceiptsForEvent(event: MatrixEvent): IReadReceiptProps[] | null {
|
private getReadReceiptsForEvent(event: MatrixEvent): IReadReceiptProps[] | null {
|
||||||
const myUserId = MatrixClientPeg.get().credentials.userId;
|
const myUserId = MatrixClientPeg.safeGet().credentials.userId;
|
||||||
|
|
||||||
// get list of read receipts, sorted most recent first
|
// get list of read receipts, sorted most recent first
|
||||||
const { room } = this.props;
|
const { room } = this.props;
|
||||||
|
@ -856,7 +856,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
|
||||||
if (!r.userId || !isSupportedReceiptType(r.type) || r.userId === myUserId) {
|
if (!r.userId || !isSupportedReceiptType(r.type) || r.userId === myUserId) {
|
||||||
return; // ignore non-read receipts and receipts from self.
|
return; // ignore non-read receipts and receipts from self.
|
||||||
}
|
}
|
||||||
if (MatrixClientPeg.get().isUserIgnored(r.userId)) {
|
if (MatrixClientPeg.safeGet().isUserIgnored(r.userId)) {
|
||||||
return; // ignore ignored users
|
return; // ignore ignored users
|
||||||
}
|
}
|
||||||
const member = room.getMember(r.userId);
|
const member = room.getMember(r.userId);
|
||||||
|
@ -1301,7 +1301,7 @@ class MainGrouper extends BaseGrouper {
|
||||||
public add({ event: ev, shouldShow }: EventAndShouldShow): void {
|
public add({ event: ev, shouldShow }: EventAndShouldShow): void {
|
||||||
if (ev.getType() === EventType.RoomMember) {
|
if (ev.getType() === EventType.RoomMember) {
|
||||||
// We can ignore any events that don't actually have a message to display
|
// We can ignore any events that don't actually have a message to display
|
||||||
if (!hasText(ev, MatrixClientPeg.get(), this.panel.showHiddenEvents)) return;
|
if (!hasText(ev, MatrixClientPeg.safeGet(), this.panel.showHiddenEvents)) return;
|
||||||
}
|
}
|
||||||
this.readMarker = this.readMarker || this.panel.readMarkerForEvent(ev.getId()!, ev === this.lastShownEvent);
|
this.readMarker = this.readMarker || this.panel.readMarkerForEvent(ev.getId()!, ev === this.lastShownEvent);
|
||||||
if (!this.panel.showHiddenEvents && !shouldShow) {
|
if (!this.panel.showHiddenEvents && !shouldShow) {
|
||||||
|
|
|
@ -63,8 +63,8 @@ export default class NotificationPanel extends React.PureComponent<IProps, IStat
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
let content;
|
let content: JSX.Element;
|
||||||
const timelineSet = MatrixClientPeg.get().getNotifTimelineSet();
|
const timelineSet = MatrixClientPeg.safeGet().getNotifTimelineSet();
|
||||||
if (timelineSet) {
|
if (timelineSet) {
|
||||||
// wrap a TimelinePanel with the jump-to-event bits turned off.
|
// wrap a TimelinePanel with the jump-to-event bits turned off.
|
||||||
content = (
|
content = (
|
||||||
|
|
|
@ -139,8 +139,8 @@ class PipContainerInner extends React.Component<IProps, IState> {
|
||||||
LegacyCallHandler.instance.addListener(LegacyCallHandlerEvent.CallChangeRoom, this.updateCalls);
|
LegacyCallHandler.instance.addListener(LegacyCallHandlerEvent.CallChangeRoom, this.updateCalls);
|
||||||
LegacyCallHandler.instance.addListener(LegacyCallHandlerEvent.CallState, this.updateCalls);
|
LegacyCallHandler.instance.addListener(LegacyCallHandlerEvent.CallState, this.updateCalls);
|
||||||
SdkContextClass.instance.roomViewStore.addListener(UPDATE_EVENT, this.onRoomViewStoreUpdate);
|
SdkContextClass.instance.roomViewStore.addListener(UPDATE_EVENT, this.onRoomViewStoreUpdate);
|
||||||
MatrixClientPeg.get().on(CallEvent.RemoteHoldUnhold, this.onCallRemoteHold);
|
MatrixClientPeg.safeGet().on(CallEvent.RemoteHoldUnhold, this.onCallRemoteHold);
|
||||||
const room = MatrixClientPeg.get()?.getRoom(this.state.viewedRoomId);
|
const room = MatrixClientPeg.safeGet().getRoom(this.state.viewedRoomId);
|
||||||
if (room) {
|
if (room) {
|
||||||
WidgetLayoutStore.instance.on(WidgetLayoutStore.emissionForRoom(room), this.updateCalls);
|
WidgetLayoutStore.instance.on(WidgetLayoutStore.emissionForRoom(room), this.updateCalls);
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ class PipContainerInner extends React.Component<IProps, IState> {
|
||||||
let notDocked = false;
|
let notDocked = false;
|
||||||
// Sanity check the room - the widget may have been destroyed between render cycles, and
|
// Sanity check the room - the widget may have been destroyed between render cycles, and
|
||||||
// thus no room is associated anymore.
|
// thus no room is associated anymore.
|
||||||
if (persistentWidgetId && persistentRoomId && MatrixClientPeg.get().getRoom(persistentRoomId)) {
|
if (persistentWidgetId && persistentRoomId && MatrixClientPeg.safeGet().getRoom(persistentRoomId)) {
|
||||||
notDocked = !ActiveWidgetStore.instance.isDocked(persistentWidgetId, persistentRoomId);
|
notDocked = !ActiveWidgetStore.instance.isDocked(persistentWidgetId, persistentRoomId);
|
||||||
fromAnotherRoom = this.state.viewedRoomId !== persistentRoomId;
|
fromAnotherRoom = this.state.viewedRoomId !== persistentRoomId;
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ class PipContainerInner extends React.Component<IProps, IState> {
|
||||||
pipContent.push(({ onStartMoving }) => (
|
pipContent.push(({ onStartMoving }) => (
|
||||||
<WidgetPip
|
<WidgetPip
|
||||||
widgetId={this.state.persistentWidgetId!}
|
widgetId={this.state.persistentWidgetId!}
|
||||||
room={MatrixClientPeg.get().getRoom(this.state.persistentRoomId ?? undefined)!}
|
room={MatrixClientPeg.safeGet().getRoom(this.state.persistentRoomId ?? undefined)!}
|
||||||
viewingRoom={this.state.viewedRoomId === this.state.persistentRoomId}
|
viewingRoom={this.state.viewedRoomId === this.state.persistentRoomId}
|
||||||
onStartMoving={onStartMoving}
|
onStartMoving={onStartMoving}
|
||||||
movePersistedElement={this.props.movePersistedElement}
|
movePersistedElement={this.props.movePersistedElement}
|
||||||
|
|
|
@ -329,7 +329,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
|
||||||
Array.from(dataTransfer.files),
|
Array.from(dataTransfer.files),
|
||||||
roomId,
|
roomId,
|
||||||
this.threadRelation,
|
this.threadRelation,
|
||||||
MatrixClientPeg.get(),
|
MatrixClientPeg.safeGet(),
|
||||||
TimelineRenderingType.Thread,
|
TimelineRenderingType.Thread,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -291,7 +291,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
readMarkerEventId: this.initialReadMarkerId,
|
readMarkerEventId: this.initialReadMarkerId,
|
||||||
backPaginating: false,
|
backPaginating: false,
|
||||||
forwardPaginating: false,
|
forwardPaginating: false,
|
||||||
clientSyncState: MatrixClientPeg.get().getSyncState(),
|
clientSyncState: MatrixClientPeg.safeGet().getSyncState(),
|
||||||
isTwelveHour: SettingsStore.getValue("showTwelveHourTimestamps"),
|
isTwelveHour: SettingsStore.getValue("showTwelveHourTimestamps"),
|
||||||
alwaysShowTimestamps: SettingsStore.getValue("alwaysShowTimestamps"),
|
alwaysShowTimestamps: SettingsStore.getValue("alwaysShowTimestamps"),
|
||||||
readMarkerInViewThresholdMs: SettingsStore.getValue("readMarkerInViewThresholdMs"),
|
readMarkerInViewThresholdMs: SettingsStore.getValue("readMarkerInViewThresholdMs"),
|
||||||
|
@ -299,7 +299,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
this.dispatcherRef = dis.register(this.onAction);
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
cli.on(RoomEvent.Timeline, this.onRoomTimeline);
|
cli.on(RoomEvent.Timeline, this.onRoomTimeline);
|
||||||
cli.on(RoomEvent.TimelineReset, this.onRoomTimelineReset);
|
cli.on(RoomEvent.TimelineReset, this.onRoomTimelineReset);
|
||||||
cli.on(RoomEvent.Redaction, this.onRoomRedaction);
|
cli.on(RoomEvent.Redaction, this.onRoomRedaction);
|
||||||
|
@ -788,7 +788,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
// read-marker when a remote echo of an event we have just sent takes
|
// read-marker when a remote echo of an event we have just sent takes
|
||||||
// more than the timeout on userActiveRecently.
|
// more than the timeout on userActiveRecently.
|
||||||
//
|
//
|
||||||
const myUserId = MatrixClientPeg.get().credentials.userId;
|
const myUserId = MatrixClientPeg.safeGet().credentials.userId;
|
||||||
callRMUpdated = false;
|
callRMUpdated = false;
|
||||||
if (ev.getSender() !== myUserId && !UserActivity.sharedInstance().userActiveRecently()) {
|
if (ev.getSender() !== myUserId && !UserActivity.sharedInstance().userActiveRecently()) {
|
||||||
updatedState.readMarkerVisible = true;
|
updatedState.readMarkerVisible = true;
|
||||||
|
@ -881,7 +881,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
if (!this.hasTimelineSetFor(member.roomId)) return;
|
if (!this.hasTimelineSetFor(member.roomId)) return;
|
||||||
|
|
||||||
// ignore events for other users
|
// ignore events for other users
|
||||||
if (member.userId != MatrixClientPeg.get().credentials?.userId) return;
|
if (member.userId != MatrixClientPeg.safeGet().credentials?.userId) return;
|
||||||
|
|
||||||
// We could skip an update if the power level change didn't cross the
|
// We could skip an update if the power level change didn't cross the
|
||||||
// threshold for `VISIBILITY_CHANGE_TYPE`.
|
// threshold for `VISIBILITY_CHANGE_TYPE`.
|
||||||
|
@ -1276,7 +1276,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// now think about advancing it
|
// now think about advancing it
|
||||||
const myUserId = MatrixClientPeg.get().credentials.userId;
|
const myUserId = MatrixClientPeg.safeGet().credentials.userId;
|
||||||
for (i++; i < events.length; i++) {
|
for (i++; i < events.length; i++) {
|
||||||
const ev = events[i];
|
const ev = events[i];
|
||||||
if (ev.getSender() !== myUserId) {
|
if (ev.getSender() !== myUserId) {
|
||||||
|
@ -1557,7 +1557,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
* @param {boolean?} scrollIntoView whether to scroll the event into view.
|
* @param {boolean?} scrollIntoView whether to scroll the event into view.
|
||||||
*/
|
*/
|
||||||
private loadTimeline(eventId?: string, pixelOffset?: number, offsetBase?: number, scrollIntoView = true): void {
|
private loadTimeline(eventId?: string, pixelOffset?: number, offsetBase?: number, scrollIntoView = true): void {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
this.timelineWindow = new TimelineWindow(cli, this.props.timelineSet, { windowLimit: this.props.timelineCap });
|
this.timelineWindow = new TimelineWindow(cli, this.props.timelineSet, { windowLimit: this.props.timelineCap });
|
||||||
this.overlayTimelineWindow = this.props.overlayTimelineSet
|
this.overlayTimelineWindow = this.props.overlayTimelineSet
|
||||||
? new TimelineWindow(cli, this.props.overlayTimelineSet, { windowLimit: this.props.timelineCap })
|
? new TimelineWindow(cli, this.props.overlayTimelineSet, { windowLimit: this.props.timelineCap })
|
||||||
|
@ -1748,7 +1748,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
arrayFastClone(events)
|
arrayFastClone(events)
|
||||||
.reverse()
|
.reverse()
|
||||||
.forEach((event) => {
|
.forEach((event) => {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
client.decryptEventIfNeeded(event);
|
client.decryptEventIfNeeded(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1796,7 +1796,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
* such events were found, then it returns 0.
|
* such events were found, then it returns 0.
|
||||||
*/
|
*/
|
||||||
private checkForPreJoinUISI(events: MatrixEvent[]): number {
|
private checkForPreJoinUISI(events: MatrixEvent[]): number {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const room = this.props.timelineSet.room;
|
const room = this.props.timelineSet.room;
|
||||||
|
|
||||||
const isThreadTimeline = [TimelineRenderingType.Thread, TimelineRenderingType.ThreadsList].includes(
|
const isThreadTimeline = [TimelineRenderingType.Thread, TimelineRenderingType.ThreadsList].includes(
|
||||||
|
@ -1921,7 +1921,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
const messagePanelNode = ReactDOM.findDOMNode(messagePanel) as Element;
|
const messagePanelNode = ReactDOM.findDOMNode(messagePanel) as Element;
|
||||||
if (!messagePanelNode) return null; // sometimes this happens for fresh rooms/post-sync
|
if (!messagePanelNode) return null; // sometimes this happens for fresh rooms/post-sync
|
||||||
const wrapperRect = messagePanelNode.getBoundingClientRect();
|
const wrapperRect = messagePanelNode.getBoundingClientRect();
|
||||||
const myUserId = MatrixClientPeg.get().credentials.userId;
|
const myUserId = MatrixClientPeg.safeGet().credentials.userId;
|
||||||
|
|
||||||
const isNodeInView = (node?: HTMLElement): boolean => {
|
const isNodeInView = (node?: HTMLElement): boolean => {
|
||||||
if (node) {
|
if (node) {
|
||||||
|
@ -2121,7 +2121,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
canBackPaginate={this.state.canBackPaginate && this.state.firstVisibleEventIndex === 0}
|
canBackPaginate={this.state.canBackPaginate && this.state.firstVisibleEventIndex === 0}
|
||||||
showUrlPreview={this.props.showUrlPreview}
|
showUrlPreview={this.props.showUrlPreview}
|
||||||
showReadReceipts={this.props.showReadReceipts}
|
showReadReceipts={this.props.showReadReceipts}
|
||||||
ourUserId={MatrixClientPeg.get().getSafeUserId()}
|
ourUserId={MatrixClientPeg.safeGet().getSafeUserId()}
|
||||||
stickyBottom={stickyBottom}
|
stickyBottom={stickyBottom}
|
||||||
onScroll={this.onMessageListScroll}
|
onScroll={this.onMessageListScroll}
|
||||||
onFillRequest={this.onMessageListFillRequest}
|
onFillRequest={this.onMessageListFillRequest}
|
||||||
|
|
|
@ -291,7 +291,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
if (!this.state.contextMenuPosition) return null;
|
if (!this.state.contextMenuPosition) return null;
|
||||||
|
|
||||||
let topSection: JSX.Element | undefined;
|
let topSection: JSX.Element | undefined;
|
||||||
if (MatrixClientPeg.get().isGuest()) {
|
if (MatrixClientPeg.safeGet().isGuest()) {
|
||||||
topSection = (
|
topSection = (
|
||||||
<div className="mx_UserMenu_contextMenu_header mx_UserMenu_contextMenu_guestPrompts">
|
<div className="mx_UserMenu_contextMenu_header mx_UserMenu_contextMenu_guestPrompts">
|
||||||
{_t(
|
{_t(
|
||||||
|
@ -372,7 +372,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
</IconizedContextMenuOptionList>
|
</IconizedContextMenuOptionList>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (MatrixClientPeg.get().isGuest()) {
|
if (MatrixClientPeg.safeGet().isGuest()) {
|
||||||
primaryOptionList = (
|
primaryOptionList = (
|
||||||
<IconizedContextMenuOptionList>
|
<IconizedContextMenuOptionList>
|
||||||
{homeButton}
|
{homeButton}
|
||||||
|
@ -399,7 +399,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
</span>
|
</span>
|
||||||
<span className="mx_UserMenu_contextMenu_userId">
|
<span className="mx_UserMenu_contextMenu_userId">
|
||||||
{UserIdentifierCustomisations.getDisplayUserIdentifier(
|
{UserIdentifierCustomisations.getDisplayUserIdentifier(
|
||||||
MatrixClientPeg.get().getSafeUserId(),
|
MatrixClientPeg.safeGet().getSafeUserId(),
|
||||||
{
|
{
|
||||||
withDisplayName: true,
|
withDisplayName: true,
|
||||||
},
|
},
|
||||||
|
@ -428,7 +428,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
const avatarSize = 32; // should match border-radius of the avatar
|
const avatarSize = 32; // should match border-radius of the avatar
|
||||||
|
|
||||||
const userId = MatrixClientPeg.get().getSafeUserId();
|
const userId = MatrixClientPeg.safeGet().getSafeUserId();
|
||||||
const displayName = OwnProfileStore.instance.displayName || userId;
|
const displayName = OwnProfileStore.instance.displayName || userId;
|
||||||
const avatarUrl = OwnProfileStore.instance.getHttpAvatarUrl(avatarSize);
|
const avatarUrl = OwnProfileStore.instance.getHttpAvatarUrl(avatarSize);
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ export default class ViewSource extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private canSendStateEvent(mxEvent: MatrixEvent): boolean {
|
private canSendStateEvent(mxEvent: MatrixEvent): boolean {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const room = cli.getRoom(mxEvent.getRoomId());
|
const room = cli.getRoom(mxEvent.getRoomId());
|
||||||
return !!room?.currentState.mayClientSendStateEvent(mxEvent.getType(), cli);
|
return !!room?.currentState.mayClientSendStateEvent(mxEvent.getType(), cli);
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ export default class ViewSource extends React.Component<IProps, IState> {
|
||||||
const eventId = mxEvent.getId()!;
|
const eventId = mxEvent.getId()!;
|
||||||
const canEdit = mxEvent.isState()
|
const canEdit = mxEvent.isState()
|
||||||
? this.canSendStateEvent(mxEvent)
|
? this.canSendStateEvent(mxEvent)
|
||||||
: canEditContent(MatrixClientPeg.get(), this.props.mxEvent);
|
: canEditContent(MatrixClientPeg.safeGet(), this.props.mxEvent);
|
||||||
return (
|
return (
|
||||||
<BaseDialog className="mx_ViewSource" onFinished={this.props.onFinished} title={_t("View Source")}>
|
<BaseDialog className="mx_ViewSource" onFinished={this.props.onFinished} title={_t("View Source")}>
|
||||||
<div className="mx_ViewSource_header">
|
<div className="mx_ViewSource_header">
|
||||||
|
|
|
@ -420,7 +420,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
||||||
if (!this.props.brand) {
|
if (!this.props.brand) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
const matrixClient = MatrixClientPeg.get();
|
const matrixClient = MatrixClientPeg.safeGet();
|
||||||
return matrixClient.getPushers().then(
|
return matrixClient.getPushers().then(
|
||||||
(resp) => {
|
(resp) => {
|
||||||
const pushers = resp.pushers;
|
const pushers = resp.pushers;
|
||||||
|
|
|
@ -87,7 +87,7 @@ export default class SetupEncryptionBody extends React.Component<IProps, IState>
|
||||||
};
|
};
|
||||||
|
|
||||||
private onVerifyClick = (): void => {
|
private onVerifyClick = (): void => {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const userId = cli.getSafeUserId();
|
const userId = cli.getSafeUserId();
|
||||||
const requestPromise = cli.requestVerification(userId);
|
const requestPromise = cli.requestVerification(userId);
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ export default class SetupEncryptionBody extends React.Component<IProps, IState>
|
||||||
};
|
};
|
||||||
|
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const { phase, lostKeys } = this.state;
|
const { phase, lostKeys } = this.state;
|
||||||
|
|
||||||
if (this.state.verificationRequest && cli.getUser(this.state.verificationRequest.otherUserId)) {
|
if (this.state.verificationRequest && cli.getUser(this.state.verificationRequest.otherUserId)) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
||||||
|
|
||||||
this.initLogin();
|
this.initLogin();
|
||||||
|
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
if (cli.isCryptoEnabled()) {
|
if (cli.isCryptoEnabled()) {
|
||||||
cli.countSessionsNeedingBackup().then((remaining) => {
|
cli.countSessionsNeedingBackup().then((remaining) => {
|
||||||
this.setState({ keyBackupNeeded: remaining > 0 });
|
this.setState({ keyBackupNeeded: remaining > 0 });
|
||||||
|
@ -124,7 +124,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
||||||
|
|
||||||
// Note: we don't use the existing Login class because it is heavily flow-based. We don't
|
// Note: we don't use the existing Login class because it is heavily flow-based. We don't
|
||||||
// care about login flows here, unless it is the single flow we support.
|
// care about login flows here, unless it is the single flow we support.
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
const flows = (await client.loginFlows()).flows;
|
const flows = (await client.loginFlows()).flows;
|
||||||
const loginViews = flows.map((f) => STATIC_FLOWS_TO_VIEWS[f.type]);
|
const loginViews = flows.map((f) => STATIC_FLOWS_TO_VIEWS[f.type]);
|
||||||
|
|
||||||
|
@ -148,16 +148,17 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
||||||
|
|
||||||
this.setState({ busy: true });
|
this.setState({ busy: true });
|
||||||
|
|
||||||
const hsUrl = MatrixClientPeg.get().getHomeserverUrl();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const isUrl = MatrixClientPeg.get().getIdentityServerUrl();
|
const hsUrl = cli.getHomeserverUrl();
|
||||||
|
const isUrl = cli.getIdentityServerUrl();
|
||||||
const loginType = "m.login.password";
|
const loginType = "m.login.password";
|
||||||
const loginParams = {
|
const loginParams = {
|
||||||
identifier: {
|
identifier: {
|
||||||
type: "m.id.user",
|
type: "m.id.user",
|
||||||
user: MatrixClientPeg.get().getUserId(),
|
user: cli.getUserId(),
|
||||||
},
|
},
|
||||||
password: this.state.password,
|
password: this.state.password,
|
||||||
device_id: MatrixClientPeg.get().getDeviceId() ?? undefined,
|
device_id: cli.getDeviceId() ?? undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
let credentials: IMatrixClientCreds;
|
let credentials: IMatrixClientCreds;
|
||||||
|
@ -196,11 +197,11 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isUrl = localStorage.getItem(SSO_ID_SERVER_URL_KEY) || MatrixClientPeg.get().getIdentityServerUrl();
|
const isUrl = localStorage.getItem(SSO_ID_SERVER_URL_KEY) || MatrixClientPeg.safeGet().getIdentityServerUrl();
|
||||||
const loginType = "m.login.token";
|
const loginType = "m.login.token";
|
||||||
const loginParams = {
|
const loginParams = {
|
||||||
token: this.props.realQueryParams["loginToken"],
|
token: this.props.realQueryParams["loginToken"],
|
||||||
device_id: MatrixClientPeg.get().getDeviceId() ?? undefined,
|
device_id: MatrixClientPeg.safeGet().getDeviceId() ?? undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
let credentials: IMatrixClientCreds;
|
let credentials: IMatrixClientCreds;
|
||||||
|
@ -262,7 +263,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
||||||
<div>
|
<div>
|
||||||
{introText ? <p>{introText}</p> : null}
|
{introText ? <p>{introText}</p> : null}
|
||||||
<SSOButtons
|
<SSOButtons
|
||||||
matrixClient={MatrixClientPeg.get()}
|
matrixClient={MatrixClientPeg.safeGet()}
|
||||||
flow={flow}
|
flow={flow}
|
||||||
loginType={loginType}
|
loginType={loginType}
|
||||||
fragmentAfterLogin={this.props.fragmentAfterLogin}
|
fragmentAfterLogin={this.props.fragmentAfterLogin}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import { filterBoolean } from "../../utils/arrays";
|
||||||
|
|
||||||
export const useRecentSearches = (): [Room[], () => void] => {
|
export const useRecentSearches = (): [Room[], () => void] => {
|
||||||
const [rooms, setRooms] = useState(() => {
|
const [rooms, setRooms] = useState(() => {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const recents = SettingsStore.getValue<string[]>("SpotlightSearch.recentSearches", null);
|
const recents = SettingsStore.getValue<string[]>("SpotlightSearch.recentSearches", null);
|
||||||
return filterBoolean(recents.map((r) => cli.getRoom(r)));
|
return filterBoolean(recents.map((r) => cli.getRoom(r)));
|
||||||
});
|
});
|
||||||
|
|
|
@ -74,7 +74,7 @@ export const usePermalinkEvent = (
|
||||||
|
|
||||||
const fetchRoomEvent = async (): Promise<void> => {
|
const fetchRoomEvent = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const eventData = await MatrixClientPeg.get().fetchRoomEvent(
|
const eventData = await MatrixClientPeg.safeGet().fetchRoomEvent(
|
||||||
parseResult.roomIdOrAlias!,
|
parseResult.roomIdOrAlias!,
|
||||||
parseResult.eventId!,
|
parseResult.eventId!,
|
||||||
);
|
);
|
||||||
|
|
|
@ -59,7 +59,7 @@ const determineInitialRoom = (
|
||||||
* @returns Room if found, else null.
|
* @returns Room if found, else null.
|
||||||
*/
|
*/
|
||||||
const findRoom = (roomIdOrAlias: string): Room | null => {
|
const findRoom = (roomIdOrAlias: string): Room | null => {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
return roomIdOrAlias[0] === "#"
|
return roomIdOrAlias[0] === "#"
|
||||||
? client.getRooms().find((r) => {
|
? client.getRooms().find((r) => {
|
||||||
|
|
|
@ -51,7 +51,7 @@ export const useProfileInfo = (): {
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const result = await MatrixClientPeg.get().getProfileInfo(term);
|
const result = await MatrixClientPeg.safeGet().getProfileInfo(term);
|
||||||
updateResult(term, {
|
updateResult(term, {
|
||||||
user_id: term,
|
user_id: term,
|
||||||
avatar_url: result.avatar_url,
|
avatar_url: result.avatar_url,
|
||||||
|
|
|
@ -72,7 +72,7 @@ export const usePublicRoomDirectory = (): {
|
||||||
} else if (thirdParty) {
|
} else if (thirdParty) {
|
||||||
setProtocols(thirdParty);
|
setProtocols(thirdParty);
|
||||||
} else {
|
} else {
|
||||||
const response = await MatrixClientPeg.get().getThirdpartyProtocols();
|
const response = await MatrixClientPeg.safeGet().getThirdpartyProtocols();
|
||||||
thirdParty = response;
|
thirdParty = response;
|
||||||
setProtocols(response);
|
setProtocols(response);
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ export const usePublicRoomDirectory = (): {
|
||||||
generic_search_term: query,
|
generic_search_term: query,
|
||||||
room_types:
|
room_types:
|
||||||
roomTypes &&
|
roomTypes &&
|
||||||
(await MatrixClientPeg.get().doesServerSupportUnstableFeature("org.matrix.msc3827.stable"))
|
(await MatrixClientPeg.safeGet().doesServerSupportUnstableFeature("org.matrix.msc3827.stable"))
|
||||||
? Array.from<RoomType | null>(roomTypes)
|
? Array.from<RoomType | null>(roomTypes)
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
|
@ -114,7 +114,7 @@ export const usePublicRoomDirectory = (): {
|
||||||
updateQuery(opts);
|
updateQuery(opts);
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const { chunk } = await MatrixClientPeg.get().publicRooms(opts);
|
const { chunk } = await MatrixClientPeg.safeGet().publicRooms(opts);
|
||||||
updateResult(opts, showNsfwPublicRooms ? chunk : chunk.filter(cheapNsfwFilter));
|
updateResult(opts, showNsfwPublicRooms ? chunk : chunk.filter(cheapNsfwFilter));
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ export const useSlidingSyncRoomSearch = (): {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (roomIndexToRoomId[i]) {
|
while (roomIndexToRoomId[i]) {
|
||||||
const roomId = roomIndexToRoomId[i];
|
const roomId = roomIndexToRoomId[i];
|
||||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
const room = MatrixClientPeg.safeGet().getRoom(roomId);
|
||||||
if (room) {
|
if (room) {
|
||||||
rooms.push(room);
|
rooms.push(room);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ export const useSpaceResults = (space: Room | undefined, query: string): [IHiera
|
||||||
const lcQuery = trimmedQuery.toLowerCase();
|
const lcQuery = trimmedQuery.toLowerCase();
|
||||||
const normalizedQuery = normalize(trimmedQuery);
|
const normalizedQuery = normalize(trimmedQuery);
|
||||||
|
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
return rooms?.filter((r) => {
|
return rooms?.filter((r) => {
|
||||||
return (
|
return (
|
||||||
r.room_type !== RoomType.Space &&
|
r.room_type !== RoomType.Space &&
|
||||||
|
|
|
@ -49,7 +49,7 @@ export const useUserDirectory = (): {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const { results } = await MatrixClientPeg.get().searchUserDirectory(opts);
|
const { results } = await MatrixClientPeg.safeGet().searchUserDirectory(opts);
|
||||||
updateResult(
|
updateResult(
|
||||||
opts,
|
opts,
|
||||||
results.map((user) => new DirectoryMember(user)),
|
results.map((user) => new DirectoryMember(user)),
|
||||||
|
|
|
@ -51,7 +51,7 @@ export default class ActiveWidgetStore extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public start(): void {
|
public start(): void {
|
||||||
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onRoomStateEvents);
|
MatrixClientPeg.safeGet().on(RoomStateEvent.Events, this.onRoomStateEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop(): void {
|
public stop(): void {
|
||||||
|
|
|
@ -159,7 +159,7 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
||||||
);
|
);
|
||||||
|
|
||||||
private onStateEvents = async (ev: MatrixEvent): Promise<void> => {
|
private onStateEvents = async (ev: MatrixEvent): Promise<void> => {
|
||||||
const myUserId = MatrixClientPeg.get().getUserId();
|
const myUserId = MatrixClientPeg.safeGet().getUserId();
|
||||||
if (ev.getType() === EventType.RoomMember && ev.getSender() === myUserId && ev.getStateKey() === myUserId) {
|
if (ev.getType() === EventType.RoomMember && ev.getSender() === myUserId && ev.getStateKey() === myUserId) {
|
||||||
await this.onProfileUpdate();
|
await this.onProfileUpdate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,7 @@ export class RoomViewStore extends EventEmitter {
|
||||||
this.setState({ shouldPeek: false });
|
this.setState({ shouldPeek: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
awaitRoomDownSync(MatrixClientPeg.get(), payload.roomId).then((room) => {
|
awaitRoomDownSync(MatrixClientPeg.safeGet(), payload.roomId).then((room) => {
|
||||||
const numMembers = room.getJoinedMemberCount();
|
const numMembers = room.getJoinedMemberCount();
|
||||||
const roomSize =
|
const roomSize =
|
||||||
numMembers > 1000
|
numMembers > 1000
|
||||||
|
@ -361,7 +361,7 @@ export class RoomViewStore extends EventEmitter {
|
||||||
|
|
||||||
private async viewRoom(payload: ViewRoomPayload): Promise<void> {
|
private async viewRoom(payload: ViewRoomPayload): Promise<void> {
|
||||||
if (payload.room_id) {
|
if (payload.room_id) {
|
||||||
const room = MatrixClientPeg.get().getRoom(payload.room_id);
|
const room = MatrixClientPeg.safeGet().getRoom(payload.room_id);
|
||||||
|
|
||||||
if (payload.metricsTrigger !== null && payload.room_id !== this.state.roomId) {
|
if (payload.metricsTrigger !== null && payload.room_id !== this.state.roomId) {
|
||||||
let activeSpace: ViewRoomEvent["activeSpace"];
|
let activeSpace: ViewRoomEvent["activeSpace"];
|
||||||
|
@ -488,7 +488,7 @@ export class RoomViewStore extends EventEmitter {
|
||||||
viewingCall: payload.view_call ?? false,
|
viewingCall: payload.view_call ?? false,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
const result = await MatrixClientPeg.get().getRoomIdForAlias(payload.room_alias);
|
const result = await MatrixClientPeg.safeGet().getRoomIdForAlias(payload.room_alias);
|
||||||
storeRoomAliasInCache(payload.room_alias, result.room_id);
|
storeRoomAliasInCache(payload.room_alias, result.room_id);
|
||||||
roomId = result.room_id;
|
roomId = result.room_id;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -531,12 +531,12 @@ export class RoomViewStore extends EventEmitter {
|
||||||
joining: true,
|
joining: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const cli = MatrixClientPeg.get();
|
|
||||||
// take a copy of roomAlias & roomId as they may change by the time the join is complete
|
// take a copy of roomAlias & roomId as they may change by the time the join is complete
|
||||||
const { roomAlias, roomId = payload.roomId } = this.state;
|
const { roomAlias, roomId = payload.roomId } = this.state;
|
||||||
const address = roomAlias || roomId!;
|
const address = roomAlias || roomId!;
|
||||||
const viaServers = this.state.viaServers || [];
|
const viaServers = this.state.viaServers || [];
|
||||||
try {
|
try {
|
||||||
|
const cli = MatrixClientPeg.safeGet();
|
||||||
await retry<Room, MatrixError>(
|
await retry<Room, MatrixError>(
|
||||||
() =>
|
() =>
|
||||||
cli.joinRoom(address, {
|
cli.joinRoom(address, {
|
||||||
|
@ -568,7 +568,7 @@ export class RoomViewStore extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getInvitingUserId(roomId: string): string | undefined {
|
private getInvitingUserId(roomId: string): string | undefined {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const room = cli.getRoom(roomId);
|
const room = cli.getRoom(roomId);
|
||||||
if (room?.getMyMembership() === "invite") {
|
if (room?.getMyMembership() === "invite") {
|
||||||
const myMember = room.getMember(cli.getSafeUserId());
|
const myMember = room.getMember(cli.getSafeUserId());
|
||||||
|
@ -596,7 +596,7 @@ export class RoomViewStore extends EventEmitter {
|
||||||
// provide a better error message for invites
|
// provide a better error message for invites
|
||||||
if (invitingUserId) {
|
if (invitingUserId) {
|
||||||
// if the inviting user is on the same HS, there can only be one cause: they left.
|
// if the inviting user is on the same HS, there can only be one cause: they left.
|
||||||
if (invitingUserId.endsWith(`:${MatrixClientPeg.get().getDomain()}`)) {
|
if (invitingUserId.endsWith(`:${MatrixClientPeg.safeGet().getDomain()}`)) {
|
||||||
description = _t("The person who invited you has already left.");
|
description = _t("The person who invited you has already left.");
|
||||||
} else {
|
} else {
|
||||||
description = _t("The person who invited you has already left, or their server is offline.");
|
description = _t("The person who invited you has already left, or their server is offline.");
|
||||||
|
|
|
@ -62,7 +62,7 @@ export class SetupEncryptionStore extends EventEmitter {
|
||||||
this.started = true;
|
this.started = true;
|
||||||
this.phase = Phase.Loading;
|
this.phase = Phase.Loading;
|
||||||
|
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
cli.on(CryptoEvent.VerificationRequest, this.onVerificationRequest);
|
cli.on(CryptoEvent.VerificationRequest, this.onVerificationRequest);
|
||||||
cli.on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
|
cli.on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
|
||||||
|
|
||||||
|
@ -83,15 +83,17 @@ export class SetupEncryptionStore extends EventEmitter {
|
||||||
}
|
}
|
||||||
this.started = false;
|
this.started = false;
|
||||||
this.verificationRequest?.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
|
this.verificationRequest?.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
|
||||||
if (MatrixClientPeg.get()) {
|
|
||||||
MatrixClientPeg.get().removeListener(CryptoEvent.VerificationRequest, this.onVerificationRequest);
|
const cli = MatrixClientPeg.get();
|
||||||
MatrixClientPeg.get().removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
|
if (!!cli) {
|
||||||
|
cli.removeListener(CryptoEvent.VerificationRequest, this.onVerificationRequest);
|
||||||
|
cli.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchKeyInfo(): Promise<void> {
|
public async fetchKeyInfo(): Promise<void> {
|
||||||
if (!this.started) return; // bail if we were stopped
|
if (!this.started) return; // bail if we were stopped
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const keys = await cli.isSecretStored("m.cross_signing.master");
|
const keys = await cli.isSecretStored("m.cross_signing.master");
|
||||||
if (keys === null || Object.keys(keys).length === 0) {
|
if (keys === null || Object.keys(keys).length === 0) {
|
||||||
this.keyId = null;
|
this.keyId = null;
|
||||||
|
@ -120,8 +122,8 @@ export class SetupEncryptionStore extends EventEmitter {
|
||||||
public async usePassPhrase(): Promise<void> {
|
public async usePassPhrase(): Promise<void> {
|
||||||
this.phase = Phase.Busy;
|
this.phase = Phase.Busy;
|
||||||
this.emit("update");
|
this.emit("update");
|
||||||
const cli = MatrixClientPeg.get();
|
|
||||||
try {
|
try {
|
||||||
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const backupInfo = await cli.getKeyBackupVersion();
|
const backupInfo = await cli.getKeyBackupVersion();
|
||||||
this.backupInfo = backupInfo;
|
this.backupInfo = backupInfo;
|
||||||
this.emit("update");
|
this.emit("update");
|
||||||
|
@ -161,8 +163,8 @@ export class SetupEncryptionStore extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private onUserTrustStatusChanged = async (userId: string): Promise<void> => {
|
private onUserTrustStatusChanged = async (userId: string): Promise<void> => {
|
||||||
if (userId !== MatrixClientPeg.get().getUserId()) return;
|
if (userId !== MatrixClientPeg.safeGet().getSafeUserId()) return;
|
||||||
const publicKeysTrusted = await MatrixClientPeg.get().getCrypto()?.getCrossSigningKeyId();
|
const publicKeysTrusted = await MatrixClientPeg.safeGet().getCrypto()?.getCrossSigningKeyId();
|
||||||
if (publicKeysTrusted) {
|
if (publicKeysTrusted) {
|
||||||
this.phase = Phase.Done;
|
this.phase = Phase.Done;
|
||||||
this.emit("update");
|
this.emit("update");
|
||||||
|
@ -184,7 +186,7 @@ export class SetupEncryptionStore extends EventEmitter {
|
||||||
// At this point, the verification has finished, we just need to wait for
|
// At this point, the verification has finished, we just need to wait for
|
||||||
// cross signing to be ready to use, so wait for the user trust status to
|
// cross signing to be ready to use, so wait for the user trust status to
|
||||||
// change (or change to DONE if it's already ready).
|
// change (or change to DONE if it's already ready).
|
||||||
const publicKeysTrusted = await MatrixClientPeg.get().getCrypto()?.getCrossSigningKeyId();
|
const publicKeysTrusted = await MatrixClientPeg.safeGet().getCrypto()?.getCrossSigningKeyId();
|
||||||
this.phase = publicKeysTrusted ? Phase.Done : Phase.Busy;
|
this.phase = publicKeysTrusted ? Phase.Done : Phase.Busy;
|
||||||
this.emit("update");
|
this.emit("update");
|
||||||
}
|
}
|
||||||
|
@ -217,7 +219,7 @@ export class SetupEncryptionStore extends EventEmitter {
|
||||||
// secret storage and setting up a new recovery key, then
|
// secret storage and setting up a new recovery key, then
|
||||||
// create new cross-signing keys once that succeeds.
|
// create new cross-signing keys once that succeeds.
|
||||||
await accessSecretStorage(async (): Promise<void> => {
|
await accessSecretStorage(async (): Promise<void> => {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
await cli.bootstrapCrossSigning({
|
await cli.bootstrapCrossSigning({
|
||||||
authUploadDeviceSigningKeys: async (makeRequest): Promise<void> => {
|
authUploadDeviceSigningKeys: async (makeRequest): Promise<void> => {
|
||||||
const cachedPassword = SdkContextClass.instance.accountPasswordStore.getPassword();
|
const cachedPassword = SdkContextClass.instance.accountPasswordStore.getPassword();
|
||||||
|
@ -227,9 +229,9 @@ export class SetupEncryptionStore extends EventEmitter {
|
||||||
type: "m.login.password",
|
type: "m.login.password",
|
||||||
identifier: {
|
identifier: {
|
||||||
type: "m.id.user",
|
type: "m.id.user",
|
||||||
user: cli.getUserId(),
|
user: cli.getSafeUserId(),
|
||||||
},
|
},
|
||||||
user: cli.getUserId(),
|
user: cli.getSafeUserId(),
|
||||||
password: cachedPassword,
|
password: cachedPassword,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -265,12 +267,12 @@ export class SetupEncryptionStore extends EventEmitter {
|
||||||
this.phase = Phase.Finished;
|
this.phase = Phase.Finished;
|
||||||
this.emit("update");
|
this.emit("update");
|
||||||
// async - ask other clients for keys, if necessary
|
// async - ask other clients for keys, if necessary
|
||||||
MatrixClientPeg.get().crypto?.cancelAndResendAllOutgoingKeyRequests();
|
MatrixClientPeg.safeGet().crypto?.cancelAndResendAllOutgoingKeyRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setActiveVerificationRequest(request: VerificationRequest): Promise<void> {
|
private async setActiveVerificationRequest(request: VerificationRequest): Promise<void> {
|
||||||
if (!this.started) return; // bail if we were stopped
|
if (!this.started) return; // bail if we were stopped
|
||||||
if (request.otherUserId !== MatrixClientPeg.get().getUserId()) return;
|
if (request.otherUserId !== MatrixClientPeg.safeGet().getUserId()) return;
|
||||||
|
|
||||||
if (this.verificationRequest) {
|
if (this.verificationRequest) {
|
||||||
this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
|
this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
|
||||||
|
|
|
@ -59,7 +59,7 @@ export class RoomNotificationState extends NotificationState implements IDestroy
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleReadReceipt = (event: MatrixEvent, room: Room): void => {
|
private handleReadReceipt = (event: MatrixEvent, room: Room): void => {
|
||||||
if (!readReceiptChangeIsFor(event, MatrixClientPeg.get())) return; // not our own - ignore
|
if (!readReceiptChangeIsFor(event, MatrixClientPeg.safeGet())) return; // not our own - ignore
|
||||||
if (room.roomId !== this.room.roomId) return; // not for us - ignore
|
if (room.roomId !== this.room.roomId) return; // not for us - ignore
|
||||||
this.updateNotificationState();
|
this.updateNotificationState();
|
||||||
};
|
};
|
||||||
|
|
|
@ -310,7 +310,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
|
||||||
// RightPanelPhases.RoomMemberInfo -> needs to be changed to RightPanelPhases.EncryptionPanel if there is a pending verification request
|
// RightPanelPhases.RoomMemberInfo -> needs to be changed to RightPanelPhases.EncryptionPanel if there is a pending verification request
|
||||||
const { member } = card.state;
|
const { member } = card.state;
|
||||||
const pendingRequest = member
|
const pendingRequest = member
|
||||||
? pendingVerificationRequestForUser(MatrixClientPeg.get(), member)
|
? pendingVerificationRequestForUser(MatrixClientPeg.safeGet(), member)
|
||||||
: undefined;
|
: undefined;
|
||||||
if (pendingRequest) {
|
if (pendingRequest) {
|
||||||
return {
|
return {
|
||||||
|
@ -344,7 +344,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
|
||||||
if (!this.currentCard?.state) return;
|
if (!this.currentCard?.state) return;
|
||||||
const { member } = this.currentCard.state;
|
const { member } = this.currentCard.state;
|
||||||
if (!member) return;
|
if (!member) return;
|
||||||
const pendingRequest = pendingVerificationRequestForUser(MatrixClientPeg.get(), member);
|
const pendingRequest = pendingVerificationRequestForUser(MatrixClientPeg.safeGet(), member);
|
||||||
if (pendingRequest) {
|
if (pendingRequest) {
|
||||||
this.currentCard.state.verificationRequest = pendingRequest;
|
this.currentCard.state.verificationRequest = pendingRequest;
|
||||||
this.emitAndUpdateSettings();
|
this.emitAndUpdateSettings();
|
||||||
|
|
|
@ -56,7 +56,7 @@ export const sortRooms = (rooms: Room[]): Room[] => {
|
||||||
// See https://github.com/vector-im/element-web/issues/14458
|
// See https://github.com/vector-im/element-web/issues/14458
|
||||||
let myUserId = "";
|
let myUserId = "";
|
||||||
if (MatrixClientPeg.get()) {
|
if (MatrixClientPeg.get()) {
|
||||||
myUserId = MatrixClientPeg.get().getUserId()!;
|
myUserId = MatrixClientPeg.get()!.getSafeUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
const tsCache: { [roomId: string]: number } = {};
|
const tsCache: { [roomId: string]: number } = {};
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||||
import { DefaultTagID, TagID } from "../models";
|
import { DefaultTagID, TagID } from "../models";
|
||||||
|
|
||||||
export function isSelf(event: MatrixEvent): boolean {
|
export function isSelf(event: MatrixEvent): boolean {
|
||||||
const selfUserId = MatrixClientPeg.get().getSafeUserId();
|
const selfUserId = MatrixClientPeg.safeGet().getSafeUserId();
|
||||||
if (event.getType() === "m.room.member") {
|
if (event.getType() === "m.room.member") {
|
||||||
return event.getStateKey() === selfUserId;
|
return event.getStateKey() === selfUserId;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ export function shouldPrefixMessagesIn(roomId: string, tagId?: TagID): boolean {
|
||||||
if (tagId !== DefaultTagID.DM) return true;
|
if (tagId !== DefaultTagID.DM) return true;
|
||||||
|
|
||||||
// We don't prefix anything in 1:1s
|
// We don't prefix anything in 1:1s
|
||||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
const room = MatrixClientPeg.safeGet().getRoom(roomId);
|
||||||
if (!room) return true;
|
if (!room) return true;
|
||||||
return room.currentState.getJoinedMemberCount() !== 2;
|
return room.currentState.getJoinedMemberCount() !== 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ export class StopGapWidget extends EventEmitter {
|
||||||
|
|
||||||
public constructor(private appTileProps: IAppTileProps) {
|
public constructor(private appTileProps: IAppTileProps) {
|
||||||
super();
|
super();
|
||||||
this.client = MatrixClientPeg.get();
|
this.client = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
let app = appTileProps.app;
|
let app = appTileProps.app;
|
||||||
// Backwards compatibility: not all old widgets have a creatorUserId
|
// Backwards compatibility: not all old widgets have a creatorUserId
|
||||||
|
|
|
@ -138,7 +138,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||||
WidgetEventCapability.forStateEvent(
|
WidgetEventCapability.forStateEvent(
|
||||||
EventDirection.Send,
|
EventDirection.Send,
|
||||||
"org.matrix.msc3401.call.member",
|
"org.matrix.msc3401.call.member",
|
||||||
MatrixClientPeg.get().getUserId()!,
|
MatrixClientPeg.safeGet().getSafeUserId(),
|
||||||
).raw,
|
).raw,
|
||||||
);
|
);
|
||||||
this.allowedCapabilities.add(
|
this.allowedCapabilities.add(
|
||||||
|
@ -266,7 +266,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||||
encrypted: boolean,
|
encrypted: boolean,
|
||||||
contentMap: { [userId: string]: { [deviceId: string]: object } },
|
contentMap: { [userId: string]: { [deviceId: string]: object } },
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
const deviceInfoMap = await client.crypto!.deviceList.downloadKeys(Object.keys(contentMap), false);
|
const deviceInfoMap = await client.crypto!.deviceList.downloadKeys(Object.keys(contentMap), false);
|
||||||
|
@ -382,7 +382,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||||
if (opts.approved) {
|
if (opts.approved) {
|
||||||
return observer.update({
|
return observer.update({
|
||||||
state: OpenIDRequestState.Allowed,
|
state: OpenIDRequestState.Allowed,
|
||||||
token: await MatrixClientPeg.get().getOpenIdToken(),
|
token: await MatrixClientPeg.safeGet().getOpenIdToken(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||||
);
|
);
|
||||||
|
|
||||||
const getToken = (): Promise<IOpenIDCredentials> => {
|
const getToken = (): Promise<IOpenIDCredentials> => {
|
||||||
return MatrixClientPeg.get().getOpenIdToken();
|
return MatrixClientPeg.safeGet().getOpenIdToken();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (oidcState === OIDCState.Denied) {
|
if (oidcState === OIDCState.Denied) {
|
||||||
|
@ -425,7 +425,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async *getTurnServers(): AsyncGenerator<ITurnServer> {
|
public async *getTurnServers(): AsyncGenerator<ITurnServer> {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
if (!client.pollingTurnServers || !client.getTurnServers().length) return;
|
if (!client.pollingTurnServers || !client.getTurnServers().length) return;
|
||||||
|
|
||||||
let setTurnServer: (server: ITurnServer) => void;
|
let setTurnServer: (server: ITurnServer) => void;
|
||||||
|
@ -468,7 +468,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||||
limit?: number,
|
limit?: number,
|
||||||
direction?: "f" | "b",
|
direction?: "f" | "b",
|
||||||
): Promise<IReadEventRelationsResult> {
|
): Promise<IReadEventRelationsResult> {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
const dir = direction as Direction;
|
const dir = direction as Direction;
|
||||||
roomId = roomId ?? SdkContextClass.instance.roomViewStore.getRoomId() ?? undefined;
|
roomId = roomId ?? SdkContextClass.instance.roomViewStore.getRoomId() ?? undefined;
|
||||||
|
|
||||||
|
@ -492,7 +492,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async searchUserDirectory(searchTerm: string, limit?: number): Promise<ISearchUserDirectoryResult> {
|
public async searchUserDirectory(searchTerm: string, limit?: number): Promise<ISearchUserDirectoryResult> {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
const { limited, results } = await client.searchUserDirectory({ term: searchTerm, limit });
|
const { limited, results } = await client.searchUserDirectory({ term: searchTerm, limit });
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ _td("Short keyboard patterns are easy to guess");
|
||||||
* @param matrixClient the client of the logged in user, if any
|
* @param matrixClient the client of the logged in user, if any
|
||||||
* @returns {object} Score result with `score` and `feedback` properties
|
* @returns {object} Score result with `score` and `feedback` properties
|
||||||
*/
|
*/
|
||||||
export function scorePassword(matrixClient: MatrixClient | undefined, password: string): zxcvbn.ZXCVBNResult | null {
|
export function scorePassword(matrixClient: MatrixClient | null, password: string): zxcvbn.ZXCVBNResult | null {
|
||||||
if (password.length === 0) return null;
|
if (password.length === 0) return null;
|
||||||
|
|
||||||
const userInputs = ZXCVBN_USER_INPUTS.slice();
|
const userInputs = ZXCVBN_USER_INPUTS.slice();
|
||||||
|
|
|
@ -24,6 +24,10 @@ jest.spyOn(MatrixClientPeg, "get").mockReturnValue({
|
||||||
getUserId: () => "@me:example.com",
|
getUserId: () => "@me:example.com",
|
||||||
getSafeUserId: () => "@me:example.com",
|
getSafeUserId: () => "@me:example.com",
|
||||||
} as unknown as MatrixClient);
|
} as unknown as MatrixClient);
|
||||||
|
jest.spyOn(MatrixClientPeg, "safeGet").mockReturnValue({
|
||||||
|
getUserId: () => "@me:example.com",
|
||||||
|
getSafeUserId: () => "@me:example.com",
|
||||||
|
} as unknown as MatrixClient);
|
||||||
|
|
||||||
describe("PollStartEventPreview", () => {
|
describe("PollStartEventPreview", () => {
|
||||||
it("shows the question for a poll I created", async () => {
|
it("shows the question for a poll I created", async () => {
|
||||||
|
|
|
@ -63,6 +63,7 @@ describe("StopGapWidgetDriver", () => {
|
||||||
stubClient();
|
stubClient();
|
||||||
client = mocked(MatrixClientPeg.safeGet());
|
client = mocked(MatrixClientPeg.safeGet());
|
||||||
client.getUserId.mockReturnValue("@alice:example.org");
|
client.getUserId.mockReturnValue("@alice:example.org");
|
||||||
|
client.getSafeUserId.mockReturnValue("@alice:example.org");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("auto-approves capabilities of virtual Element Call widgets", async () => {
|
it("auto-approves capabilities of virtual Element Call widgets", async () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue