Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' into andybalaam/bump-analytics-events-to-0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam authored Jan 12, 2023
2 parents 4c5396f + 030b7e9 commit 0493f81
Show file tree
Hide file tree
Showing 683 changed files with 3,460 additions and 3,014 deletions.
8 changes: 6 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ module.exports = {
files: ["src/**/*.{ts,tsx}", "test/**/*.{ts,tsx}", "cypress/**/*.ts"],
extends: ["plugin:matrix-org/typescript", "plugin:matrix-org/react"],
rules: {
// temporary disabled
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true,
},
],

// Things we do that break the ideal style
"prefer-promise-reject-errors": "off",
Expand Down
8 changes: 4 additions & 4 deletions src/@types/diff-dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ declare module "diff-dom" {
name: string;
text?: string;
route: number[];
value: string;
element: unknown;
oldValue: string;
newValue: string;
value: HTMLElement | string;
element: HTMLElement | string;
oldValue: HTMLElement | string;
newValue: HTMLElement | string;
}

interface IOpts {}
Expand Down
2 changes: 1 addition & 1 deletion src/@types/polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

// This is intended to fix re-resizer because of its unguarded `instanceof TouchEvent` checks.
export function polyfillTouchEvent() {
export function polyfillTouchEvent(): void {
// Firefox doesn't have touch events without touch devices being present, so create a fake
// one we can rely on lying about.
if (!window.TouchEvent) {
Expand Down
8 changes: 4 additions & 4 deletions src/AsyncWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class AsyncWrapper extends React.Component<IProps, IState> {
error: null,
};

public componentDidMount() {
public componentDidMount(): void {
// XXX: temporary logging to try to diagnose
// https://github.com/vector-im/element-web/issues/3148
logger.log("Starting load of AsyncWrapper for modal");
Expand All @@ -69,15 +69,15 @@ export default class AsyncWrapper extends React.Component<IProps, IState> {
});
}

public componentWillUnmount() {
public componentWillUnmount(): void {
this.unmounted = true;
}

private onWrapperCancelClick = () => {
private onWrapperCancelClick = (): void => {
this.props.onFinished(false);
};

public render() {
public render(): JSX.Element {
if (this.state.component) {
const Component = this.state.component;
return <Component {...this.props} />;
Expand Down
7 changes: 6 additions & 1 deletion src/Avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ export function getInitialLetter(name: string): string {
return split(name, "", 1)[0].toUpperCase();
}

export function avatarUrlForRoom(room: Room, width: number, height: number, resizeMethod?: ResizeMethod) {
export function avatarUrlForRoom(
room: Room,
width: number,
height: number,
resizeMethod?: ResizeMethod,
): string | null {
if (!room) return null; // null-guard

if (room.getMxcAvatarUrl()) {
Expand Down
4 changes: 2 additions & 2 deletions src/BasePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ export default abstract class BasePlatform {
return null;
}

public setLanguage(preferredLangs: string[]) {}
public setLanguage(preferredLangs: string[]): void {}

public setSpellCheckEnabled(enabled: boolean): void {}

public async getSpellCheckEnabled(): Promise<boolean> {
return null;
}

public setSpellCheckLanguages(preferredLangs: string[]) {}
public setSpellCheckLanguages(preferredLangs: string[]): void {}

public getSpellCheckLanguages(): Promise<string[]> | null {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/BlurhashEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class BlurhashEncoder {
this.worker.onmessage = this.onMessage;
}

private onMessage = (ev: MessageEvent<IBlurhashWorkerResponse>) => {
private onMessage = (ev: MessageEvent<IBlurhashWorkerResponse>): void => {
const { seq, blurhash } = ev.data;
const deferred = this.pendingDeferredMap.get(seq);
if (deferred) {
Expand Down
30 changes: 17 additions & 13 deletions src/ContentMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,20 @@ interface IMediaConfig {
* @param {File} imageFile The file to load in an image element.
* @return {Promise} A promise that resolves with the html image element.
*/
async function loadImageElement(imageFile: File) {
async function loadImageElement(imageFile: File): Promise<{
width: number;
height: number;
img: HTMLImageElement;
}> {
// Load the file into an html element
const img = new Image();
const objectUrl = URL.createObjectURL(imageFile);
const imgPromise = new Promise((resolve, reject) => {
img.onload = function () {
img.onload = function (): void {
URL.revokeObjectURL(objectUrl);
resolve(img);
};
img.onerror = function (e) {
img.onerror = function (e): void {
reject(e);
};
});
Expand Down Expand Up @@ -185,13 +189,13 @@ function loadVideoElement(videoFile: File): Promise<HTMLVideoElement> {

const reader = new FileReader();

reader.onload = function (ev) {
reader.onload = function (ev): void {
// Wait until we have enough data to thumbnail the first frame.
video.onloadeddata = async function () {
video.onloadeddata = async function (): Promise<void> {
resolve(video);
video.pause();
};
video.onerror = function (e) {
video.onerror = function (e): void {
reject(e);
};

Expand All @@ -206,7 +210,7 @@ function loadVideoElement(videoFile: File): Promise<HTMLVideoElement> {
video.load();
video.play();
};
reader.onerror = function (e) {
reader.onerror = function (e): void {
reject(e);
};
reader.readAsDataURL(videoFile);
Expand Down Expand Up @@ -253,10 +257,10 @@ function infoForVideoFile(
function readFileAsArrayBuffer(file: File | Blob): Promise<ArrayBuffer> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = function (e) {
reader.onload = function (e): void {
resolve(e.target.result as ArrayBuffer);
};
reader.onerror = function (e) {
reader.onerror = function (e): void {
reject(e);
};
reader.readAsArrayBuffer(file);
Expand Down Expand Up @@ -461,7 +465,7 @@ export default class ContentMessages {
matrixClient: MatrixClient,
replyToEvent: MatrixEvent | undefined,
promBefore?: Promise<any>,
) {
): Promise<void> {
const fileName = file.name || _t("Attachment");
const content: Omit<IMediaEventContent, "info"> & { info: Partial<IMediaEventInfo> } = {
body: fileName,
Expand Down Expand Up @@ -491,7 +495,7 @@ export default class ContentMessages {
this.inprogress.push(upload);
dis.dispatch<UploadStartedPayload>({ action: Action.UploadStarted, upload });

function onProgress(progress: UploadProgress) {
function onProgress(progress: UploadProgress): void {
upload.onProgress(progress);
dis.dispatch<UploadProgressPayload>({ action: Action.UploadProgress, upload });
}
Expand Down Expand Up @@ -568,7 +572,7 @@ export default class ContentMessages {
}
}

private isFileSizeAcceptable(file: File) {
private isFileSizeAcceptable(file: File): boolean {
if (
this.mediaConfig !== null &&
this.mediaConfig["m.upload.size"] !== undefined &&
Expand Down Expand Up @@ -599,7 +603,7 @@ export default class ContentMessages {
});
}

public static sharedInstance() {
public static sharedInstance(): ContentMessages {
if (window.mxContentMessages === undefined) {
window.mxContentMessages = new ContentMessages();
}
Expand Down
4 changes: 2 additions & 2 deletions src/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function wantsDateSeparator(prevEventDate: Date, nextEventDate: Date): bo
return prevEventDate.getDay() !== nextEventDate.getDay();
}

export function formatFullDateNoDay(date: Date) {
export function formatFullDateNoDay(date: Date): string {
return _t("%(date)s at %(time)s", {
date: date.toLocaleDateString().replace(/\//g, "-"),
time: date.toLocaleTimeString().replace(/:/g, "-"),
Expand All @@ -205,7 +205,7 @@ export function formatFullDateNoDayISO(date: Date): string {
return date.toISOString();
}

export function formatFullDateNoDayNoTime(date: Date) {
export function formatFullDateNoDayNoTime(date: Date): string {
return date.getFullYear() + "/" + pad(date.getMonth() + 1) + "/" + pad(date.getDate());
}

Expand Down
43 changes: 22 additions & 21 deletions src/DeviceListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { logger } from "matrix-js-sdk/src/logger";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { ClientEvent, EventType, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import { SyncState } from "matrix-js-sdk/src/sync";
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";

import { MatrixClientPeg } from "./MatrixClientPeg";
import dis from "./dispatcher/dispatcher";
Expand Down Expand Up @@ -56,7 +57,7 @@ export default class DeviceListener {
// has the user dismissed any of the various nag toasts to setup encryption on this device?
private dismissedThisDeviceToast = false;
// cache of the key backup info
private keyBackupInfo: object = null;
private keyBackupInfo: IKeyBackupInfo | null = null;
private keyBackupFetchedAt: number = null;
private keyBackupStatusChecked = false;
// We keep a list of our own device IDs so we can batch ones that were already
Expand All @@ -70,12 +71,12 @@ export default class DeviceListener {
private enableBulkUnverifiedSessionsReminder = true;
private deviceClientInformationSettingWatcherRef: string | undefined;

public static sharedInstance() {
public static sharedInstance(): DeviceListener {
if (!window.mxDeviceListener) window.mxDeviceListener = new DeviceListener();
return window.mxDeviceListener;
}

public start() {
public start(): void {
this.running = true;
MatrixClientPeg.get().on(CryptoEvent.WillUpdateDevices, this.onWillUpdateDevices);
MatrixClientPeg.get().on(CryptoEvent.DevicesUpdated, this.onDevicesUpdated);
Expand All @@ -98,7 +99,7 @@ export default class DeviceListener {
this.updateClientInformation();
}

public stop() {
public stop(): void {
this.running = false;
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener(CryptoEvent.WillUpdateDevices, this.onWillUpdateDevices);
Expand Down Expand Up @@ -134,7 +135,7 @@ export default class DeviceListener {
*
* @param {String[]} deviceIds List of device IDs to dismiss notifications for
*/
public async dismissUnverifiedSessions(deviceIds: Iterable<string>) {
public async dismissUnverifiedSessions(deviceIds: Iterable<string>): Promise<void> {
logger.log("Dismissing unverified sessions: " + Array.from(deviceIds).join(","));
for (const d of deviceIds) {
this.dismissed.add(d);
Expand All @@ -143,19 +144,19 @@ export default class DeviceListener {
this.recheck();
}

public dismissEncryptionSetup() {
public dismissEncryptionSetup(): void {
this.dismissedThisDeviceToast = true;
this.recheck();
}

private ensureDeviceIdsAtStartPopulated() {
private ensureDeviceIdsAtStartPopulated(): void {
if (this.ourDeviceIdsAtStart === null) {
const cli = MatrixClientPeg.get();
this.ourDeviceIdsAtStart = new Set(cli.getStoredDevicesForUser(cli.getUserId()).map((d) => d.deviceId));
}
}

private onWillUpdateDevices = async (users: string[], initialFetch?: boolean) => {
private onWillUpdateDevices = async (users: string[], initialFetch?: boolean): Promise<void> => {
// If we didn't know about *any* devices before (ie. it's fresh login),
// then they are all pre-existing devices, so ignore this and set the
// devicesAtStart list to the devices that we see after the fetch.
Expand All @@ -168,26 +169,26 @@ export default class DeviceListener {
// before we download any new ones.
};

private onDevicesUpdated = (users: string[]) => {
private onDevicesUpdated = (users: string[]): void => {
if (!users.includes(MatrixClientPeg.get().getUserId())) return;
this.recheck();
};

private onDeviceVerificationChanged = (userId: string) => {
private onDeviceVerificationChanged = (userId: string): void => {
if (userId !== MatrixClientPeg.get().getUserId()) return;
this.recheck();
};

private onUserTrustStatusChanged = (userId: string) => {
private onUserTrustStatusChanged = (userId: string): void => {
if (userId !== MatrixClientPeg.get().getUserId()) return;
this.recheck();
};

private onCrossSingingKeysChanged = () => {
private onCrossSingingKeysChanged = (): void => {
this.recheck();
};

private onAccountData = (ev: MatrixEvent) => {
private onAccountData = (ev: MatrixEvent): void => {
// User may have:
// * migrated SSSS to symmetric
// * uploaded keys to secret storage
Expand All @@ -202,29 +203,29 @@ export default class DeviceListener {
}
};

private onSync = (state: SyncState, prevState?: SyncState) => {
private onSync = (state: SyncState, prevState?: SyncState): void => {
if (state === "PREPARED" && prevState === null) {
this.recheck();
}
};

private onRoomStateEvents = (ev: MatrixEvent) => {
private onRoomStateEvents = (ev: MatrixEvent): void => {
if (ev.getType() !== EventType.RoomEncryption) return;

// If a room changes to encrypted, re-check as it may be our first
// encrypted room. This also catches encrypted room creation as well.
this.recheck();
};

private onAction = ({ action }: ActionPayload) => {
private onAction = ({ action }: ActionPayload): void => {
if (action !== Action.OnLoggedIn) return;
this.recheck();
this.updateClientInformation();
};

// The server doesn't tell us when key backup is set up, so we poll
// & cache the result
private async getKeyBackupInfo() {
private async getKeyBackupInfo(): Promise<IKeyBackupInfo> {
const now = new Date().getTime();
if (!this.keyBackupInfo || this.keyBackupFetchedAt < now - KEY_BACKUP_POLL_INTERVAL) {
this.keyBackupInfo = await MatrixClientPeg.get().getKeyBackupVersion();
Expand All @@ -233,7 +234,7 @@ export default class DeviceListener {
return this.keyBackupInfo;
}

private shouldShowSetupEncryptionToast() {
private shouldShowSetupEncryptionToast(): boolean {
// If we're in the middle of a secret storage operation, we're likely
// modifying the state involved here, so don't add new toasts to setup.
if (isSecretStorageBeingAccessed()) return false;
Expand All @@ -242,7 +243,7 @@ export default class DeviceListener {
return cli && cli.getRooms().some((r) => cli.isRoomEncrypted(r.roomId));
}

private async recheck() {
private async recheck(): Promise<void> {
if (!this.running) return; // we have been stopped
const cli = MatrixClientPeg.get();

Expand Down Expand Up @@ -359,7 +360,7 @@ export default class DeviceListener {
this.displayingToastsForDeviceIds = newUnverifiedDeviceIds;
}

private checkKeyBackupStatus = async () => {
private checkKeyBackupStatus = async (): Promise<void> => {
if (this.keyBackupStatusChecked) {
return;
}
Expand Down Expand Up @@ -388,7 +389,7 @@ export default class DeviceListener {
}
};

private updateClientInformation = async () => {
private updateClientInformation = async (): Promise<void> => {
try {
if (this.shouldRecordClientInformation) {
await recordClientInformation(MatrixClientPeg.get(), SdkConfig.get(), PlatformPeg.get());
Expand Down
Loading

0 comments on commit 0493f81

Please sign in to comment.