From c3dc51c4526eeb0c78b3c46bd59b4392781f74c1 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Sat, 26 Jun 2021 12:14:18 +0530 Subject: [PATCH] Create export dialog and async import export utils --- src/components/views/dialogs/ExportDialog.tsx | 56 +++++++++++++++++++ .../views/right_panel/RoomSummaryCard.tsx | 9 ++- src/components/views/rooms/RoomHeader.js | 21 ------- src/i18n/strings/en_EN.json | 4 +- 4 files changed, 66 insertions(+), 24 deletions(-) create mode 100644 src/components/views/dialogs/ExportDialog.tsx diff --git a/src/components/views/dialogs/ExportDialog.tsx b/src/components/views/dialogs/ExportDialog.tsx new file mode 100644 index 0000000000..22223848ea --- /dev/null +++ b/src/components/views/dialogs/ExportDialog.tsx @@ -0,0 +1,56 @@ +import React from 'react'; +import { Room } from 'matrix-js-sdk/src'; +import { _t } from '../../../languageHandler'; +import { IDialogProps } from './IDialogProps'; +import BaseDialog from "./BaseDialog" +import DialogButtons from "../elements/DialogButtons"; + +interface IProps extends IDialogProps{ + room: Room; +} + +export default class ExportDialog extends React.PureComponent { + onExportClick = async () => { + const { + default: exportConversationalHistory, + exportFormats, + exportTypes, + } = await import("../../../utils/exportUtils/exportUtils"); + + await exportConversationalHistory( + this.props.room, + exportFormats.PLAIN_TEXT, + exportTypes.START_DATE, + { + startDate: parseInt(new Date("2021.05.20").getTime().toFixed(0)), + attachmentsIncluded: true, + maxSize: 7 * 1024 * 1024, // 7 MB + }, + ); + }; + + onCancel = () => { + this.props.onFinished(false); + }; + + render() { + return ( + +
+ Export +
+ +
+ ); + } +} diff --git a/src/components/views/right_panel/RoomSummaryCard.tsx b/src/components/views/right_panel/RoomSummaryCard.tsx index 28996305c7..0cc5bf8e7f 100644 --- a/src/components/views/right_panel/RoomSummaryCard.tsx +++ b/src/components/views/right_panel/RoomSummaryCard.tsx @@ -47,6 +47,7 @@ import {useRoomMemberCount} from "../../../hooks/useRoomMembers"; import { Container, MAX_PINNED, WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore"; import RoomName from "../elements/RoomName"; import UIStore from "../../../stores/UIStore"; +import ExportDialog from "../dialogs/ExportDialog"; interface IProps { room: Room; @@ -233,6 +234,12 @@ const RoomSummaryCard: React.FC = ({ room, onClose }) => { }); }; + const onRoomExportClick = () => { + Modal.createTrackedDialog('export room dialog', '', ExportDialog, { + room, + }); + }; + const isRoomEncrypted = useIsEncrypted(cli, room); const roomContext = useContext(RoomContext); const e2eStatus = roomContext.e2eStatus; @@ -279,7 +286,7 @@ const RoomSummaryCard: React.FC = ({ room, onClose }) => { - diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index d977b6d87b..0e1a7bc60b 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -31,7 +31,6 @@ import RoomTopic from "../elements/RoomTopic"; import RoomName from "../elements/RoomName"; import { PlaceCallType } from "../../../CallHandler"; import { replaceableComponent } from "../../../utils/replaceableComponent"; -import exportConversationalHistory, { exportTypes, exportFormats } from '../../../utils/exportUtils/exportUtils'; @replaceableComponent("views.rooms.RoomHeader") @@ -80,20 +79,6 @@ export default class RoomHeader extends React.Component { this.forceUpdate(); }, 500); - - _exportConversationalHistory = async () => { - await exportConversationalHistory( - this.props.room, - exportFormats.PLAIN_TEXT, - exportTypes.START_DATE, - { - startDate: parseInt(new Date("2021.05.20").getTime().toFixed(0)), - attachmentsIncluded: true, - maxSize: 7 * 1024 * 1024, // 7 MB - }, - ); - } - render() { let searchStatus = null; @@ -197,14 +182,8 @@ export default class RoomHeader extends React.Component { title={_t("Video call")} />; } - const exportButton = ; - const rightRow =
- { exportButton } { videoCallButton } { voiceCallButton } { forgetButton } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 189c686815..00212fa137 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1593,7 +1593,6 @@ "Search": "Search", "Voice call": "Voice call", "Video call": "Video call", - "Export conversation": "Export conversation", "Start a Conversation": "Start a Conversation", "Open dial pad": "Open dial pad", "Invites": "Invites", @@ -2250,6 +2249,8 @@ "There was an error updating your community. The server is unable to process your request.": "There was an error updating your community. The server is unable to process your request.", "Update community": "Update community", "An error has occurred.": "An error has occurred.", + "Export Chat": "Export Chat", + "Export": "Export", "Feedback sent": "Feedback sent", "Rate %(brand)s": "Rate %(brand)s", "Tell us below how you feel about %(brand)s so far.": "Tell us below how you feel about %(brand)s so far.", @@ -2978,7 +2979,6 @@ "The exported file will allow anyone who can read it to decrypt any encrypted messages that you can see, so you should be careful to keep it secure. To help with this, you should enter a passphrase below, which will be used to encrypt the exported data. It will only be possible to import the data by using the same passphrase.": "The exported file will allow anyone who can read it to decrypt any encrypted messages that you can see, so you should be careful to keep it secure. To help with this, you should enter a passphrase below, which will be used to encrypt the exported data. It will only be possible to import the data by using the same passphrase.", "Enter passphrase": "Enter passphrase", "Confirm passphrase": "Confirm passphrase", - "Export": "Export", "Import room keys": "Import room keys", "This process allows you to import encryption keys that you had previously exported from another Matrix client. You will then be able to decrypt any messages that the other client could decrypt.": "This process allows you to import encryption keys that you had previously exported from another Matrix client. You will then be able to decrypt any messages that the other client could decrypt.", "The export file will be protected with a passphrase. You should enter the passphrase here, to decrypt the file.": "The export file will be protected with a passphrase. You should enter the passphrase here, to decrypt the file.",