Switch completely to TypeScript, updated userColors
This commit is contained in:
parent
e3b0d89ae9
commit
3147acec0c
4 changed files with 33 additions and 23 deletions
|
@ -54,6 +54,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.12.5",
|
"@babel/runtime": "^7.12.5",
|
||||||
|
"@types/streamsaver": "^2.0.0",
|
||||||
"await-lock": "^2.1.0",
|
"await-lock": "^2.1.0",
|
||||||
"blueimp-canvas-to-blob": "^3.28.0",
|
"blueimp-canvas-to-blob": "^3.28.0",
|
||||||
"browser-encrypt-attachment": "^0.3.0",
|
"browser-encrypt-attachment": "^0.3.0",
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import streamSaver from "streamsaver";
|
import streamSaver from "streamsaver";
|
||||||
import JSZip from "jszip";
|
import JSZip from "jszip";
|
||||||
import { decryptFile } from "../DecryptFile";
|
import { decryptFile } from "../DecryptFile";
|
||||||
|
@ -237,16 +236,18 @@ div.mx_selected {
|
||||||
|
|
||||||
|
|
||||||
const userColors = [
|
const userColors = [
|
||||||
"#64bf47",
|
"#368bd6",
|
||||||
"#4f9cd9",
|
"#ac3ba8",
|
||||||
"#9884e8",
|
"#03b381",
|
||||||
"#fb6238",
|
"#e64f7a",
|
||||||
"#00cdac",
|
"#ff812d",
|
||||||
"#ff5eaa",
|
"#2dc2c5",
|
||||||
|
"#5c56f5",
|
||||||
|
"#74d12c",
|
||||||
];
|
];
|
||||||
|
|
||||||
//Get a color associated with string length. This is to map userId to a specific color
|
//Get a color associated with string length. This is to map userId to a specific color
|
||||||
const getUserColor = (userId: string) => {
|
const getUserNameColorClass = (userId: string) => {
|
||||||
return userColors[userId.length % userColors.length];
|
return userColors[userId.length % userColors.length];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -256,7 +257,10 @@ const getUserPic = async (event: MatrixEvent) => {
|
||||||
if (!member.getMxcAvatarUrl()) {
|
if (!member.getMxcAvatarUrl()) {
|
||||||
return `
|
return `
|
||||||
<div class="mx_pull_left mx_userpic_wrap">
|
<div class="mx_pull_left mx_userpic_wrap">
|
||||||
<div class="mx_userpic" style="width: 42px;height: 42px;background-color: ${getUserColor(member.userId)}">
|
<div
|
||||||
|
class="mx_userpic"
|
||||||
|
style="width: 42px;height: 42px;background-color: ${getUserNameColorClass(member.userId)}"
|
||||||
|
>
|
||||||
<div class="mx_initials" style="line-height: 42px;" src="users/${member.userId}">
|
<div class="mx_initials" style="line-height: 42px;" src="users/${member.userId}">
|
||||||
${event.sender.name[0]}
|
${event.sender.name[0]}
|
||||||
</div>
|
</div>
|
||||||
|
@ -369,7 +373,7 @@ const createMessageBody = async (event: MatrixEvent, joined = false, isReply = f
|
||||||
${new Date(event.getTs()).toLocaleTimeString().slice(0, -3)}
|
${new Date(event.getTs()).toLocaleTimeString().slice(0, -3)}
|
||||||
</div>
|
</div>
|
||||||
${!joined ? `
|
${!joined ? `
|
||||||
<div class="mx_from_name" style="color:${getUserColor(event.sender.name)}">
|
<div class="mx_from_name" style="color:${getUserNameColorClass(event.sender.name)}">
|
||||||
${event.sender.name}
|
${event.sender.name}
|
||||||
</div>`: ``}
|
</div>`: ``}
|
||||||
${isReply ?
|
${isReply ?
|
||||||
|
@ -414,7 +418,7 @@ const createHTML = async (events: MatrixEvent[], room: Room) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const avatars = new Map();
|
const avatars = new Map();
|
||||||
let zip: any;
|
let zip: JSZip;
|
||||||
|
|
||||||
const exportAsHTML = async (res: MatrixEvent[], room: Room) => {
|
const exportAsHTML = async (res: MatrixEvent[], room: Room) => {
|
||||||
zip = new JSZip();
|
zip = new JSZip();
|
||||||
|
@ -432,7 +436,7 @@ const exportAsHTML = async (res: MatrixEvent[], room: Room) => {
|
||||||
const blob = await zip.generateAsync({ type: "blob" });
|
const blob = await zip.generateAsync({ type: "blob" });
|
||||||
|
|
||||||
//Create a writable stream to the directory
|
//Create a writable stream to the directory
|
||||||
const fileStream = streamSaver.createWriteStream(filename, blob.size);
|
const fileStream = streamSaver.createWriteStream(filename, { size: blob.size });
|
||||||
const writer = fileStream.getWriter();
|
const writer = fileStream.getWriter();
|
||||||
|
|
||||||
// Here we chunk the blob into pieces of 10 MB, the size might be dynamically generated.
|
// Here we chunk the blob into pieces of 10 MB, the size might be dynamically generated.
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||||
import { arrayFastClone } from "../arrays";
|
import { arrayFastClone } from "../arrays";
|
||||||
import { TimelineWindow } from "matrix-js-sdk/src/timeline-window";
|
import { TimelineWindow } from "matrix-js-sdk/src/timeline-window";
|
||||||
|
import Room from 'matrix-js-sdk/src/models/room';
|
||||||
import exportAsHTML from "./HtmlExport";
|
import exportAsHTML from "./HtmlExport";
|
||||||
|
|
||||||
export const exportFormats = Object.freeze({
|
export enum exportFormats {
|
||||||
"HTML": "HTML",
|
HTML = "HTML",
|
||||||
"JSON": "JSON",
|
JSON = "JSON",
|
||||||
"LOGS": "LOGS",
|
LOGS = "LOGS",
|
||||||
});
|
}
|
||||||
|
|
||||||
export const exportOptions = Object.freeze({
|
export enum exportOptions {
|
||||||
"TIMELINE": "TIMELINE",
|
TIMELINE = "TIMELINE",
|
||||||
});
|
}
|
||||||
|
|
||||||
const getTimelineConversation = (room) => {
|
const getTimelineConversation = (room: Room) => {
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
|
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
|
@ -35,12 +36,11 @@ const getTimelineConversation = (room) => {
|
||||||
cli.decryptEventIfNeeded(event);
|
cli.decryptEventIfNeeded(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(events);
|
|
||||||
return events;
|
return events;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const exportConversationalHistory = async (room, format, options) => {
|
const exportConversationalHistory = async (room: Room, format: string, options) => {
|
||||||
const res = getTimelineConversation(room);
|
const res = getTimelineConversation(room);
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case exportFormats.HTML:
|
case exportFormats.HTML:
|
|
@ -1655,6 +1655,11 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff"
|
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff"
|
||||||
integrity sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==
|
integrity sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==
|
||||||
|
|
||||||
|
"@types/streamsaver@^2.0.0":
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/streamsaver/-/streamsaver-2.0.0.tgz#2a6bdec0389f41a74c60091d37e84f8840d27ac9"
|
||||||
|
integrity sha512-TzUEZk30QmNaS6GAhcOnH/Cl2mO7HCFhQUr6GpzvuoFziFCxmvuyLftHW79agJpZvIrqti9jSiDHMgflUwbejg==
|
||||||
|
|
||||||
"@types/unist@*", "@types/unist@^2.0.0", "@types/unist@^2.0.2":
|
"@types/unist@*", "@types/unist@^2.0.0", "@types/unist@^2.0.2":
|
||||||
version "2.0.3"
|
version "2.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
|
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
|
||||||
|
|
Loading…
Reference in a new issue