Apply suggestions from code review

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Jaiwanth 2021-08-13 08:59:28 +05:30 committed by GitHub
parent e88edba650
commit 00d5a0baa4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 13 deletions

View file

@ -167,7 +167,7 @@ function textForTopicEvent(ev: MatrixEvent): () => string | null {
} }
function textForRoomAvatarEvent(ev: MatrixEvent): () => string | null { function textForRoomAvatarEvent(ev: MatrixEvent): () => string | null {
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); const senderDisplayName = ev?.sender?.name || ev.getSender();
return () => _t('%(senderDisplayName)s changed the room avatar.', { senderDisplayName }); return () => _t('%(senderDisplayName)s changed the room avatar.', { senderDisplayName });
} }
@ -298,11 +298,12 @@ function textForMessageEvent(ev: MatrixEvent): () => string | null {
if (ev.isRedacted()) { if (ev.isRedacted()) {
message = _t("Message deleted"); message = _t("Message deleted");
const unsigned = ev.getUnsigned(); const unsigned = ev.getUnsigned();
const redactedBecauseUserId = unsigned && unsigned.redacted_because && unsigned.redacted_because.sender; const redactedBecauseUserId = unsigned?.redacted_because?.sender;
if (redactedBecauseUserId && redactedBecauseUserId !== ev.getSender()) { if (redactedBecauseUserId && redactedBecauseUserId !== ev.getSender()) {
const room = MatrixClientPeg.get().getRoom(ev.getRoomId()); const room = MatrixClientPeg.get().getRoom(ev.getRoomId());
const sender = room && room.getMember(redactedBecauseUserId); const sender = room?.getMember(redactedBecauseUserId);
message = _t("Message deleted by %(name)s", { name: sender ? sender.name : redactedBecauseUserId }); message = _t("Message deleted by %(name)s", { name: sender?.name
|| redactedBecauseUserId });
} }
} }
if (ev.getContent().msgtype === "m.emote") { if (ev.getContent().msgtype === "m.emote") {

View file

@ -428,7 +428,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
// Overidden by MStickerBody // Overidden by MStickerBody
protected wrapImage(contentUrl: string, children: JSX.Element): JSX.Element { protected wrapImage(contentUrl: string, children: JSX.Element): JSX.Element {
return <a href={contentUrl} target={this.props.forExport ? "__blank" : undefined} onClick={this.onClick}> return <a href={contentUrl} target={this.props.forExport ? "_blank" : undefined} onClick={this.onClick}>
{ children } { children }
</a>; </a>;
} }

View file

@ -32,9 +32,9 @@ type BlobFile = {
}; };
export default abstract class Exporter { export default abstract class Exporter {
protected files: BlobFile[]; protected files: BlobFile[] = [];
protected client: MatrixClient; protected client: MatrixClient;
protected cancelled: boolean; protected cancelled = false;
protected constructor( protected constructor(
protected room: Room, protected room: Room,
@ -47,8 +47,6 @@ export default abstract class Exporter {
exportOptions.numberOfMessages > 10**8) { exportOptions.numberOfMessages > 10**8) {
throw new Error("Invalid export options"); throw new Error("Invalid export options");
} }
this.cancelled = false;
this.files = [];
this.client = MatrixClientPeg.get(); this.client = MatrixClientPeg.get();
window.addEventListener("beforeunload", this.onBeforeUnload); window.addEventListener("beforeunload", this.onBeforeUnload);
} }
@ -71,7 +69,7 @@ export default abstract class Exporter {
this.files.push(file); this.files.push(file);
} }
protected async downloadZIP(): Promise<any> { protected async downloadZIP(): Promise<void> {
const filename = `matrix-export-${formatFullDateNoDay(new Date())}.zip`; const filename = `matrix-export-${formatFullDateNoDay(new Date())}.zip`;
const zip = new JSZip(); const zip = new JSZip();
@ -257,5 +255,5 @@ export default abstract class Exporter {
return mxEv.getType() === attachmentTypes[0] || attachmentTypes.includes(mxEv.getContent().msgtype); return mxEv.getType() === attachmentTypes[0] || attachmentTypes.includes(mxEv.getContent().msgtype);
} }
abstract export(): Promise<any>; abstract export(): Promise<void>;
} }

View file

@ -29,7 +29,7 @@ export enum ExportTypes {
// START_DATE = "START_DATE", // START_DATE = "START_DATE",
} }
export const textForFormat = (format: string): string => { export const textForFormat = (format: ExportFormat): string => {
switch (format) { switch (format) {
case ExportFormats.HTML: case ExportFormats.HTML:
return _t("HTML"); return _t("HTML");
@ -42,7 +42,7 @@ export const textForFormat = (format: string): string => {
} }
}; };
export const textForType = (type: string): string => { export const textForType = (type: ExportType): string => {
switch (type) { switch (type) {
case ExportTypes.BEGINNING: case ExportTypes.BEGINNING:
return _t("From the beginning"); return _t("From the beginning");