Skip to content

Commit 619e41e

Browse files
committed
Remove usages of Buffer
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 974d3c1 commit 619e41e

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ module.exports = {
4242
name: "setImmediate",
4343
message: "Use setTimeout instead.",
4444
},
45+
{
46+
name: "Buffer",
47+
message: "Buffer is not available in the web.",
48+
},
4549
],
4650

4751
"import/no-duplicates": ["error"],
@@ -255,6 +259,9 @@ module.exports = {
255259
additionalTestBlockFunctions: ["beforeAll", "beforeEach", "oldBackendOnly"],
256260
},
257261
],
262+
263+
// These are fine in tests
264+
"no-restricted-globals": "off",
258265
},
259266
},
260267
{

src/@types/png-chunks-extract.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare module "png-chunks-extract" {
1212
data: Uint8Array;
1313
}
1414

15-
function extractPngChunks(data: Uint8Array | Buffer): IChunk[];
15+
function extractPngChunks(data: Uint8Array): IChunk[];
1616

1717
export default extractPngChunks;
1818
}

src/components/views/auth/LoginWithQR.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ interface IState {
3737
userCode?: string;
3838
checkCode?: string;
3939
failureReason?: FailureReason;
40-
lastScannedCode?: Buffer;
4140
}
4241

4342
export enum LoginWithQRFailureReason {
@@ -154,7 +153,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
154153
throw new Error("Rendezvous not found");
155154
}
156155

157-
if (!this.state.lastScannedCode && this.state.rendezvous?.checkCode !== checkCode) {
156+
if (this.state.rendezvous?.checkCode !== checkCode) {
158157
this.setState({ failureReason: LoginWithQRFailureReason.CheckCodeMismatch });
159158
return;
160159
}
@@ -201,7 +200,6 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
201200
failureReason: undefined,
202201
userCode: undefined,
203202
checkCode: undefined,
204-
lastScannedCode: undefined,
205203
mediaPermissionError: false,
206204
});
207205
}

src/stores/ThreepidInviteStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default class ThreepidInviteStore extends EventEmitter {
9999

100100
private generateIdOf(persisted: IPersistedThreepidInvite): string {
101101
// Use a consistent "hash" to form an ID.
102-
return base32.stringify(Buffer.from(JSON.stringify(persisted)));
102+
return base32.stringify(new TextEncoder().encode(JSON.stringify(persisted)));
103103
}
104104

105105
private translateInvite(persisted: IPersistedThreepidInvite): IThreepidInvite {

src/utils/WidgetUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export default class WidgetUtils {
445445
// For compatibility with Jitsi, use base32 without padding.
446446
// More details here:
447447
// https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification
448-
confId = base32.stringify(Buffer.from(roomId), { pad: false });
448+
confId = base32.stringify(new TextEncoder().encode(roomId), { pad: false });
449449
} else {
450450
// Create a random conference ID
451451
confId = `Jitsi${randomUppercaseString(1)}${randomLowercaseString(23)}`;

src/utils/exportUtils/HtmlExport.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ export default class HTMLExporter extends Exporter {
431431
!this.needsDateSeparator(event, prevEvent) &&
432432
shouldFormContinuation(prevEvent, event, this.room.client, false);
433433
const body = await this.createMessageBody(event, shouldBeJoined);
434-
this.totalSize += Buffer.byteLength(body);
434+
this.totalSize += new TextEncoder().encode(body).byteLength;
435435
content += body;
436436
prevEvent = event;
437437
}

0 commit comments

Comments
 (0)