Handle requests with no attachments
This commit is contained in:
parent
a1b614f2b3
commit
ab653d9952
3 changed files with 31 additions and 12 deletions
|
@ -86,7 +86,7 @@ export default class RoomHeader extends React.Component {
|
||||||
this.props.room,
|
this.props.room,
|
||||||
exportFormats.HTML,
|
exportFormats.HTML,
|
||||||
exportTypes.START_DATE,
|
exportTypes.START_DATE,
|
||||||
{ startDate: parseInt(new Date("2021.05.20").getTime().toFixed(0)) },
|
{ startDate: parseInt(new Date("2021.05.20").getTime().toFixed(0)), attachmentsIncluded: false },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,10 +72,9 @@ export default class HTMLExporter extends Exporter {
|
||||||
protected async wrapHTML(content: string) {
|
protected async wrapHTML(content: string) {
|
||||||
const roomAvatar = await this.getRoomAvatar();
|
const roomAvatar = await this.getRoomAvatar();
|
||||||
const exportDate = formatFullDateNoDayNoTime(new Date());
|
const exportDate = formatFullDateNoDayNoTime(new Date());
|
||||||
const cli = MatrixClientPeg.get();
|
|
||||||
const creator = this.room.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
|
const creator = this.room.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
|
||||||
const creatorName = this.room?.getMember(creator)?.rawDisplayName || creator;
|
const creatorName = this.room?.getMember(creator)?.rawDisplayName || creator;
|
||||||
const exporter = cli.getUserId();
|
const exporter = this.matrixClient.getUserId();
|
||||||
const exporterName = this.room?.getMember(exporter)?.rawDisplayName;
|
const exporterName = this.room?.getMember(exporter)?.rawDisplayName;
|
||||||
const topic = this.room.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic
|
const topic = this.room.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic
|
||||||
|| this.room.topic || "";
|
|| this.room.topic || "";
|
||||||
|
@ -113,10 +112,8 @@ export default class HTMLExporter extends Exporter {
|
||||||
</p>,
|
</p>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const topicText = topic ? _t("Topic: %(topic)s", { topic }) : "";
|
const topicText = topic ? _t("Topic: %(topic)s", { topic }) : "";
|
||||||
|
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
@ -279,10 +276,10 @@ export default class HTMLExporter extends Exporter {
|
||||||
return fileDirectory + "/" + fileName + '-' + fileDate + fileExt;
|
return fileDirectory + "/" + fileName + '-' + fileDate + fileExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected async getEventTile(mxEv: MatrixEvent, continuation: boolean, filePath?: string) {
|
protected async getEventTile(mxEv: MatrixEvent, continuation: boolean, filePath?: string) {
|
||||||
const hasAvatar = this.hasAvatar(mxEv);
|
const hasAvatar = this.hasAvatar(mxEv);
|
||||||
if (hasAvatar) await this.saveAvatarIfNeeded(mxEv);
|
if (hasAvatar) await this.saveAvatarIfNeeded(mxEv);
|
||||||
|
|
||||||
const eventTile = <div className="mx_Export_EventWrapper" id={mxEv.getId()}>
|
const eventTile = <div className="mx_Export_EventWrapper" id={mxEv.getId()}>
|
||||||
<MatrixClientContext.Provider value = {this.matrixClient}>
|
<MatrixClientContext.Provider value = {this.matrixClient}>
|
||||||
<EventTile
|
<EventTile
|
||||||
|
@ -317,15 +314,36 @@ export default class HTMLExporter extends Exporter {
|
||||||
return eventTileMarkup;
|
return eventTileMarkup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected isAttachment(mxEv: MatrixEvent) {
|
||||||
|
const attachmentTypes = ["m.sticker", "m.image", "m.file", "m.video", "m.audio"];
|
||||||
|
return mxEv.getType() === attachmentTypes[0] || attachmentTypes.includes(mxEv.getContent().msgtype);
|
||||||
|
}
|
||||||
|
|
||||||
protected async createMessageBody(mxEv: MatrixEvent, joined = false) {
|
protected async createMessageBody(mxEv: MatrixEvent, joined = false) {
|
||||||
let eventTile: string;
|
let eventTile: string;
|
||||||
const attachmentTypes = ["m.sticker", "m.image", "m.file", "m.video", "m.audio"]
|
|
||||||
|
|
||||||
if (mxEv.getType() === attachmentTypes[0] || attachmentTypes.includes(mxEv.getContent().msgtype)) {
|
if (this.isAttachment(mxEv)) {
|
||||||
|
if (this.exportOptions.attachmentsIncluded) {
|
||||||
const blob = await this.getMediaBlob(mxEv);
|
const blob = await this.getMediaBlob(mxEv);
|
||||||
const filePath = this.getFilePath(mxEv);
|
const filePath = this.getFilePath(mxEv);
|
||||||
eventTile = await this.getEventTile(mxEv, joined, filePath);
|
eventTile = await this.getEventTile(mxEv, joined, filePath);
|
||||||
this.zip.file(filePath, blob);
|
this.zip.file(filePath, blob);
|
||||||
|
} else {
|
||||||
|
const modifiedContent = {
|
||||||
|
msgtype: "m.text",
|
||||||
|
body: "**Media omitted**",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: "<strong>Media omitted</strong>",
|
||||||
|
}
|
||||||
|
if (mxEv.isEncrypted()) {
|
||||||
|
mxEv._clearEvent.content = modifiedContent;
|
||||||
|
mxEv._clearEvent.type = "m.room.message";
|
||||||
|
} else {
|
||||||
|
mxEv.event.content = modifiedContent;
|
||||||
|
mxEv.event.type = "m.room.message";
|
||||||
|
}
|
||||||
|
eventTile = await this.getEventTile(mxEv, joined);
|
||||||
|
}
|
||||||
} else eventTile = await this.getEventTile(mxEv, joined);
|
} else eventTile = await this.getEventTile(mxEv, joined);
|
||||||
|
|
||||||
return eventTile;
|
return eventTile;
|
||||||
|
|
|
@ -17,6 +17,7 @@ export enum exportTypes {
|
||||||
export interface exportOptions {
|
export interface exportOptions {
|
||||||
startDate?: number;
|
startDate?: number;
|
||||||
numberOfMessages?: number;
|
numberOfMessages?: number;
|
||||||
|
attachmentsIncluded: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportConversationalHistory = async (
|
const exportConversationalHistory = async (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue