Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tab to download csv file of the list of users in a room #613

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/node_modules/matrix-react-sdk/src/components/views/right_panel/RoomSummaryCard.tsx b/node_modules/matrix-react-sdk/src/components/views/right_panel/RoomSummaryCard.tsx
index a32d8da..d3d704f 100644
--- a/node_modules/matrix-react-sdk/src/components/views/right_panel/RoomSummaryCard.tsx
+++ b/node_modules/matrix-react-sdk/src/components/views/right_panel/RoomSummaryCard.tsx
@@ -17,7 +17,12 @@ limitations under the License.
import React, { useCallback, useContext, useEffect, useMemo, useState } from "react";
import classNames from "classnames";
import { Room } from "matrix-js-sdk/src/models/room";
+import { keys } from "lodash"; // :TCHAP:

+// /src/tchap/util/TchapExportFiles.ts
+// /yarn-linked-dependencies/matrix-react-sdk/src/components/views/right_panel/RoomSummaryCard.tsx
+import { generateAndDownloadTextFile } from "../../../../../../src/tchap/util/TchapExportFiles"; // :TCHAP:
+import { useRoomContext } from "../../../contexts/RoomContext";
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import { useIsEncrypted } from "../../../hooks/useIsEncrypted";
import BaseCard, { Group } from "./BaseCard";
@@ -274,6 +279,7 @@ const onRoomSettingsClick = (ev: ButtonEvent): void => {

const RoomSummaryCard: React.FC<IProps> = ({ room, permalinkCreator, onClose }) => {
const cli = useContext(MatrixClientContext);
+ const context = useRoomContext();

const onShareRoomClick = (): void => {
Modal.createDialog(ShareDialog, {
@@ -287,6 +293,21 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, permalinkCreator, onClose })
});
};

+ /* :TCHAP:
+ add a tab to download the list of users in current room
+ so that they can create new rooms with the same users
+ */
+ const onRoomExportMemberEmailsClick = async (): Promise<void> => {
odelcroi marked this conversation as resolved.
Show resolved Hide resolved
+ const members = keys(context?.room?.currentState?.members);
+
+ generateAndDownloadTextFile({
+ fileName: "members",
+ format: "txt",
+ content: members.join(",")
+ });
+ }
+ /* end :TCHAP: */
+
const onRoomPollHistoryClick = (): void => {
Modal.createDialog(PollHistoryDialog, {
room,
@@ -295,6 +316,7 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, permalinkCreator, onClose })
});
};

+
const isRoomEncrypted = useIsEncrypted(cli, room);
const roomContext = useContext(RoomContext);
const e2eStatus = roomContext.e2eStatus;
@@ -357,6 +379,11 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, permalinkCreator, onClose })
{_t("Export chat")}
</Button>
)}
+ {/* :TCHAP: */ !isVideoRoom && (
+ <Button className="mx_RoomSummaryCard_icon_export" onClick={onRoomExportMemberEmailsClick}>
+ {_t("Export room members (txt)")}
+ </Button>
+ ) /* end :TCHAP */}
<Button
data-testid="shareRoomButton"
className="mx_RoomSummaryCard_icon_share"
7 changes: 7 additions & 0 deletions patches/patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,12 @@
"files": [
"src/stores/RoomViewStore.tsx"
]
},
"add-tab-to-download-csv-file-of-the-list-of-users-in-a-room": {
"github-issue": "https://github.com/tchapgouv/tchap-web-v4/issues/593",
"package": "matrix-react-sdk",
"files": [
"src/components/views/right_panel/RoomSummaryCard.tsx"
]
}
}
4 changes: 4 additions & 0 deletions src/tchap/i18n/strings/tchap_translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -934,5 +934,9 @@
"Please only proceed if you're sure you've lost all of your other devices and your Security Key.": {
"fr": "Veuillez ne continuer que si vous êtes certain d’avoir perdu tous vos autres appareils et votre Code de Récupération.",
"en": "Please only proceed if you're sure you've lost all of your other devices and your Recovery Code."
},
"Export room members (txt)": {
"fr": "Exporter les membres du salon (txt)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remplacer (txt) par csv qui est le format des données alors que txt est le format du fichier

"en": "Export room members (txt)"
}
}
22 changes: 22 additions & 0 deletions src/tchap/util/TchapExportFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const generateAndDownloadTextFile = ({
fileName,
format,
content
}: {
fileName: string,
format: "csv" | "txt",
content: string
}) => {
const formats = {
csv: "csv",
txt: "plain",
};
const contentToSend = `data:text/${formats[format]};charset=utf-8,${content}`;
const encodedUri = encodeURI(contentToSend);
const link = document.createElement("a");

link.setAttribute("href", encodedUri);
link.setAttribute("download", `${fileName}.${format}`);
document.body.appendChild(link); // Required for firefox
link.click(); // download the data file named "emails.csv".
}