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

Commit 27d7945

Browse files
authored
Remove dead & duplicated code (#11405)
* Remove dead code * Make dead code happier * DRY pickle additional data calculation * Iterate
1 parent 672ad98 commit 27d7945

25 files changed

+50
-201
lines changed

src/AddThreepid.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,15 @@ export default class AddThreepid {
281281
): Promise<[success?: boolean, result?: IAuthData | Error | null] | undefined> {
282282
const authClient = new IdentityAuthClient();
283283

284-
let result: { success: boolean } | MatrixError;
285284
if (this.submitUrl) {
286-
result = await this.matrixClient.submitMsisdnTokenOtherUrl(
285+
await this.matrixClient.submitMsisdnTokenOtherUrl(
287286
this.submitUrl,
288287
this.sessionId!,
289288
this.clientSecret,
290289
msisdnToken,
291290
);
292291
} else if (this.bind) {
293-
result = await this.matrixClient.submitMsisdnToken(
292+
await this.matrixClient.submitMsisdnToken(
294293
this.sessionId!,
295294
this.clientSecret,
296295
msisdnToken,
@@ -299,9 +298,6 @@ export default class AddThreepid {
299298
} else {
300299
throw new UserFriendlyError("The add / bind with MSISDN flow is misconfigured");
301300
}
302-
if (result instanceof Error) {
303-
throw result;
304-
}
305301

306302
if (this.bind) {
307303
await this.matrixClient.bindThreePid({

src/BasePlatform.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default abstract class BasePlatform {
6767
protected notificationCount = 0;
6868
protected errorDidOccur = false;
6969

70-
public constructor() {
70+
protected constructor() {
7171
dis.register(this.onAction);
7272
this.startUpdateCheck = this.startUpdateCheck.bind(this);
7373
}
@@ -365,14 +365,7 @@ export default abstract class BasePlatform {
365365
return null;
366366
}
367367

368-
const additionalData = new Uint8Array(userId.length + deviceId.length + 1);
369-
for (let i = 0; i < userId.length; i++) {
370-
additionalData[i] = userId.charCodeAt(i);
371-
}
372-
additionalData[userId.length] = 124; // "|"
373-
for (let i = 0; i < deviceId.length; i++) {
374-
additionalData[userId.length + 1 + i] = deviceId.charCodeAt(i);
375-
}
368+
const additionalData = this.getPickleAdditionalData(userId, deviceId);
376369

377370
try {
378371
const key = await crypto.subtle.decrypt(
@@ -387,6 +380,18 @@ export default abstract class BasePlatform {
387380
}
388381
}
389382

383+
private getPickleAdditionalData(userId: string, deviceId: string): Uint8Array {
384+
const additionalData = new Uint8Array(userId.length + deviceId.length + 1);
385+
for (let i = 0; i < userId.length; i++) {
386+
additionalData[i] = userId.charCodeAt(i);
387+
}
388+
additionalData[userId.length] = 124; // "|"
389+
for (let i = 0; i < deviceId.length; i++) {
390+
additionalData[userId.length + 1 + i] = deviceId.charCodeAt(i);
391+
}
392+
return additionalData;
393+
}
394+
390395
/**
391396
* Create and store a pickle key for encrypting libolm objects.
392397
* @param {string} userId the user ID for the user that the pickle key is for.
@@ -408,15 +413,7 @@ export default abstract class BasePlatform {
408413
const iv = new Uint8Array(32);
409414
crypto.getRandomValues(iv);
410415

411-
const additionalData = new Uint8Array(userId.length + deviceId.length + 1);
412-
for (let i = 0; i < userId.length; i++) {
413-
additionalData[i] = userId.charCodeAt(i);
414-
}
415-
additionalData[userId.length] = 124; // "|"
416-
for (let i = 0; i < deviceId.length; i++) {
417-
additionalData[userId.length + 1 + i] = deviceId.charCodeAt(i);
418-
}
419-
416+
const additionalData = this.getPickleAdditionalData(userId, deviceId);
420417
const encrypted = await crypto.subtle.encrypt({ name: "AES-GCM", iv, additionalData }, cryptoKey, randomArray);
421418

422419
try {

src/IdentityAuthClient.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ export default class IdentityAuthClient {
7575
return window.localStorage.getItem("mx_is_access_token");
7676
}
7777

78-
public hasCredentials(): boolean {
79-
return Boolean(this.accessToken);
80-
}
81-
8278
// Returns a promise that resolves to the access_token string from the IS
8379
public async getAccessToken({ check = true } = {}): Promise<string | null> {
8480
if (!this.authEnabled) {

src/LegacyCallHandler.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,6 @@ export default class LegacyCallHandler extends EventEmitter {
429429
return this.calls.get(roomId) || null;
430430
}
431431

432-
public getAnyActiveCall(): MatrixCall | null {
433-
for (const call of this.calls.values()) {
434-
if (call.state !== CallState.Ended) {
435-
return call;
436-
}
437-
}
438-
return null;
439-
}
440-
441432
public getAllActiveCalls(): MatrixCall[] {
442433
const activeCalls: MatrixCall[] = [];
443434

src/PasswordReset.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,41 +47,6 @@ export default class PasswordReset {
4747
this.clientSecret = this.client.generateClientSecret();
4848
}
4949

50-
/**
51-
* Attempt to reset the user's password. This will trigger a side-effect of
52-
* sending an email to the provided email address.
53-
* @param {string} emailAddress The email address
54-
* @param {string} newPassword The new password for the account.
55-
* @param {boolean} logoutDevices Should all devices be signed out after the reset? Defaults to `true`.
56-
* @return {Promise} Resolves when the email has been sent. Then call checkEmailLinkClicked().
57-
*/
58-
public async resetPassword(
59-
emailAddress: string,
60-
newPassword: string,
61-
logoutDevices = true,
62-
): Promise<IRequestTokenResponse> {
63-
this.password = newPassword;
64-
this.logoutDevices = logoutDevices;
65-
this.sendAttempt++;
66-
67-
try {
68-
const result = await this.client.requestPasswordEmailToken(
69-
emailAddress,
70-
this.clientSecret,
71-
this.sendAttempt,
72-
);
73-
this.sessionId = result.sid;
74-
return result;
75-
} catch (err: any) {
76-
if (err.errcode === "M_THREEPID_NOT_FOUND") {
77-
err.message = _t("This email address was not found");
78-
} else if (err.httpStatus) {
79-
err.message = err.message + ` (Status ${err.httpStatus})`;
80-
}
81-
throw err;
82-
}
83-
}
84-
8550
/**
8651
* Request a password reset token.
8752
* This will trigger a side-effect of sending an email to the provided email address.

src/RoomNotifs.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,8 @@ export function determineUnreadState(
256256
return { symbol: null, count: trueCount, color: NotificationColor.Grey };
257257
}
258258

259-
// We don't have any notified messages, but we might have unread messages. Let's
260-
// find out.
261-
let hasUnread = false;
259+
// We don't have any notified messages, but we might have unread messages. Let's find out.
260+
let hasUnread: boolean;
262261
if (threadId) hasUnread = doesRoomOrThreadHaveUnreadMessages(room.getThread(threadId)!);
263262
else hasUnread = doesRoomHaveUnreadMessages(room);
264263

src/ScalarMessaging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ function canSendEvent(event: MessageEvent<any>, roomId: string): void {
679679
}
680680
const me = client.credentials.userId!;
681681

682-
let canSend = false;
682+
let canSend: boolean;
683683
if (isState) {
684684
canSend = room.currentState.maySendStateEvent(evType, me);
685685
} else {

src/components/views/dialogs/FeedbackDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const FeedbackDialog: React.FC<IProps> = (props: IProps) => {
117117
return (
118118
<QuestionDialog
119119
className="mx_FeedbackDialog"
120-
hasCancelButton={!!hasFeedback}
120+
hasCancelButton={hasFeedback}
121121
title={_t("Feedback")}
122122
description={
123123
<React.Fragment>

src/editor/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export default class EditorModel {
461461
*/
462462
public transform(callback: ManualTransformCallback): Promise<void> {
463463
const pos = callback();
464-
let acPromise: Promise<void> | null = null;
464+
let acPromise: Promise<void> | null;
465465
if (!(pos instanceof Range)) {
466466
acPromise = this.setActivePart(pos, true);
467467
} else {

src/indexing/BaseEventIndexManager.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ export default abstract class BaseEventIndexManager {
112112
throw new Error("Unimplemented");
113113
}
114114

115-
/**
116-
* Check if our event index is empty.
117-
*/
118-
public indexIsEmpty(): Promise<boolean> {
119-
throw new Error("Unimplemented");
120-
}
121-
122115
/**
123116
* Check if the room with the given id is already indexed.
124117
*

0 commit comments

Comments
 (0)